@beyondwork/docx-react-component 1.0.132 → 1.0.133

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 (94) hide show
  1. package/dist/api/public-types.cjs +158 -67
  2. package/dist/api/public-types.d.cts +1 -1
  3. package/dist/api/public-types.d.ts +1 -1
  4. package/dist/api/public-types.js +3 -3
  5. package/dist/api/v3.cjs +9326 -7478
  6. package/dist/api/v3.d.cts +2 -2
  7. package/dist/api/v3.d.ts +2 -2
  8. package/dist/api/v3.js +10 -10
  9. package/dist/{chunk-XYTWOJII.js → chunk-224TSMEB.js} +635 -89
  10. package/dist/{chunk-43JAPM2F.js → chunk-3JEE5RJU.js} +92 -131
  11. package/dist/{chunk-UP2KDOYE.js → chunk-57HTKX3P.js} +6 -2
  12. package/dist/{chunk-RYMMKOFI.js → chunk-5KTJKTNE.js} +32 -0
  13. package/dist/{chunk-LPLJZJT2.js → chunk-CVSD3UNK.js} +128 -69
  14. package/dist/{chunk-JVTDBX67.js → chunk-EFEW7BTT.js} +2 -2
  15. package/dist/{chunk-UFPBYJMA.js → chunk-INLRCC4N.js} +2 -2
  16. package/dist/{chunk-6736GA6J.js → chunk-KL4TZSZV.js} +1 -1
  17. package/dist/{chunk-N5FTU4HZ.js → chunk-MQ5GAJ54.js} +68 -39
  18. package/dist/{chunk-W2I47J2Q.js → chunk-NJFKPDNG.js} +216 -2
  19. package/dist/{chunk-YUHNDEV5.js → chunk-OTRVGNZQ.js} +2934 -1815
  20. package/dist/{chunk-4HGFJ6Z2.js → chunk-PZIEOEJZ.js} +1 -1
  21. package/dist/{chunk-C5LXKR54.js → chunk-QTRJLKR2.js} +1 -1
  22. package/dist/{chunk-SZ6BJA4Q.js → chunk-REFHJ2FN.js} +3 -3
  23. package/dist/{chunk-ZDYGRO2Z.js → chunk-RP76USJE.js} +1 -1
  24. package/dist/{chunk-QUTVR72L.js → chunk-S3PEKX6H.js} +246 -43
  25. package/dist/{chunk-RBWJHRNP.js → chunk-T66OS7MN.js} +8 -3
  26. package/dist/{chunk-ALWXYGXP.js → chunk-V2JF42SI.js} +2 -2
  27. package/dist/{chunk-6TLZ6CMP.js → chunk-WDDFU2N2.js} +2 -2
  28. package/dist/{chunk-U3UMKA7B.js → chunk-XBQFDBXE.js} +1 -1
  29. package/dist/{chunk-CDEZGLQ3.js → chunk-ZFCZ7XXH.js} +1 -1
  30. package/dist/core/commands/formatting-commands.d.cts +1 -1
  31. package/dist/core/commands/formatting-commands.d.ts +1 -1
  32. package/dist/core/commands/image-commands.cjs +32 -0
  33. package/dist/core/commands/image-commands.d.cts +1 -1
  34. package/dist/core/commands/image-commands.d.ts +1 -1
  35. package/dist/core/commands/image-commands.js +5 -5
  36. package/dist/core/commands/section-layout-commands.d.cts +1 -1
  37. package/dist/core/commands/section-layout-commands.d.ts +1 -1
  38. package/dist/core/commands/style-commands.d.cts +1 -1
  39. package/dist/core/commands/style-commands.d.ts +1 -1
  40. package/dist/core/commands/table-structure-commands.cjs +32 -0
  41. package/dist/core/commands/table-structure-commands.d.cts +1 -1
  42. package/dist/core/commands/table-structure-commands.d.ts +1 -1
  43. package/dist/core/commands/table-structure-commands.js +4 -4
  44. package/dist/core/commands/text-commands.cjs +99 -38
  45. package/dist/core/commands/text-commands.d.cts +12 -1
  46. package/dist/core/commands/text-commands.d.ts +12 -1
  47. package/dist/core/commands/text-commands.js +5 -5
  48. package/dist/core/selection/mapping.d.cts +1 -1
  49. package/dist/core/selection/mapping.d.ts +1 -1
  50. package/dist/core/state/editor-state.d.cts +1 -1
  51. package/dist/core/state/editor-state.d.ts +1 -1
  52. package/dist/index.cjs +4827 -2434
  53. package/dist/index.d.cts +4 -4
  54. package/dist/index.d.ts +4 -4
  55. package/dist/index.js +292 -53
  56. package/dist/io/docx-session.cjs +7 -2
  57. package/dist/io/docx-session.d.cts +3 -3
  58. package/dist/io/docx-session.d.ts +3 -3
  59. package/dist/io/docx-session.js +4 -4
  60. package/dist/legal.js +3 -3
  61. package/dist/{loader-MAa8VpzW.d.cts → loader-B2H99237.d.cts} +2 -2
  62. package/dist/{loader-CfpeEPAa.d.ts → loader-DfTjqVwn.d.ts} +2 -2
  63. package/dist/{public-types-Cjs8glST.d.ts → public-types-B5lOUIrP.d.ts} +689 -232
  64. package/dist/{public-types-KBS6JnOs.d.cts → public-types-S8gTYwKo.d.cts} +689 -232
  65. package/dist/public-types.cjs +158 -67
  66. package/dist/public-types.d.cts +1 -1
  67. package/dist/public-types.d.ts +1 -1
  68. package/dist/public-types.js +3 -3
  69. package/dist/runtime/collab.d.cts +2 -2
  70. package/dist/runtime/collab.d.ts +2 -2
  71. package/dist/runtime/document-runtime.cjs +1032 -416
  72. package/dist/runtime/document-runtime.d.cts +1 -1
  73. package/dist/runtime/document-runtime.d.ts +1 -1
  74. package/dist/runtime/document-runtime.js +14 -14
  75. package/dist/{session-CkoH8FoY.d.ts → session-CBDIOYXA.d.ts} +2 -2
  76. package/dist/{session-wwe0Gib-.d.cts → session-CR2A1hGZ.d.cts} +2 -2
  77. package/dist/session.cjs +7 -2
  78. package/dist/session.d.cts +4 -4
  79. package/dist/session.d.ts +4 -4
  80. package/dist/session.js +5 -5
  81. package/dist/tailwind.cjs +398 -105
  82. package/dist/tailwind.d.cts +1 -1
  83. package/dist/tailwind.d.ts +1 -1
  84. package/dist/tailwind.js +7 -7
  85. package/dist/{types-CH7NWqVL.d.ts → types-B-90ywjU.d.ts} +1 -1
  86. package/dist/{types-B3SGRW0w.d.cts → types-yty2K-hk.d.cts} +1 -1
  87. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +2 -2
  88. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +2 -2
  89. package/dist/ui-tailwind/editor-surface/search-plugin.js +4 -4
  90. package/dist/ui-tailwind.cjs +398 -105
  91. package/dist/ui-tailwind.d.cts +3 -2
  92. package/dist/ui-tailwind.d.ts +3 -2
  93. package/dist/ui-tailwind.js +7 -7
  94. package/package.json +1 -1
