@beyondwork/docx-react-component 1.0.124 → 1.0.125

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 (101) hide show
  1. package/dist/api/public-types.cjs +147 -35
  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 +791 -101
  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-CG2TgAzj.d.cts → canonical-document-CXCFCbAz.d.cts} +2 -0
  10. package/dist/{canonical-document-CG2TgAzj.d.ts → canonical-document-CXCFCbAz.d.ts} +2 -0
  11. package/dist/{chunk-PFYUJU3Q.js → chunk-2QL5DAKF.js} +98 -43
  12. package/dist/{chunk-4IPEZYQX.js → chunk-4EENH4FG.js} +1 -1
  13. package/dist/{chunk-BOHHIVQ2.js → chunk-4G3OS2H6.js} +3 -3
  14. package/dist/{chunk-A74Y5NE4.js → chunk-4YJVRIUB.js} +52 -21
  15. package/dist/{chunk-FNWKE74J.js → chunk-5DGKFNQT.js} +5 -1
  16. package/dist/{chunk-RSYN6FTS.js → chunk-6F5QW44A.js} +2 -2
  17. package/dist/{chunk-KOHQFZMM.js → chunk-BYSRJ4FE.js} +1 -1
  18. package/dist/{chunk-H6IL5ABU.js → chunk-CXSYRB37.js} +64 -20
  19. package/dist/{chunk-32ZAOQ54.js → chunk-D5HYZQTG.js} +1 -1
  20. package/dist/{chunk-TY4DIJO3.js → chunk-ESJ2MES5.js} +1 -1
  21. package/dist/{chunk-ZMRO6P3A.js → chunk-JN444Z5S.js} +505 -44
  22. package/dist/{chunk-IR7QV2BX.js → chunk-KV435YXO.js} +2 -2
  23. package/dist/{chunk-N4VIXI2Z.js → chunk-MWSBGJQO.js} +137 -18
  24. package/dist/{chunk-Q76XPPTA.js → chunk-OHTK7F3F.js} +96 -13
  25. package/dist/{chunk-MPH4ZQS4.js → chunk-QT3LX4FA.js} +321 -51
  26. package/dist/{chunk-7PC6XUNO.js → chunk-TQDQU2E3.js} +2 -2
  27. package/dist/{chunk-4B74ETJI.js → chunk-V6XVZFFH.js} +2 -2
  28. package/dist/{chunk-NAMAWCXN.js → chunk-YD2JE54B.js} +1 -1
  29. package/dist/{chunk-ZRHLLPSJ.js → chunk-YHZHPXDB.js} +85 -18
  30. package/dist/{chunk-HXHQA4BU.js → chunk-YIYM4ZAP.js} +1 -1
  31. package/dist/{chunk-LGWNN3L2.js → chunk-ZDOAUP3V.js} +2 -2
  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 +65 -20
  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 +65 -20
  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 -21
  49. package/dist/core/commands/text-commands.d.cts +2 -2
  50. package/dist/core/commands/text-commands.d.ts +2 -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 +1341 -193
  57. package/dist/index.d.cts +5 -5
  58. package/dist/index.d.ts +5 -5
  59. package/dist/index.js +39 -21
  60. package/dist/io/docx-session.cjs +51 -20
  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 +36 -12
  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-D9y4ZRjj.d.ts → loader-B1MxvbeV.d.ts} +3 -3
  69. package/dist/{loader-D9KCtj4m.d.cts → loader-CJXsswcd.d.cts} +3 -3
  70. package/dist/{public-types-CNnMHZM9.d.ts → public-types-BEGhv2YR.d.ts} +108 -6
  71. package/dist/{public-types-DajNGKV4.d.cts → public-types-DrhlQ5Zy.d.cts} +108 -6
  72. package/dist/public-types.cjs +147 -35
  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 +685 -98
  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-DyQGlryH.d.cts → session-Bp3zqnkS.d.cts} +3 -3
  83. package/dist/{session-DEmaOEjA.d.ts → session-xMOU_NtL.d.ts} +3 -3
  84. package/dist/session.cjs +51 -20
  85. package/dist/session.d.cts +5 -5
  86. package/dist/session.d.ts +5 -5
  87. package/dist/session.js +5 -5
  88. package/dist/tailwind.cjs +238 -73
  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-DjJNaE9c.d.ts → types-BFT8536T.d.ts} +2 -2
  93. package/dist/{types-CxE1aZiv.d.cts → types-DDPxEygX.d.cts} +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.cjs +238 -73
  98. package/dist/ui-tailwind.d.cts +3 -3
  99. package/dist/ui-tailwind.d.ts +3 -3
  100. package/dist/ui-tailwind.js +7 -7
  101. package/package.json +1 -1
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-M6XR534O.js";
12
12
  import {
13
13
  buildBookmarkNameMap
14
- } from "./chunk-NAMAWCXN.js";
14
+ } from "./chunk-YD2JE54B.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-BOHHIVQ2.js";
25
+ } from "./chunk-4G3OS2H6.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-RSYN6FTS.js";
35
+ } from "./chunk-6F5QW44A.js";
36
36
  import {
37
37
  applyTextTransaction
38
- } from "./chunk-IR7QV2BX.js";
38
+ } from "./chunk-KV435YXO.js";
39
39
  import {
40
40
  applyTableStructureOperationForEditableTarget,
41
41
  removeCellFromRow,
42
42
  removeTableRowPure
43
- } from "./chunk-LGWNN3L2.js";
43
+ } from "./chunk-ZDOAUP3V.js";
44
44
  import {
45
45
  resolveParagraphScope
46
- } from "./chunk-KOHQFZMM.js";
46
+ } from "./chunk-BYSRJ4FE.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-N4VIXI2Z.js";
54
+ } from "./chunk-MWSBGJQO.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-Q76XPPTA.js";
77
+ } from "./chunk-OHTK7F3F.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-ZRHLLPSJ.js";
112
+ } from "./chunk-YHZHPXDB.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-H6IL5ABU.js";
131
+ } from "./chunk-CXSYRB37.js";
132
132
  import {
133
133
  createCommentSidebarProjection,
134
134
  createCommentStoreFromRuntimeComments
@@ -152,12 +152,12 @@ import {
152
152
  persistedSnapshotFromEditorSessionState,
153
153
  remapRevisionStore,
154
154
  setRevisionStatus
155
- } from "./chunk-TY4DIJO3.js";
155
+ } from "./chunk-ESJ2MES5.js";
156
156
  import {
157
157
  isSupportedFieldFamily,
158
158
  parseTocLevelRange,
159
159
  resolveRefFieldText
160
- } from "./chunk-A74Y5NE4.js";
160
+ } from "./chunk-4YJVRIUB.js";
161
161
  import {
162
162
  collectEditableTargetRefs,
163
163
  collectEditableTargetRefsForStoryBlockRanges,
@@ -165,7 +165,7 @@ import {
165
165
  createEditableTargetBlockCache,
166
166
  createHeaderFooterStoryKey,
167
167
  sha256TextHex
168
- } from "./chunk-FNWKE74J.js";
168
+ } from "./chunk-5DGKFNQT.js";
169
169
  import {
170
170
  setActiveSerializeTelemetryBus
171
171
  } from "./chunk-EB6M3GE6.js";
