@stll/docx-core 0.46.0 → 0.47.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.
Binary file
@@ -2034,11 +2034,10 @@ type PendingSuggestionProjectionOptions = {
2034
2034
  * comment a suggestion proposes is left out with it.
2035
2035
  */
2036
2036
  export declare const withoutPendingSuggestions: (document: Document, { commentIds, onAbsorptions }?: PendingSuggestionProjectionOptions) => Result<Document, DocumentOpRefusal>;
2037
- /**
2038
- * The revisions of one pending suggestion in a story, one info per revision
2039
- * id, in document order.
2040
- */
2037
+ /** Revisions of one pending suggestion, one info per ID in document order. */
2041
2038
  export declare const suggestionRevisionInfos: (document: Document, story: OpStory, suggestionId: string) => TrackedChangeInfo[];
2039
+ /** The first proposal owning each physical revision ID in this story. */
2040
+ export declare const suggestionOwnersInStory: (document: Document, story: OpStory) => ReadonlyMap<number, string>;
2042
2041
  /**
2043
2042
  * The ids of every pending suggestion in a document, in every story, and of
2044
2043
  * every suggestion that proposes a comment.
@@ -2269,6 +2268,22 @@ type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
2269
2268
  paragraphs: readonly Paragraph[];
2270
2269
  openStart: 0 | 1;
2271
2270
  openEnd: 0 | 1;
2271
+ } | {
2272
+ /**
2273
+ * Blocks, tables among them, dragged from a range to a target. The
2274
+ * tables standing wholly between `from` and `to` are removed, or in
2275
+ * suggesting mode recorded as deleted, the text of the range is
2276
+ * deleted as `moveFragment` deletes it, and the blocks go in at the
2277
+ * target as `pasteBlocks` places them, a suggestion recording them as
2278
+ * inserted. Without a table it is `moveFragment`.
2279
+ */
2280
+ type: "moveBlocks";
2281
+ from: TextPosition;
2282
+ to: TextPosition;
2283
+ target: TextPosition;
2284
+ blocks: readonly (Paragraph | Table)[];
2285
+ openStart: 0 | 1;
2286
+ openEnd: 0 | 1;
2272
2287
  } | {
2273
2288
  type: "replaceText";
2274
2289
  from: TextPosition;
@@ -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 WeakMap();
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.length === 0 ? NO_KEYS : Object.freeze([...census.keys]);
388
- let byContext = known.get(value);
389
- if (byContext === void 0) {
390
- byContext = /* @__PURE__ */ new Map();
391
- known.set(value, byContext);
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
- byContext.set(key, keys);
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(value)?.get(key);
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
@@ -14320,9 +14320,65 @@ const withMergesEnded = (table, rowIndex) => {
14320
14320
  cells
14321
14321
  };
14322
14322
  };
14323
+ const BOUNDARIES = rangeBoundaryDefinitions();
14324
+ /** Every range boundary in `value`, at any depth, in source order. */
14325
+ const boundariesIn = (value, out = []) => {
14326
+ if (typeof value !== "object" || value === null) return out;
14327
+ const type = Reflect.get(value, "type");
14328
+ if (typeof type === "string" && Object.hasOwn(BOUNDARIES, type)) out.push(value);
14329
+ else for (const field of Object.values(value)) boundariesIn(field, out);
14330
+ return out;
14331
+ };
14332
+ /**
14333
+ * The range boundaries in `removed`, other than those `kept` still holds,
14334
+ * whose other end stands outside it. Removed content takes its words, not
14335
+ * the end of a range reaching past it: these ends stay where it was. A range
14336
+ * wholly inside goes with it.
14337
+ */
14338
+ const rangeEndsReachingPast = (removed, kept) => {
14339
+ const keeps = new Set(boundariesIn(kept));
14340
+ const key = (node) => `${BOUNDARIES[node.type].family}:${node.id}`;
14341
+ const lost = boundariesIn(removed).filter((node) => !keeps.has(node));
14342
+ return lost.filter((node) => lost.filter((other) => key(other) === key(node)).length === 1);
14343
+ };
14344
+ /**
14345
+ * `rows` with the ends of ranges reaching past the removed row
14346
+ * ({@link rangeEndsReachingPast}) where the row was: at the start of the row
14347
+ * after it, else at the end of the row before. With no row left the table
14348
+ * goes, and its removal keeps them.
14349
+ */
14350
+ const withRangeEndsKept = (removed, rows, rowIndex) => {
14351
+ const ends = rangeEndsReachingPast(removed, rows[rowIndex]);
14352
+ const after = rowIndex < rows.length;
14353
+ const at = after ? rowIndex : rowIndex - 1;
14354
+ const row = rows[at];
14355
+ const cellAt = after ? 0 : (row?.cells.length ?? 0) - 1;
14356
+ const cell = row?.cells[cellAt];
14357
+ if (ends.length === 0 || row === void 0 || cell === void 0) return rows;
14358
+ const content = [...cell.content];
14359
+ const index = after ? content.findIndex((block) => block.type === "paragraph") : content.findLastIndex((block) => block.type === "paragraph");
14360
+ const paragraph = content[index];
14361
+ if (paragraph?.type !== "paragraph") return rows;
14362
+ content[index] = {
14363
+ ...paragraph,
14364
+ content: after ? [...ends, ...paragraph.content] : [...paragraph.content, ...ends]
14365
+ };
14366
+ const cells = [...row.cells];
14367
+ cells[cellAt] = {
14368
+ ...cell,
14369
+ content
14370
+ };
14371
+ const out = [...rows];
14372
+ out[at] = {
14373
+ ...row,
14374
+ cells
14375
+ };
14376
+ return out;
14377
+ };
14323
14378
  /**
14324
14379
  * The table's rows without row `rowIndex`: the merges it starts handed on,
14325
- * and those it alone continues ended.
14380
+ * those it alone continues ended, and the ends of ranges reaching past it
14381
+ * kept.
14326
14382
  */
14327
14383
  const rowsWithoutRow = (table, rowIndex) => {
14328
14384
  const rows = [...table.rows];
@@ -14331,7 +14387,8 @@ const rowsWithoutRow = (table, rowIndex) => {
14331
14387
  const next = withMergesHandedOn(table, rowIndex);
14332
14388
  if (next === void 0) rows.splice(rowIndex, 1);
14333
14389
  else rows.splice(rowIndex, 2, next);
14334
- return rows;
14390
+ const removed = table.rows[rowIndex];
14391
+ return removed === void 0 ? rows : withRangeEndsKept(removed, rows, rowIndex);
14335
14392
  };
14336
14393
  /**
14337
14394
  * Whether taking rows out left a vertical merge without the cell that starts
@@ -16288,7 +16345,7 @@ const withRejoinedBlockers = ({ nodes, retired, resolution }) => {
16288
16345
  }
16289
16346
  }
16290
16347
  if (children === void 0) next = withKeptCutHoldersRenamed(next, successor);
16291
- if (next !== node) carryResolutionState(resolution, node, next);
16348
+ if (next !== node && resolution !== void 0) carryResolutionState(resolution, node, next);
16292
16349
  return next;
16293
16350
  };
16294
16351
  return nodes.map(rewrite);
@@ -16363,7 +16420,11 @@ const cutReach = ({ before, after, depth, spanning, resolution }) => {
16363
16420
  const node = chains[side][index];
16364
16421
  if (node === void 0 || !isTrackedWrapper(node) || !resolution.ids.has(node.info.id) || !removesContent(node, resolution.decision)) return false;
16365
16422
  const chain = edgeChainPastRemoved(chains[side], index, side === "before" ? "end" : "start");
16366
- if (chain === void 0) return false;
16423
+ if (chain === void 0) {
16424
+ const parent = chains[side][index - 1];
16425
+ if (parent !== void 0 && childNodes(parent)?.length === 1) reach.gone = true;
16426
+ return false;
16427
+ }
16367
16428
  chains[side] = chain;
16368
16429
  return true;
16369
16430
  };
@@ -17852,6 +17913,14 @@ const resolveList = ({ nodes: listed, resolution, path }) => {
17852
17913
  if (inner.edges.first !== void 0) edges.first = inner.edges.first + 1;
17853
17914
  if (inner.edges.last !== void 0) edges.last = inner.edges.last + 1;
17854
17915
  resolution.cutEdges.set(rebuilt, edges);
17916
+ if ((rebuilt.type === "deletion" || rebuilt.type === "moveFrom") && rebuilt.resolutionJoins !== void 0) {
17917
+ const joins = rebuilt.resolutionJoins;
17918
+ rebuilt = Object.assign({}, rebuilt, { resolutionJoins: Object.assign({}, joins, {
17919
+ before: Math.max(joins.before, inner.edges.first ?? 0),
17920
+ after: Math.max(joins.after, inner.edges.last ?? 0)
17921
+ }) });
17922
+ resolution.cutEdges.set(rebuilt, edges);
17923
+ }
17855
17924
  }
17856
17925
  appendSource(rebuilt, index);
17857
17926
  }
@@ -19033,7 +19102,10 @@ const joinOps = (document, { op, story, paraId, revisionId, added, depth, holder
19033
19102
  })) rejoined.set(id, into);
19034
19103
  const keepsFirst = paragraph.pPrMark?.survivor === "first";
19035
19104
  ends.set(keepsFirst ? idKey(paraId) : nextId, emptiedEndsOf(merged, emptied));
19036
- const mergedContent = asParagraphContent(merged);
19105
+ const mergedContent = asParagraphContent(withRejoinedBlockers({
19106
+ nodes: merged,
19107
+ retired: rejoined
19108
+ }));
19037
19109
  let survivor;
19038
19110
  if (keepsFirst) survivor = joinedKeepingFirst(paragraph, next, mergedContent);
19039
19111
  else if (structurallyEqual(mergedContent, next.content)) survivor = next;
@@ -19906,7 +19978,7 @@ const planSingleRecordResolution = ({ document, op, applyOps }, paragraphs) => {
19906
19978
  const key = idKey(candidate.paraId ?? "");
19907
19979
  const firstCut = resolvedCutEdges.get(key)?.first ?? 0;
19908
19980
  const mark = candidate.pPrMark;
19909
- if ((resolvedContents.get(key)?.length ?? 0) !== 0 || mark === void 0 || !markWasAdded(mark.kind)) {
19981
+ if (!(resolvedContents.get(key) ?? []).every(isKeptBoundaryCarrier) || mark === void 0 || !markWasAdded(mark.kind)) {
19910
19982
  suffix = {
19911
19983
  leadingCut: firstCut,
19912
19984
  chainCut: 0
@@ -20478,9 +20550,9 @@ const tableEditBoundaryRefusal = (op) => {
20478
20550
  // src/ops/tableEditDependencies.ts
20479
20551
  /**
20480
20552
  * Records a removed column cell cannot take with it: comments and moves pair
20481
- * with records outside the cell, and captured markup is opaque. Bookmark
20482
- * boundaries, content controls and the review records of the cell's own
20483
- * words go with the cell, as they go with a removed row.
20553
+ * with records outside the cell, and captured markup is opaque. Bookmarks
20554
+ * wholly in the cell, content controls and the review records of the cell's
20555
+ * own words go with the cell.
20484
20556
  */
20485
20557
  const REACHING_TYPES = /* @__PURE__ */ new Set([
20486
20558
  "commentRangeStart",
@@ -21278,8 +21350,17 @@ const applyTableOp = (document, op) => {
21278
21350
  message: "Removing a table requires a surviving paragraph in its block list."
21279
21351
  });
21280
21352
  const blocks = [...blockListAt(body.content, location.list)];
21281
- if (op.revision === void 0) blocks.splice(location.index, 1);
21282
- else {
21353
+ if (op.revision === void 0) {
21354
+ blocks.splice(location.index, 1);
21355
+ const ends = rangeEndsReachingPast(location.table);
21356
+ const before = blocks[location.index - 1]?.type === "paragraph";
21357
+ const at = before ? location.index - 1 : blocks.findIndex((block, index) => index >= location.index && block.type === "paragraph");
21358
+ const host = blocks[at];
21359
+ if (ends.length > 0 && host?.type === "paragraph") blocks[at] = {
21360
+ ...host,
21361
+ content: before ? [...host.content, ...ends] : [...ends, ...host.content]
21362
+ };
21363
+ } else {
21283
21364
  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
21365
  op,
21285
21366
  reason: DOCUMENT_OP_REFUSAL_REASONS.UNTRACKABLE,
@@ -21594,7 +21675,15 @@ const withOmission = (row, side, value) => {
21594
21675
  formatting
21595
21676
  };
21596
21677
  };
21597
- const hasStructuralMarkup = (table) => table.preserved !== void 0 || table.bookmarks !== void 0 || table.carrierStack !== void 0 || table.rows.some((row) => row.preserved !== void 0 || row.carrierStack !== void 0 || row.contentControls !== void 0);
21678
+ /**
21679
+ * Markup a column or cell edit would have to relocate: what a row keeps
21680
+ * beside its cells, counted by the cells before it. A column or cell edit
21681
+ * keeps every row, so what stands beside or around rows keeps its place as
21682
+ * it stands: bookmarks and captured markup beside a table's rows count the
21683
+ * rows before them, and a row content control or another wrapper around the
21684
+ * table or its rows wraps them whatever cells they hold.
21685
+ */
21686
+ const hasStructuralMarkup = (table) => table.rows.some((row) => row.preserved !== void 0);
21598
21687
  /** A cell holding one paragraph with nothing in it. */
21599
21688
  const isEmptyCell = (cell) => cell.content.length === 1 && cell.content[0]?.type === "paragraph" && cell.content[0].content.length === 0;
21600
21689
  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));
@@ -25733,20 +25822,28 @@ const withoutPendingSuggestions = (document, { commentIds, onAbsorptions } = {})
25733
25822
  for (const { story, absorbed } of receipts) onAbsorptions?.(story, absorbed);
25734
25823
  return Result.ok(current);
25735
25824
  };
25736
- /**
25737
- * The revisions of one pending suggestion in a story, one info per revision
25738
- * id, in document order.
25739
- */
25825
+ const visitStorySuggestionRevisions = (body, visit) => {
25826
+ visitSuggestionRevisions(body.content, (info) => visit(info, info.suggestionId));
25827
+ for (const { info } of body.finalSectionProperties?.propertyChanges ?? []) if (info.suggestionId !== void 0) visit(info, info.suggestionId);
25828
+ };
25829
+ /** Revisions of one pending suggestion, one info per ID in document order. */
25740
25830
  const suggestionRevisionInfos = (document, story, suggestionId) => {
25741
25831
  const out = /* @__PURE__ */ new Map();
25742
- const body = storyBody$1(document, story);
25743
- const add = (info) => {
25744
- if (info.suggestionId === suggestionId && !out.has(info.id)) out.set(info.id, info);
25745
- };
25746
- visitSuggestionRevisions(body.content, add);
25747
- for (const { info } of body.finalSectionProperties?.propertyChanges ?? []) add(info);
25832
+ visitStorySuggestionRevisions(storyBody$1(document, story), (info, owner) => {
25833
+ if (owner === suggestionId && !out.has(info.id)) out.set(info.id, info);
25834
+ });
25748
25835
  return [...out.values()];
25749
25836
  };
25837
+ /** The first proposal owning each physical revision ID in this story. */
25838
+ const suggestionOwnersInStory = (document, story) => {
25839
+ const owners = /* @__PURE__ */ new Map();
25840
+ const body = findStoryBody$1(document, story);
25841
+ if (body === void 0) return owners;
25842
+ visitStorySuggestionRevisions(body, ({ id }, suggestionId) => {
25843
+ if (!owners.has(id)) owners.set(id, suggestionId);
25844
+ });
25845
+ return owners;
25846
+ };
25750
25847
  /**
25751
25848
  * The ids of every pending suggestion in a document, in every story, and of
25752
25849
  * every suggestion that proposes a comment.
@@ -25754,11 +25851,7 @@ const suggestionRevisionInfos = (document, story, suggestionId) => {
25754
25851
  const pendingSuggestionIdsIn = (document) => {
25755
25852
  const out = /* @__PURE__ */ new Set();
25756
25853
  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
- }
25854
+ for (const story of documentStories(document)) visitStorySuggestionRevisions(storyBody$1(document, story), (_info, suggestionId) => out.add(suggestionId));
25762
25855
  return out;
