@beyondwork/docx-react-component 1.0.121 → 1.0.123

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.
Files changed (102) hide show
  1. package/dist/api/public-types.cjs +318 -32
  2. package/dist/api/public-types.d.cts +2 -2
  3. package/dist/api/public-types.d.ts +2 -2
  4. package/dist/api/public-types.js +3 -3
  5. package/dist/api/v3.cjs +349 -62
  6. package/dist/api/v3.d.cts +3 -3
  7. package/dist/api/v3.d.ts +3 -3
  8. package/dist/api/v3.js +10 -10
  9. package/dist/{canonical-document-ByIqTd4s.d.cts → canonical-document-CG2TgAzj.d.cts} +1 -1
  10. package/dist/{canonical-document-ByIqTd4s.d.ts → canonical-document-CG2TgAzj.d.ts} +1 -1
  11. package/dist/{chunk-B4YHWFE3.js → chunk-32ZAOQ54.js} +1 -1
  12. package/dist/{chunk-QNGJRZ2D.js → chunk-4IPEZYQX.js} +1 -1
  13. package/dist/{chunk-3OFSP2IX.js → chunk-BOHHIVQ2.js} +3 -3
  14. package/dist/{chunk-EMDH4IQN.js → chunk-E5IBDE5E.js} +4 -3
  15. package/dist/{chunk-TFSXOIAI.js → chunk-FNWKE74J.js} +43 -3
  16. package/dist/{chunk-IT2DK3A7.js → chunk-H2YQKA55.js} +9 -7
  17. package/dist/{chunk-3TUQCHYT.js → chunk-H6IL5ABU.js} +47 -7
  18. package/dist/{chunk-GON2DNTE.js → chunk-HXHQA4BU.js} +1 -1
  19. package/dist/{chunk-3OHVK2D6.js → chunk-IR7QV2BX.js} +17 -1
  20. package/dist/{chunk-ZKSDVHGH.js → chunk-KOHQFZMM.js} +1 -1
  21. package/dist/{chunk-XVFENXLK.js → chunk-LGWNN3L2.js} +2 -2
  22. package/dist/{chunk-TMU7JMXX.js → chunk-MB7RJBSN.js} +9 -21
  23. package/dist/{chunk-UWDWGQH5.js → chunk-ML4A4WUN.js} +1 -1
  24. package/dist/{chunk-GZW2ERUO.js → chunk-N4VIXI2Z.js} +3 -3
  25. package/dist/{chunk-S4ANOS2M.js → chunk-NNPVA5VL.js} +2 -2
  26. package/dist/{chunk-QFU7ZOAD.js → chunk-PFYUJU3Q.js} +176 -36
  27. package/dist/{chunk-37SEJQ3G.js → chunk-RSYN6FTS.js} +2 -2
  28. package/dist/{chunk-OBCP6VTG.js → chunk-RWERZWHR.js} +1 -1
  29. package/dist/{chunk-UHQOUTAX.js → chunk-SGSJ4DQA.js} +377 -50
  30. package/dist/{chunk-PCXTMEGY.js → chunk-UHJLCPLU.js} +24 -14
  31. package/dist/{chunk-G3B2OBCZ.js → chunk-ZRHLLPSJ.js} +271 -26
  32. package/dist/compare.d.cts +1 -1
  33. package/dist/compare.d.ts +1 -1
  34. package/dist/core/commands/formatting-commands.d.cts +2 -2
  35. package/dist/core/commands/formatting-commands.d.ts +2 -2
  36. package/dist/core/commands/image-commands.cjs +50 -9
  37. package/dist/core/commands/image-commands.d.cts +2 -2
  38. package/dist/core/commands/image-commands.d.ts +2 -2
  39. package/dist/core/commands/image-commands.js +5 -5
  40. package/dist/core/commands/section-layout-commands.d.cts +2 -2
  41. package/dist/core/commands/section-layout-commands.d.ts +2 -2
  42. package/dist/core/commands/style-commands.d.cts +2 -2
  43. package/dist/core/commands/style-commands.d.ts +2 -2
  44. package/dist/core/commands/table-structure-commands.cjs +50 -9
  45. package/dist/core/commands/table-structure-commands.d.cts +2 -2
  46. package/dist/core/commands/table-structure-commands.d.ts +2 -2
  47. package/dist/core/commands/table-structure-commands.js +4 -4
  48. package/dist/core/commands/text-commands.cjs +66 -9
  49. package/dist/core/commands/text-commands.d.cts +3 -2
  50. package/dist/core/commands/text-commands.d.ts +3 -2
  51. package/dist/core/commands/text-commands.js +5 -5
  52. package/dist/core/selection/mapping.d.cts +2 -2
  53. package/dist/core/selection/mapping.d.ts +2 -2
  54. package/dist/core/state/editor-state.d.cts +2 -2
  55. package/dist/core/state/editor-state.d.ts +2 -2
  56. package/dist/index.cjs +1196 -197
  57. package/dist/index.d.cts +5 -5
  58. package/dist/index.d.ts +5 -5
  59. package/dist/index.js +278 -85
  60. package/dist/io/docx-session.cjs +10 -21
  61. package/dist/io/docx-session.d.cts +4 -4
  62. package/dist/io/docx-session.d.ts +4 -4
  63. package/dist/io/docx-session.js +4 -4
  64. package/dist/legal.cjs +8 -20
  65. package/dist/legal.d.cts +1 -1
  66. package/dist/legal.d.ts +1 -1
  67. package/dist/legal.js +3 -3
  68. package/dist/{loader-BF8ju_LK.d.ts → loader-D9KCtj4m.d.cts} +4 -22
  69. package/dist/{loader-g54WRvj1.d.cts → loader-D9y4ZRjj.d.ts} +4 -22
  70. package/dist/{public-types-Dl1jiWjk.d.ts → public-types-CNnMHZM9.d.ts} +263 -213
  71. package/dist/{public-types-D_y4Ptcj.d.cts → public-types-DajNGKV4.d.cts} +263 -213
  72. package/dist/public-types.cjs +318 -32
  73. package/dist/public-types.d.cts +2 -2
  74. package/dist/public-types.d.ts +2 -2
  75. package/dist/public-types.js +3 -3
  76. package/dist/runtime/collab.d.cts +3 -3
  77. package/dist/runtime/collab.d.ts +3 -3
  78. package/dist/runtime/document-runtime.cjs +752 -77
  79. package/dist/runtime/document-runtime.d.cts +2 -2
  80. package/dist/runtime/document-runtime.d.ts +2 -2
  81. package/dist/runtime/document-runtime.js +14 -14
  82. package/dist/{session-C1EPAkcI.d.ts → session-DEmaOEjA.d.ts} +3 -3
  83. package/dist/{session-D15QOO0Q.d.cts → session-DyQGlryH.d.cts} +3 -3
  84. package/dist/session.cjs +12 -618
  85. package/dist/session.d.cts +5 -5
  86. package/dist/session.d.ts +5 -5
  87. package/dist/session.js +7 -9
  88. package/dist/tailwind.cjs +489 -63
  89. package/dist/tailwind.d.cts +2 -2
  90. package/dist/tailwind.d.ts +2 -2
  91. package/dist/tailwind.js +7 -7
  92. package/dist/{types-BoSRp2Vg.d.cts → types-CxE1aZiv.d.cts} +2 -2
  93. package/dist/{types-DEvRwq9C.d.ts → types-DjJNaE9c.d.ts} +2 -2
  94. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +3 -3
  95. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +3 -3
  96. package/dist/ui-tailwind/editor-surface/search-plugin.js +4 -4
  97. package/dist/ui-tailwind/theme/tokens.css +387 -0
  98. package/dist/ui-tailwind.cjs +489 -63
  99. package/dist/ui-tailwind.d.cts +3 -3
  100. package/dist/ui-tailwind.d.ts +3 -3
  101. package/dist/ui-tailwind.js +7 -7
  102. package/package.json +7 -3
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-M6XR534O.js";
12
12
  import {
13
13
  buildBookmarkNameMap
14
- } from "./chunk-OBCP6VTG.js";
14
+ } from "./chunk-RWERZWHR.js";
15
15
  import {
16
16
  deleteSelectionOrBackward,
17
17
  deleteSelectionOrForward,
@@ -22,7 +22,7 @@ import {
22
22
  insertText,
23
23
  outdentParagraphAtSelection,
24
24
  splitParagraph
25
- } from "./chunk-3OFSP2IX.js";
25
+ } from "./chunk-BOHHIVQ2.js";
26
26
  import {
27
27
  applyFormattingOperationToDocument,
28
28
  applyTextMarkOperationToDocumentRange,
@@ -32,18 +32,18 @@ import {
32
32
  insertImage,
33
33
  repositionFloatingImage,
34
34
  resizeImage
35
- } from "./chunk-37SEJQ3G.js";
35
+ } from "./chunk-RSYN6FTS.js";
36
36
  import {
37
37
  applyTextTransaction
38
- } from "./chunk-3OHVK2D6.js";
38
+ } from "./chunk-IR7QV2BX.js";
39
39
  import {
40
40
  applyTableStructureOperationForEditableTarget,
41
41
  removeCellFromRow,
42
42
  removeTableRowPure
43
- } from "./chunk-XVFENXLK.js";
43
+ } from "./chunk-LGWNN3L2.js";
44
44
  import {
45
45
  resolveParagraphScope
46
- } from "./chunk-ZKSDVHGH.js";
46
+ } from "./chunk-KOHQFZMM.js";
47
47
  import {
48
48
  buildGeometryDebugEntry,
49
49
  collectLineBoxesForRegion,
@@ -51,7 +51,7 @@ import {
51
51
  createRenderKernel,
52
52
  incrementInvalidationCounter,
53
53
  recordPerfSample
54
- } from "./chunk-GZW2ERUO.js";
54
+ } from "./chunk-N4VIXI2Z.js";
55
55
  import {
56
56
  AI_ACTION_POLICIES,
57
57
  buildFormattingDebugEntry,
@@ -74,7 +74,7 @@ import {
74
74
  resolveHeadingPath,
75
75
  resolveScope,
76
76
  serializeFragmentToWordML
77
- } from "./chunk-PCXTMEGY.js";
77
+ } from "./chunk-UHJLCPLU.js";
78
78
  import {
79
79
  ISSUE_METADATA_ID,
80
80
  LAYOUT_ENGINE_VERSION,
@@ -109,7 +109,7 @@ import {
109
109
  setWorkspaceMode,
110
110
  setZoomLevel,
111
111
  snapCommentAnchorAwayFromTable
112
- } from "./chunk-G3B2OBCZ.js";
112
+ } from "./chunk-ZRHLLPSJ.js";
113
113
  import {
114
114
  countLogicalPositions,
115
115
  createPlainText,
@@ -128,7 +128,7 @@ import {
128
128
  replaceStoryBlocks,
129
129
  resolvePageFieldDisplayText,
130
130
  storyTargetKey
131
- } from "./chunk-3TUQCHYT.js";
131
+ } from "./chunk-H6IL5ABU.js";
132
132
  import {
133
133
  createCommentSidebarProjection,
134
134
  createCommentStoreFromRuntimeComments
@@ -152,18 +152,20 @@ import {
152
152
  persistedSnapshotFromEditorSessionState,
153
153
  remapRevisionStore,
154
154
  setRevisionStatus
155
- } from "./chunk-UWDWGQH5.js";
155
+ } from "./chunk-ML4A4WUN.js";
156
156
  import {
157
157
  isSupportedFieldFamily,
158
158
  parseTocLevelRange,
159
159
  resolveRefFieldText
160
- } from "./chunk-TMU7JMXX.js";
160
+ } from "./chunk-MB7RJBSN.js";
161
161
  import {
162
162
  collectEditableTargetRefs,
163
+ collectEditableTargetRefsForStoryBlockRanges,
163
164
  collectStoryBlockContexts,
164
165
  createEditableTargetBlockCache,
165
- createHeaderFooterStoryKey
166
- } from "./chunk-TFSXOIAI.js";
166
+ createHeaderFooterStoryKey,
167
+ sha256TextHex
168
+ } from "./chunk-FNWKE74J.js";
167
169
  import {
168
170
  setActiveSerializeTelemetryBus
169
171
  } from "./chunk-EB6M3GE6.js";
