@pierre/diffs 1.3.0-beta.6 → 1.3.0-beta.8

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 (180) hide show
  1. package/dist/components/CodeView.d.ts +90 -5
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +291 -38
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +1 -0
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +20 -6
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +38 -23
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +144 -61
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts +3 -2
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +4 -2
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  18. package/dist/components/VirtualizedFile.js +6 -8
  19. package/dist/components/VirtualizedFile.js.map +1 -1
  20. package/dist/components/VirtualizedFileDiff.d.ts +13 -5
  21. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  22. package/dist/components/VirtualizedFileDiff.js +192 -55
  23. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  24. package/dist/components/Virtualizer.d.ts +2 -0
  25. package/dist/components/Virtualizer.d.ts.map +1 -1
  26. package/dist/components/Virtualizer.js +16 -3
  27. package/dist/components/Virtualizer.js.map +1 -1
  28. package/dist/constants.d.ts +3 -1
  29. package/dist/constants.d.ts.map +1 -1
  30. package/dist/constants.js +3 -1
  31. package/dist/constants.js.map +1 -1
  32. package/dist/editor/command.d.ts +1 -1
  33. package/dist/editor/command.d.ts.map +1 -1
  34. package/dist/editor/command.js +8 -0
  35. package/dist/editor/command.js.map +1 -1
  36. package/dist/editor/editor.d.ts +10 -3
  37. package/dist/editor/editor.d.ts.map +1 -1
  38. package/dist/editor/editor.js +325 -135
  39. package/dist/editor/editor.js.map +1 -1
  40. package/dist/editor/editor2.js +1 -1
  41. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  42. package/dist/editor/lineAnnotations.js +84 -12
  43. package/dist/editor/lineAnnotations.js.map +1 -1
  44. package/dist/editor/marker.d.ts +5 -3
  45. package/dist/editor/marker.d.ts.map +1 -1
  46. package/dist/editor/marker.js +35 -12
  47. package/dist/editor/marker.js.map +1 -1
  48. package/dist/editor/matchBrackets.d.ts +8 -0
  49. package/dist/editor/matchBrackets.d.ts.map +1 -0
  50. package/dist/editor/matchBrackets.js +146 -0
  51. package/dist/editor/matchBrackets.js.map +1 -0
  52. package/dist/editor/popover.d.ts +45 -0
  53. package/dist/editor/popover.d.ts.map +1 -0
  54. package/dist/editor/popover.js +145 -0
  55. package/dist/editor/popover.js.map +1 -0
  56. package/dist/editor/selection.d.ts +14 -2
  57. package/dist/editor/selection.d.ts.map +1 -1
  58. package/dist/editor/selection.js +142 -41
  59. package/dist/editor/selection.js.map +1 -1
  60. package/dist/editor/selectionAction.d.ts +20 -3
  61. package/dist/editor/selectionAction.d.ts.map +1 -1
  62. package/dist/editor/selectionAction.js +41 -10
  63. package/dist/editor/selectionAction.js.map +1 -1
  64. package/dist/editor/textDocument.d.ts +2 -0
  65. package/dist/editor/textDocument.d.ts.map +1 -1
  66. package/dist/editor/textDocument.js +22 -6
  67. package/dist/editor/textDocument.js.map +1 -1
  68. package/dist/editor/textMeasure.d.ts.map +1 -1
  69. package/dist/editor/textMeasure.js +25 -7
  70. package/dist/editor/textMeasure.js.map +1 -1
  71. package/dist/editor/tokenzier.d.ts +6 -7
  72. package/dist/editor/tokenzier.d.ts.map +1 -1
  73. package/dist/editor/tokenzier.js +83 -34
  74. package/dist/editor/tokenzier.js.map +1 -1
  75. package/dist/editor/utils.d.ts +3 -1
  76. package/dist/editor/utils.d.ts.map +1 -1
  77. package/dist/editor/utils.js +14 -1
  78. package/dist/editor/utils.js.map +1 -1
  79. package/dist/index.d.ts +9 -7
  80. package/dist/index.js +6 -4
  81. package/dist/managers/InteractionManager.d.ts.map +1 -1
  82. package/dist/managers/InteractionManager.js +0 -1
  83. package/dist/managers/InteractionManager.js.map +1 -1
  84. package/dist/managers/ResizeManager.d.ts +10 -2
  85. package/dist/managers/ResizeManager.d.ts.map +1 -1
  86. package/dist/managers/ResizeManager.js +33 -13
  87. package/dist/managers/ResizeManager.js.map +1 -1
  88. package/dist/react/CodeView.d.ts +25 -1
  89. package/dist/react/CodeView.d.ts.map +1 -1
  90. package/dist/react/CodeView.js +76 -17
  91. package/dist/react/CodeView.js.map +1 -1
  92. package/dist/react/EditorContext.d.ts +2 -2
  93. package/dist/react/EditorContext.d.ts.map +1 -1
  94. package/dist/react/EditorContext.js.map +1 -1
  95. package/dist/react/MultiFileDiff.d.ts +3 -4
  96. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  97. package/dist/react/MultiFileDiff.js.map +1 -1
  98. package/dist/react/index.d.ts +2 -2
  99. package/dist/react/utils/useFileDiffInstance.js +14 -15
  100. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  101. package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
  102. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  103. package/dist/renderers/DiffHunksRenderer.js +45 -23
  104. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  105. package/dist/renderers/FileRenderer.d.ts +2 -1
  106. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  107. package/dist/renderers/FileRenderer.js +58 -38
  108. package/dist/renderers/FileRenderer.js.map +1 -1
  109. package/dist/ssr/index.d.ts +2 -2
  110. package/dist/ssr/preloadDiffs.d.ts +11 -10
  111. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  112. package/dist/ssr/preloadDiffs.js +14 -6
  113. package/dist/ssr/preloadDiffs.js.map +1 -1
  114. package/dist/types.d.ts +100 -6
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/utils/applyLineTextWithNewline.d.ts +5 -0
  117. package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -0
  118. package/dist/utils/applyLineTextWithNewline.js +11 -0
  119. package/dist/utils/applyLineTextWithNewline.js.map +1 -0
  120. package/dist/utils/areHunkDataEqual.js +1 -1
  121. package/dist/utils/areHunkDataEqual.js.map +1 -1
  122. package/dist/utils/areManagedSnapshotsEqual.d.ts +2 -2
  123. package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
  124. package/dist/utils/areManagedSnapshotsEqual.js +5 -0
  125. package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
  126. package/dist/utils/awaitWithTimeout.d.ts +5 -0
  127. package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
  128. package/dist/utils/awaitWithTimeout.js +15 -0
  129. package/dist/utils/awaitWithTimeout.js.map +1 -0
  130. package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
  131. package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
  132. package/dist/utils/cloneFileDiffMetadata.js +16 -0
  133. package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
  134. package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
  135. package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
  136. package/dist/utils/computeEstimatedDiffHeights.js +8 -1
  137. package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
  138. package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts +5 -0
  139. package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -0
  140. package/dist/utils/createCodeViewHeaderFooterHostElement.js +19 -0
  141. package/dist/utils/createCodeViewHeaderFooterHostElement.js.map +1 -0
  142. package/dist/utils/createPreElement.js +0 -1
  143. package/dist/utils/createPreElement.js.map +1 -1
  144. package/dist/utils/getDiffFileInput.d.ts +14 -0
  145. package/dist/utils/getDiffFileInput.d.ts.map +1 -0
  146. package/dist/utils/getDiffFileInput.js +24 -0
  147. package/dist/utils/getDiffFileInput.js.map +1 -0
  148. package/dist/utils/getDiffHunksRendererOptions.js +1 -0
  149. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  150. package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
  151. package/dist/utils/getFiletypeFromFileName.js +2 -0
  152. package/dist/utils/getFiletypeFromFileName.js.map +1 -1
  153. package/dist/utils/hydratePartialDiff.d.ts +10 -0
  154. package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
  155. package/dist/utils/hydratePartialDiff.js +140 -0
  156. package/dist/utils/hydratePartialDiff.js.map +1 -0
  157. package/dist/utils/iterateOverDiff.js +3 -3
  158. package/dist/utils/iterateOverDiff.js.map +1 -1
  159. package/dist/utils/parseDiffFromFile.d.ts +1 -1
  160. package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
  161. package/dist/utils/parseDiffFromFile.js +26 -5
  162. package/dist/utils/parseDiffFromFile.js.map +1 -1
  163. package/dist/utils/setWrapperNodeProps.js +0 -1
  164. package/dist/utils/setWrapperNodeProps.js.map +1 -1
  165. package/dist/utils/updateDiffHunks.d.ts +5 -1
  166. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  167. package/dist/utils/updateDiffHunks.js +48 -4
  168. package/dist/utils/updateDiffHunks.js.map +1 -1
  169. package/dist/worker/WorkerPoolManager.d.ts +7 -2
  170. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  171. package/dist/worker/WorkerPoolManager.js +78 -15
  172. package/dist/worker/WorkerPoolManager.js.map +1 -1
  173. package/dist/worker/index.d.ts +2 -2
  174. package/dist/worker/types.d.ts +7 -1
  175. package/dist/worker/types.d.ts.map +1 -1
  176. package/dist/worker/worker-portable.js +5 -3
  177. package/dist/worker/worker-portable.js.map +1 -1
  178. package/dist/worker/worker.js +5 -3
  179. package/dist/worker/worker.js.map +1 -1
  180. package/package.json +1 -1