25763
25856
  };
25764
25857
  // src/ops/compoundIntent.ts
@@ -28385,6 +28478,7 @@ const intentEndpoints = (intent) => {
28385
28478
  case "replaceFragment":
28386
28479
  case "pasteBlocks":
28387
28480
  case "moveFragment":
28481
+ case "moveBlocks":
28388
28482
  case "replaceText":
28389
28483
  case "insertAtom":
28390
28484
  case "formatRun": return {
@@ -28515,9 +28609,10 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
28515
28609
  for (const span of leafSpans(paragraph.content)) demand += 4 * (1 + span.ancestors.length);
28516
28610
  }
28517
28611
  if (incoming.length > 0) demand += 8;
28518
- if (intent.type === "pasteBlocks") {
28612
+ if (intent.type === "pasteBlocks" || intent.type === "moveBlocks") {
28519
28613
  demand += 11;
28520
28614
  for (const block of intent.blocks) {
28615
+ if (intent.type === "moveBlocks" && block.type === "table") demand += 2 + block.rows.length;
28521
28616
  const paragraphs = block.type === "table" ? storyParagraphs({ content: [block] }).map(({ paragraph }) => paragraph) : [block];
28522
28617
  if (block.type === "table") demand += 2 + block.rows.length;
28523
28618
  for (const paragraph of paragraphs) {
@@ -28530,7 +28625,7 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
28530
28625
  demand += 4;
28531
28626
  continue;
28532
28627
  }
28533
- const note = intent.annotations?.notes.find(({ type, id }) => type === anchor.note && id === anchor.id);
28628
+ const note = (intent.type === "pasteBlocks" ? intent.annotations : void 0)?.notes.find(({ type, id }) => type === anchor.note && id === anchor.id);
28534
28629
  demand += 4;
28535
28630
  for (const block of note?.content ?? []) {
28536
28631
  if (block.type !== "paragraph") continue;
@@ -28541,7 +28636,7 @@ const createEditorIntentIdAllocator = ({ reservedBlockIds } = {}) => {
28541
28636
  }
28542
28637
  if (intent.type === "setHyperlink" || intent.type === "removeHyperlink" || intent.type === "insertHyperlink") demand = 2 * demand + 8;
28543
28638
  if (intent.type === "generateTOC") demand += 8 + (intent.headings.length + 1) * (PARAGRAPH_REVISION_DEMAND + 4 * leafRevisionDemand(3));
28544
- if (intent.type === "moveFragment") {
28639
+ if (intent.type === "moveFragment" || intent.type === "moveBlocks") {
28545
28640
  const target = storyParagraphs(storyBody$1(document, intent.target.story)).find(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(intent.target.blockId));
28546
28641
  if (target !== void 0) {
28547
28642
  demand += 3;
@@ -29907,6 +30002,303 @@ const gapWithoutLeaves = (content, at, removed) => {
29907
30002
  zeroWidthBefore
29908
30003
  };
29909
30004
  };
30005
+ /**
30006
+ * A move of the text between `from` and `to`: the range is deleted, as
30007
+ * `replaceText` with no text deletes it (a suggestion records the
30008
+ * deletion), and the moved content goes in where the target stands once
30009
+ * the deletion is made. A target inside the range moves nothing.
30010
+ */
30011
+ const compileRangeMove = (document, { intent, mode, insert }) => {
30012
+ const range = selectedParagraphRuns(document, intent.from, intent.to);
30013
+ if (range.isErr()) return Result.err(range.error);
30014
+ const sourceParagraph = paragraphAt(document, intent.from);
30015
+ const fromGap = intent.from.zeroWidthBefore ?? (sourceParagraph === void 0 ? 0 : zeroWidthLeavesAt(sourceParagraph.content, intent.from.offset).length);
30016
+ const toGap = intent.to.zeroWidthBefore ?? 0;
30017
+ if (idKey(intent.from.blockId) === idKey(intent.to.blockId) && intent.from.offset === intent.to.offset && fromGap >= toGap) {
30018
+ if (fromGap > toGap && (intent.from.zeroWidthBefore !== void 0 || intent.to.zeroWidthBefore !== void 0)) return Result.err(new DocumentOpRefusal({
30019
+ reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OFFSET,
30020
+ message: "The move source marker gaps are reversed.",
30021
+ opType: DOCUMENT_OP_TYPES.DELETE_RANGE
30022
+ }));
30023
+ return Result.ok({
30024
+ ops: [],
30025
+ selection: intent.target
30026
+ });
30027
+ }
30028
+ const locations = storyParagraphs(storyBody$1(document, intent.from.story));
30029
+ const indexOf = (at) => locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(at.blockId));
30030
+ const first = indexOf(intent.from);
30031
+ const last = indexOf(intent.to);
30032
+ const targetIndex = indexOf(intent.target);
30033
+ const targetGap = intent.target.zeroWidthBefore ?? defaultInsertionGap(paragraphAt(document, intent.target)?.content ?? [], intent.target.offset).zeroWidthBefore;
30034
+ const targetPosition = {
30035
+ offset: intent.target.offset,
30036
+ zeroWidthBefore: targetGap
30037
+ };
30038
+ if (intent.target.story === intent.from.story && targetIndex >= first && targetIndex <= last && (targetIndex !== first || compareGaps(targetPosition, {
30039
+ offset: intent.from.offset,
30040
+ zeroWidthBefore: fromGap
30041
+ }) >= 0) && (targetIndex !== last || compareGaps(targetPosition, {
30042
+ offset: intent.to.offset,
30043
+ zeroWidthBefore: toGap
30044
+ }) <= 0)) return Result.ok({
30045
+ ops: [],
30046
+ selection: intent.target
30047
+ });
30048
+ const anchorDeletions = [];
30049
+ const sourceAnchors = mode.type === "editing" ? range.value.flat() : [];
30050
+ for (const { paragraph } of sourceAnchors) {
30051
+ const blockId = paragraph.paraId ?? "";
30052
+ const from = idKey(blockId) === idKey(intent.from.blockId) ? {
30053
+ offset: intent.from.offset,
30054
+ zeroWidthBefore: fromGap
30055
+ } : {
30056
+ offset: 0,
30057
+ zeroWidthBefore: 0
30058
+ };
30059
+ const to = idKey(blockId) === idKey(intent.to.blockId) ? {
30060
+ offset: intent.to.offset,
30061
+ zeroWidthBefore: toGap
30062
+ } : {
30063
+ offset: paragraphLength(paragraph),
30064
+ zeroWidthBefore: zeroWidthLeavesAt(paragraph.content, paragraphLength(paragraph)).length
30065
+ };
30066
+ for (const span of leafSpans(paragraph.content)) {
30067
+ if (!isMoveAnchor(span.node) || span.ancestors.some(isRemovedRevisionNode) || compareGaps(span.before, from) < 0 || compareGaps(span.after, to) > 0) continue;
30068
+ anchorDeletions.push({
30069
+ type: DOCUMENT_OP_TYPES.DELETE_RANGE,
30070
+ from: {
30071
+ story: intent.from.story,
30072
+ blockId,
30073
+ ...span.before
30074
+ },
30075
+ to: {
30076
+ story: intent.from.story,
30077
+ blockId,
30078
+ ...span.after
30079
+ }
30080
+ });
30081
+ }
30082
+ }
30083
+ const deleted = compileEditorIntent(document, {
30084
+ intent: {
30085
+ type: "replaceText",
30086
+ from: intent.from,
30087
+ to: intent.to,
30088
+ text: ""
30089
+ },
30090
+ mode
30091
+ });
30092
+ if (deleted.isErr()) return deleted;
30093
+ 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({
30094
+ offset: right.from.offset,
30095
+ zeroWidthBefore: right.from.zeroWidthBefore ?? 0
30096
+ }, {
30097
+ offset: left.from.offset,
30098
+ zeroWidthBefore: left.from.zeroWidthBefore ?? 0
30099
+ })), ...deleted.value.ops.filter((op) => op.type !== DOCUMENT_OP_TYPES.DELETE_RANGE)];
30100
+ const anchors = new Set(anchorDeletions);
30101
+ const deletionOps = [];
30102
+ const movedNoteBodies = [];
30103
+ let afterDeletion = document;
30104
+ for (const planned of logicalDeletions) {
30105
+ let op = planned;
30106
+ if (planned.type === DOCUMENT_OP_TYPES.DELETE_RANGE && anchors.has(planned)) {
30107
+ const paragraph = paragraphAt(afterDeletion, planned.from);
30108
+ if (paragraph === void 0) panic("A move anchor lost its selected paragraph.");
30109
+ op = {
30110
+ type: DOCUMENT_OP_TYPES.REPLACE_INLINE,
30111
+ story: planned.from.story,
30112
+ blockId: planned.from.blockId,
30113
+ expected: paragraph.content,
30114
+ content: deleteBetween(paragraph.content, {
30115
+ offset: planned.from.offset,
30116
+ zeroWidthBefore: planned.from.zeroWidthBefore ?? 0
30117
+ }, {
30118
+ offset: planned.to.offset,
30119
+ zeroWidthBefore: planned.to.zeroWidthBefore ?? 0
30120
+ }).content
30121
+ };
30122
+ }
30123
+ const applied = applyDocumentOps(afterDeletion, [op]);
30124
+ if (applied.isErr()) return Result.err(applied.error);
30125
+ afterDeletion = applied.value.document;
30126
+ deletionOps.push(op);
30127
+ 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({
30128
+ type: DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS,
30129
+ expected: {
30130
+ ...inverse.expected.footnotes === void 0 ? {} : { footnotes: inverse.expected.footnotes },
30131
+ ...inverse.expected.endnotes === void 0 ? {} : { endnotes: inverse.expected.endnotes }
30132
+ },
30133
+ parts: {
30134
+ ...inverse.parts.footnotes === void 0 ? {} : { footnotes: inverse.parts.footnotes },
30135
+ ...inverse.parts.endnotes === void 0 ? {} : { endnotes: inverse.parts.endnotes }
30136
+ }
30137
+ });
30138
+ }
30139
+ if (movedNoteBodies.length > 0) {
30140
+ const restorations = movedNoteBodies.toReversed();
30141
+ const restored = applyDocumentOps(afterDeletion, restorations);
30142
+ if (restored.isErr()) return Result.err(restored.error);
30143
+ afterDeletion = restored.value.document;
30144
+ deletionOps.push(...restorations);
30145
+ }
30146
+ let target = intent.target;
30147
+ for (const op of logicalDeletions) {
30148
+ 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) {
30149
+ const source = paragraphAt(document, op.from);
30150
+ const deletionFromGap = op.from.zeroWidthBefore ?? zeroWidthLeavesAt(source?.content ?? [], op.from.offset).length;
30151
+ const deletionToGap = op.to.zeroWidthBefore ?? 0;
30152
+ const deletionTargetGap = target.zeroWidthBefore ?? defaultInsertionGap(source?.content ?? [], target.offset).zeroWidthBefore;
30153
+ const rebased = Object.assign({}, target, { offset: target.offset - (op.to.offset - op.from.offset) });
30154
+ if (target.offset === op.to.offset) rebased.zeroWidthBefore = deletionFromGap + deletionTargetGap - deletionToGap;
30155
+ target = rebased;
30156
+ }
30157
+ 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 });
30158
+ else if (op.type === DOCUMENT_OP_TYPES.JOIN_BLOCKS && op.revision === void 0 && idKey(target.blockId) === idKey(op.nextBlockId) && target.story === op.story) {
30159
+ const prefix = paragraphAt(document, {
30160
+ story: op.story,
30161
+ blockId: op.blockId,
30162
+ offset: 0
30163
+ });
30164
+ const remaining = idKey(op.blockId) === idKey(intent.from.blockId) ? intent.from.offset : 0;
30165
+ if (prefix !== void 0) {
30166
+ const rebased = Object.assign({}, target, { offset: target.offset + remaining });
30167
+ if (target.offset === 0 && idKey(op.blockId) === idKey(intent.from.blockId)) rebased.zeroWidthBefore = fromGap + (target.zeroWidthBefore ?? 0);
30168
+ target = rebased;
30169
+ }
30170
+ }
30171
+ }
30172
+ const inserted = insert(afterDeletion, target, modeAfterOps(afterDeletion, mode));
30173
+ if (inserted.isErr()) return inserted;
30174
+ return Result.ok({
30175
+ ops: [...deletionOps, ...inserted.value.ops],
30176
+ selection: inserted.value.selection
30177
+ });
30178
+ };
30179
+ /**
30180
+ * A paragraph without the move range markers it carried: a suggested move is
30181
+ * recorded as a deletion and an insertion, and a copied marker would pair
30182
+ * with no range.
30183
+ */
30184
+ const withoutParagraphMoveAnchors = (paragraph) => Object.assign({}, paragraph, { content: asParagraphContent(withoutMoveAnchors(paragraph.content)) });
30185
+ /** A block without move range markers, a table's cell paragraphs among them. */
30186
+ const withoutBlockMoveAnchors = (block) => block.type === "paragraph" ? withoutParagraphMoveAnchors(block) : {
30187
+ ...block,
30188
+ rows: block.rows.map((row) => ({
30189
+ ...row,
30190
+ cells: row.cells.map((cell) => ({
30191
+ ...cell,
30192
+ content: cell.content.map((inner) => inner.type === "paragraph" || inner.type === "table" ? withoutBlockMoveAnchors(inner) : inner)
30193
+ }))
30194
+ }))
30195
+ };
30196
+ /**
30197
+ * Blocks, tables among them, moved from a range to a target. The tables
30198
+ * standing wholly between the range's paragraphs are removed, the latest
30199
+ * first, or in suggesting mode recorded as deleted; the range's text is then
30200
+ * deleted and the blocks placed at the rebased target as a paste places them.
30201
+ * A suggestion records the move as the deletion of its source and the
30202
+ * insertion of its copy, as a moved paragraph is recorded. A target inside
30203
+ * the range, a moved table's cell among them, moves nothing.
30204
+ */
30205
+ const compileBlockMove = (document, { intent, mode, firstBlockId }) => {
30206
+ const { blocks, ...range } = intent;
30207
+ const paragraphs = blocks.filter((block) => block.type === "paragraph");
30208
+ if (paragraphs.length === blocks.length) return compileEditorIntent(document, {
30209
+ intent: {
30210
+ ...range,
30211
+ type: "moveFragment",
30212
+ paragraphs
30213
+ },
30214
+ mode,
30215
+ ...firstBlockId === void 0 ? {} : { firstBlockId }
30216
+ });
30217
+ const story = intent.from.story;
30218
+ const body = storyBody$1(document, story);
30219
+ const locations = storyParagraphs(body);
30220
+ const indexOf = (at) => locations.findIndex(({ paragraph }) => idKey(paragraph.paraId ?? "") === idKey(at.blockId));
30221
+ const first = indexOf(intent.from);
30222
+ const last = indexOf(intent.to);
30223
+ const start = locations[first];
30224
+ const end = locations[last];
30225
+ if (start === void 0 || end === void 0 || intent.to.story !== story) return Result.err(new DocumentOpRefusal({
30226
+ reason: DOCUMENT_OP_REFUSAL_REASONS.BLOCK_NOT_FOUND,
30227
+ message: "The moved range names a paragraph the story does not hold.",
30228
+ opType: DOCUMENT_OP_TYPES.DELETE_RANGE
30229
+ }));
30230
+ if (!sameBlockList(start.list, end.list) || last < first) return Result.err(new DocumentOpRefusal({
30231
+ reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OPERATION,
30232
+ message: "Moved blocks start and end in one block list.",
30233
+ opType: DOCUMENT_OP_TYPES.DELETE_RANGE
30234
+ }));
30235
+ const target = indexOf(intent.target);
30236
+ if (intent.target.story === story && target > first && target < last) return Result.ok({
30237
+ ops: [],
30238
+ selection: intent.target
30239
+ });
30240
+ const covered = blockListAt(body.content, start.list).slice(start.index + 1, end.index).filter((block) => block.type === "table");
30241
+ const reserved = mode.reservedBlockIds === void 0 ? {} : { reservedBlockIds: mode.reservedBlockIds };
30242
+ const ops = [];
30243
+ let current = document;
30244
+ let currentMode = mode;
30245
+ for (const table of covered.toReversed()) {
30246
+ const blockId = storyParagraphs({ content: [table] }).at(0)?.paragraph.paraId;
30247
+ if (blockId === void 0) return Result.err(new DocumentOpRefusal({
30248
+ reason: DOCUMENT_OP_REFUSAL_REASONS.MISSING_BLOCK_ID,
30249
+ message: "A moved table holds no paragraph that addresses it.",
30250
+ opType: DOCUMENT_OP_TYPES.DELETE_TABLE
30251
+ }));
30252
+ const removed = compileEditorIntent(current, {
30253
+ intent: {
30254
+ type: "tableBlock",
30255
+ operation: {
30256
+ type: DOCUMENT_OP_TYPES.DELETE_TABLE,
30257
+ story,
30258
+ blockId
30259
+ }
30260
+ },
30261
+ mode: currentMode
30262
+ });
30263
+ if (removed.isErr()) return removed;
30264
+ const applied = applyDocumentOps(current, removed.value.ops);
30265
+ if (applied.isErr()) return Result.err(applied.error);
30266
+ ops.push(...removed.value.ops);
30267
+ current = applied.value.document;
30268
+ currentMode = {
30269
+ ...modeAfterOps(current, currentMode),
30270
+ ...reserved
30271
+ };
30272
+ }
30273
+ const moved = compileRangeMove(current, {
30274
+ intent: range,
30275
+ mode: currentMode,
30276
+ insert: (afterDeletion, at, insertMode) => compileEditorIntent(afterDeletion, {
30277
+ intent: {
30278
+ type: "pasteBlocks",
30279
+ from: at,
30280
+ to: at,
30281
+ blocks: mode.type === "suggesting" ? blocks.map(withoutBlockMoveAnchors) : blocks,
30282
+ openStart: intent.openStart,
30283
+ openEnd: intent.openEnd
30284
+ },
30285
+ mode: {
30286
+ ...insertMode,
30287
+ ...reserved
30288
+ },
30289
+ ...firstBlockId === void 0 ? {} : { firstBlockId }
30290
+ })
30291
+ });
30292
+ if (moved.isErr()) return moved;
30293
+ if (moved.value.ops.length === 0) return Result.ok({
30294
+ ops: [],
30295
+ selection: intent.target
30296
+ });
30297
+ return Result.ok({
30298
+ ops: [...ops, ...moved.value.ops],
30299
+ selection: moved.value.selection
30300
+ });
30301
+ };
29910
30302
  /** Compile one batch; the caller applies it atomically and journals its exact inverse. */
29911
30303
  const compileEditorIntent = (document, input) => {
29912
30304
  const routed = textBoxOfIntent(document, input.intent);
@@ -30343,182 +30735,36 @@ const compileInStory = (document, { intent, mode, firstBlockId, typedFormatting
30343
30735
  break;
30344
30736
  }
30345
30737
  case "moveFragment": {
30346
- const range = selectedParagraphRuns(document, intent.from, intent.to);
30347
- if (range.isErr()) return Result.err(range.error);
30348
- const sourceParagraph = paragraphAt(document, intent.from);
30349
- const fromGap = intent.from.zeroWidthBefore ?? (sourceParagraph === void 0 ? 0 : zeroWidthLeavesAt(sourceParagraph.content, intent.from.offset).length);
30350
- const toGap = intent.to.zeroWidthBefore ?? 0;
30351
- if (idKey(intent.from.blockId) === idKey(intent.to.blockId) && intent.from.offset === intent.to.offset && fromGap >= toGap) {
30352
- if (fromGap > toGap && (intent.from.zeroWidthBefore !== void 0 || intent.to.zeroWidthBefore !== void 0)) return Result.err(new DocumentOpRefusal({
30353
- reason: DOCUMENT_OP_REFUSAL_REASONS.INVALID_OFFSET,
30354
- message: "The move source marker gaps are reversed.",
30355
- opType: DOCUMENT_OP_TYPES.DELETE_RANGE
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 }
30738
+ const compiled = compileRangeMove(document, {
30739
+ intent,
30740
+ mode,
30741
+ insert: (afterDeletion, target, insertMode) => compileEditorIntent(afterDeletion, {
30742
+ intent: {
30743
+ type: "replaceFragment",
30744
+ from: target,
30745
+ to: target,
30746
+ paragraphs: mode.type === "suggesting" ? intent.paragraphs.map(withoutParagraphMoveAnchors) : intent.paragraphs,
30747
+ openStart: intent.openStart,
30748
+ openEnd: intent.openEnd
30466
30749
  },
30467
- parts: {
30468
- ...inverse.parts.footnotes === void 0 ? {} : { footnotes: inverse.parts.footnotes },
30469
- ...inverse.parts.endnotes === void 0 ? {} : { endnotes: inverse.parts.endnotes }
30470
- }
30471
- });
30472
- }
30473
- if (movedNoteBodies.length > 0) {
30474
- const restorations = movedNoteBodies.toReversed();
30475
- const restored = applyDocumentOps(afterDeletion, restorations);
30476
- if (restored.isErr()) return Result.err(restored.error);
30477
- afterDeletion = restored.value.document;
30478
- deletionOps.push(...restorations);
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),
30750
+ mode: insertMode,
30751
+ ...firstBlockId === void 0 ? {} : { firstBlockId }
30752
+ })
30753
+ });
30754
+ if (compiled.isErr()) return compiled;
30755
+ ops = compiled.value.ops;
30756
+ selection = compiled.value.selection;
30757
+ break;
30758
+ }
30759
+ case "moveBlocks": {
30760
+ const compiled = compileBlockMove(document, {
30761
+ intent,
30762
+ mode,
30517
30763
  ...firstBlockId === void 0 ? {} : { firstBlockId }
30518
30764
  });
30519
- if (inserted.isErr()) return inserted;
30520
- ops = [...deletionOps, ...inserted.value.ops];
30521
- selection = inserted.value.selection;
30765
+ if (compiled.isErr()) return compiled;
30766
+ ops = compiled.value.ops;
30767
+ selection = compiled.value.selection;
30522
30768
  break;
30523
30769
  }
30524
30770
  case "table": {
@@ -37036,4 +37282,4 @@ const resolvedDocumentView = (document, decision) => {
37036
37282
  const storyBody = storyBody$1;
37037
37283
  const findStoryBody = findStoryBody$1;
37038
37284
  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 };
37285
+ 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, suggestionOwnersInStory, suggestionRevisionInfos, survivingComments, textBoxContentsIn, toOpEnvelope, transferParagraphPropertySnapshot, transformBatch, transformPosition, trimIdLease, tryTrackedInsertionGroup, validateDocumentBatch, validateOpsDocument, validateSequencedBatch, withBodyContent, withParagraphCopies, withParagraphRenderings, withTextBoxesClosed, withoutCommentThreads, withoutPendingSuggestions, zeroWidthLeavesAt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/docx-core",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "Typed OOXML/DOCX model, validation, serialization, legal-source compilation, and browser-native package projection.",
5
5
  "keywords": [
6
6
  "document-model",