@@ -1602,7 +1602,7 @@ function validateResult(result, context) {
1602
1602
  return { ...result, selection: validated };
1603
1603
  }
1604
1604
  function getPostMutationMaxOffset(result, context) {
1605
- if (typeof context.activeStorySize !== "number" || context.textTarget?.kind === "text-leaf") {
1605
+ if (typeof context.activeStorySize !== "number" || isTargetLocalTextLeaf(context.textTarget)) {
1606
1606
  return result.storyText.length;
1607
1607
  }
1608
1608
  let storySize = context.activeStorySize;
@@ -1611,6 +1611,9 @@ function getPostMutationMaxOffset(result, context) {
1611
1611
  }
1612
1612
  return Math.max(result.storyText.length, storySize);
1613
1613
  }
1614
+ function isTargetLocalTextLeaf(textTarget) {
1615
+ return textTarget?.kind === "text-leaf" && textTarget.blockPath.includes("/txbx/");
1616
+ }
1614
1617
  var editLayer = {
1615
1618
  applyTextInsert(doc, selection, text, context, formatting) {
1616
1619
  return validateResult(insertText(doc, selection, text, context, formatting), context);
@@ -8731,6 +8734,16 @@ function createLayoutFacet(input) {
8731
8734
  function currentGraph() {
8732
8735
  return engine.getPageGraph(getQueryInput());
8733
8736
  }
8737
+ function fullGraphForViewportIndependentReads() {
8738
+ const query = getQueryInput();
8739
+ if (!query.viewportPageWindow) {
8740
+ return engine.getPageGraph(query);
8741
+ }
8742
+ return engine.getPageGraph({
8743
+ document: query.document,
8744
+ ...query.viewState ? { viewState: query.viewState } : {}
8745
+ });
8746
+ }
8734
8747
  function currentMapper() {
8735
8748
  return engine.getFragmentMapper(getQueryInput());
8736
8749
  }
@@ -8868,7 +8881,7 @@ function createLayoutFacet(input) {
8868
8881
  return graph.sections.map((section) => toPublicSectionNode(graph, section.index)).filter((node) => node !== null);
8869
8882
  },
8870
8883
  getPageForOffset(offset, story) {
8871
- const graph = currentGraph();
8884
+ const graph = fullGraphForViewportIndependentReads();
8872
8885
  const page = findPageForOffsetAndStory(graph, offset, story);
8873
8886
  return page ? toPublicPageNode(page, graph) : null;
8874
8887
  },
@@ -9180,7 +9193,7 @@ function createLayoutFacet(input) {
9180
9193
  return null;
9181
9194
  },
9182
9195
  getBlockHeightsTwips() {
9183
- const graph = currentGraph();
9196
+ const graph = fullGraphForViewportIndependentReads();
9184
9197
  if (blockHeightsCache.revision === graph.revision && blockHeightsCache.map) {
9185
9198
  return blockHeightsCache.map;
9186
9199
  }
@@ -11971,6 +11984,8 @@ function mapLocalSelectionOnRemoteReplay(selection, mapping) {
11971
11984
 
11972
11985
  // src/runtime/document-runtime.ts
11973
11986
  var CANONICAL_BLOCK_REFS_SYMBOL = /* @__PURE__ */ Symbol.for("wre.canonical-block-refs");
11987
+ var LOCAL_TEXT_PATCH_MAX_SHIFTED_SURFACE_NODES = 5e3;
11988
+ var LOCAL_TEXT_PATCH_MAX_SHIFTED_NODES_PER_BLOCK = 256;
11974
11989
  function getLocalTextPatchMetadata(mapping) {
11975
11990
  const metadata = mapping.metadata?.localTextPatch;
11976
11991
  if (!metadata || typeof metadata !== "object") {
@@ -12143,8 +12158,10 @@ function createDocumentRuntime(options) {
12143
12158
  void upgradeMeasurementProvider(layoutEngine, fontLoader);
12144
12159
  let renderKernelRef = null;
12145
12160
  let runtimeRef = null;
12161
+ const normalizedInitialSurfaceViewportRanges = options.initialSurfaceViewportBlockRanges && options.initialSurfaceViewportBlockRanges.length > 0 ? normalizeViewportRanges(options.initialSurfaceViewportBlockRanges) : null;
12162
+ let initialSurfaceViewportBlockRanges = normalizedInitialSurfaceViewportRanges && normalizedInitialSurfaceViewportRanges.length > 0 ? normalizedInitialSurfaceViewportRanges : null;
12146
12163
  let viewportBlockRanges = null;
12147
- let viewportRangesKey = serializeViewportRanges(null);
12164
+ let viewportRangesKey = serializeViewportRanges(viewportBlockRanges);
12148
12165
  let viewportBlocksPerPageEstimate = null;
12149
12166
  const EDITING_CORRIDOR_BLOCK_RADIUS = 8;
12150
12167
  const getRuntimeForLayoutFacet = () => {
@@ -12384,10 +12401,11 @@ function createDocumentRuntime(options) {
12384
12401
  const cachedContextAnalyticsSnapshots = /* @__PURE__ */ new Map();
12385
12402
  let lastEmittedContextAnalyticsSnapshots;
12386
12403
  function getCachedFullSurface(document, nextActiveStory) {
12387
- const activeStoryKey = storyTargetKey(nextActiveStory);
12388
- if (cachedFullSurface && cachedFullSurface.content === document.content && cachedFullSurface.subParts === document.subParts && cachedFullSurface.styles === document.styles && cachedFullSurface.numbering === document.numbering && cachedFullSurface.media === document.media && cachedFullSurface.preservation === document.preservation && cachedFullSurface.review === document.review && cachedFullSurface.effectiveMarkupModeProvider === effectiveMarkupModeProvider && cachedFullSurface.activeStoryKey === activeStoryKey) {
12389
- return cachedFullSurface.snapshot;
12404
+ const cached = getReusableCachedFullSurface(document, nextActiveStory);
12405
+ if (cached) {
12406
+ return cached;
12390
12407
  }
12408
+ const activeStoryKey = storyTargetKey(nextActiveStory);
12391
12409
  const snapshot = createEditorSurfaceSnapshot(document, state.selection, nextActiveStory, {
12392
12410
  viewportBlockRanges: null,
12393
12411
  editableTargetsByBlockPath: getEditableTargetsByBlockPath(document),
@@ -12409,6 +12427,13 @@ function createDocumentRuntime(options) {
12409
12427
  };
12410
12428
  return snapshot;
12411
12429
  }
12430
+ function getReusableCachedFullSurface(document, nextActiveStory) {
12431
+ const activeStoryKey = storyTargetKey(nextActiveStory);
12432
+ if (cachedFullSurface && cachedFullSurface.content === document.content && cachedFullSurface.subParts === document.subParts && cachedFullSurface.styles === document.styles && cachedFullSurface.numbering === document.numbering && cachedFullSurface.media === document.media && cachedFullSurface.preservation === document.preservation && cachedFullSurface.review === document.review && cachedFullSurface.effectiveMarkupModeProvider === effectiveMarkupModeProvider && cachedFullSurface.activeStoryKey === activeStoryKey) {
12433
+ return cachedFullSurface.snapshot;
12434
+ }
12435
+ return void 0;
12436
+ }
12412
12437
  function getCachedSurface(document, nextActiveStory, options2 = {}) {
12413
12438
  const activeStoryKey = storyTargetKey(nextActiveStory);
12414
12439
  const surfaceViewportRanges = "viewportBlockRangesOverride" in options2 ? options2.viewportBlockRangesOverride ?? null : viewportBlockRanges;
@@ -12419,12 +12444,20 @@ function createDocumentRuntime(options) {
12419
12444
  }
12420
12445
  const snapshot = createEditorSurfaceSnapshot(document, state.selection, nextActiveStory, {
12421
12446
  viewportBlockRanges: surfaceViewportRanges,
12422
- editableTargetsByBlockPath: options2.editableTargetsByBlockPathOverride ?? getEditableTargetsByBlockPath(document),
12447
+ editableTargetsByBlockPath: options2.editableTargetsByBlockPathOverride ?? getEditableTargetsByBlockPathForRanges(
12448
+ document,
12449
+ activeStoryKey,
12450
+ surfaceViewportRanges
12451
+ ),
12423
12452
  ...effectiveMarkupModeProvider ? { getEffectiveMarkupMode: effectiveMarkupModeProvider } : {}
12424
12453
  });
12425
12454
  recordPerfSample("snapshot.surface");
12426
12455
  incrementInvalidationCounter("runtime.snapshot.surfaceMisses");
12427
- const enrichedSnapshot = options2.enrichCulledPlaceholders === false ? snapshot : enrichCulledPlaceholdersWithHeights(snapshot);
12456
+ const enrichedSnapshot = options2.enrichCulledPlaceholders === false ? snapshot : enrichCulledPlaceholdersWithHeights(
12457
+ snapshot,
12458
+ document,
12459
+ nextActiveStory
12460
+ );
12428
12461
  if (surfaceViewportRanges === null) {
12429
12462
  cachedFullSurface = {
12430
12463
  content: document.content,
@@ -12482,7 +12515,7 @@ function createDocumentRuntime(options) {
12482
12515
  }
12483
12516
  return -1;
12484
12517
  }
12485
- function cachePatchedLocalTextSurface(surface) {
12518
+ function cachePatchedLocalTextSurface(surface, fullSurfaceForCache) {
12486
12519
  const activeStoryKey = storyTargetKey(activeStory);
12487
12520
  const rangesKey = serializeViewportRanges(surface.viewportBlockRanges);
12488
12521
  cachedSurface = {
@@ -12498,7 +12531,8 @@ function createDocumentRuntime(options) {
12498
12531
  viewportRangesKey: rangesKey,
12499
12532
  snapshot: surface
12500
12533
  };
12501
- if (surface.viewportBlockRanges === null) {
12534
+ const fullSurface = fullSurfaceForCache ?? (surface.viewportBlockRanges === null ? surface : void 0);
12535
+ if (fullSurface) {
12502
12536
  cachedFullSurface = {
12503
12537
  content: state.document.content,
12504
12538
  subParts: state.document.subParts,
@@ -12509,11 +12543,15 @@ function createDocumentRuntime(options) {
12509
12543
  review: state.document.review,
12510
12544
  effectiveMarkupModeProvider,
12511
12545
  activeStoryKey,
12512
- snapshot: surface
12546
+ snapshot: fullSurface
12513
12547
  };
12514
12548
  }
12515
12549
  cachedSurfaceFingerprint = `${activeStoryKey}|${rangesKey}|${String(state.selection.anchor)}:${String(state.selection.head)}`;
12516
12550
  }
12551
+ function createLocalTextCorridorSurfaceFromFullSurface(fullSurface) {
12552
+ const ranges = getSelectionCorridorViewportRanges(fullSurface);
12553
+ return ranges ? createViewportCulledSurfaceFromFullSurface(fullSurface, ranges) : fullSurface;
12554
+ }
12517
12555
  function tryPatchLocalTextSurface(previousSurface, mapping) {
12518
12556
  const tTotal0 = performance.now();
12519
12557
  try {
@@ -12549,6 +12587,13 @@ function createDocumentRuntime(options) {
12549
12587
  perfCounters.increment("surface.localText.patchMiss");
12550
12588
  return null;
12551
12589
  }
12590
+ const shiftBudget = estimateLocalTextPatchShiftBudget(previousSurface.blocks, blockIndex + 1);
12591
+ perfCounters.increment("surface.localText.shiftedBlocks", shiftBudget.shiftedBlocks);
12592
+ perfCounters.increment("surface.localText.shiftedNodes", shiftBudget.shiftedNodes);
12593
+ if (!shiftBudget.withinBudget) {
12594
+ perfCounters.increment("surface.localText.patchBudgetFallback");
12595
+ return null;
12596
+ }
12552
12597
  const segmentIndex = block.segments.findIndex(
12553
12598
  (segment2) => segment2.kind === "text" && editFrom >= segment2.from && editTo <= segment2.to
12554
12599
  );
@@ -12656,7 +12701,83 @@ function createDocumentRuntime(options) {
12656
12701
  };
12657
12702
  }
12658
12703
  }
12659
- function enrichCulledPlaceholdersWithHeights(snapshot) {
12704
+ function estimateLocalTextPatchShiftBudget(blocks, startIndex) {
12705
+ const shiftedBlocks = Math.max(0, blocks.length - startIndex);
12706
+ let shiftedNodes = 0;
12707
+ for (let index = startIndex; index < blocks.length; index += 1) {
12708
+ const shiftedBlockNodes = countSurfaceShiftNodesUpTo(
12709
+ blocks[index],
12710
+ Math.min(
12711
+ LOCAL_TEXT_PATCH_MAX_SHIFTED_NODES_PER_BLOCK,
12712
+ LOCAL_TEXT_PATCH_MAX_SHIFTED_SURFACE_NODES - shiftedNodes
12713
+ ) + 1
12714
+ );
12715
+ shiftedNodes += shiftedBlockNodes;
12716
+ if (shiftedBlockNodes > LOCAL_TEXT_PATCH_MAX_SHIFTED_NODES_PER_BLOCK) {
12717
+ return {
12718
+ shiftedBlocks,
12719
+ shiftedNodes,
12720
+ withinBudget: false
12721
+ };
12722
+ }
12723
+ if (shiftedNodes > LOCAL_TEXT_PATCH_MAX_SHIFTED_SURFACE_NODES) {
12724
+ return {
12725
+ shiftedBlocks,
12726
+ shiftedNodes,
12727
+ withinBudget: false
12728
+ };
12729
+ }
12730
+ }
12731
+ return {
12732
+ shiftedBlocks,
12733
+ shiftedNodes,
12734
+ withinBudget: true
12735
+ };
12736
+ }
12737
+ function countSurfaceShiftNodesUpTo(block, limit) {
12738
+ if (limit <= 0) {
12739
+ return 1;
12740
+ }
12741
+ switch (block.kind) {
12742
+ case "paragraph":
12743
+ return 1 + block.segments.length;
12744
+ case "opaque_block":
12745
+ return 1;
12746
+ case "sdt_block": {
12747
+ let total = 1;
12748
+ for (const child of block.children) {
12749
+ total += countSurfaceShiftNodesUpTo(child, limit - total);
12750
+ if (total > limit) {
12751
+ return total;
12752
+ }
12753
+ }
12754
+ return total;
12755
+ }
12756
+ case "table": {
12757
+ let total = 1;
12758
+ for (const row2 of block.rows) {
12759
+ total += 1;
12760
+ if (total > limit) {
12761
+ return total;
12762
+ }
12763
+ for (const cell of row2.cells) {
12764
+ total += 1;
12765
+ if (total > limit) {
12766
+ return total;
12767
+ }
12768
+ for (const child of cell.content) {
12769
+ total += countSurfaceShiftNodesUpTo(child, limit - total);
12770
+ if (total > limit) {
12771
+ return total;
12772
+ }
12773
+ }
12774
+ }
12775
+ }
12776
+ return total;
12777
+ }
12778
+ }
12779
+ }
12780
+ function enrichCulledPlaceholdersWithHeights(snapshot, document, nextActiveStory, fullSurfaceForPlaceholders) {
12660
12781
  let heights;
12661
12782
  try {
12662
12783
  heights = layoutFacet.getBlockHeightsTwips();
@@ -12664,17 +12785,19 @@ function createDocumentRuntime(options) {
12664
12785
  return snapshot;
12665
12786
  }
12666
12787
  if (heights.size === 0) return snapshot;
12788
+ const fullSurface = fullSurfaceForPlaceholders ?? getReusableCachedFullSurface(document, nextActiveStory);
12789
+ if (!fullSurface) return snapshot;
12667
12790
  let changed = false;
12668
12791
  const enrichedBlocks = snapshot.blocks.map((block) => {
12669
12792
  if (block.kind !== "opaque_block" || block.state !== "placeholder-culled") {
12670
12793
  return block;
12671
12794
  }
12672
- const realBlockIdFromOffset = resolveBlockIdFromRuntimeOffset(
12673
- layoutFacet,
12674
- block.from
12795
+ const realBlock = resolveFullSurfaceBlockForPlaceholder(
12796
+ fullSurface,
12797
+ block
12675
12798
  );
12676
- if (!realBlockIdFromOffset) return block;
12677
- const heightTwips = heights.get(realBlockIdFromOffset);
12799
+ if (!realBlock) return block;
12800
+ const heightTwips = heights.get(realBlock.blockId);
12678
12801
  if (typeof heightTwips !== "number" || heightTwips <= 0) return block;
12679
12802
  changed = true;
12680
12803
  return { ...block, placeholderHeightTwips: heightTwips };
@@ -12682,13 +12805,20 @@ function createDocumentRuntime(options) {
12682
12805
  if (!changed) return snapshot;
12683
12806
  return { ...snapshot, blocks: enrichedBlocks };
12684
12807
  }
12685
- function resolveBlockIdFromRuntimeOffset(facet, runtimeOffset) {
12686
- try {
12687
- const frag = facet.getFragmentForOffset?.(runtimeOffset);
12688
- return frag?.blockId ?? null;
12689
- } catch {
12690
- return null;
12808
+ function resolveFullSurfaceBlockForPlaceholder(fullSurface, placeholder) {
12809
+ const index = parsePlaceholderCulledIndex(placeholder.blockId);
12810
+ if (index !== null) {
12811
+ return fullSurface.blocks[index] ?? null;
12691
12812
  }
12813
+ return fullSurface.blocks.find(
12814
+ (block) => block.from === placeholder.from && block.to === placeholder.to
12815
+ ) ?? null;
12816
+ }
12817
+ function parsePlaceholderCulledIndex(blockId) {
12818
+ const match = /^placeholder-culled-(\d+)$/.exec(blockId);
12819
+ if (!match) return null;
12820
+ const index = Number(match[1]);
12821
+ return Number.isSafeInteger(index) ? index : null;
12692
12822
  }
12693
12823
  function getCachedFieldSnapshot(document) {
12694
12824
  const blockCount = document.content.children.length;
@@ -13253,7 +13383,14 @@ function createDocumentRuntime(options) {
13253
13383
  revisionToken: state.revisionToken
13254
13384
  });
13255
13385
  perfCounters.increment("refresh.all");
13256
- const surface = timeFacet("surface", () => getCachedSurface(state.document, activeStory));
13386
+ const firstSurfaceViewportBlockRanges = initialSurfaceViewportBlockRanges;
13387
+ initialSurfaceViewportBlockRanges = null;
13388
+ const surface = timeFacet(
13389
+ "surface",
13390
+ () => firstSurfaceViewportBlockRanges ? getCachedSurface(state.document, activeStory, {
13391
+ viewportBlockRangesOverride: firstSurfaceViewportBlockRanges
13392
+ }) : getCachedSurface(state.document, activeStory)
13393
+ );
13257
13394
  const snapshot = {
13258
13395
  documentId: state.documentId,
13259
13396
  sessionId: state.sessionId,
@@ -13351,8 +13488,10 @@ function createDocumentRuntime(options) {
13351
13488
  if (options2.forceProjection) {
13352
13489
  cachedFullSurface = void 0;
13353
13490
  }
13354
- const newSurface = viewportBlockRanges !== null && options2.forceProjection !== true ? createViewportCulledSurfaceFromFullSurface(
13355
- getCachedFullSurface(state.document, activeStory),
13491
+ const reusableFullSurface = viewportBlockRanges !== null && options2.forceProjection !== true ? getReusableCachedFullSurface(state.document, activeStory) : void 0;
13492
+ const derivedFromFull = viewportBlockRanges !== null && reusableFullSurface !== void 0;
13493
+ const projectedSurface = derivedFromFull ? createViewportCulledSurfaceFromFullSurface(
13494
+ reusableFullSurface,
13356
13495
  viewportBlockRanges
13357
13496
  ) : createEditorSurfaceSnapshot(
13358
13497
  state.document,
@@ -13360,11 +13499,21 @@ function createDocumentRuntime(options) {
13360
13499
  activeStory,
13361
13500
  {
13362
13501
  viewportBlockRanges,
13363
- editableTargetsByBlockPath: getEditableTargetsByBlockPath(state.document),
13502
+ editableTargetsByBlockPath: getEditableTargetsByBlockPathForRanges(
13503
+ state.document,
13504
+ activeStoryKey,
13505
+ viewportBlockRanges
13506
+ ),
13364
13507
  ...effectiveMarkupModeProvider ? { getEffectiveMarkupMode: effectiveMarkupModeProvider } : {}
13365
13508
  }
13366
13509
  );
13367
- if (viewportBlockRanges !== null && options2.forceProjection !== true) {
13510
+ const newSurface = viewportBlockRanges !== null ? enrichCulledPlaceholdersWithHeights(
13511
+ projectedSurface,
13512
+ state.document,
13513
+ activeStory,
13514
+ reusableFullSurface
13515
+ ) : projectedSurface;
13516
+ if (derivedFromFull) {
13368
13517
  perfCounters.increment("runtime.viewport.derivedSurfaceRefreshes");
13369
13518
  } else {
13370
13519
  recordPerfSample("snapshot.surface");
@@ -14435,12 +14584,86 @@ function createDocumentRuntime(options) {
14435
14584
  }
14436
14585
  },
14437
14586
  applyScopeReplacement(plan) {
14587
+ const resolveEditableTargetHint = (hint) => {
14588
+ if (!hint) return void 0;
14589
+ const activeStoryKey = storyTargetKey(activeStory);
14590
+ if (hint.storyKey !== activeStoryKey) return null;
14591
+ const currentTargets = collectEditableTargetRefs(
14592
+ state.document,
14593
+ editableTargetBlockCache
14594
+ );
14595
+ const target = currentTargets.find(
14596
+ (target2) => target2.storyKey === hint.storyKey && target2.blockPath === hint.blockPath && target2.commandFamily === "text-leaf"
14597
+ );
14598
+ if (!target) return null;
14599
+ const fallbackTextTarget = {
14600
+ kind: "text-leaf",
14601
+ blockPath: target.blockPath,
14602
+ paragraphStart: hint.semanticBlockRange.from,
14603
+ paragraphEnd: hint.semanticBlockRange.to
14604
+ };
14605
+ const resolved = resolveEditableTextTarget({
14606
+ document: state.document,
14607
+ surface: cachedRenderSnapshot.surface?.blocks ?? [],
14608
+ target,
14609
+ activeStoryKey,
14610
+ editableTargetCache: editableTargetBlockCache
14611
+ });
14612
+ if (resolved.kind === "rejected") {
14613
+ return {
14614
+ textTarget: fallbackTextTarget,
14615
+ range: hint.semanticBlockRange
14616
+ };
14617
+ }
14618
+ return {
14619
+ target,
14620
+ textTarget: resolved.textTarget ?? fallbackTextTarget,
14621
+ range: resolved.range
14622
+ };
14623
+ };
14624
+ const mapSemanticStepRangeToEditableTarget = (stepRange, hint, editableRange) => {
14625
+ if (!hint || !editableRange) return stepRange;
14626
+ const semanticFrom = hint.semanticBlockRange.from;
14627
+ const semanticTo = hint.semanticBlockRange.to;
14628
+ const localFrom = Math.max(0, stepRange.from - semanticFrom);
14629
+ const localTo = Math.max(localFrom, stepRange.to - semanticFrom);
14630
+ const semanticLength = Math.max(0, semanticTo - semanticFrom);
14631
+ const editableLength = Math.max(0, editableRange.to - editableRange.from);
14632
+ if (semanticLength === editableLength) {
14633
+ return {
14634
+ from: editableRange.from + localFrom,
14635
+ to: editableRange.from + localTo
14636
+ };
14637
+ }
14638
+ if (stepRange.from === semanticFrom && stepRange.to === semanticTo) {
14639
+ return editableRange;
14640
+ }
14641
+ return stepRange;
14642
+ };
14438
14643
  for (const step of plan.steps) {
14439
14644
  if (step.kind === "text-replace" && step.range && typeof step.text === "string") {
14645
+ const editableTarget = resolveEditableTargetHint(step.editableTargetHint);
14646
+ if (editableTarget === null) {
14647
+ emit({
14648
+ type: "command_blocked",
14649
+ documentId: state.documentId,
14650
+ command: "applyScopeReplacement",
14651
+ reasons: [{
14652
+ code: "unsupported_surface",
14653
+ message: "Scope replacement editable target no longer resolves."
14654
+ }]
14655
+ });
14656
+ continue;
14657
+ }
14658
+ const dispatchRange = mapSemanticStepRangeToEditableTarget(
14659
+ step.range,
14660
+ step.editableTargetHint,
14661
+ editableTarget?.range
14662
+ );
14440
14663
  const anchor = {
14441
14664
  kind: "range",
14442
- from: step.range.from,
14443
- to: step.range.to,
14665
+ from: dispatchRange.from,
14666
+ to: dispatchRange.to,
14444
14667
  assoc: { start: -1, end: 1 }
14445
14668
  };
14446
14669
  const timestamp = clock();
@@ -14449,6 +14672,8 @@ function createDocumentRuntime(options) {
14449
14672
  {
14450
14673
  type: "text.insert",
14451
14674
  text: step.text,
14675
+ ...editableTarget?.target ? { editableTarget: editableTarget.target } : {},
14676
+ ...editableTarget?.textTarget ? { textTarget: editableTarget.textTarget } : {},
14452
14677
  ...step.formatting ? { formatting: step.formatting } : {},
14453
14678
  origin: createOrigin("api", timestamp)
14454
14679
  },
@@ -14486,10 +14711,28 @@ function createDocumentRuntime(options) {
14486
14711
  emitError(toRuntimeError(error));
14487
14712
  }
14488
14713
  } else if (step.kind === "text-insert-tracked" && step.range && typeof step.text === "string") {
14714
+ const editableTarget = resolveEditableTargetHint(step.editableTargetHint);
14715
+ if (editableTarget === null) {
14716
+ emit({
14717
+ type: "command_blocked",
14718
+ documentId: state.documentId,
14719
+ command: "applyScopeReplacement",
14720
+ reasons: [{
14721
+ code: "unsupported_surface",
14722
+ message: "Scope replacement editable target no longer resolves."
14723
+ }]
14724
+ });
14725
+ continue;
14726
+ }
14727
+ const dispatchRange = mapSemanticStepRangeToEditableTarget(
14728
+ step.range,
14729
+ step.editableTargetHint,
14730
+ editableTarget?.range
14731
+ );
14489
14732
  const anchor = {
14490
14733
  kind: "range",
14491
- from: step.range.from,
14492
- to: step.range.to,
14734
+ from: dispatchRange.from,
14735
+ to: dispatchRange.to,
14493
14736
  assoc: { start: -1, end: 1 }
14494
14737
  };
14495
14738
  const timestamp = clock();
@@ -14498,6 +14741,8 @@ function createDocumentRuntime(options) {
14498
14741
  {
14499
14742
  type: "text.insert",
14500
14743
  text: step.text,
14744
+ ...editableTarget?.target ? { editableTarget: editableTarget.target } : {},
14745
+ ...editableTarget?.textTarget ? { textTarget: editableTarget.textTarget } : {},
14501
14746
  ...step.formatting ? { formatting: step.formatting } : {},
14502
14747
  origin: createOrigin("api", timestamp)
14503
14748
  },
@@ -14512,10 +14757,28 @@ function createDocumentRuntime(options) {
14512
14757
  emitError(toRuntimeError(error));
14513
14758
  }
14514
14759
  } else if (step.kind === "text-delete-tracked" && step.range && step.range.to > step.range.from) {
14760
+ const editableTarget = resolveEditableTargetHint(step.editableTargetHint);
14761
+ if (editableTarget === null) {
14762
+ emit({
14763
+ type: "command_blocked",
14764
+ documentId: state.documentId,
14765
+ command: "applyScopeReplacement",
14766
+ reasons: [{
14767
+ code: "unsupported_surface",
14768
+ message: "Scope replacement editable target no longer resolves."
14769
+ }]
14770
+ });
14771
+ continue;
14772
+ }
14773
+ const dispatchRange = mapSemanticStepRangeToEditableTarget(
14774
+ step.range,
14775
+ step.editableTargetHint,
14776
+ editableTarget?.range
14777
+ );
14515
14778
  const anchor = {
14516
14779
  kind: "range",
14517
- from: step.range.from,
14518
- to: step.range.to,
14780
+ from: dispatchRange.from,
14781
+ to: dispatchRange.to,
14519
14782
  assoc: { start: -1, end: 1 }
14520
14783
  };
14521
14784
  const timestamp = clock();
@@ -14523,6 +14786,8 @@ function createDocumentRuntime(options) {
14523
14786
  applyTextCommandInActiveStory(
14524
14787
  {
14525
14788
  type: "text.delete-forward",
14789
+ ...editableTarget?.target ? { editableTarget: editableTarget.target } : {},
14790
+ ...editableTarget?.textTarget ? { textTarget: editableTarget.textTarget } : {},
14526
14791
  origin: createOrigin("api", timestamp)
14527
14792
  },
14528
14793
  {
@@ -16043,9 +16308,13 @@ function createDocumentRuntime(options) {
16043
16308
  applyViewportRanges(getSelectionCorridorViewportRanges(cachedRenderSnapshot.surface));
16044
16309
  }
16045
16310
  const tValidation0 = performance.now();
16046
- const patchedLocalTextSurface = useLocalTextCommitSnapshot ? tryPatchLocalTextSurface(cachedRenderSnapshot.surface, transaction.mapping) : null;
16311
+ const patchedFullLocalTextSurface = useLocalTextCommitSnapshot ? tryPatchLocalTextSurface(cachedRenderSnapshot.surface, transaction.mapping) : null;
16312
+ const patchedLocalTextSurface = patchedFullLocalTextSurface ? createLocalTextCorridorSurfaceFromFullSurface(patchedFullLocalTextSurface) : null;
16047
16313
  if (patchedLocalTextSurface) {
16048
- cachePatchedLocalTextSurface(patchedLocalTextSurface);
16314
+ cachePatchedLocalTextSurface(
16315
+ patchedLocalTextSurface,
16316
+ patchedFullLocalTextSurface ?? void 0
16317
+ );
16049
16318
  perfCounters.increment("commit.localTextValidation.storySizeOnly");
16050
16319
  }
16051
16320
  const localTextViewportRanges = useLocalTextCommitSnapshot && !patchedLocalTextSurface ? getSelectionCorridorViewportRanges(cachedRenderSnapshot.surface) : void 0;
@@ -16085,7 +16354,8 @@ function createDocumentRuntime(options) {
16085
16354
  cachedRenderSnapshot = useLocalTextCommitSnapshot ? refreshLocalTextCommitSnapshot(surfaceForValidation, transaction.mapping) : refreshRenderSnapshot();
16086
16355
  perfCounters.increment("commit.refresh.us", Math.round((performance.now() - tRefresh0) * 1e3));
16087
16356
  const tNotify0 = performance.now();
16088
- deferNextContextAnalyticsEmit = useLocalTextCommitSnapshot;
16357
+ const shouldDeferContextAnalyticsEmit = transaction.markDirty && transaction.mapping.steps.length > 0;
16358
+ deferNextContextAnalyticsEmit = shouldDeferContextAnalyticsEmit;
16089
16359
  try {
16090
16360
  notify(previous, state, {
16091
16361
  ...transaction,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  loadDocxSessionAsync
3
- } from "./chunk-4B74ETJI.js";
3
+ } from "./chunk-V6XVZFFH.js";
4
4
  import {
5
5
  buildCompatibilityReport,
6
6
  createLoadScheduler
7
- } from "./chunk-TY4DIJO3.js";
7
+ } from "./chunk-ESJ2MES5.js";
8
8
  import {
9
9
  decodePersistedSourcePackageBytes,
10
10
  hasValidPersistedSourcePackageDigest,