@@ -1,16 +1,20 @@
1
1
  import "../constants.js";
2
2
  import { areObjectsEqual } from "../utils/areObjectsEqual.js";
3
3
  import { areOptionsEqual } from "../utils/areOptionsEqual.js";
4
+ import { areFilesEqual } from "../utils/areFilesEqual.js";
4
5
  import { computeVirtualFileMetrics, getVirtualFileHeaderRegion, getVirtualFilePaddingBottom } from "../utils/computeVirtualFileMetrics.js";
5
6
  import { FILE_ANNOTATION_DOM_KEY, includesFileAnnotations, shouldRenderFileAnnotations } from "../utils/includesFileAnnotations.js";
6
7
  import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
8
+ import { awaitWithTimeout } from "../utils/awaitWithTimeout.js";
7
9
  import { getExpandedRegion, getLeadingHunkSeparatorLayout, getTrailingExpandedRegion, getTrailingHunkSeparatorLayout } from "../utils/virtualDiffLayout.js";
8
10
  import { computeEstimatedDiffHeights } from "../utils/computeEstimatedDiffHeights.js";
11
+ import { getDiffFileInput } from "../utils/getDiffFileInput.js";
12
+ import { hydratePartialDiff } from "../utils/hydratePartialDiff.js";
9
13
  import { iterateOverDiff } from "../utils/iterateOverDiff.js";
10
14
  import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
11
15
  import { FileDiff } from "./FileDiff.js";
12
16
  //#region src/components/VirtualizedFileDiff.ts