@@ -1581,8 +1583,8 @@ function isNodeSelectableSegment(segment) {
1581
1583
  }
1582
1584
 
1583
1585
  // src/runtime/edit-ops/index.ts
1584
- function validateResult(result) {
1585
- const maxOffset = result.storyText.length;
1586
+ function validateResult(result, context) {
1587
+ const maxOffset = getPostMutationMaxOffset(result, context);
1586
1588
  const options = result.selection.activeRange.kind === "node" ? {
1587
1589
  isValidNodeTarget: createSurfaceNodeSelectionProbe(
1588
1590
  createEditorSurfaceSnapshot(result.document, result.selection)
@@ -1599,24 +1601,34 @@ function validateResult(result) {
1599
1601
  }
1600
1602
  return { ...result, selection: validated };
1601
1603
  }
1604
+ function getPostMutationMaxOffset(result, context) {
1605
+ if (typeof context.activeStorySize !== "number" || context.textTarget?.kind === "text-leaf") {
1606
+ return result.storyText.length;
1607
+ }
1608
+ let storySize = context.activeStorySize;
1609
+ for (const step of result.mapping.steps) {
1610
+ storySize += step.insertSize - Math.max(0, step.to - step.from);
1611
+ }
1612
+ return Math.max(result.storyText.length, storySize);
1613
+ }
1602
1614
  var editLayer = {
1603
1615
  applyTextInsert(doc, selection, text, context, formatting) {
1604
- return validateResult(insertText(doc, selection, text, context, formatting));
1616
+ return validateResult(insertText(doc, selection, text, context, formatting), context);
1605
1617
  },
1606
1618
  applyDeleteBackward(doc, selection, context) {
1607
- return validateResult(deleteSelectionOrBackward(doc, selection, context));
1619
+ return validateResult(deleteSelectionOrBackward(doc, selection, context), context);
1608
1620
  },
1609
1621
  applyDeleteForward(doc, selection, context) {
1610
- return validateResult(deleteSelectionOrForward(doc, selection, context));
1622
+ return validateResult(deleteSelectionOrForward(doc, selection, context), context);
1611
1623
  },
1612
1624
  applyInsertTab(doc, selection, context) {
1613
- return validateResult(insertTab(doc, selection, context));
1625
+ return validateResult(insertTab(doc, selection, context), context);
1614
1626
  },
1615
1627
  applyInsertHardBreak(doc, selection, context) {
1616
- return validateResult(insertHardBreak(doc, selection, context));
1628
+ return validateResult(insertHardBreak(doc, selection, context), context);
1617
1629
  },
1618
1630
  applySplitParagraph(doc, selection, context) {
1619
- return validateResult(splitParagraph(doc, selection, context));
1631
+ return validateResult(splitParagraph(doc, selection, context), context);
1620
1632
  }
1621
1633
  };
1622
1634
 
@@ -9356,12 +9368,37 @@ function toPublicStoryAnchoredObject(object) {
9356
9368
  }
9357
9369
  } : {},
9358
9370
  ...object.anchorRectTwips ? { anchorRectTwips: toPublicTwipsRect(object.anchorRectTwips) } : {},
9371
+ ...object.textBoxBody ? { textBoxBody: toPublicTextBoxBodyFacts(object.textBoxBody) } : {},
9359
9372
  ...object.relationshipIds ? { relationshipIds: [...object.relationshipIds] } : {},
9360
9373
  ...object.mediaIds ? { mediaIds: [...object.mediaIds] } : {},
9361
9374
  preserveOnly: object.preserveOnly,
9362
9375
  divergenceIds: [...object.divergenceIds]
9363
9376
  };
9364
9377
  }