@@ -19,13 +19,13 @@ import {
19
19
  resolveSectionVariants,
20
20
  sectionSupportsStoryTarget,
21
21
  storyTargetKey
22
- } from "./chunk-U3UMKA7B.js";
22
+ } from "./chunk-XBQFDBXE.js";
23
23
  import {
24
24
  createSelectionSnapshot
25
25
  } from "./chunk-OYGMRRR7.js";
26
26
  import {
27
27
  collectCanonicalLayoutInputs
28
- } from "./chunk-RYMMKOFI.js";
28
+ } from "./chunk-5KTJKTNE.js";
29
29
  import {
30
30
  MAIN_STORY_TARGET,
31
31
  createDetachedAnchor,
@@ -8085,7 +8085,7 @@ function fnv1a(input) {
8085
8085
  }
8086
8086
 
8087
8087
  // src/runtime/layout/layout-engine-version.ts
8088
- var LAYOUT_ENGINE_VERSION = 93;
8088
+ var LAYOUT_ENGINE_VERSION = 94;
8089
8089
  var LAYCACHE_SCHEMA_VERSION = 13;
8090
8090
 
8091
8091
  // src/runtime/layout/layout-engine-instance.ts
@@ -8312,11 +8312,45 @@ function createLayoutEngine(options = {}) {
8312
8312
  const telemetryBus = options.telemetryBus;
8313
8313
  const dirtyFieldFamilies = /* @__PURE__ */ new Set();
8314
8314
  const listeners = /* @__PURE__ */ new Set();
8315
- let cachedKey = null;
8316
- let cachedGraph = null;
8317
- let cachedFormatting = null;
8318
- let cachedMapper = null;
8315
+ let cachedFull = null;
8316
+ let cachedWindowed = null;
8319
8317
  let previousPageCount = 0;
8318
+ function isFullViewportKey(key) {
8319
+ return key === FULL_VIEWPORT_WINDOW_KEY;
8320
+ }
8321
+ function getCachedSlot(viewportWindowKeyValue) {
8322
+ return isFullViewportKey(viewportWindowKeyValue) ? cachedFull : cachedWindowed;
8323
+ }
8324
+ function preferredCachedGraph() {
8325
+ return cachedFull?.graph ?? cachedWindowed?.graph ?? null;
8326
+ }
8327
+ function clearAllSlots() {
8328
+ cachedFull = null;
8329
+ cachedWindowed = null;
8330
+ }
8331
+ function clearWindowedSlot() {
8332
+ cachedWindowed = null;
8333
+ }
8334
+ function evictStaleSiblingSlot(freshKey) {
8335
+ const sibling = isFullViewportKey(freshKey.viewportWindowKey) ? cachedWindowed : cachedFull;
8336
+ if (sibling === null) return;
8337
+ if (sibling.key.content === freshKey.content && sibling.key.styles === freshKey.styles && sibling.key.subParts === freshKey.subParts) {
8338
+ return;
8339
+ }
8340
+ if (isFullViewportKey(freshKey.viewportWindowKey)) {
8341
+ cachedWindowed = null;
8342
+ } else {
8343
+ cachedFull = null;
8344
+ }
8345
+ }
8346
+ function commitSlot(slot) {
8347
+ if (isFullViewportKey(slot.key.viewportWindowKey)) {
8348
+ cachedFull = slot;
8349
+ } else {
8350
+ cachedWindowed = slot;
8351
+ }
8352
+ evictStaleSiblingSlot(slot.key);
8353
+ }
8320
8354
  let pendingInvalidation = null;
8321
8355
  function emit(event) {
8322
8356
  for (const listener of listeners) {
@@ -8462,27 +8496,31 @@ function createLayoutEngine(options = {}) {
8462
8496
  subParts: document2.subParts,
8463
8497
  anchors: layoutInputs.anchors
8464
8498
  });
8499
+ const priorGraphForMaterialization = preferredCachedGraph();
8465
8500
  const graph = applyViewportWindowMaterialization(
8466
8501
  measuredGraph,
8467
8502
  viewportWindow,
8468
- cachedGraph
8503
+ priorGraphForMaterialization
8469
8504
  );
8470
- const dirtyFamilies = computeFieldDirtiness(cachedGraph, graph);
8505
+ const priorGraphForFieldDirtiness = preferredCachedGraph();
8506
+ const dirtyFamilies = computeFieldDirtiness(priorGraphForFieldDirtiness, graph);
8471
8507
  for (const family of dirtyFamilies) {
8472
8508
  dirtyFieldFamilies.add(family);
8473
8509
  }
8474
8510
  const formatting = buildResolvedFormattingState(document2, mainSurface);
8475
8511
  const currentPageCount = graph.contentPageCount;
8476
8512
  const pageCountDelta = currentPageCount !== previousPageCount ? { previous: previousPageCount, current: currentPageCount } : void 0;
8477
- cachedKey = {
8478
- content: document2.content,
8479
- styles: document2.styles,
8480
- subParts: document2.subParts,
8481
- viewportWindowKey: viewportWindowKey(viewportWindow)
8482
- };
8483
- cachedGraph = graph;
8484
- cachedFormatting = formatting;
8485
- cachedMapper = createPageFragmentMapper(graph);
8513
+ commitSlot({
8514
+ key: {
8515
+ content: document2.content,
8516
+ styles: document2.styles,
8517
+ subParts: document2.subParts,
8518
+ viewportWindowKey: viewportWindowKey(viewportWindow)
8519
+ },
8520
+ graph,
8521
+ formatting,
8522
+ mapper: createPageFragmentMapper(graph)
8523
+ });
8486
8524
  if (pageCountDelta) {
8487
8525
  emit({
8488
8526
  kind: "page_count_changed",
@@ -8523,7 +8561,7 @@ function createLayoutEngine(options = {}) {
8523
8561
  return graph;
8524
8562
  }
8525
8563
  function incrementalRelayout(input, pending) {
8526
- const priorGraph = cachedGraph;
8564
+ const priorGraph = cachedFull?.graph ?? null;
8527
8565
  const range = pending.result.dirtyPageRange;
8528
8566
  if (!priorGraph || !range) return null;
8529
8567
  const telemetryOn = telemetryBus?.isEnabled("layout") ?? false;
@@ -8616,6 +8654,22 @@ function createLayoutEngine(options = {}) {
8616
8654
  deriveDocumentPageSnapshots(splicedGraph)
8617
8655
  );
8618
8656
  const pageCountDelta = currentPageCount !== previousPageCount ? { previous: previousPageCount, current: currentPageCount } : void 0;
8657
+ const priorMapper = cachedFull?.mapper ?? null;
8658
+ commitSlot({
8659
+ key: {
8660
+ content: document2.content,
8661
+ styles: document2.styles,
8662
+ subParts: document2.subParts,
8663
+ viewportWindowKey: FULL_VIEWPORT_WINDOW_KEY
8664
+ },
8665
+ graph: splicedGraph,
8666
+ formatting,
8667
+ mapper: rebuildMapper(
8668
+ priorMapper ?? createPageFragmentMapper(splicedGraph),
8669
+ splicedGraph,
8670
+ firstDirty
8671
+ )
8672
+ });
8619
8673
  if (pageCountDelta) {
8620
8674
  emit({
8621
8675
  kind: "page_count_changed",
@@ -8645,19 +8699,6 @@ function createLayoutEngine(options = {}) {
8645
8699
  ...dirtyFamilies.length > 0 ? { dirtyFieldFamilies: dirtyFamilies } : {},
8646
8700
  ...pageCountDelta ? { pageCountDelta } : {}
8647
8701
  });
8648
- cachedKey = {
8649
- content: document2.content,
8650
- styles: document2.styles,
8651
- subParts: document2.subParts,
8652
- viewportWindowKey: FULL_VIEWPORT_WINDOW_KEY
8653
- };
8654
- cachedGraph = splicedGraph;
8655
- cachedFormatting = formatting;
8656
- cachedMapper = rebuildMapper(
8657
- cachedMapper ?? createPageFragmentMapper(splicedGraph),
8658
- splicedGraph,
8659
- firstDirty
8660
- );
8661
8702
  if (telemetryOn) {
8662
8703
  emitRecomputeCompleted(
8663
8704
  "bounded",
@@ -8674,13 +8715,14 @@ function createLayoutEngine(options = {}) {
8674
8715
  const document2 = input.document;
8675
8716
  const normalizedWindow = normalizeViewportPageWindow(input.viewportPageWindow);
8676
8717
  const currentViewportWindowKey = viewportWindowKey(normalizedWindow);
8677
- const keyEqual = cachedGraph !== null && cachedKey !== null && cachedKey.content === document2.content && cachedKey.styles === document2.styles && cachedKey.subParts === document2.subParts && cachedKey.viewportWindowKey === currentViewportWindowKey;
8718
+ const slot = getCachedSlot(currentViewportWindowKey);
8719
+ const keyEqual = slot !== null && slot.key.content === document2.content && slot.key.styles === document2.styles && slot.key.subParts === document2.subParts && slot.key.viewportWindowKey === currentViewportWindowKey;
8678
8720
  if (keyEqual && pendingInvalidation === null) {
8679
- return cachedGraph;
8721
+ return slot.graph;
8680
8722
  }
8681
8723
  const pending = pendingInvalidation;
8682
8724
  pendingInvalidation = null;
8683
- if (pending !== null && pending.result.scope === "bounded" && cachedGraph !== null && normalizedWindow === void 0) {
8725
+ if (pending !== null && pending.result.scope === "bounded" && cachedFull !== null && normalizedWindow === void 0) {
8684
8726
  const spliced = incrementalRelayout(input, pending);
8685
8727
  if (spliced !== null) {
8686
8728
  return spliced;
@@ -8689,16 +8731,39 @@ function createLayoutEngine(options = {}) {
8689
8731
  }
8690
8732
  return fullRebuild(input, pending?.reason);
8691
8733
  }
8734
+ function ensureSlotMapperAndFormatting(slot, document2) {
8735
+ if (slot.mapper === null) {
8736
+ slot.mapper = createPageFragmentMapper(slot.graph);
8737
+ }
8738
+ if (slot.formatting === null) {
8739
+ const mainSurface = createEditorSurfaceSnapshot(
8740
+ document2,
8741
+ createSelectionSnapshot(0, 0),
8742
+ MAIN_STORY_TARGET
8743
+ );
8744
+ slot.formatting = buildResolvedFormattingState(document2, mainSurface);
8745
+ }
8746
+ }
8692
8747
  function getMapper(input) {
8693
8748
  getGraphInternal(input);
8694
- return cachedMapper;
8749
+ const currentViewportWindowKey = viewportWindowKey(
8750
+ normalizeViewportPageWindow(input.viewportPageWindow)
8751
+ );
8752
+ const slot = getCachedSlot(currentViewportWindowKey);
8753
+ ensureSlotMapperAndFormatting(slot, input.document);
8754
+ return slot.mapper;
8695
8755
  }
8696
8756
  function getFormatting(input) {
8697
8757
  getGraphInternal(input);
8698
- return cachedFormatting;
8758
+ const currentViewportWindowKey = viewportWindowKey(
8759
+ normalizeViewportPageWindow(input.viewportPageWindow)
8760
+ );
8761
+ const slot = getCachedSlot(currentViewportWindowKey);
8762
+ ensureSlotMapperAndFormatting(slot, input.document);
8763
+ return slot.formatting;
8699
8764
  }
8700
8765
  if (autoUpgradeToCanvas && options.measurementProvider === void 0 && typeof document !== "undefined" && typeof HTMLCanvasElement !== "undefined") {
8701
- const readCachedRevision = () => cachedGraph?.revision ?? 0;
8766
+ const readCachedRevision = () => preferredCachedGraph()?.revision ?? 0;
8702
8767
  void (async () => {
8703
8768
  try {
8704
8769
  const mod = await import("./measurement-backend-canvas-F7ZYDACK.js");
@@ -8708,10 +8773,7 @@ function createLayoutEngine(options = {}) {
8708
8773
  options.measurementCache,
8709
8774
  telemetryBus
8710
8775
  );
8711
- cachedKey = null;
8712
- cachedGraph = null;
8713
- cachedFormatting = null;
8714
- cachedMapper = null;
8776
+ clearAllSlots();
8715
8777
  emit({
8716
8778
  kind: "measurement_backend_ready",
8717
8779
  revision: readCachedRevision(),
@@ -8755,22 +8817,19 @@ function createLayoutEngine(options = {}) {
8755
8817
  return getMapper(input);
8756
8818
  },
8757
8819
  invalidate(reason) {
8758
- const result = analyzeInvalidation(reason, cachedGraph);
8820
+ const result = analyzeInvalidation(reason, preferredCachedGraph());
8759
8821
  for (const family of result.dirtyFieldFamilies) {
8760
8822
  dirtyFieldFamilies.add(family);
8761
8823
  }
8762
8824
  if (result.scope === "bounded") {
8763
8825
  pendingInvalidation = { reason, result };
8764
8826
  } else {
8765
- cachedKey = null;
8766
- cachedGraph = null;
8767
- cachedFormatting = null;
8768
- cachedMapper = null;
8827
+ clearAllSlots();
8769
8828
  pendingInvalidation = { reason, result };
8770
8829
  }
8771
8830
  },
8772
8831
  analyzeInvalidation(reason) {
8773
- return analyzeInvalidation(reason, cachedGraph);
8832
+ return analyzeInvalidation(reason, preferredCachedGraph());
8774
8833
  },
8775
8834
  getDirtyFieldFamilies() {
8776
8835
  return Array.from(dirtyFieldFamilies);
@@ -8798,14 +8857,11 @@ function createLayoutEngine(options = {}) {
8798
8857
  telemetryBus
8799
8858
  );
8800
8859
  if (previousFidelity !== provider.fidelity) {
8801
- cachedKey = null;
8802
- cachedGraph = null;
8803
- cachedFormatting = null;
8804
- cachedMapper = null;
8860
+ clearAllSlots();
8805
8861
  }
8806
8862
  emit({
8807
8863
  kind: "measurement_backend_ready",
8808
- revision: cachedGraph?.revision ?? 0,
8864
+ revision: preferredCachedGraph()?.revision ?? 0,
8809
8865
  fidelity: provider.fidelity
8810
8866
  });
8811
8867
  },
@@ -8820,30 +8876,33 @@ function createLayoutEngine(options = {}) {
8820
8876
  */
8821
8877
  invalidateMeasurementCache() {
8822
8878
  measurementProvider.invalidateCache();
8823
- cachedKey = null;
8824
- cachedGraph = null;
8825
- cachedFormatting = null;
8826
- cachedMapper = null;
8879
+ clearAllSlots();
8827
8880
  },
8828
8881
  getMeasurementCacheStats() {
8829
8882
  if (!isCachedLayoutMeasurementProvider(measurementProvider)) return null;
8830
8883
  return measurementProvider.measurementCacheStats();
8831
8884
  },
8832
8885
  /**
8833
- * L7 Phase 2.5 — seed the cached graph from a prerender envelope.
8834
- * Populates both `cachedGraph` and `cachedKey` (keyed on the provided
8835
- * document's identity-equal slots) so the next getPageGraph query
8836
- * returns the seeded graph directly. Any subsequent mutation
8837
- * invalidates normally through the existing path.
8886
+ * L7 Phase 2.5 — seed the full-slot cached graph from a prerender
8887
+ * envelope. Populates the full slot (graph + key, with formatting and
8888
+ * mapper computed lazily on first read) so the next viewport-
8889
+ * independent `getPageGraph` query returns the seeded graph directly.
8890
+ * Any subsequent mutation invalidates normally through the existing
8891
+ * path; sibling eviction in `commitSlot` clears `cachedWindowed` if
8892
+ * it carried a different document tuple.
8838
8893
  */
8839
8894
  seedCachedGraph(graph, document2) {
8840
- cachedGraph = graph;
8841
- cachedKey = {
8842
- content: document2.content,
8843
- styles: document2.styles,
8844
- subParts: document2.subParts,
8845
- viewportWindowKey: FULL_VIEWPORT_WINDOW_KEY
8846
- };
8895
+ commitSlot({
8896
+ key: {
8897
+ content: document2.content,
8898
+ styles: document2.styles,
8899
+ subParts: document2.subParts,
8900
+ viewportWindowKey: FULL_VIEWPORT_WINDOW_KEY
8901
+ },
8902
+ graph,
8903
+ formatting: null,
8904
+ mapper: null
8905
+ });
8847
8906
  previousPageCount = graph.contentPageCount;
8848
8907
  }
8849
8908
  };
@@ -8,7 +8,7 @@ import {
8
8
  getRevisionActionability,
9
9
  normalizeParsedTextDocument,
10
10
  normalizeParsedTextDocumentAsync
11
- } from "./chunk-4HGFJ6Z2.js";
11
+ } from "./chunk-PZIEOEJZ.js";
12
12
  import {
13
13
  OLE_RELATIONSHIP_TYPES,
14
14
  buildFieldRegistry,
@@ -59,7 +59,7 @@ import {
59
59
  resolveHighlightColor,
60
60
  setActiveParseTelemetryBus,
61
61
  toCanonicalNumberingInstanceId
62
- } from "./chunk-RBWJHRNP.js";
62
+ } from "./chunk-T66OS7MN.js";
63
63
  import {
64
64
  createPersistedSourcePackage,
65
65
  decodeBytesBase64,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  TextTransactionError
3
- } from "./chunk-N5FTU4HZ.js";
3
+ } from "./chunk-MQ5GAJ54.js";
4
4
  import {
5
5
  replaceParagraphScope,
6
6
  resolveParagraphScope
7
- } from "./chunk-C5LXKR54.js";
7
+ } from "./chunk-QTRJLKR2.js";
8
8
  import {
9
9
  cloneParagraphProperties,
10
10
  cloneStoryUnit,
@@ -8,7 +8,7 @@ import {
8
8
  getRevisionRangeState,
9
9
  selectionTouchesRange,
10
10
  shouldHideInCleanMode
11
- } from "./chunk-QUTVR72L.js";
11
+ } from "./chunk-S3PEKX6H.js";
12
12
 
13
13
  // src/ui-tailwind/editor-surface/tw-editor-surface.tsx
14
14
  import { useMemo } from "react";
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  NO_EDITABLE_TARGETS_INDEX,
12
12
  createEditorSurfaceSnapshot
13
- } from "./chunk-U3UMKA7B.js";
13
+ } from "./chunk-XBQFDBXE.js";
14
14
  import {
15
15
  createSelectionSnapshot
16
16
  } from "./chunk-OYGMRRR7.js";
@@ -24,7 +24,38 @@ var TextTransactionError = class extends Error {
24
24
  this.code = code;
25
25
  }
26
26
  };
27
+ function isUsableScopeSurface(surface, document) {
28
+ if (surface.viewportBlockRanges !== null) return false;
29
+ const root = document.content;
30
+ if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
31
+ return false;
32
+ }
33
+ return surface.blocks.length === root.children.length;
34
+ }
35
+ function createScopeSurfaceCache(document, selection, precomputedSurface, telemetry) {
36
+ let cached;
37
+ if (precomputedSurface && isUsableScopeSurface(precomputedSurface, document)) {
38
+ cached = precomputedSurface;
39
+ telemetry?.onPrecomputedSurfaceHit?.();
40
+ }
41
+ return {
42
+ get() {
43
+ if (cached) return cached;
44
+ telemetry?.onScopeSurfaceBuild?.();
45
+ cached = createEditorSurfaceSnapshot(document, selection, void 0, {
46
+ editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
47
+ });
48
+ return cached;
49
+ }
50
+ };
51
+ }
27
52
  function applyTextTransaction(document, selection, intent, options) {
53
+ const scopeSurfaceCache = createScopeSurfaceCache(
54
+ document,
55
+ selection,
56
+ options.precomputedSurface,
57
+ options.surfaceTelemetry
58
+ );
28
59
  if (options.textTarget) {
29
60
  if (options.textTarget.kind === "hyperlink-display") {
30
61
  const targetedHyperlinkResult = tryApplyHyperlinkDisplayTransaction(
@@ -60,7 +91,8 @@ function applyTextTransaction(document, selection, intent, options) {
60
91
  document,
61
92
  selection,
62
93
  intent,
63
- options
94
+ options,
95
+ scopeSurfaceCache
64
96
  );
65
97
  if (targetedTableResult) {
66
98
  return targetedTableResult;
@@ -74,7 +106,8 @@ function applyTextTransaction(document, selection, intent, options) {
74
106
  const tableStructureRefusal = resolveTargetlessTableStructureInsertRefusal(
75
107
  document,
76
108
  selection,
77
- intent
109
+ intent,
110
+ scopeSurfaceCache
78
111
  );
79
112
  if (tableStructureRefusal) {
80
113
  throw new TextTransactionError("unsupported_content", tableStructureRefusal);
@@ -84,7 +117,8 @@ function applyTextTransaction(document, selection, intent, options) {
84
117
  document,
85
118
  selection,
86
119
  intent,
87
- options
120
+ options,
121
+ scopeSurfaceCache
88
122
  );
89
123
  if (topLevelParagraphResult) {
90
124
  return topLevelParagraphResult;
@@ -93,7 +127,8 @@ function applyTextTransaction(document, selection, intent, options) {
93
127
  document,
94
128
  selection,
95
129
  intent,
96
- options
130
+ options,
131
+ scopeSurfaceCache
97
132
  );
98
133
  if (sdtScopedResult) {
99
134
  return sdtScopedResult;
@@ -102,7 +137,8 @@ function applyTextTransaction(document, selection, intent, options) {
102
137
  document,
103
138
  selection,
104
139
  intent,
105
- options
140
+ options,
141
+ scopeSurfaceCache
106
142
  );
107
143
  if (tableScopedResult) {
108
144
  return tableScopedResult;
@@ -155,9 +191,9 @@ function applyLinearTextTransaction(document, selection, intent, options) {
155
191
  storyText: createPlainText(nextStory)
156
192
  };
157
193
  }
158
- function tryApplyTableParagraphTransaction(document, selection, intent, options) {
194
+ function tryApplyTableParagraphTransaction(document, selection, intent, options, scopeSurfaceCache) {
159
195
  const tableTarget = options.textTarget?.kind === "table-paragraph" ? options.textTarget : void 0;
160
- const scope = resolveTableParagraphScope(document, selection, tableTarget);
196
+ const scope = resolveTableParagraphScope(document, selection, tableTarget, scopeSurfaceCache);
161
197
  if (!scope) {
162
198
  return null;
163
199
  }
@@ -280,7 +316,11 @@ function tryApplyTargetedTextLeafTransaction(document, selection, intent, option
280
316
  };
281
317
  }
282
318
  function tryApplyHyperlinkDisplayTransaction(document, selection, intent, options) {
283
- const scope = resolveTargetedHyperlinkDisplayScope(document, selection, options.textTarget);
319
+ const scope = resolveTargetedHyperlinkDisplayScope(
320
+ document,
321
+ selection,
322
+ options.textTarget
323
+ );
284
324
  if (!scope) {
285
325
  return null;
286
326
  }
@@ -338,8 +378,8 @@ function tryApplyHyperlinkDisplayTransaction(document, selection, intent, option
338
378
  storyText: localResult.storyText
339
379
  };
340
380
  }
341
- function tryApplyTopLevelSdtParagraphTransaction(document, selection, intent, options) {
342
- const scope = resolveTopLevelSdtParagraphScope(document, selection);
381
+ function tryApplyTopLevelSdtParagraphTransaction(document, selection, intent, options, scopeSurfaceCache) {
382
+ const scope = resolveTopLevelSdtParagraphScope(document, selection, scopeSurfaceCache);
343
383
  if (!scope) {
344
384
  return null;
345
385
  }
@@ -391,8 +431,8 @@ function tryApplyTopLevelSdtParagraphTransaction(document, selection, intent, op
391
431
  storyText: localResult.storyText
392
432
  };
393
433
  }
394
- function tryApplyTopLevelParagraphTransaction(document, selection, intent, options) {
395
- const scope = resolveTopLevelParagraphScope(document, selection);
434
+ function tryApplyTopLevelParagraphTransaction(document, selection, intent, options, scopeSurfaceCache) {
435
+ const scope = resolveTopLevelParagraphScope(document, selection, scopeSurfaceCache);
396
436
  if (!scope) {
397
437
  return null;
398
438
  }
@@ -502,17 +542,15 @@ function resolveTargetedHyperlinkDisplayScope(document, selection, target) {
502
542
  replace: resolved.replace
503
543
  };
504
544
  }
505
- function resolveTableParagraphScope(document, selection, target) {
545
+ function resolveTableParagraphScope(document, selection, target, scopeSurfaceCache) {
506
546
  if (target) {
507
- return resolveTargetedTableParagraphScope(document, selection, target);
547
+ return resolveTargetedTableParagraphScope(document, selection, target, scopeSurfaceCache);
508
548
  }
509
549
  const root = document.content;
510
550
  if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
511
551
  return null;
512
552
  }
513
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
514
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
515
- });
553
+ const surface = scopeSurfaceCache.get();
516
554
  const selectionFrom = Math.min(selection.anchor, selection.head);
517
555
  const selectionTo = Math.max(selection.anchor, selection.head);
518
556
  for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
@@ -617,7 +655,7 @@ function resolveTableParagraphScope(document, selection, target) {
617
655
  }
618
656
  return null;
619
657
  }
620
- function resolveTargetlessTableStructureInsertRefusal(document, selection, intent) {
658
+ function resolveTargetlessTableStructureInsertRefusal(document, selection, intent, scopeSurfaceCache) {
621
659
  if (!isCollapsedInsertIntent(intent, selection)) {
622
660
  return null;
623
661
  }
@@ -625,9 +663,7 @@ function resolveTargetlessTableStructureInsertRefusal(document, selection, inten
625
663
  if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
626
664
  return null;
627
665
  }
628
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
629
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
630
- });
666
+ const surface = scopeSurfaceCache.get();
631
667
  if (!selectionTouchesTableStructureBoundary(surface.blocks, selection.anchor)) {
632
668
  return null;
633
669
  }
@@ -641,7 +677,7 @@ function isCollapsedInsertIntent(intent, selection) {
641
677
  const rangeTo = intent.range ? Math.max(intent.range.from, intent.range.to) : Math.max(selection.anchor, selection.head);
642
678
  return rangeFrom === rangeTo;
643
679
  }
644
- function resolveTargetedTableParagraphScope(document, selection, target) {
680
+ function resolveTargetedTableParagraphScope(document, selection, target, scopeSurfaceCache) {
645
681
  const root = document.content;
646
682
  if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
647
683
  return null;
@@ -654,7 +690,8 @@ function resolveTargetedTableParagraphScope(document, selection, target) {
654
690
  root,
655
691
  document,
656
692
  selection,
657
- target
693
+ target,
694
+ scopeSurfaceCache
658
695
  );
659
696
  if (targetScope) {
660
697
  return targetScope;
@@ -677,9 +714,7 @@ function resolveTargetedTableParagraphScope(document, selection, target) {
677
714
  if (cell.verticalMerge === "continue") {
678
715
  return "unsupported";
679
716
  }
680
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
681
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
682
- });
717
+ const surface = scopeSurfaceCache.get();
683
718
  const surfaceBlock = surface.blocks[target.tableBlockIndex];
684
719
  const surfaceRow = surfaceBlock?.kind === "table" ? surfaceBlock.rows[target.rowIndex] : void 0;
685
720
  const surfaceCell = surfaceRow?.cells[target.cellIndex];
@@ -743,16 +778,14 @@ function resolveTargetedTableParagraphScope(document, selection, target) {
743
778
  }
744
779
  };
745
780
  }
746
- function resolveTargetedTableParagraphScopeByPath(root, document, selection, target) {
781
+ function resolveTargetedTableParagraphScopeByPath(root, document, selection, target, scopeSurfaceCache) {
747
782
  if (!target.blockPath) return null;
748
783
  const tokens = parseCanonicalBlockPath(target.blockPath);
749
784
  if (!tokens) return null;
750
785
  const resolved = resolveBlockPathInCanonicalBlocks(root.children, tokens, 0);
751
786
  if (!resolved || resolved.block.type !== "paragraph") return null;
752
787
  if (resolved.hasVerticalMergeContinuation) return null;
753
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
754
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
755
- });
788
+ const surface = scopeSurfaceCache.get();
756
789
  const surfaceResolved = resolveBlockPathInSurfaceBlocks(surface.blocks, tokens, 0);
757
790
  if (!surfaceResolved || surfaceResolved.kind !== "paragraph") return null;
758
791
  if (surfaceResolved.hasVerticalMergeContinuation) return null;
@@ -1207,14 +1240,12 @@ function resolveBlockPathInSurfaceBlocks(blocks, tokens, tokenIndex, hasVertical
1207
1240
  hasVerticalMergeContinuation || cell.verticalMerge === "continue"
1208
1241
  );
1209
1242
  }
1210
- function resolveTopLevelParagraphScope(document, selection) {
1243
+ function resolveTopLevelParagraphScope(document, selection, scopeSurfaceCache) {
1211
1244
  const root = document.content;
1212
1245
  if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
1213
1246
  return null;
1214
1247
  }
1215
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
1216
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
1217
- });
1248
+ const surface = scopeSurfaceCache.get();
1218
1249
  const selectionFrom = Math.min(selection.anchor, selection.head);
1219
1250
  const selectionTo = Math.max(selection.anchor, selection.head);
1220
1251
  for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {
@@ -1243,14 +1274,12 @@ function resolveTopLevelParagraphScope(document, selection) {
1243
1274
  }
1244
1275
  return null;
1245
1276
  }
1246
- function resolveTopLevelSdtParagraphScope(document, selection) {
1277
+ function resolveTopLevelSdtParagraphScope(document, selection, scopeSurfaceCache) {
1247
1278
  const root = document.content;
1248
1279
  if (!root || root.type !== "doc" || !Array.isArray(root.children)) {
1249
1280
  return null;
1250
1281
  }
1251
- const surface = createEditorSurfaceSnapshot(document, selection, void 0, {
1252
- editableTargetsByBlockPath: NO_EDITABLE_TARGETS_INDEX
1253
- });
1282
+ const surface = scopeSurfaceCache.get();
1254
1283
  const selectionFrom = Math.min(selection.anchor, selection.head);
1255
1284
  const selectionTo = Math.max(selection.anchor, selection.head);
1256
1285
  for (let blockIndex = 0; blockIndex < root.children.length; blockIndex += 1) {