13
- const LAYOUT_CHECKPOINT_INTERVAL = 5e3;
17
+ const VIRTUALIZED_FILE_DIFF_LAYOUT_CHECKPOINT_INTERVAL = 3e3;
14
18
  let instanceId = -1;
15
19
  var VirtualizedFileDiff = class extends FileDiff {
16
20
  __id = `little-virtualized-file-diff:${++instanceId}`;
@@ -32,6 +36,9 @@ var VirtualizedFileDiff = class extends FileDiff {
32
36
  layoutDirty = true;
33
37
  forceRenderOverride;
34
38
  currentCollapsed;
39
+ currentExpandUnchanged;
40
+ pendingHydratedDiff;
41
+ pendingExpansions;
35
42
  constructor(options, virtualizer, metrics, workerManager, isContainerManaged = false) {
36
43
  super(options, workerManager, isContainerManaged);
37
44
  this.virtualizer = virtualizer;
@@ -92,19 +99,23 @@ var VirtualizedFileDiff = class extends FileDiff {
92
99
  if (this.isAdvancedMode()) throw new Error("VirtualizedFileDiff.setThemeType cannot be used inside CodeView. Update CodeView options instead.");
93
100
  super.setThemeType(themeType);
94
101
  }
95
- resetLayoutCache({ forceSimpleRecompute = false, includeEstimatedHeights = false } = {}) {
102
+ resetLayoutCache({ forceSimpleRecompute = false, includeEstimatedHeights = false, resetRenderRange = true } = {}) {
96
103
  this.layoutDirty = true;
97
104
  this.cache.fileAnnotationHeight = 0;
98
105
  if (this.cache.heightDeltas.size > 0) this.cache.heightDeltas.clear();
99
106
  if (this.cache.measuredHeightDeltaTotal !== 0) this.cache.measuredHeightDeltaTotal = 0;
107
+ this.invalidateDerivedLayoutCache(includeEstimatedHeights, resetRenderRange);
108
+ if (forceSimpleRecompute && this.isSimpleMode()) this.computeApproximateSize();
109
+ }
110
+ invalidateDerivedLayoutCache(includeEstimatedHeights, resetRenderRange = true) {
111
+ this.layoutDirty = true;
100
112
  if (this.cache.checkpoints.length > 0) this.cache.checkpoints.length = 0;
101
113
  if (this.cache.totalLines !== 0) this.cache.totalLines = 0;
102
114
  if (includeEstimatedHeights) {
103
115
  this.cache.estimatedSplitHeight = void 0;
104
116
  this.cache.estimatedUnifiedHeight = void 0;
105
117
  }
106
- if (this.renderRange != null) this.renderRange = void 0;
107
- if (forceSimpleRecompute && this.isSimpleMode()) this.computeApproximateSize();
118
+ if (this.renderRange != null && resetRenderRange) this.renderRange = void 0;
108
119
  }
109
120
  reconcileHeights() {
110
121
  let hasHeightChange = false;
@@ -166,11 +177,16 @@ var VirtualizedFileDiff = class extends FileDiff {
166
177
  shouldResetLayoutCache = true;
167
178
  includeEstimatedHeights = true;
168
179
  }
169
- const { collapsed = false } = this.options;
180
+ const { collapsed = false, expandUnchanged = false } = this.options;
170
181
  if (this.currentCollapsed !== collapsed) {
171
182
  this.currentCollapsed = collapsed;
172
183
  shouldResetLayoutCache = true;
173
184
  }
185
+ if (this.currentExpandUnchanged !== expandUnchanged) {
186
+ this.currentExpandUnchanged = expandUnchanged;
187
+ shouldResetLayoutCache = true;
188
+ includeEstimatedHeights = true;
189
+ }
174
190
  if (shouldResetLayoutCache) this.resetLayoutCache({ includeEstimatedHeights });
175
191
  this.fileDiff = fileDiff;
176
192
  this.top = top;
@@ -331,17 +347,88 @@ var VirtualizedFileDiff = class extends FileDiff {
331
347
  }
332
348
  cleanUp(recycle = false) {
333
349
  if (this.fileContainer != null && this.isSimpleMode()) this.getSimpleVirtualizer()?.disconnect(this.fileContainer);
334
- if (!recycle) this.resetLayoutCache({ includeEstimatedHeights: true });
350
+ if (!recycle) {
351
+ this.resetLayoutCache({ includeEstimatedHeights: true });
352
+ this.pendingExpansions = void 0;
353
+ this.pendingHydratedDiff = void 0;
354
+ }
335
355
  this.isSetup = false;
336
356
  super.cleanUp(recycle);
337
357
  }
338
358
  expandHunk = (hunkIndex, direction, expansionLineCountOverride) => {
339
- this.hunksRenderer.expandHunk(hunkIndex, direction, expansionLineCountOverride);
359
+ if (this.fileDiff == null) return;
360
+ if (this.isAdvancedMode()) {
361
+ this.pendingExpansions ??= [];
362
+ this.pendingExpansions.push({
363
+ hunkIndex,
364
+ direction,
365
+ expansionLineCountOverride
366
+ });
367
+ } else {
368
+ this.hunksRenderer.expandHunk(hunkIndex, direction, expansionLineCountOverride);
369
+ this.resetLayoutCache({ includeEstimatedHeights: true });
370
+ this.computeApproximateSize();
371
+ }
372
+ this.loadFilesIfNecessary();
340
373
  this.forceRenderOverride = true;
341
- this.resetLayoutCache({ includeEstimatedHeights: true });
342
- if (this.isSimpleMode()) this.computeApproximateSize();
343
374
  this.virtualizer.instanceChanged(this, true);
344
375
  };
376
+ async handleFilesLoaded(expectedDiff, files) {
377
+ if (this.fileDiff !== expectedDiff || !expectedDiff.isPartial) return;
378
+ if (this.isAdvancedMode()) {
379
+ const nextDiff = hydratePartialDiff("clone", expectedDiff, files);
380
+ await awaitWithTimeout(() => this.primeHighlightCache(nextDiff));
381
+ if (!this.enabled || this.fileDiff !== expectedDiff) return;
382
+ this.pendingHydratedDiff = {
383
+ expectedDiff,
384
+ nextDiff,
385
+ files
386
+ };
387
+ } else {
388
+ hydratePartialDiff("merge", expectedDiff, files);
389
+ this.setHydratedState(files);
390
+ await awaitWithTimeout(() => this.primeHighlightCache(expectedDiff));
391
+ if (!this.enabled || this.fileDiff !== expectedDiff) return;
392
+ this.resetLayoutCache({ includeEstimatedHeights: true });
393
+ this.computeApproximateSize();
394
+ }
395
+ this.forceRenderOverride = true;
396
+ this.virtualizer.instanceChanged(this, true);
397
+ }
398
+ consumeCodeViewLayoutChanges(expectedFileDiff) {
399
+ let hasLayoutChange = false;
400
+ let nextDiff;
401
+ const { pendingExpansions, pendingHydratedDiff } = this;
402
+ if (pendingExpansions != null) {
403
+ this.pendingExpansions = void 0;
404
+ for (const pendingExpansion of pendingExpansions) {
405
+ this.hunksRenderer.expandHunk(pendingExpansion.hunkIndex, pendingExpansion.direction, pendingExpansion.expansionLineCountOverride);
406
+ hasLayoutChange = true;
407
+ }
408
+ }
409
+ if (pendingHydratedDiff != null) {
410
+ this.pendingHydratedDiff = void 0;
411
+ if (pendingHydratedDiff.expectedDiff === expectedFileDiff) {
412
+ this.setHydratedState(pendingHydratedDiff.files);
413
+ nextDiff = pendingHydratedDiff.nextDiff;
414
+ }
415
+ }
416
+ if (nextDiff != null) {
417
+ this.forceRenderOverride = true;
418
+ this.resetLayoutCache({ includeEstimatedHeights: true });
419
+ } else if (hasLayoutChange) {
420
+ this.forceRenderOverride = true;
421
+ this.invalidateDerivedLayoutCache(true);
422
+ }
423
+ return nextDiff;
424
+ }
425
+ loadFilesIfNecessary() {
426
+ if (this.pendingHydratedDiff != null) {
427
+ if (this.pendingHydratedDiff.expectedDiff === this.fileDiff) return;
428
+ this.pendingHydratedDiff = void 0;
429
+ }
430
+ super.loadFilesIfNecessary();
431
+ }
345
432
  setVisibility(visible) {
346
433
  if (this.isAdvancedMode() || this.fileContainer == null) return;
347
434
  this.renderRange = void 0;
@@ -364,22 +451,24 @@ var VirtualizedFileDiff = class extends FileDiff {
364
451
  this.getSimpleVirtualizer()?.markDOMDirty();
365
452
  this.resetLayoutCache({
366
453
  forceSimpleRecompute: this.isSimpleMode(),
367
- includeEstimatedHeights: true
454
+ includeEstimatedHeights: true,
455
+ resetRenderRange: false
368
456
  });
457
+ if (!this.isSimpleMode()) this.computeApproximateSize(true);
369
458
  if (shouldUpdateBuffer && previousRenderRange !== void 0 && this.fileDiff !== void 0) {
370
459
  const windowSpecs = this.virtualizer.getWindowSpecs();
371
460
  const renderRange = this.computeRenderRangeFromWindow(this.fileDiff, this.top ?? 0, windowSpecs);
372
461
  if (renderRange.bufferAfter !== previousRenderRange.bufferAfter) this.updateBuffers(renderRange);
373
462
  }
374
463
  }
375
- computeApproximateSize(force = false) {
464
+ computeApproximateSize(force = false, fileDiff = this.fileDiff) {
376
465
  const shouldValidateSize = this.isResizeDebuggingEnabled();
377
466
  if (!force && !this.layoutDirty && !shouldValidateSize) return;
378
467
  const isFirstCompute = this.height === 0;
379
468
  this.height = 0;
380
469
  this.cache.checkpoints = [];
381
470
  this.cache.totalLines = 0;
382
- if (this.fileDiff == null) {
471
+ if (fileDiff == null) {
383
472
  this.layoutDirty = false;
384
473
  return;
385
474
  }
@@ -390,18 +479,18 @@ var VirtualizedFileDiff = class extends FileDiff {
390
479
  this.layoutDirty = false;
391
480
  return;
392
481
  }
393
- this.height = this.getActiveEstimatedHeight() + this.cache.measuredHeightDeltaTotal;
394
- if (shouldValidateSize && !isFirstCompute) this.validateComputedHeight();
482
+ this.height = this.getActiveEstimatedHeight(fileDiff) + this.cache.measuredHeightDeltaTotal;
483
+ if (shouldValidateSize && !isFirstCompute) this.validateComputedHeight(fileDiff);
395
484
  this.layoutDirty = false;
396
485
  }
397
- getActiveEstimatedHeight() {
398
- this.ensureEstimatedDiffHeights();
486
+ getActiveEstimatedHeight(fileDiff = this.fileDiff) {
487
+ this.ensureEstimatedDiffHeights(fileDiff);
399
488
  const estimatedHeight = this.getDiffStyle() === "split" ? this.cache.estimatedSplitHeight : this.cache.estimatedUnifiedHeight;
400
489
  if (estimatedHeight == null) throw new Error("VirtualizedFileDiff.getActiveEstimatedHeight: missing estimated height");
401
490
  return estimatedHeight;
402
491
  }
403
- ensureEstimatedDiffHeights() {
404
- if (this.fileDiff == null) {
492
+ ensureEstimatedDiffHeights(fileDiff = this.fileDiff) {
493
+ if (fileDiff == null) {
405
494
  this.cache.estimatedSplitHeight = void 0;
406
495
  this.cache.estimatedUnifiedHeight = void 0;
407
496
  return;
@@ -409,40 +498,51 @@ var VirtualizedFileDiff = class extends FileDiff {
409
498
  if (this.cache.estimatedSplitHeight != null && this.cache.estimatedUnifiedHeight != null) return;
410
499
  const { disableFileHeader = false, expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
411
500
  const { splitHeight, unifiedHeight } = computeEstimatedDiffHeights({
412
- fileDiff: this.fileDiff,
501
+ fileDiff,
413
502
  metrics: this.metrics,
414
503
  disableFileHeader,
415
504
  hunkSeparators: this.getHunkSeparatorType(),
416
505
  expandUnchanged,
417
506
  expandedHunks: this.hunksRenderer.getExpandedHunksMap(),
418
- collapsedContextThreshold
507
+ collapsedContextThreshold,
508
+ canHydratePartialDiff: canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null)
419
509
  });
420
510
  this.cache.estimatedSplitHeight = splitHeight;
421
511
  this.cache.estimatedUnifiedHeight = unifiedHeight;
422
512
  }
423
- validateComputedHeight() {
424
- if (this.fileContainer == null || this.fileDiff == null) return;
513
+ validateComputedHeight(fileDiff = this.fileDiff) {
514
+ if (this.fileContainer == null || fileDiff == null) return;
425
515
  const rect = this.fileContainer.getBoundingClientRect();
426
516
  if (rect.height !== this.height) console.log("VirtualizedFileDiff.computeApproximateSize: computed height doesnt match", {
427
- name: this.fileDiff.name,
517
+ name: fileDiff.name,
428
518
  elementHeight: rect.height,
429
519
  computedHeight: this.height
430
520
  });
431
521
  else console.log("VirtualizedFileDiff.computeApproximateSize: computed height IS CORRECT");
432
522
  }
433
- render({ fileContainer, oldFile, newFile, fileDiff, forceRender = false, lineAnnotations, ...props } = {}) {
523
+ render({ fileContainer, fileDiff, forceRender = false, lineAnnotations, ...fileInputProps } = {}) {
524
+ const fileInput = getDiffFileInput(fileInputProps, "VirtualizedFileDiff.render");
525
+ const hasFileInput = fileInput != null;
526
+ const oldFile = fileInput?.oldFile;
527
+ const newFile = fileInput?.newFile;
528
+ const filesDidChange = hasFileInput && (!areOptionalFilesEqual(oldFile, this.deletionFile) || !areOptionalFilesEqual(newFile, this.additionFile));
529
+ let nextFileDiff = fileDiff ?? this.fileDiff;
530
+ if (fileDiff == null && hasFileInput && (filesDidChange || this.fileDiff == null)) nextFileDiff = parseDiffFromFile(fileInput.oldFile, fileInput.newFile, this.options.parseDiffOptions);
434
531
  const { forceRenderOverride, isSetup } = this;
435
532
  this.forceRenderOverride = void 0;
436
533
  const annotationsChanged = this.syncLineAnnotations(lineAnnotations);
437
534
  if (annotationsChanged) this.resetLayoutCache({ includeEstimatedHeights: false });
438
- this.fileDiff ??= fileDiff ?? (oldFile != null && newFile != null ? parseDiffFromFile(oldFile, newFile, this.options.parseDiffOptions) : void 0);
535
+ const diffInputChanged = fileDiff != null && fileDiff !== this.fileDiff;
536
+ const targetChanged = nextFileDiff != null && !areDiffTargetsEqual(this.fileDiff, nextFileDiff);
537
+ const dataChanged = diffInputChanged || filesDidChange;
538
+ if (targetChanged) this.resetLayoutCache({ includeEstimatedHeights: true });
439
539
  fileContainer = this.getOrCreateFileContainer(fileContainer);
440
- if (this.fileDiff == null) {
540
+ if (nextFileDiff == null) {
441
541
  console.error("VirtualizedFileDiff.render: attempting to virtually render when we dont have the correct data");
442
542
  return false;
443
543
  }
444
544
  if (!isSetup) {
445
- this.computeApproximateSize();
545
+ this.computeApproximateSize(false, nextFileDiff);
446
546
  const virtualizer = this.getSimpleVirtualizer();
447
547
  this.top ??= this.getVirtualizedTop();
448
548
  if (this.isAdvancedMode()) this.isVisible = true;
@@ -452,21 +552,33 @@ var VirtualizedFileDiff = class extends FileDiff {
452
552
  this.isVisible = virtualizer.isInstanceVisible(this.top ?? 0, this.height);
453
553
  }
454
554
  this.isSetup = true;
455
- } else this.top ??= this.getVirtualizedTop();
456
- if (!this.isVisible && this.isSimpleMode()) return this.renderPlaceholder(this.height);
555
+ } else {
556
+ this.top ??= this.getVirtualizedTop();
557
+ if (targetChanged) this.computeApproximateSize(false, nextFileDiff);
558
+ }
559
+ if (!this.isVisible && this.isSimpleMode() && (!dataChanged || !isSetup)) {
560
+ this.fileDiff = nextFileDiff;
561
+ if (fileInput != null) {
562
+ this.deletionFile = oldFile;
563
+ this.additionFile = newFile;
564
+ }
565
+ if (targetChanged) this.cachedHeaderHTML = void 0;
566
+ return this.renderPlaceholder(this.height);
567
+ }
457
568
  const windowSpecs = this.virtualizer.getWindowSpecs();
458
569
  const fileTop = this.top ?? 0;
459
- const renderRange = this.computeRenderRangeFromWindow(this.fileDiff, fileTop, windowSpecs);
460
- return super.render({
461
- fileDiff: this.fileDiff,
570
+ const renderRange = this.computeRenderRangeFromWindow(nextFileDiff, fileTop, windowSpecs);
571
+ const rendered = super.render({
572
+ fileDiff: nextFileDiff,
462
573
  fileContainer,
463
574
  renderRange,
464
- oldFile,
465
- newFile,
466
575
  lineAnnotations,
467
- forceRender: (forceRenderOverride ?? forceRender) || annotationsChanged,
468
- ...props
576
+ forceRender: (forceRenderOverride ?? forceRender) || annotationsChanged || targetChanged,
577
+ ...fileInput,
578
+ ...fileInputProps
469
579
  });
580
+ if (this.isSimpleMode() && rendered) this.getSimpleVirtualizer()?.requestHeightReconcile(this);
581
+ return rendered;
470
582
  }
471
583
  syncVirtualizedTop() {
472
584
  this.top = this.getVirtualizedTop();
@@ -496,10 +608,11 @@ var VirtualizedFileDiff = class extends FileDiff {
496
608
  getHunkSeparatorType() {
497
609
  return getOptionHunkSeparatorType(this.options.hunkSeparators);
498
610
  }
499
- approximateLayoutCheckpoints() {
500
- if (this.cache.checkpoints.length > 0 || this.fileDiff == null || this.fileDiff.hunks.length === 0 || this.options.collapsed === true) return;
611
+ approximateLayoutCheckpoints(fileDiff = this.fileDiff) {
612
+ if (!this.layoutDirty && this.cache.checkpoints.length > 0 || fileDiff == null || fileDiff.hunks.length === 0 || this.options.collapsed === true) return;
501
613
  const { disableFileHeader = false, expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
502
- const finalHunkIndex = this.fileDiff.hunks.length - 1;
614
+ const finalHunkIndex = fileDiff.hunks.length - 1;
615
+ const canHydratePartialDiff = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
503
616
  const diffStyle = this.getDiffStyle();
504
617
  const hunkSeparators = this.getHunkSeparatorType();
505
618
  const expandedHunks = expandUnchanged ? true : this.hunksRenderer.getExpandedHunksMap();
@@ -519,16 +632,16 @@ var VirtualizedFileDiff = class extends FileDiff {
519
632
  lineIndex: startLineIndex + offset,
520
633
  top: checkpointTop
521
634
  });
522
- nextCheckpoint += LAYOUT_CHECKPOINT_INTERVAL;
635
+ nextCheckpoint += VIRTUALIZED_FILE_DIFF_LAYOUT_CHECKPOINT_INTERVAL;
523
636
  }
524
637
  top += preSeparatorHeight + rowCount * this.metrics.lineHeight + metadataOffsets.length * this.metrics.lineHeight + sumHeightDeltas(heightDeltaPrefix, startLineIndex, startLineIndex + rowCount) + postSeparatorHeight;
525
638
  renderedLineIndex = blockEnd;
526
639
  };
527
- for (let hunkIndex = 0; hunkIndex < this.fileDiff.hunks.length; hunkIndex++) {
528
- const hunk = this.fileDiff.hunks[hunkIndex];
640
+ for (let hunkIndex = 0; hunkIndex < fileDiff.hunks.length; hunkIndex++) {
641
+ const hunk = fileDiff.hunks[hunkIndex];
529
642
  if (hunk == null) throw new Error("VirtualizedFileDiff.approximateLayoutCheckpoints: invalid hunk index");
530
643
  const leadingRegion = getExpandedRegion({
531
- isPartial: this.fileDiff.isPartial,
644
+ isPartial: fileDiff.isPartial,
532
645
  rangeSize: hunk.collapsedBefore,
533
646
  expandedHunks,
534
647
  hunkIndex,
@@ -552,7 +665,7 @@ var VirtualizedFileDiff = class extends FileDiff {
552
665
  });
553
666
  if (leadingRegion.fromEnd > 0) pendingLeadingSeparatorHeight = 0;
554
667
  const trailingRegion = hunkIndex === finalHunkIndex ? getTrailingExpandedRegion({
555
- fileDiff: this.fileDiff,
668
+ fileDiff,
556
669
  hunkIndex,
557
670
  expandedHunks,
558
671
  collapsedContextThreshold,
@@ -561,6 +674,9 @@ var VirtualizedFileDiff = class extends FileDiff {
561
674
  const trailingSeparatorHeight = trailingRegion != null && trailingRegion.collapsedLines > 0 ? getTrailingHunkSeparatorLayout({
562
675
  type: hunkSeparators,
563
676
  metrics: this.metrics
677
+ })?.totalHeight ?? 0 : hunkIndex === finalHunkIndex && canHydratePartialDiff ? getTrailingHunkSeparatorLayout({
678
+ type: hunkSeparators,
679
+ metrics: this.metrics
564
680
  })?.totalHeight ?? 0 : 0;
565
681
  const trailingExpandedCount = trailingRegion != null ? trailingRegion.fromStart + trailingRegion.fromEnd : 0;
566
682
  const hunkBodyRowCount = diffStyle === "split" ? hunk.splitLineCount : hunk.unifiedLineCount;
@@ -651,13 +767,19 @@ var VirtualizedFileDiff = class extends FileDiff {
651
767
  if (trailingRegion != null) count += trailingRegion.fromStart + trailingRegion.fromEnd;
652
768
  return count;
653
769
  }
770
+ getLayoutLineCount(fileDiff, diffStyle) {
771
+ const expandedLineCount = this.getExpandedLineCount(fileDiff, diffStyle);
772
+ const metadataLineCount = diffStyle === "split" ? fileDiff.splitLineCount : fileDiff.unifiedLineCount;
773
+ return Math.max(expandedLineCount, metadataLineCount, fileDiff.additionLines.length, fileDiff.deletionLines.length, this.cache.totalLines);
774
+ }
654
775
  computeRenderRangeFromWindow(fileDiff, fileTop, { top, bottom }) {
655
776
  const { disableFileHeader = false, expandUnchanged = false, collapsedContextThreshold = 1 } = this.options;
656
777
  const { hunkLineCount, lineHeight } = this.metrics;
657
778
  const diffStyle = this.getDiffStyle();
658
779
  const hunkSeparators = this.getHunkSeparatorType();
780
+ const canHydratePartialDiff = canHydrateCollapsedContext(fileDiff, this.options.loadDiffFiles != null);
659
781
  const fileHeight = this.height;
660
- let lineCount = this.cache.totalLines > 0 ? this.cache.totalLines : this.getExpandedLineCount(fileDiff, diffStyle);
782
+ let lineCount = this.getLayoutLineCount(fileDiff, diffStyle);
661
783
  const headerRegion = getVirtualFileHeaderRegion(this.metrics, disableFileHeader);
662
784
  const paddingBottom = fileDiff.hunks.length > 0 ? getVirtualFilePaddingBottom(this.metrics) : 0;
663
785
  const { fileAnnotationHeight } = this.cache;
@@ -678,8 +800,8 @@ var VirtualizedFileDiff = class extends FileDiff {
678
800
  bufferBefore: 0,
679
801
  bufferAfter: 0
680
802
  };
681
- this.approximateLayoutCheckpoints();
682
- lineCount = this.cache.totalLines > 0 ? this.cache.totalLines : lineCount;
803
+ this.approximateLayoutCheckpoints(fileDiff);
804
+ lineCount = this.getLayoutLineCount(fileDiff, diffStyle);
683
805
  const estimatedTargetLines = Math.ceil(Math.max(bottom - top, 0) / lineHeight);
684
806
  const totalLines = Math.ceil(estimatedTargetLines / hunkLineCount) * hunkLineCount + hunkLineCount;
685
807
  const totalHunks = totalLines / hunkLineCount;
@@ -702,6 +824,7 @@ var VirtualizedFileDiff = class extends FileDiff {
702
824
  const splitLineIndex = additionLine != null ? additionLine.splitLineIndex : deletionLine.splitLineIndex;
703
825
  const unifiedLineIndex = additionLine != null ? additionLine.unifiedLineIndex : deletionLine.unifiedLineIndex;
704
826
  const hasMetadata = (additionLine?.noEOFCR ?? false) || (deletionLine?.noEOFCR ?? false);
827
+ const isFinalHunkRow = hunkIndex === fileDiff.hunks.length - 1 && hunk != null && (diffStyle === "split" ? splitLineIndex === hunk.splitLineStart + hunk.splitLineCount - 1 : unifiedLineIndex === hunk.unifiedLineStart + hunk.unifiedLineCount - 1);
705
828
  const gapAdjustment = (collapsedBefore > 0 ? getLeadingHunkSeparatorLayout({
706
829
  type: hunkSeparators,
707
830
  metrics: this.metrics,
@@ -724,10 +847,17 @@ var VirtualizedFileDiff = class extends FileDiff {
724
847
  if (overflowCounter == null && absoluteLineTop >= bottom && isAtHunkBoundary) overflowCounter = overflowHunks;
725
848
  currentLine++;
726
849
  absoluteLineTop += lineHeight;
727
- if (collapsedAfter > 0) absoluteLineTop += getTrailingHunkSeparatorLayout({
728
- type: hunkSeparators,
729
- metrics: this.metrics
730
- })?.totalHeight ?? 0;
850
+ if (collapsedAfter > 0 || isFinalHunkRow && canHydratePartialDiff) {
851
+ const trailingSeparator = getTrailingHunkSeparatorLayout({
852
+ type: hunkSeparators,
853
+ metrics: this.metrics
854
+ });
855
+ if (trailingSeparator != null) {
856
+ if (absoluteLineTop < bottom && absoluteLineTop + trailingSeparator.totalHeight > top) firstVisibleHunk ??= currentHunk;
857
+ if (centerHunk == null && absoluteLineTop + trailingSeparator.totalHeight > viewportCenter) centerHunk = currentHunk;
858
+ absoluteLineTop += trailingSeparator.totalHeight;
859
+ }
860
+ }
731
861
  return false;
732
862
  }
733
863
  });
@@ -805,7 +935,7 @@ function lowerBound(values, target) {
805
935
  return low;
806
936
  }
807
937
  function getNextCheckpointIndex(renderedLineIndex) {
808
- return Math.ceil(renderedLineIndex / LAYOUT_CHECKPOINT_INTERVAL) * LAYOUT_CHECKPOINT_INTERVAL;
938
+ return Math.ceil(renderedLineIndex / VIRTUALIZED_FILE_DIFF_LAYOUT_CHECKPOINT_INTERVAL) * VIRTUALIZED_FILE_DIFF_LAYOUT_CHECKPOINT_INTERVAL;
809
939
  }
810
940
  function countMetadataOffsetsBefore(metadataOffsets, offset) {
811
941
  let count = 0;
@@ -827,19 +957,26 @@ function getHunkMetadataOffsets({ diffStyle, hunk, rowCount }) {
827
957
  return offsets;
828
958
  }
829
959
  function hasDiffLayoutOptionChanged(previousOptions, nextOptions) {
830
- return (previousOptions.diffStyle ?? "split") !== (nextOptions.diffStyle ?? "split") || (previousOptions.overflow ?? "scroll") !== (nextOptions.overflow ?? "scroll") || (previousOptions.collapsed ?? false) !== (nextOptions.collapsed ?? false) || (previousOptions.disableLineNumbers ?? false) !== (nextOptions.disableLineNumbers ?? false) || (previousOptions.disableFileHeader ?? false) !== (nextOptions.disableFileHeader ?? false) || (previousOptions.diffIndicators ?? "bars") !== (nextOptions.diffIndicators ?? "bars") || (previousOptions.hunkSeparators ?? "line-info") !== (nextOptions.hunkSeparators ?? "line-info") || (previousOptions.expandUnchanged ?? false) !== (nextOptions.expandUnchanged ?? false) || (previousOptions.collapsedContextThreshold ?? 1) !== (nextOptions.collapsedContextThreshold ?? 1) || previousOptions.unsafeCSS !== nextOptions.unsafeCSS;
960
+ return (previousOptions.diffStyle ?? "split") !== (nextOptions.diffStyle ?? "split") || (previousOptions.overflow ?? "scroll") !== (nextOptions.overflow ?? "scroll") || (previousOptions.collapsed ?? false) !== (nextOptions.collapsed ?? false) || (previousOptions.disableLineNumbers ?? false) !== (nextOptions.disableLineNumbers ?? false) || (previousOptions.disableFileHeader ?? false) !== (nextOptions.disableFileHeader ?? false) || (previousOptions.diffIndicators ?? "bars") !== (nextOptions.diffIndicators ?? "bars") || (previousOptions.hunkSeparators ?? "line-info") !== (nextOptions.hunkSeparators ?? "line-info") || Boolean(previousOptions.loadDiffFiles) !== Boolean(nextOptions.loadDiffFiles) || (previousOptions.expandUnchanged ?? false) !== (nextOptions.expandUnchanged ?? false) || (previousOptions.collapsedContextThreshold ?? 1) !== (nextOptions.collapsedContextThreshold ?? 1) || previousOptions.unsafeCSS !== nextOptions.unsafeCSS;
831
961
  }
832
962
  function hasDiffEstimateOptionChanged(previousOptions, nextOptions) {
833
- return (previousOptions.disableFileHeader ?? false) !== (nextOptions.disableFileHeader ?? false) || (previousOptions.hunkSeparators ?? "line-info") !== (nextOptions.hunkSeparators ?? "line-info") || (previousOptions.expandUnchanged ?? false) !== (nextOptions.expandUnchanged ?? false) || (previousOptions.collapsedContextThreshold ?? 1) !== (nextOptions.collapsedContextThreshold ?? 1);
963
+ return (previousOptions.disableFileHeader ?? false) !== (nextOptions.disableFileHeader ?? false) || (previousOptions.hunkSeparators ?? "line-info") !== (nextOptions.hunkSeparators ?? "line-info") || Boolean(previousOptions.loadDiffFiles) !== Boolean(nextOptions.loadDiffFiles) || (previousOptions.expandUnchanged ?? false) !== (nextOptions.expandUnchanged ?? false) || (previousOptions.collapsedContextThreshold ?? 1) !== (nextOptions.collapsedContextThreshold ?? 1);
964
+ }
965
+ function canHydrateCollapsedContext(fileDiff, hasFileLoader) {
966
+ return fileDiff.isPartial && hasFileLoader && (fileDiff.type === "change" || fileDiff.type === "rename-changed");
834
967
  }
835
968
  function getOptionHunkSeparatorType(hunkSeparators) {
836
969
  return typeof hunkSeparators === "function" ? "custom" : hunkSeparators ?? "line-info";
837
970
  }
971
+ function areOptionalFilesEqual(fileA, fileB) {
972
+ if (fileA == null || fileB == null) return fileA == null && fileB == null;
973
+ return areFilesEqual(fileA, fileB);
974
+ }
838
975
  function parseLineIndex(lineIndexAttr, diffStyle) {
839
976
  const [unifiedIndex, splitIndex] = lineIndexAttr.split(",").map(Number);
840
977
  return diffStyle === "split" ? splitIndex : unifiedIndex;
841
978
  }
842
979
  //#endregion
843
- export { VirtualizedFileDiff };
980
+ export { VIRTUALIZED_FILE_DIFF_LAYOUT_CHECKPOINT_INTERVAL, VirtualizedFileDiff };
844
981
 
845
982
  //# sourceMappingURL=VirtualizedFileDiff.js.map