9378
+ function toPublicTextBoxBodyFacts(textBoxBody) {
9379
+ return {
9380
+ bodyKey: textBoxBody.bodyKey,
9381
+ status: textBoxBody.status,
9382
+ ...textBoxBody.unavailableReason !== void 0 ? { unavailableReason: textBoxBody.unavailableReason } : {},
9383
+ ...textBoxBody.bodyProperties ? { bodyProperties: { ...textBoxBody.bodyProperties } } : {},
9384
+ ...textBoxBody.bodyInsetsTwips ? { bodyInsetsTwips: { ...textBoxBody.bodyInsetsTwips } } : {},
9385
+ ...textBoxBody.contentRectTwips ? { contentRectTwips: toPublicTwipsRect(textBoxBody.contentRectTwips) } : {},
9386
+ blockCount: textBoxBody.blockCount,
9387
+ paragraphCount: textBoxBody.paragraphCount,
9388
+ unsupportedBlockCount: textBoxBody.unsupportedBlockCount,
9389
+ paragraphs: textBoxBody.paragraphs.map((paragraph) => ({
9390
+ paragraphKey: paragraph.paragraphKey,
9391
+ blockPath: paragraph.blockPath,
9392
+ blockIndex: paragraph.blockIndex,
9393
+ ...paragraph.rectTwips ? { rectTwips: toPublicTwipsRect(paragraph.rectTwips) } : {},
9394
+ ...paragraph.unavailableReason !== void 0 ? { unavailableReason: paragraph.unavailableReason } : {},
9395
+ ...paragraph.styleId !== void 0 ? { styleId: paragraph.styleId } : {},
9396
+ ...paragraph.alignment !== void 0 ? { alignment: paragraph.alignment } : {},
9397
+ textLength: paragraph.textLength,
9398
+ runCount: paragraph.runCount
9399
+ }))
9400
+ };
9401
+ }
9365
9402
  function toPublicLayoutDivergence(divergence) {
9366
9403
  return {
9367
9404
  divergenceId: divergence.divergenceId,
@@ -11933,6 +11970,26 @@ function mapLocalSelectionOnRemoteReplay(selection, mapping) {
11933
11970
  }
11934
11971
 
11935
11972
  // src/runtime/document-runtime.ts
11973
+ var CANONICAL_BLOCK_REFS_SYMBOL = /* @__PURE__ */ Symbol.for("wre.canonical-block-refs");
11974
+ function getLocalTextPatchMetadata(mapping) {
11975
+ const metadata = mapping.metadata?.localTextPatch;
11976
+ if (!metadata || typeof metadata !== "object") {
11977
+ return null;
11978
+ }
11979
+ const insertedText = metadata.insertedText;
11980
+ return typeof insertedText === "string" ? { insertedText } : null;
11981
+ }
11982
+ function getSurfaceCanonicalBlockRefs(snapshot) {
11983
+ return snapshot[CANONICAL_BLOCK_REFS_SYMBOL];
11984
+ }
11985
+ function attachSurfaceCanonicalBlockRefs(snapshot, refs) {
11986
+ Object.defineProperty(snapshot, CANONICAL_BLOCK_REFS_SYMBOL, {
11987
+ value: refs,
11988
+ enumerable: false,
11989
+ configurable: true,
11990
+ writable: false
11991
+ });
11992
+ }
11936
11993
  function normalizeViewportRanges(ranges) {
11937
11994
  const cleaned = ranges.filter((r) => Number.isFinite(r.start) && Number.isFinite(r.end) && r.end > r.start).map((r) => ({ start: r.start, end: r.end }));
11938
11995
  if (cleaned.length === 0) return Object.freeze([]);
@@ -12296,6 +12353,22 @@ function createDocumentRuntime(options) {
12296
12353
  cachedEditableTargetMap = { document, map: byBlockPath };
12297
12354
  return byBlockPath;
12298
12355
  }
12356
+ function getEditableTargetsByBlockPathForRanges(document, storyKey, ranges) {
12357
+ if (ranges === null) return getEditableTargetsByBlockPath(document);
12358
+ perfCounters.increment("runtime.editableTargets.boundedBuilds");
12359
+ const targets = collectEditableTargetRefsForStoryBlockRanges(
12360
+ document,
12361
+ storyKey,
12362
+ ranges,
12363
+ editableTargetBlockCache
12364
+ );
12365
+ if (targets.length === 0) return /* @__PURE__ */ new Map();
12366
+ const byBlockPath = /* @__PURE__ */ new Map();
12367
+ for (const target of targets) {
12368
+ byBlockPath.set(target.blockPath, target);
12369
+ }
12370
+ return byBlockPath;
12371
+ }
12299
12372
  function invalidateEditableTargetMap() {
12300
12373
  cachedEditableTargetMap = null;
12301
12374
  }
@@ -12346,7 +12419,7 @@ function createDocumentRuntime(options) {
12346
12419
  }
12347
12420
  const snapshot = createEditorSurfaceSnapshot(document, state.selection, nextActiveStory, {
12348
12421
  viewportBlockRanges: surfaceViewportRanges,
12349
- editableTargetsByBlockPath: getEditableTargetsByBlockPath(document),
12422
+ editableTargetsByBlockPath: options2.editableTargetsByBlockPathOverride ?? getEditableTargetsByBlockPath(document),
12350
12423
  ...effectiveMarkupModeProvider ? { getEffectiveMarkupMode: effectiveMarkupModeProvider } : {}
12351
12424
  });
12352
12425
  recordPerfSample("snapshot.surface");
@@ -12409,6 +12482,180 @@ function createDocumentRuntime(options) {
12409
12482
  }
12410
12483
  return -1;
12411
12484
  }
12485
+ function cachePatchedLocalTextSurface(surface) {
12486
+ const activeStoryKey = storyTargetKey(activeStory);
12487
+ const rangesKey = serializeViewportRanges(surface.viewportBlockRanges);
12488
+ cachedSurface = {
12489
+ content: state.document.content,
12490
+ subParts: state.document.subParts,
12491
+ styles: state.document.styles,
12492
+ numbering: state.document.numbering,
12493
+ media: state.document.media,
12494
+ preservation: state.document.preservation,
12495
+ review: state.document.review,
12496
+ effectiveMarkupModeProvider,
12497
+ activeStoryKey,
12498
+ viewportRangesKey: rangesKey,
12499
+ snapshot: surface
12500
+ };
12501
+ if (surface.viewportBlockRanges === null) {
12502
+ cachedFullSurface = {
12503
+ content: state.document.content,
12504
+ subParts: state.document.subParts,
12505
+ styles: state.document.styles,
12506
+ numbering: state.document.numbering,
12507
+ media: state.document.media,
12508
+ preservation: state.document.preservation,
12509
+ review: state.document.review,
12510
+ effectiveMarkupModeProvider,
12511
+ activeStoryKey,
12512
+ snapshot: surface
12513
+ };
12514
+ }
12515
+ cachedSurfaceFingerprint = `${activeStoryKey}|${rangesKey}|${String(state.selection.anchor)}:${String(state.selection.head)}`;
12516
+ }
12517
+ function tryPatchLocalTextSurface(previousSurface, mapping) {
12518
+ const tTotal0 = performance.now();
12519
+ try {
12520
+ if (!previousSurface || activeStory.kind !== "main") {
12521
+ perfCounters.increment("surface.localText.patchMiss");
12522
+ return null;
12523
+ }
12524
+ const patch = getLocalTextPatchMetadata(mapping);
12525
+ if (!patch || mapping.steps.length !== 1) {
12526
+ perfCounters.increment("surface.localText.patchMiss");
12527
+ return null;
12528
+ }
12529
+ const step = mapping.steps[0];
12530
+ if (patch.insertedText.length !== step.insertSize) {
12531
+ perfCounters.increment("surface.localText.patchMiss");
12532
+ return null;
12533
+ }
12534
+ const editFrom = step.from;
12535
+ const editTo = step.to;
12536
+ if (editTo < editFrom || editFrom < 0) {
12537
+ perfCounters.increment("surface.localText.patchMiss");
12538
+ return null;
12539
+ }
12540
+ const blockIndex = previousSurface.blocks.findIndex(
12541
+ (block2) => block2.kind === "paragraph" && editFrom >= block2.from && editTo <= block2.to
12542
+ );
12543
+ if (blockIndex < 0) {
12544
+ perfCounters.increment("surface.localText.patchMiss");
12545
+ return null;
12546
+ }
12547
+ const block = previousSurface.blocks[blockIndex];
12548
+ if (block.kind !== "paragraph") {
12549
+ perfCounters.increment("surface.localText.patchMiss");
12550
+ return null;
12551
+ }
12552
+ const segmentIndex = block.segments.findIndex(
12553
+ (segment2) => segment2.kind === "text" && editFrom >= segment2.from && editTo <= segment2.to
12554
+ );
12555
+ if (segmentIndex < 0) {
12556
+ perfCounters.increment("surface.localText.patchMiss");
12557
+ return null;
12558
+ }
12559
+ const segment = block.segments[segmentIndex];
12560
+ if (segment.kind !== "text") {
12561
+ perfCounters.increment("surface.localText.patchMiss");
12562
+ return null;
12563
+ }
12564
+ if (segment.text.length !== segment.to - segment.from) {
12565
+ perfCounters.increment("surface.localText.patchMiss");
12566
+ return null;
12567
+ }
12568
+ const localFrom = editFrom - segment.from;
12569
+ const localTo = editTo - segment.from;
12570
+ const delta = patch.insertedText.length - (editTo - editFrom);
12571
+ const nextText = segment.text.slice(0, localFrom) + patch.insertedText + segment.text.slice(localTo);
12572
+ const nextSegments = block.segments.map((candidate, index) => {
12573
+ if (index < segmentIndex) return candidate;
12574
+ if (index === segmentIndex) {
12575
+ return {
12576
+ ...segment,
12577
+ text: nextText,
12578
+ to: segment.to + delta
12579
+ };
12580
+ }
12581
+ return shiftSurfaceInlineSegment(candidate, delta);
12582
+ });
12583
+ const nextBlock = {
12584
+ ...block,
12585
+ to: block.to + delta,
12586
+ segments: nextSegments
12587
+ };
12588
+ const nextBlocks = previousSurface.blocks.map((candidate, index) => {
12589
+ if (index < blockIndex) return candidate;
12590
+ if (index === blockIndex) return nextBlock;
12591
+ return shiftSurfaceBlock(candidate, delta);
12592
+ });
12593
+ const nextPlainText = previousSurface.plainText.slice(0, editFrom) + patch.insertedText + previousSurface.plainText.slice(editTo);
12594
+ const nextSurface = {
12595
+ ...previousSurface,
12596
+ storySize: previousSurface.storySize + delta,
12597
+ plainText: nextPlainText,
12598
+ blocks: nextBlocks
12599
+ };
12600
+ const refs = getSurfaceCanonicalBlockRefs(previousSurface);
12601
+ if (refs) {
12602
+ const nextRefs = [...refs];
12603
+ nextRefs[blockIndex] = state.document.content.children[blockIndex] ?? null;
12604
+ attachSurfaceCanonicalBlockRefs(nextSurface, nextRefs);
12605
+ }
12606
+ perfCounters.increment("surface.localText.patchHit");
12607
+ perfCounters.increment("surface.localText.patchDelta", delta);
12608
+ return nextSurface;
12609
+ } finally {
12610
+ perfCounters.increment("surface.localText.total.us", Math.round((performance.now() - tTotal0) * 1e3));
12611
+ }
12612
+ }
12613
+ function shiftSurfaceInlineSegment(segment, delta) {
12614
+ if (delta === 0) return segment;
12615
+ return {
12616
+ ...segment,
12617
+ from: segment.from + delta,
12618
+ to: segment.to + delta
12619
+ };
12620
+ }
12621
+ function shiftSurfaceBlock(block, delta) {
12622
+ if (delta === 0) return block;
12623
+ switch (block.kind) {
12624
+ case "paragraph":
12625
+ return {
12626
+ ...block,
12627
+ from: block.from + delta,
12628
+ to: block.to + delta,
12629
+ segments: block.segments.map((segment) => shiftSurfaceInlineSegment(segment, delta))
12630
+ };
12631
+ case "table":
12632
+ return {
12633
+ ...block,
12634
+ from: block.from + delta,
12635
+ to: block.to + delta,
12636
+ rows: block.rows.map((row2) => ({
12637
+ ...row2,
12638
+ cells: row2.cells.map((cell) => ({
12639
+ ...cell,
12640
+ content: cell.content.map((child) => shiftSurfaceBlock(child, delta))
12641
+ }))
12642
+ }))
12643
+ };
12644
+ case "sdt_block":
12645
+ return {
12646
+ ...block,
12647
+ from: block.from + delta,
12648
+ to: block.to + delta,
12649
+ children: block.children.map((child) => shiftSurfaceBlock(child, delta))
12650
+ };
12651
+ case "opaque_block":
12652
+ return {
12653
+ ...block,
12654
+ from: block.from + delta,
12655
+ to: block.to + delta
12656
+ };
12657
+ }
12658
+ }
12412
12659
  function enrichCulledPlaceholdersWithHeights(snapshot) {
12413
12660
  let heights;
12414
12661
  try {
@@ -13294,7 +13541,8 @@ function createDocumentRuntime(options) {
13294
13541
  document,
13295
13542
  target: command.editableTarget,
13296
13543
  activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
13297
- selectionDescriptor: command.selectionDescriptor
13544
+ selectionDescriptor: command.selectionDescriptor,
13545
+ editableTargetCache: editableTargetBlockCache
13298
13546
  });
13299
13547
  if (resolution.kind === "rejected") {
13300
13548
  emit({
@@ -13357,7 +13605,8 @@ function createDocumentRuntime(options) {
13357
13605
  document,
13358
13606
  surface,
13359
13607
  target,
13360
- activeStoryKey: canonicalEditableTargetStoryKey(storyTarget)
13608
+ activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
13609
+ editableTargetCache: editableTargetBlockCache
13361
13610
  });
13362
13611
  if (resolution.kind === "rejected") {
13363
13612
  emit({
@@ -13387,7 +13636,8 @@ function createDocumentRuntime(options) {
13387
13636
  document,
13388
13637
  surface,
13389
13638
  target: command.editableTarget,
13390
- activeStoryKey: canonicalEditableTargetStoryKey(storyTarget)
13639
+ activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
13640
+ editableTargetCache: editableTargetBlockCache
13391
13641
  });
13392
13642
  if (resolution.kind === "rejected") {
13393
13643
  emit({
@@ -13415,7 +13665,8 @@ function createDocumentRuntime(options) {
13415
13665
  activeStoryKey: canonicalEditableTargetStoryKey(storyTarget),
13416
13666
  commandFamilies: command.type === "field.refresh" || command.type === "toc.refresh" ? ["field"] : ["link-bookmark"],
13417
13667
  targetKinds: targetKindsForModeledCommand(command.type),
13418
- allowGeneratedPosture: true
13668
+ allowGeneratedPosture: true,
13669
+ editableTargetCache: editableTargetBlockCache
13419
13670
  });
13420
13671
  if (resolution.kind === "rejected") {
13421
13672
  emit({
@@ -13457,7 +13708,8 @@ function createDocumentRuntime(options) {
13457
13708
  baseState.selection.head,
13458
13709
  storyTarget,
13459
13710
  getFullPageGraph(),
13460
- command.options
13711
+ command.options,
13712
+ command.editableTarget
13461
13713
  );
13462
13714
  if (!refreshed2.changed) return null;
13463
13715
  cachedFieldSnapshotEntry = null;
@@ -13499,6 +13751,9 @@ function createDocumentRuntime(options) {
13499
13751
  );
13500
13752
  }
13501
13753
  const runtime = {
13754
+ getEditableTargetCache() {
13755
+ return editableTargetBlockCache;
13756
+ },
13502
13757
  subscribe(listener) {
13503
13758
  listeners.add(listener);
13504
13759
  return () => {
@@ -15702,6 +15957,12 @@ function createDocumentRuntime(options) {
15702
15957
  }
15703
15958
  return !effects.commentAdded && !effects.commentResolved && !effects.commentReopened && !effects.commentReplyAdded && !effects.commentBodyEdited && !effects.changeAccepted && !effects.changeRejected && !effects.revisionAuthored && !effects.commandBlocked;
15704
15959
  }
15960
+ function canSkipOverlaySyncForLocalText(transaction) {
15961
+ if (transaction.mapping.steps.length !== 1) return false;
15962
+ if (transaction.mapping.metadata?.invalidatesStructures) return false;
15963
+ if (transaction.mapping.metadata?.scopeTagTouches) return false;
15964
+ return getLocalTextPatchMetadata(transaction.mapping) !== null;
15965
+ }
15705
15966
  function applyTransactionToState(transaction, options2 = {}) {
15706
15967
  const effects = transaction.effects;
15707
15968
  const selectionUnchanged = transaction.nextState.selection === state.selection;
@@ -15723,9 +15984,28 @@ function createDocumentRuntime(options) {
15723
15984
  state = finalizeState(transaction.nextState, transaction.markDirty, clock());
15724
15985
  perfCounters.increment("commit.finalizeState.us", Math.round((performance.now() - tFinalize0) * 1e3));
15725
15986
  storySelections.set(storyTargetKey(activeStory), state.selection);
15987
+ const tClassify0 = performance.now();
15988
+ const useLocalTextCommitSnapshot = options2.allowLocalTextFastPath === true && shouldUseLocalTextCommitSnapshot(
15989
+ previous,
15990
+ state,
15991
+ transaction,
15992
+ transaction.effects
15993
+ );
15994
+ perfCounters.increment("commit.refreshClassify.us", Math.round((performance.now() - tClassify0) * 1e3));
15726
15995
  const tOverlay0 = performance.now();
15727
- overlayStore.replaceOverlay(overlayStore.getOverlay(), state.document);
15728
- const detachedWorkflowScopeWarnings = syncDetachedWorkflowScopeWarningsInState();
15996
+ const skipOverlaySync = useLocalTextCommitSnapshot && canSkipOverlaySyncForLocalText(transaction);
15997
+ const detachedWorkflowScopeWarnings = skipOverlaySync ? { added: [], cleared: [] } : (() => {
15998
+ const tReplace0 = performance.now();
15999
+ overlayStore.replaceOverlay(overlayStore.getOverlay(), state.document);
16000
+ perfCounters.increment("commit.overlaySync.replaceOverlay.us", Math.round((performance.now() - tReplace0) * 1e3));
16001
+ const tWarnings0 = performance.now();
16002
+ const result = syncDetachedWorkflowScopeWarningsInState();
16003
+ perfCounters.increment("commit.overlaySync.detachedWarnings.us", Math.round((performance.now() - tWarnings0) * 1e3));
16004
+ return result;
16005
+ })();
16006
+ if (skipOverlaySync) {
16007
+ perfCounters.increment("commit.overlaySync.skipped");
16008
+ }
15729
16009
  perfCounters.increment("commit.overlaySync.us", Math.round((performance.now() - tOverlay0) * 1e3));
15730
16010
  const tInvalidate0 = performance.now();
15731
16011
  if (transaction.markDirty && transaction.mapping.steps.length > 0) {
@@ -15759,22 +16039,34 @@ function createDocumentRuntime(options) {
15759
16039
  ...detachedWorkflowScopeWarnings.cleared
15760
16040
  ]
15761
16041
  };
15762
- const tClassify0 = performance.now();
15763
- const useLocalTextCommitSnapshot = options2.allowLocalTextFastPath === true && shouldUseLocalTextCommitSnapshot(
15764
- previous,
15765
- state,
15766
- transaction,
15767
- notifyEffects
15768
- );
15769
- perfCounters.increment("commit.refreshClassify.us", Math.round((performance.now() - tClassify0) * 1e3));
15770
16042
  if (!useLocalTextCommitSnapshot && transaction.markDirty && previous.document !== state.document) {
15771
16043
  applyViewportRanges(getSelectionCorridorViewportRanges(cachedRenderSnapshot.surface));
15772
16044
  }
15773
16045
  const tValidation0 = performance.now();
15774
- const surfaceForValidation = useLocalTextCommitSnapshot ? getCachedSurface(state.document, activeStory, {
15775
- viewportBlockRangesOverride: getSelectionCorridorViewportRanges(cachedRenderSnapshot.surface),
15776
- enrichCulledPlaceholders: false
15777
- }) : getCachedSurface(state.document, activeStory);
16046
+ const patchedLocalTextSurface = useLocalTextCommitSnapshot ? tryPatchLocalTextSurface(cachedRenderSnapshot.surface, transaction.mapping) : null;
16047
+ if (patchedLocalTextSurface) {
16048
+ cachePatchedLocalTextSurface(patchedLocalTextSurface);
16049
+ perfCounters.increment("commit.localTextValidation.storySizeOnly");
16050
+ }
16051
+ const localTextViewportRanges = useLocalTextCommitSnapshot && !patchedLocalTextSurface ? getSelectionCorridorViewportRanges(cachedRenderSnapshot.surface) : void 0;
16052
+ const localTextEditableTargetsByBlockPath = useLocalTextCommitSnapshot && !patchedLocalTextSurface ? getEditableTargetsByBlockPathForRanges(
16053
+ state.document,
16054
+ storyTargetKey(activeStory),
16055
+ localTextViewportRanges ?? null
16056
+ ) : void 0;
16057
+ const surfaceForValidation = patchedLocalTextSurface ? patchedLocalTextSurface : useLocalTextCommitSnapshot ? (() => {
16058
+ const tSurface0 = performance.now();
16059
+ try {
16060
+ perfCounters.increment("surface.localText.fullProjectionFallback");
16061
+ return getCachedSurface(state.document, activeStory, {
16062
+ viewportBlockRangesOverride: localTextViewportRanges,
16063
+ enrichCulledPlaceholders: false,
16064
+ editableTargetsByBlockPathOverride: localTextEditableTargetsByBlockPath
16065
+ });
16066
+ } finally {
16067
+ perfCounters.increment("surface.localText.fullProjection.us", Math.round((performance.now() - tSurface0) * 1e3));
16068
+ }
16069
+ })() : getCachedSurface(state.document, activeStory);
15778
16070
  const validationOptions = state.selection.activeRange.kind === "node" ? {
15779
16071
  isValidNodeTarget: createSurfaceNodeSelectionProbe(surfaceForValidation)
15780
16072
  } : void 0;
@@ -16041,7 +16333,8 @@ function createDocumentRuntime(options) {
16041
16333
  selection,
16042
16334
  surface: cachedRenderSnapshot.surface?.blocks ?? [],
16043
16335
  target: editableTarget,
16044
- activeStoryKey: canonicalEditableTargetStoryKey(activeStory)
16336
+ activeStoryKey: canonicalEditableTargetStoryKey(activeStory),
16337
+ editableTargetCache: editableTargetBlockCache
16045
16338
  }) : null;
16046
16339
  if (targetResolution?.kind === "rejected") {
16047
16340
  const blockedReason = targetResolution.blockedReason;
@@ -16093,6 +16386,7 @@ function createDocumentRuntime(options) {
16093
16386
  documentMode: textOptions.documentModeOverride ?? workflowCoordinator.getEffectiveDocumentMode(selection),
16094
16387
  defaultAuthorId: defaultAuthorId ?? void 0,
16095
16388
  renderSnapshot: cachedRenderSnapshot,
16389
+ activeStorySize: cachedRenderSnapshot.surface?.storySize,
16096
16390
  textTarget,
16097
16391
  rejectTargetlessTableStructureInsert: true
16098
16392
  };
@@ -17507,15 +17801,12 @@ function flattenInlineDisplayText(children) {
17507
17801
  }
17508
17802
  }).join("");
17509
17803
  }
17510
- function refreshDocumentFields(document, selectionHead, activeStory, pageGraph, options) {
17804
+ function refreshDocumentFields(document, selectionHead, activeStory, pageGraph, options, target) {
17511
17805
  const supportedOnly = options?.supportedOnly ?? true;
17512
17806
  const bookmarkMap = buildBookmarkNameMap(document);
17513
17807
  const paragraphs = collectParagraphContexts(document.content.children);
17514
- const activePageIndex = resolveActivePageIndexFromPageGraph(
17515
- pageGraph,
17516
- selectionHead,
17517
- activeStory
17518
- );
17808
+ void selectionHead;
17809
+ void activeStory;
17519
17810
  let updatedCount = 0;
17520
17811
  let changed = false;
17521
17812
  let changedFrom;
@@ -17525,19 +17816,27 @@ function refreshDocumentFields(document, selectionHead, activeStory, pageGraph,
17525
17816
  let storyChangedFrom;
17526
17817
  let storyChangedTo;
17527
17818
  const refreshed = refreshBlocksWithCursor(blocks, (field, range) => {
17819
+ if (target !== void 0 && !fieldMatchesRefreshTarget(field, target)) {
17820
+ return field;
17821
+ }
17528
17822
  if (!field.fieldFamily || !isSupportedFieldFamily(field.fieldFamily)) {
17529
17823
  return field;
17530
17824
  }
17531
17825
  if (supportedOnly && field.fieldFamily === "TOC") {
17532
17826
  return field;
17533
17827
  }
17828
+ const fieldPageIndex = resolveActivePageIndexFromPageGraph(
17829
+ pageGraph,
17830
+ range.from,
17831
+ storyTarget
17832
+ );
17534
17833
  const display = resolveSupportedFieldDisplay(
17535
17834
  field,
17536
17835
  document,
17537
17836
  bookmarkMap,
17538
17837
  paragraphs,
17539
17838
  pageGraph,
17540
- activePageIndex,
17839
+ fieldPageIndex,
17541
17840
  storyTarget
17542
17841
  );
17543
17842
  if (!display) {
@@ -17687,6 +17986,34 @@ function refreshDocumentFields(document, selectionHead, activeStory, pageGraph,
17687
17986
  ...protectionSelection ? { protectionSelection } : {}
17688
17987
  };
17689
17988
  }
17989
+ function fieldMatchesRefreshTarget(field, target) {
17990
+ if (target.kind !== "field-result-text" && target.kind !== "field-region-refresh") {
17991
+ return false;
17992
+ }
17993
+ const targetField = target.field;
17994
+ if (targetField?.canonicalFieldId !== void 0) {
17995
+ return field.canonicalFieldId === targetField.canonicalFieldId;
17996
+ }
17997
+ const resultText = flattenInlineDisplayText(field.children);
17998
+ const fieldResultHash = sha256TextHex(`${field.instruction}\0${resultText}`);
17999
+ if (target.kind === "field-result-text" && target.staleCheck.targetHash !== void 0) {
18000
+ return target.staleCheck.targetHash === fieldResultHash;
18001
+ }
18002
+ if (targetField?.fieldFamily !== void 0 && targetField.fieldFamily !== field.fieldFamily) {
18003
+ return false;
18004
+ }
18005
+ if (targetField?.fieldTarget !== void 0 && targetField.fieldTarget !== field.fieldTarget) {
18006
+ return false;
18007
+ }
18008
+ if (target.staleCheck.sourceRef !== void 0 || target.sourceRef !== void 0) {
18009
+ return sourceRefsEqual(target.staleCheck.sourceRef ?? target.sourceRef, field.sourceRef);
18010
+ }
18011
+ return false;
18012
+ }
18013
+ function sourceRefsEqual(left, right) {
18014
+ if (left === void 0 || right === void 0) return false;
18015
+ return left.sourceId === right.sourceId && left.partPath === right.partPath && left.storyKind === right.storyKind && left.element === right.element && left.xmlPath === right.xmlPath && left.tableCellPath === right.tableCellPath && left.tableDepth === right.tableDepth && left.ordinal === right.ordinal && left.startOffset === right.startOffset && left.endOffset === right.endOffset;
18016
+ }
17690
18017
  function refreshDocumentTableOfContents(document, selectionHead, activeStory, options, resolveDisplayPageNumber, navigationSnapshot) {
17691
18018
  const selectedRegion = selectTocRegion(document.fieldRegistry?.tocRegions, options?.tocId);
17692
18019
  const refreshMode = options?.mode ?? "regenerate";