@pierre/diffs 1.2.0-beta.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/components/CodeView.d.ts +19 -4
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +148 -32
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +5 -0
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +54 -10
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +5 -1
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +56 -14
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/FileStream.js +1 -0
  14. package/dist/components/FileStream.js.map +1 -1
  15. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  16. package/dist/components/UnresolvedFile.js +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +1 -0
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +19 -6
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +6 -0
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +75 -35
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/components/Virtualizer.js +1 -1
  26. package/dist/components/Virtualizer.js.map +1 -1
  27. package/dist/constants.js +0 -1
  28. package/dist/constants.js.map +1 -1
  29. package/dist/highlighter/shared_highlighter.js +14 -0
  30. package/dist/highlighter/shared_highlighter.js.map +1 -1
  31. package/dist/index.d.ts +5 -1
  32. package/dist/index.js +8 -4
  33. package/dist/managers/InteractionManager.d.ts.map +1 -1
  34. package/dist/managers/ResizeManager.d.ts +7 -2
  35. package/dist/managers/ResizeManager.d.ts.map +1 -1
  36. package/dist/managers/ResizeManager.js +52 -16
  37. package/dist/managers/ResizeManager.js.map +1 -1
  38. package/dist/react/CodeView.d.ts +1 -0
  39. package/dist/react/CodeView.d.ts.map +1 -1
  40. package/dist/react/CodeView.js +9 -0
  41. package/dist/react/CodeView.js.map +1 -1
  42. package/dist/renderers/DiffHunksRenderer.d.ts +2 -0
  43. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  44. package/dist/renderers/DiffHunksRenderer.js +34 -21
  45. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  46. package/dist/renderers/FileRenderer.d.ts +3 -0
  47. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  48. package/dist/renderers/FileRenderer.js +37 -23
  49. package/dist/renderers/FileRenderer.js.map +1 -1
  50. package/dist/style.js +1 -1
  51. package/dist/style.js.map +1 -1
  52. package/dist/types.d.ts +4 -3
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/utils/areDiffTargetsEqual.d.ts +7 -0
  55. package/dist/utils/areDiffTargetsEqual.d.ts.map +1 -0
  56. package/dist/utils/areDiffTargetsEqual.js +8 -0
  57. package/dist/utils/areDiffTargetsEqual.js.map +1 -0
  58. package/dist/utils/areFileRenderOptionsEqual.d.ts +7 -0
  59. package/dist/utils/areFileRenderOptionsEqual.d.ts.map +1 -0
  60. package/dist/utils/areFileRenderOptionsEqual.js +10 -0
  61. package/dist/utils/areFileRenderOptionsEqual.js.map +1 -0
  62. package/dist/utils/areWorkerStatsEqual.js +1 -1
  63. package/dist/utils/areWorkerStatsEqual.js.map +1 -1
  64. package/dist/utils/computeVirtualFileMetrics.d.ts +11 -0
  65. package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -0
  66. package/dist/utils/{resolveVirtualFileMetrics.js → computeVirtualFileMetrics.js} +7 -10
  67. package/dist/utils/computeVirtualFileMetrics.js.map +1 -0
  68. package/dist/utils/detachString.d.ts +6 -0
  69. package/dist/utils/detachString.d.ts.map +1 -0
  70. package/dist/utils/detachString.js +21 -0
  71. package/dist/utils/detachString.js.map +1 -0
  72. package/dist/utils/isStyleNode.d.ts +5 -0
  73. package/dist/utils/isStyleNode.d.ts.map +1 -0
  74. package/dist/utils/isStyleNode.js +10 -0
  75. package/dist/utils/isStyleNode.js.map +1 -0
  76. package/dist/utils/parsePatchFiles.d.ts +1 -7
  77. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  78. package/dist/utils/parsePatchFiles.js +180 -59
  79. package/dist/utils/parsePatchFiles.js.map +1 -1
  80. package/dist/utils/prefersReducedMotion.d.ts +5 -0
  81. package/dist/utils/prefersReducedMotion.d.ts.map +1 -0
  82. package/dist/utils/prefersReducedMotion.js +9 -0
  83. package/dist/utils/prefersReducedMotion.js.map +1 -0
  84. package/dist/worker/WorkerPoolManager.d.ts +33 -5
  85. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  86. package/dist/worker/WorkerPoolManager.js +278 -79
  87. package/dist/worker/WorkerPoolManager.js.map +1 -1
  88. package/dist/worker/types.d.ts +7 -3
  89. package/dist/worker/types.d.ts.map +1 -1
  90. package/dist/worker/worker-portable.js +9 -10
  91. package/dist/worker/worker-portable.js.map +1 -1
  92. package/dist/worker/worker.js +3 -1
  93. package/dist/worker/worker.js.map +1 -1
  94. package/package.json +2 -6
  95. package/dist/utils/resolveVirtualFileMetrics.d.ts +0 -10
  96. package/dist/utils/resolveVirtualFileMetrics.d.ts.map +0 -1
  97. package/dist/utils/resolveVirtualFileMetrics.js.map +0 -1
@@ -1,9 +1,25 @@
1
1
  //#region src/managers/ResizeManager.ts
2
- var ResizeManager = class {
3
- resizeObserver;
2
+ var ResizeManager = class ResizeManager {
3
+ static resizeObserver;
4
+ static managersByElement = /* @__PURE__ */ new Map();
5
+ static getResizeObserver() {
6
+ const resizeObserver = ResizeManager.resizeObserver ?? new ResizeObserver(ResizeManager.handleSharedResizeEntries);
7
+ ResizeManager.resizeObserver = resizeObserver;
8
+ return resizeObserver;
9
+ }
10
+ static handleSharedResizeEntries(entries) {
11
+ const entriesByManager = /* @__PURE__ */ new Map();
12
+ for (const entry of entries) {
13
+ const manager = ResizeManager.managersByElement.get(entry.target);
14
+ if (manager == null) continue;
15
+ const managerEntries = entriesByManager.get(manager);
16
+ if (managerEntries == null) entriesByManager.set(manager, [entry]);
17
+ else managerEntries.push(entry);
18
+ }
19
+ for (const [manager, managerEntries] of entriesByManager) manager.handleResizeEntries(managerEntries);
20
+ }
4
21
  observedNodes = /* @__PURE__ */ new Map();
5
22
  setup(pre, disableAnnotations) {
6
- this.resizeObserver ??= new ResizeObserver(this.handleResizeObserver);
7
23
  const annotationUpdates = /* @__PURE__ */ new Set();
8
24
  let columnCount = 0;
9
25
  const observedNodes = new Map(this.observedNodes);
@@ -24,11 +40,11 @@ var ResizeManager = class {
24
40
  observedNodes.delete(codeElement);
25
41
  if (item.numberElement !== numberElement) {
26
42
  if (item.numberElement != null) {
27
- this.resizeObserver.unobserve(item.numberElement);
43
+ this.unobserve(item.numberElement);
28
44
  observedNodes.delete(item.numberElement);
29
45
  }
30
46
  if (numberElement != null) {
31
- this.resizeObserver.observe(numberElement);
47
+ this.observe(numberElement);
32
48
  observedNodes.delete(numberElement);
33
49
  this.observedNodes.set(numberElement, item);
34
50
  }
@@ -47,10 +63,10 @@ var ResizeManager = class {
47
63
  numberWidth: 0
48
64
  };
49
65
  this.observedNodes.set(codeElement, item);
50
- this.resizeObserver.observe(codeElement);
66
+ this.observe(codeElement);
51
67
  if (numberElement != null) {
52
68
  this.observedNodes.set(numberElement, item);
53
- this.resizeObserver.observe(numberElement);
69
+ this.observe(numberElement);
54
70
  }
55
71
  }
56
72
  }
@@ -118,34 +134,54 @@ var ResizeManager = class {
118
134
  this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);
119
135
  this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);
120
136
  this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);
121
- this.resizeObserver.observe(pendingUpdate.child1);
122
- this.resizeObserver.observe(pendingUpdate.child2);
137
+ this.observe(pendingUpdate.child1);
138
+ this.observe(pendingUpdate.child2);
123
139
  }
124
140
  annotationUpdates.clear();
125
141
  }
126
142
  for (const [element, item] of observedNodes) {
127
- this.resizeObserver.unobserve(element);
143
+ this.unobserve(element);
128
144
  if (item.type === "code") cleanupStaleCodeItem(item);
129
145
  else cleanupStaleAnnotationItem(item);
130
146
  }
131
147
  observedNodes.clear();
132
148
  }
133
149
  cleanUp() {
134
- this.resizeObserver?.disconnect();
150
+ for (const element of this.observedNodes.keys()) this.unobserve(element);
135
151
  this.observedNodes.clear();
136
152
  }
137
- handleResizeObserver = (entries) => {
153
+ observe(element) {
154
+ const { managersByElement } = ResizeManager;
155
+ const owner = managersByElement.get(element);
156
+ if (owner === this) return;
157
+ else if (owner != null && owner !== this) throw new Error("ResizeManager.observe: element is already owned by another ResizeManager");
158
+ managersByElement.set(element, this);
159
+ ResizeManager.getResizeObserver().observe(element);
160
+ }
161
+ unobserve(element) {
162
+ const { managersByElement, resizeObserver } = ResizeManager;
163
+ const owner = managersByElement.get(element);
164
+ if (owner == null) return;
165
+ else if (owner !== this) throw new Error("ResizeManager.unobserve: element is owned by another ResizeManager");
166
+ managersByElement.delete(element);
167
+ resizeObserver?.unobserve(element);
168
+ if (resizeObserver != null && managersByElement.size === 0) {
169
+ resizeObserver.disconnect();
170
+ ResizeManager.resizeObserver = void 0;
171
+ }
172
+ }
173
+ handleResizeEntries(entries) {
138
174
  const codeUpdates = /* @__PURE__ */ new Map();
139
175
  const annotationUpdates = /* @__PURE__ */ new Set();
140
176
  for (const entry of entries) {
141
177
  const { target, borderBoxSize, contentBoxSize } = entry;
142
178
  if (!(target instanceof HTMLElement)) {
143
- console.error("FileDiff.handleResizeObserver: Invalid element for ResizeObserver", entry);
179
+ console.error("ResizeManager.handleResizeEntries: Invalid element for ResizeObserver", entry);
144
180
  continue;
145
181
  }
146
182
  const item = this.observedNodes.get(target);
147
183
  if (item == null) {
148
- console.error("FileDiff.handleResizeObserver: Not a valid observed node", entry);
184
+ console.error("ResizeManager.handleResizeEntries: Not a valid observed node", entry);
149
185
  continue;
150
186
  }
151
187
  if (item.type === "annotations") {
@@ -154,7 +190,7 @@ var ResizeManager = class {
154
190
  if (target === item.column2.child) return item.column2;
155
191
  })();
156
192
  if (column == null) {
157
- console.error(`FileDiff.handleResizeObserver: Couldn't find a column for`, {
193
+ console.error(`ResizeManager.handleResizeEntries: Couldn't find a column for`, {
158
194
  item,
159
195
  target
160
196
  });
@@ -174,7 +210,7 @@ var ResizeManager = class {
174
210
  annotationUpdates.clear();
175
211
  this.applyColumnUpdates(codeUpdates);
176
212
  codeUpdates.clear();
177
- };
213
+ }
178
214
  applyAnnotationUpdates(annotationUpdates) {
179
215
  for (const item of annotationUpdates) this.applyNewHeight(item, Math.max(item.column1.childHeight, item.column2.childHeight));
180
216
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ResizeManager.js","names":["codeElement: HTMLElement | undefined","item: ObservedGridNodes | ObservedAnnotationNodes | undefined","codeUpdates: CodeUpdateMap","annotationUpdates: Set<ObservedAnnotationNodes>"],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n private resizeObserver: ResizeObserver | undefined;\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void {\n this.resizeObserver ??= new ResizeObserver(this.handleResizeObserver);\n const annotationUpdates = new Set<AnnotationSetup>();\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.resizeObserver.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.resizeObserver.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n };\n this.observedNodes.set(codeElement, item);\n this.resizeObserver.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.resizeObserver.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^\\d+,\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.resizeObserver.observe(pendingUpdate.child1);\n this.resizeObserver.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.resizeObserver.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n // Disconnect any existing observer and nodes\n this.resizeObserver?.disconnect();\n this.observedNodes.clear();\n }\n\n private handleResizeObserver = (entries: ResizeObserverEntry[]) => {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'FileDiff.handleResizeObserver: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'FileDiff.handleResizeObserver: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `FileDiff.handleResizeObserver: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n };\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (codeWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof nextCodeWidth === 'number' ? `${nextCodeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${nextNumberWidth === 0 ? 'auto' : `${nextNumberWidth}px`}`\n );\n }\n\n if (\n codeWidthChanged ||\n (numberWidthChanged && nextCodeWidth !== 'auto')\n ) {\n const targetWidth =\n typeof nextCodeWidth === 'number'\n ? Math.max(nextCodeWidth - nextNumberWidth, 0)\n : 0;\n item.codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n}\n"],"mappings":";AAiBA,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ,gCAAgB,IAAI,KAGzB;CAEH,MAAM,KAAqB,oBAAmC;AAC5D,OAAK,mBAAmB,IAAI,eAAe,KAAK,qBAAqB;EACrE,MAAM,oCAAoB,IAAI,KAAsB;EACpD,IAAI,cAAc;EAClB,MAAM,gBAAgB,IAAI,IAAI,KAAK,cAAc;AACjD,OAAK,cAAc,OAAO;AAE1B,OAAK,MAAM,WAAW,IAAI,UAAU;AAClC,OAAI,gBAAgB,EAClB;GAEF,MAAMA,qBAA8C;AAClD,QAAI,mBAAmB,eAAe,QAAQ,YAAY,OACxD,QAAO;OAGP;AACJ,OAAI,eAAe,KACjB;AAEF;GACA,IAAIC,OACF,cAAc,IAAI,YAAY;AAChC,OAAI,QAAQ,QAAQ,KAAK,SAAS,OAChC,OAAM,IAAI,MACR,iGACD;GAGH,IAAI,gBAAgB,YAAY;AAChC,OAAI,EAAE,yBAAyB,aAC7B,iBAAgB;AAElB,OAAI,QAAQ,MAAM;AAChB,SAAK,cAAc,IAAI,aAAa,KAAK;AACzC,kBAAc,OAAO,YAAY;AACjC,QAAI,KAAK,kBAAkB,eAAe;AACxC,SAAI,KAAK,iBAAiB,MAAM;AAC9B,WAAK,eAAe,UAAU,KAAK,cAAc;AACjD,oBAAc,OAAO,KAAK,cAAc;;AAE1C,SAAI,iBAAiB,MAAM;AACzB,WAAK,eAAe,QAAQ,cAAc;AAC1C,oBAAc,OAAO,cAAc;AACnC,WAAK,cAAc,IAAI,eAAe,KAAK;;AAE7C,UAAK,gBAAgB;AACrB,UAAK,cAAc;eACV,KAAK,iBAAiB,MAAM;AACrC,mBAAc,OAAO,KAAK,cAAc;AACxC,UAAK,cAAc,IAAI,K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sBAAsB,kBAAkB,QACzC;IACA,MAAM,cACJ,OAAO,kBAAkB,WACrB,KAAK,IAAI,gBAAgB,iBAAiB,EAAE,GAC5C;AACN,SAAK,YAAY,MAAM,YACrB,gCACA,GAAG,cAAc,IAAI,GAAG,YAAY,MAAM,SAC3C;;;;CAKP,AAAQ,eAAe,MAA+B,WAAmB;AACvE,MAAI,cAAc,KAAK,eAAe;AACpC,QAAK,gBAAgB,KAAK,IAAI,WAAW,EAAE;AAC3C,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;AACD,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;;;;AAKP,SAAS,iBAAiB,YAAqC;CAC7D,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,WAAW,EAAE,EAAE;AACjD,QAAO,UAAU,IAAI,SAAS;;AAGhC,SAAS,mBAAmB,YAA4B;AACtD,QAAO,KAAK,IAAI,KAAK,KAAK,WAAW,EAAE,EAAE;;AAG3C,SAAS,qBAAqB,MAA+B;AAC3D,KAAI,KAAK,YAAY,aAAa;AAChC,OAAK,YAAY,MAAM,eAAe,+BAA+B;AACrE,OAAK,YAAY,MAAM,eAAe,8BAA8B;AACpE,OAAK,YAAY,MAAM,eAAe,uBAAuB;;;AAIjE,SAAS,2BAA2B,MAAqC;AACvE,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD;AAEH,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD"}
1
+ {"version":3,"file":"ResizeManager.js","names":["codeElement: HTMLElement | undefined","item: ObservedGridNodes | ObservedAnnotationNodes | undefined","codeUpdates: CodeUpdateMap","annotationUpdates: Set<ObservedAnnotationNodes>"],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n // Shared static resizeObserver that all ResizeManagers use\n private static resizeObserver: ResizeObserver | undefined;\n private static managersByElement = new Map<Element, ResizeManager>();\n\n private static getResizeObserver(): ResizeObserver {\n const resizeObserver =\n ResizeManager.resizeObserver ??\n new ResizeObserver(ResizeManager.handleSharedResizeEntries);\n ResizeManager.resizeObserver = resizeObserver;\n return resizeObserver;\n }\n\n private static handleSharedResizeEntries(entries: ResizeObserverEntry[]) {\n // First we need to batch all elements by manager, so callbacks are\n // properly aligned with a per-instance ResizeManager\n const entriesByManager = new Map<ResizeManager, ResizeObserverEntry[]>();\n for (const entry of entries) {\n const manager = ResizeManager.managersByElement.get(entry.target);\n if (manager == null) {\n continue;\n }\n const managerEntries = entriesByManager.get(manager);\n if (managerEntries == null) {\n entriesByManager.set(manager, [entry]);\n } else {\n managerEntries.push(entry);\n }\n }\n\n for (const [manager, managerEntries] of entriesByManager) {\n manager.handleResizeEntries(managerEntries);\n }\n }\n\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void {\n const annotationUpdates = new Set<AnnotationSetup>();\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n };\n this.observedNodes.set(codeElement, item);\n this.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^\\d+,\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.observe(pendingUpdate.child1);\n this.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n for (const element of this.observedNodes.keys()) {\n this.unobserve(element);\n }\n this.observedNodes.clear();\n }\n\n private observe(element: HTMLElement): void {\n const { managersByElement } = ResizeManager;\n const owner = managersByElement.get(element);\n // Already registered\n if (owner === this) {\n return;\n }\n // If we've already somehow registered with another manager, we in for a\n // world of pain, so complain loudly\n else if (owner != null && owner !== this) {\n throw new Error(\n 'ResizeManager.observe: element is already owned by another ResizeManager'\n );\n }\n managersByElement.set(element, this);\n ResizeManager.getResizeObserver().observe(element);\n }\n\n private unobserve(element: HTMLElement): void {\n const { managersByElement, resizeObserver } = ResizeManager;\n const owner = managersByElement.get(element);\n if (owner == null) {\n return;\n } else if (owner !== this) {\n throw new Error(\n 'ResizeManager.unobserve: element is owned by another ResizeManager'\n );\n }\n\n managersByElement.delete(element);\n resizeObserver?.unobserve(element);\n if (resizeObserver != null && managersByElement.size === 0) {\n resizeObserver.disconnect();\n ResizeManager.resizeObserver = undefined;\n }\n }\n\n private handleResizeEntries(entries: ResizeObserverEntry[]) {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'ResizeManager.handleResizeEntries: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'ResizeManager.handleResizeEntries: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `ResizeManager.handleResizeEntries: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n }\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (codeWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof nextCodeWidth === 'number' ? `${nextCodeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${nextNumberWidth === 0 ? 'auto' : `${nextNumberWidth}px`}`\n );\n }\n\n if (\n codeWidthChanged ||\n (numberWidthChanged && nextCodeWidth !== 'auto')\n ) {\n const targetWidth =\n typeof nextCodeWidth === 'number'\n ? Math.max(nextCodeWidth - nextNumberWidth, 0)\n : 0;\n item.codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n}\n"],"mappings":";AAiBA,IAAa,gBAAb,MAAa,cAAc;CAEzB,OAAe;CACf,OAAe,oCAAoB,IAAI,KAA6B;CAEpE,OAAe,oBAAoC;EACjD,MAAM,iBACJ,cAAc,kBACd,IAAI,eAAe,cAAc,0BAA0B;AAC7D,gBAAc,iBAAiB;AAC/B,SAAO;;CAGT,OAAe,0BAA0B,SAAgC;EAGvE,MAAM,mCAAmB,IAAI,KAA2C;AACxE,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,UAAU,cAAc,kBAAkB,IAAI,MAAM,OAAO;AACjE,OAAI,WAAW,KACb;GAEF,MAAM,iBAAiB,iBAAiB,IAAI,QAAQ;AACpD,OAAI,kBAAkB,KACpB,kBAAiB,IAAI,SAAS,CAAC,MAAM,CAAC;OAEtC,gBAAe,KAAK,MAAM;;AAI9B,OAAK,MAAM,CAAC,SAAS,mBAAmB,iBACtC,SAAQ,oBAAoB,eAAe;;CAI/C,AAAQ,gCAAgB,IAAI,KAGzB;CAEH,MAAM,KAAqB,oBAAmC;EAC5D,MAAM,oCAAoB,IAAI,KAAsB;EACpD,IAAI,cAAc;EAClB,MAAM,gBAAgB,IAAI,IAAI,KAAK,cAAc;AACjD,OAAK,cAAc,OAAO;AAE1B,OAAK,MAAM,WAAW,IAAI,UAAU;AAClC,OAAI,gBAAgB,EAClB;GAEF,MAAMA,qBAA8C;AACl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AG,oBAAoB,IAAI,SAAS,GAAG,gBAAgB,MACxD;AAGH,OACE,oBACC,sBAAsB,kBAAkB,QACzC;IACA,MAAM,cACJ,OAAO,kBAAkB,WACrB,KAAK,IAAI,gBAAgB,iBAAiB,EAAE,GAC5C;AACN,SAAK,YAAY,MAAM,YACrB,gCACA,GAAG,cAAc,IAAI,GAAG,YAAY,MAAM,SAC3C;;;;CAKP,AAAQ,eAAe,MAA+B,WAAmB;AACvE,MAAI,cAAc,KAAK,eAAe;AACpC,QAAK,gBAAgB,KAAK,IAAI,WAAW,EAAE;AAC3C,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;AACD,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;;;;AAKP,SAAS,iBAAiB,YAAqC;CAC7D,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,WAAW,EAAE,EAAE;AACjD,QAAO,UAAU,IAAI,SAAS;;AAGhC,SAAS,mBAAmB,YAA4B;AACtD,QAAO,KAAK,IAAI,KAAK,KAAK,WAAW,EAAE,EAAE;;AAG3C,SAAS,qBAAqB,MAA+B;AAC3D,KAAI,KAAK,YAAY,aAAa;AAChC,OAAK,YAAY,MAAM,eAAe,+BAA+B;AACrE,OAAK,YAAY,MAAM,eAAe,8BAA8B;AACpE,OAAK,YAAY,MAAM,eAAe,uBAAuB;;;AAIjE,SAAS,2BAA2B,MAAqC;AACvE,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD;AAEH,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD"}
@@ -34,6 +34,7 @@ interface CodeViewHandle<LAnnotation> {
34
34
  addItems(items: readonly CodeViewItem<LAnnotation>[]): void;
35
35
  getItem(id: string): CodeViewItem<LAnnotation> | undefined;
36
36
  updateItem(item: CodeViewItem<LAnnotation>): boolean;
37
+ updateItemId(oldId: string, newId: string): boolean;
37
38
  scrollTo(target: CodeViewScrollTarget): void;
38
39
  setSelectedLines(selection: CodeViewLineSelection | null): void;
39
40
  getSelectedLines(): CodeViewLineSelection | null;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeView.d.ts","names":["CSSProperties","ReactNode","Ref","CodeView","CodeViewClass","CodeViewItem","CodeViewLineSelection","CodeViewOptions","CodeViewScrollTarget","DiffLineAnnotation","GetHoveredLineResult","LineAnnotation","CodeViewGutterUtilityGetter","CodeViewBaseProps","LAnnotation","HTMLDivElement","ControlledCodeViewProps","UncontrolledCodeViewProps","CodeViewProps","CodeViewHandle","CodeViewComponent","React","JSX","Element"],"sources":["../../src/react/CodeView.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode, type Ref } from 'react';\nimport { CodeView as CodeViewClass, type CodeViewItem, type CodeViewLineSelection, type CodeViewOptions, type CodeViewScrollTarget, type DiffLineAnnotation, type GetHoveredLineResult, type LineAnnotation } from '../index';\ntype CodeViewGutterUtilityGetter = (() => GetHoveredLineResult<'file'> | undefined) | (() => GetHoveredLineResult<'diff'> | undefined);\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>, item: CodeViewItem<LAnnotation>): ReactNode;\n renderGutterUtility?(getHoveredLine: CodeViewGutterUtilityGetter, item: CodeViewItem<LAnnotation>): ReactNode;\n}\nexport interface ControlledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\nexport interface UncontrolledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\nexport type CodeViewProps<LAnnotation = undefined> = ControlledCodeViewProps<LAnnotation> | UncontrolledCodeViewProps<LAnnotation>;\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\ntype CodeViewComponent = <LAnnotation = undefined>(props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n}) => React.JSX.Element;\nexport declare const CodeView: CodeViewComponent;\nexport {};\n//# sourceMappingURL=CodeView.d.ts.map"],"mappings":";;;;;;;KAEKY,2BAAAA,UAAqCF,mDAAmDA;UACnFG;YACIN,gBAAgBO;;UAElBd;EAJPY,YAAAA,CAAAA,EAKcV,GALdU,CAKkBG,cALS,CAAA;EACtBF,iBAAAA,CAAAA,EAAiB,OAAAC;EACGA,aAAAA,CAAAA,EAKVR,qBALUQ,GAAAA,IAAAA;EAAhBP,qBAAAA,EAAAA,SAAAA,EAMwBD,qBANxBC,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAEFP,QAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAK6BI,UAL7BJ,CAK2Cc,WAL3Cd,CAAAA,CAAAA,EAAAA,IAAAA;EACWe,kBAAAA,EAAAA,IAAAA,EAKOV,YALPU,CAKoBD,WALpBC,CAAAA,CA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,EAAAA,MAAAA,CAAAA,EAc1DT,YAd0DS,CAc7CA,WAd6CA,CAAAA,GAAAA,SAAAA;EAAnBL,UAAAA,CAAAA,IAAAA,EAe3CJ,YAf2CI,CAe9BK,WAf8BL,CAAAA,CAAAA,EAAAA,OAAAA;EAAoDK,QAAAA,CAAAA,MAAAA,EAgB/FN,oBAhB+FM,CAAAA,EAAAA,IAAAA;EAAbT,gBAAAA,CAAAA,SAAAA,EAiBvEC,qBAjBuED,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAA4BJ,gBAAAA,EAAAA,EAkB3GK,qBAlB2GL,GAAAA,IAAAA;EAC1FW,kBAAAA,EAAAA,EAAAA,IAAAA;EAAgDE,WAAAA,EAAAA,EAmBtEV,UAnBsEU,CAmBxDA,WAnBwDA,CAAAA,GAAAA,SAAAA;;KAqBpFM,iBAAAA,GArBmGnB,CAAAA,cAAAA,SAAAA,CAAAA,CAAAA,KAAAA,EAqB9CiB,aArB8CjB,CAqBhCa,WArBgCb,CAAAA,GAAAA;EAAS,GAAA,CAAA,EAsBvGoB,KAAAA,CAAMnB,GAtBiG,CAsB7FiB,cAtB6F,CAsB9EL,WAtB8E,CAAA,CAAA;AAEjH,CAAA,EAAA,GAqBMO,KAAAA,CAAMC,GAAAA,CAAIC,OArBCP;AAA+DF,cAsB3DX,QAtB2DW,EAsBjDM,iBAtBiDN"}
1
+ {"version":3,"file":"CodeView.d.ts","names":["CSSProperties","ReactNode","Ref","CodeView","CodeViewClass","CodeViewItem","CodeViewLineSelection","CodeViewOptions","CodeViewScrollTarget","DiffLineAnnotation","GetHoveredLineResult","LineAnnotation","CodeViewGutterUtilityGetter","CodeViewBaseProps","LAnnotation","HTMLDivElement","ControlledCodeViewProps","UncontrolledCodeViewProps","CodeViewProps","CodeViewHandle","CodeViewComponent","React","JSX","Element"],"sources":["../../src/react/CodeView.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode, type Ref } from 'react';\nimport { CodeView as CodeViewClass, type CodeViewItem, type CodeViewLineSelection, type CodeViewOptions, type CodeViewScrollTarget, type DiffLineAnnotation, type GetHoveredLineResult, type LineAnnotation } from '../index';\ntype CodeViewGutterUtilityGetter = (() => GetHoveredLineResult<'file'> | undefined) | (() => GetHoveredLineResult<'diff'> | undefined);\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>, item: CodeViewItem<LAnnotation>): ReactNode;\n renderGutterUtility?(getHoveredLine: CodeViewGutterUtilityGetter, item: CodeViewItem<LAnnotation>): ReactNode;\n}\nexport interface ControlledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\nexport interface UncontrolledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\nexport type CodeViewProps<LAnnotation = undefined> = ControlledCodeViewProps<LAnnotation> | UncontrolledCodeViewProps<LAnnotation>;\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\ntype CodeViewComponent = <LAnnotation = undefined>(props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n}) => React.JSX.Element;\nexport declare const CodeView: CodeViewComponent;\nexport {};\n//# sourceMappingURL=CodeView.d.ts.map"],"mappings":";;;;;;;KAEKY,2BAAAA,UAAqCF,mDAAmDA;UACnFG;YACIN,gBAAgBO;;UAElBd;EAJPY,YAAAA,CAAAA,EAKcV,GALdU,CAKkBG,cALS,CAAA;EACtBF,iBAAAA,CAAAA,EAAiB,OAAAC;EACGA,aAAAA,CAAAA,EAKVR,qBALUQ,GAAAA,IAAAA;EAAhBP,qBAAAA,EAAAA,SAAAA,EAMwBD,qBANxBC,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAEFP,QAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAK6BI,UAL7BJ,CAK2Cc,WAL3Cd,CAAAA,CAAAA,EAAAA,IAAAA;EACWe,kBAAAA,EAAAA,IAAAA,EAKOV,YALPU,CAKoBD,WALpBC,CAAAA,CAAAA,EAKmCd,SALnCc;EAAJb,kBAAAA,EAAAA,IAAAA,EAMWG,YANXH,CAMwBY,WANxBZ,CAAAA,CAAAA,EAMuCD,SANvCC;EAECI,oBAAAA,EAAAA,IAAAA,EAKYD,YALZC,CAKyBQ,WALzBR,CAAAA,CAAAA,EAKwCL,SALxCK;EACkBA,gBAAAA,EAAAA,UAAAA,EAKJK,cALIL,CAKWQ,WALXR,CAAAA,GAK0BG,kBAL1BH,CAK6CQ,WAL7CR,CAAAA,EAAAA,IAAAA,EAKiED,YALjEC,CAK8EQ,WAL9ER,CAAAA,CAAAA,EAK6FL,SAL7FK;EACiBQ,mBAAAA,EAAAA,cAAAA,EAKdF,2BALcE,EAAAA,IAAAA,EAKqBT,YALrBS,CAKkCA,WALlCA,CAAAA,CAAAA,EAKi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AAAA,EAAAA,EAAAA,IAAAA;EAAbT,WAAAA,EAAAA,EAoBzDD,UApByDC,CAoB3CS,WApB2CT,CAAAA,GAAAA,SAAAA;;KAsBvEe,iBAAAA,GAtB4G,CAAA,cAAA,SAAA,CAAA,CAAA,KAAA,EAsBvDF,aAtBuD,CAsBzCJ,WAtByC,CAAA,GAAA;EAEhGE,GAAAA,CAAAA,EAqBPK,KAAAA,CAAMnB,GArBCc,CAqBGG,cArBoB,CAqBLL,WArBKA,CAAAA,CAAAA;CAAwCA,EAAAA,GAsB1EO,KAAAA,CAAMC,GAAAA,CAAIC,OAtBgET;AAC/CA,cAsBZX,QAtBYW,EAsBFM,iBAtBEN"}
@@ -160,6 +160,15 @@ function CodeViewInner(props, ref) {
160
160
  }
161
161
  return instance.updateItem(item);
162
162
  },
163
+ updateItemId(oldId, newId) {
164
+ const { controlled: controlled$1, instance } = cachedDataRef.current;
165
+ assertUncontrolledCodeViewAction(controlled$1, "updateItemId");
166
+ if (instance == null) {
167
+ console.error("CodeView.updateItemId: no valid instance to update item id with", oldId, newId);
168
+ return false;
169
+ }
170
+ return instance.updateItemId(oldId, newId);
171
+ },
163
172
  scrollTo(target) {
164
173
  const { instance } = cachedDataRef.current;
165
174
  if (instance == null) console.error("CodeView.scrollTo: no valid instance to scroll with", target);
@@ -1 +1 @@
1
- {"version":3,"file":"CodeView.js","names":["CodeViewClass","slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined","controlled","snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined","SlotPortals"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type DiffLineAnnotation,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewRenderedItem<LAnnotation>[] | undefined;\n publish(snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {hasRenderers && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n controlledSelection,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n onSelectedLinesChange == null &&\n !controlledSelection\n ) {\n return options;\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n options.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n options.renderGutterUtility = noopRender;\n }\n\n return options;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: SlotPortalsProps<LAnnotation>) {\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const renderedItems = useSyncExternalStore<\n CodeViewRenderedItem<LAnnotation>[] | undefined\n >(subscribe, getSnapshot, getSnapshot);\n return renderedItems?.map((renderedItem) => {\n return createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n );\n });\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,qBACJ,OAAO,WA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AS;GAC1B,CAAC;QACG;EACL,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;;;AAIN,SAAS,aAAa"}
1
+ {"version":3,"file":"CodeView.js","names":["CodeViewClass","slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined","controlled","snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined","SlotPortals"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type DiffLineAnnotation,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewRenderedItem<LAnnotation>[] | undefined;\n publish(snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {hasRenderers && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n controlledSelection,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n onSelectedLinesChange == null &&\n !controlledSelection\n ) {\n return options;\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n options.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n options.renderGutterUtility = noopRender;\n }\n\n return options;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: SlotPortalsProps<LAnnotation>) {\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const renderedItems = useSyncExternalStore<\n CodeViewRenderedItem<LAnnotation>[] | undefined\n >(subscribe, getSnapshot, getSnapshot);\n return renderedItems?.map((renderedItem) => {\n return createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n );\n });\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAqF9C,SAAS,mBACP,YAC4B;AAC5B,QAAO;EACL,UAAU;EACV,OAAO;EACP;EACA,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EAClB;;AAGH,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,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;GACN,gBAAgB,SAAS;GAC1B,CAAC;QACG;EACL,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;;;AAIN,SAAS,aAAa"}
@@ -111,6 +111,8 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
111
111
  private asyncHighlight;
112
112
  private renderDiffWithHighlighter;
113
113
  onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;
114
+ private getMatchingWorkerResultCache;
115
+ private hasHighlightedRenderCache;
114
116
  onHighlightError(error: unknown): void;
115
117
  private getTokenizeMaxLength;
116
118
  private processDiffResult;
@@ -1 +1 @@
1
- {"version":3,"file":"DiffHunksRenderer.d.ts","names":["ElementContent","Element","HASTElement","Properties","AnnotationSpan","BaseDiffOptions","BaseDiffOptionsWithDefaults","CustomPreProperties","DiffLineAnnotation","ExpansionDirections","FileDiffMetadata","FileHeaderRenderMode","HunkData","HunkExpansionRegion","LineTypes","RenderDiffOptions","RenderRange","ThemedDiffResult","DiffLineMetadata","WorkerPoolManager","DiffHunksRendererOptions","DiffHunksRendererOptionsWithDefaults","Omit","UnifiedLineDecorationProps","SplitLineDecorationProps","LineDecoration","RenderedLineContext","InjectedRow","SplitInjectedRow","UnifiedInjectedRowPlacement","SplitInjectedRowPlacement","HunksRenderResult","DiffHunksRenderer","LAnnotation","Partial","Map","lineType","side","type","Promise"],"sources":["../../src/renderers/DiffHunksRenderer.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties } from 'hast';\nimport type { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from '../types';\nimport type { DiffLineMetadata } from '../utils/iterateOverDiff';\nimport type { WorkerPoolManager } from '../worker';\nexport interface DiffHunksRendererOptions extends BaseDiffOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\nexport interface DiffHunksRendererOptionsWithDefaults extends Omit<BaseDiffOptionsWithDefaults, 'themeType'> {\n headerRenderMode: FileHeaderRenderMode;\n}\nexport interface UnifiedLineDecorationProps {\n type: 'context' | 'context-expanded' | 'change';\n lineType: LineTypes;\n additionLineIndex: number | undefined;\n deletionLineIndex: number | undefined;\n}\nexport interface SplitLineDecorationProps {\n side: 'deletions' | 'additions';\n type: 'context' | 'context-expanded' | 'change';\n lineIndex: number | undefined;\n}\nexport interface LineDecoration {\n gutterLineType: LineTypes;\n gutterProperties?: Properties;\n contentProperties?: Properties;\n}\nexport interface RenderedLineContext {\n type: 'context' | 'context-expanded' | 'change';\n hunkIndex: number;\n lineIndex: number;\n unifiedLineIndex: number;\n splitLineIndex: number;\n deletionLine?: DiffLineMetadata;\n additionLine?: DiffLineMetadata;\n}\nexport interface InjectedRow {\n content: HASTElement;\n gutter: HASTElement;\n}\nexport interface SplitInjectedRow {\n deletion: InjectedRow | undefined;\n addition: InjectedRow | undefined;\n}\nexport interface UnifiedInjectedRowPlacement {\n before?: InjectedRow[];\n after?: InjectedRow[];\n}\nexport interface SplitInjectedRowPlacement {\n before?: SplitInjectedRow[];\n after?: SplitInjectedRow[];\n}\nexport interface HunksRenderResult {\n unifiedGutterAST: ElementContent[] | undefined;\n unifiedContentAST: ElementContent[] | undefined;\n deletionsGutterAST: ElementContent[] | undefined;\n deletionsContentAST: ElementContent[] | undefined;\n additionsGutterAST: ElementContent[] | undefined;\n additionsContentAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport declare class DiffHunksRenderer<LAnnotation = undefined> {\n options: DiffHunksRendererOptions;\n private onRenderUpdate?;\n private workerManager?;\n readonly __id: string;\n private highlighter;\n private diff;\n private expandedHunks;\n private deletionAnnotations;\n private additionAnnotations;\n private computedLang;\n private renderCache;\n constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);\n cleanUp(): void;\n recycle(): void;\n setOptions(options: DiffHunksRendererOptions): void;\n mergeOptions(options: Partial<DiffHunksRendererOptions>): void;\n expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;\n getExpandedHunk(hunkIndex: number): HunkExpansionRegion;\n getExpandedHunksMap(): Map<number, HunkExpansionRegion>;\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;\n protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;\n protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;\n protected createAnnotationElement(span: AnnotationSpan): HASTElement;\n protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;\n protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;\n protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;\n private initializeHighlighter;\n hydrate(diff: FileDiffMetadata | undefined): void;\n private getRenderOptions;\n renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;\n asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;\n protected createPreElement(split: boolean, totalLines: number, customProperties?: CustomPreProperties): HASTElement;\n private asyncHighlight;\n private renderDiffWithHighlighter;\n onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;\n onHighlightError(error: unknown): void;\n private getTokenizeMaxLength;\n private processDiffResult;\n renderCodeAST(type: 'unified' | 'deletions' | 'additions', result: HunksRenderResult): ElementContent[] | undefined;\n renderFullAST(result: HunksRenderResult, children?: ElementContent[]): HASTElement;\n renderFullHTML(result: HunksRenderResult, tempChildren?: ElementContent[]): string;\n renderPartialHTML(children: ElementContent[], columnType?: 'unified' | 'deletions' | 'additions'): string;\n private getAnnotations;\n private renderHeader;\n}\n//# sourceMappingURL=DiffHunksRenderer.d.ts.map"],"mappings":";;;;;;;UAIiBoB,wBAAAA,SAAiCf;qBAC3BM;;AADNS,UAGAC,oCAAAA,SAA6CC,IAHZjB,CAGiBC,2BAHF,EAAA,WAAA,CAAA,CAAA;EAGhDe,gBAAAA,EACKV,oBADLU;;AACKV,UAELY,0BAAAA,CAFKZ;EADwCW,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EAAI,QAAA,EAKpDR,SALoD;EAGjDS,iBAAAA,EAAAA,MAAAA,GAAAA,SAA0B;EAM1BC,iBAAAA,EAAAA,MAAAA,GAAwB,SAAA;AAKzC;AACoBV,UANHU,wBAAAA,CAMGV;EACGX,IAAAA,EAAAA,WAAAA,GAAAA,WAAAA;EACCA,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EAAU,SAAA,EAAA,MAAA,GAAA,SAAA;AAElC;AASiBwB,UAdAF,cAAAA,CAeJvB;EAGI0B,cAAAA,EAjBGd,SAiBa;EAIhBe,gBAAAA,CAAAA,EApBM1B,UAoBN0B;EAIAC,iBAAAA,CAAAA,EAvBO3B,UAuBkB;AAI1C;AACsBH,UA1BL0B,mBAAAA,CA0BK1B;EACCA,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAA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EAIXgB,oBAAoB/B;wBACjE+B,8BAA8B/B,mBAAmBE;yBAChD6B,kCAAkC/B;8BAC7BA"}
1
+ {"version":3,"file":"DiffHunksRenderer.d.ts","names":["ElementContent","Element","HASTElement","Properties","AnnotationSpan","BaseDiffOptions","BaseDiffOptionsWithDefaults","CustomPreProperties","DiffLineAnnotation","ExpansionDirections","FileDiffMetadata","FileHeaderRenderMode","HunkData","HunkExpansionRegion","LineTypes","RenderDiffOptions","RenderRange","ThemedDiffResult","DiffLineMetadata","WorkerPoolManager","DiffHunksRendererOptions","DiffHunksRendererOptionsWithDefaults","Omit","UnifiedLineDecorationProps","SplitLineDecorationProps","LineDecoration","RenderedLineContext","InjectedRow","SplitInjectedRow","UnifiedInjectedRowPlacement","SplitInjectedRowPlacement","HunksRenderResult","DiffHunksRenderer","LAnnotation","Partial","Map","lineType","side","type","Promise"],"sources":["../../src/renderers/DiffHunksRenderer.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties } from 'hast';\nimport type { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from '../types';\nimport type { DiffLineMetadata } from '../utils/iterateOverDiff';\nimport type { WorkerPoolManager } from '../worker';\nexport interface DiffHunksRendererOptions extends BaseDiffOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\nexport interface DiffHunksRendererOptionsWithDefaults extends Omit<BaseDiffOptionsWithDefaults, 'themeType'> {\n headerRenderMode: FileHeaderRenderMode;\n}\nexport interface UnifiedLineDecorationProps {\n type: 'context' | 'context-expanded' | 'change';\n lineType: LineTypes;\n additionLineIndex: number | undefined;\n deletionLineIndex: number | undefined;\n}\nexport interface SplitLineDecorationProps {\n side: 'deletions' | 'additions';\n type: 'context' | 'context-expanded' | 'change';\n lineIndex: number | undefined;\n}\nexport interface LineDecoration {\n gutterLineType: LineTypes;\n gutterProperties?: Properties;\n contentProperties?: Properties;\n}\nexport interface RenderedLineContext {\n type: 'context' | 'context-expanded' | 'change';\n hunkIndex: number;\n lineIndex: number;\n unifiedLineIndex: number;\n splitLineIndex: number;\n deletionLine?: DiffLineMetadata;\n additionLine?: DiffLineMetadata;\n}\nexport interface InjectedRow {\n content: HASTElement;\n gutter: HASTElement;\n}\nexport interface SplitInjectedRow {\n deletion: InjectedRow | undefined;\n addition: InjectedRow | undefined;\n}\nexport interface UnifiedInjectedRowPlacement {\n before?: InjectedRow[];\n after?: InjectedRow[];\n}\nexport interface SplitInjectedRowPlacement {\n before?: SplitInjectedRow[];\n after?: SplitInjectedRow[];\n}\nexport interface HunksRenderResult {\n unifiedGutterAST: ElementContent[] | undefined;\n unifiedContentAST: ElementContent[] | undefined;\n deletionsGutterAST: ElementContent[] | undefined;\n deletionsContentAST: ElementContent[] | undefined;\n additionsGutterAST: ElementContent[] | undefined;\n additionsContentAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport declare class DiffHunksRenderer<LAnnotation = undefined> {\n options: DiffHunksRendererOptions;\n private onRenderUpdate?;\n private workerManager?;\n readonly __id: string;\n private highlighter;\n private diff;\n private expandedHunks;\n private deletionAnnotations;\n private additionAnnotations;\n private computedLang;\n private renderCache;\n constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);\n cleanUp(): void;\n recycle(): void;\n setOptions(options: DiffHunksRendererOptions): void;\n mergeOptions(options: Partial<DiffHunksRendererOptions>): void;\n expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;\n getExpandedHunk(hunkIndex: number): HunkExpansionRegion;\n getExpandedHunksMap(): Map<number, HunkExpansionRegion>;\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;\n protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;\n protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;\n protected createAnnotationElement(span: AnnotationSpan): HASTElement;\n protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;\n protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;\n protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;\n private initializeHighlighter;\n hydrate(diff: FileDiffMetadata | undefined): void;\n private getRenderOptions;\n renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;\n asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;\n protected createPreElement(split: boolean, totalLines: number, customProperties?: CustomPreProperties): HASTElement;\n private asyncHighlight;\n private renderDiffWithHighlighter;\n onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;\n private getMatchingWorkerResultCache;\n private hasHighlightedRenderCache;\n onHighlightError(error: unknown): void;\n private getTokenizeMaxLength;\n private processDiffResult;\n renderCodeAST(type: 'unified' | 'deletions' | 'additions', result: HunksRenderResult): ElementContent[] | undefined;\n renderFullAST(result: HunksRenderResult, children?: ElementContent[]): HASTElement;\n renderFullHTML(result: HunksRenderResult, tempChildren?: ElementContent[]): string;\n renderPartialHTML(children: ElementContent[], columnType?: 'unified' | 'deletions' | 'additions'): string;\n private getAnnotations;\n private renderHeader;\n}\n//# sourceMappingURL=DiffHunksRenderer.d.ts.map"],"mappings":";;;;;;;UAIiBoB,wBAAAA,SAAiCf;qBAC3BM;;AADNS,UAGAC,oCAAAA,SAA6CC,IAHZjB,CAGiBC,2BAHF,EAAA,WAAA,CAAA,CAAA;EAGhDe,gBAAAA,EACKV,oBADLU;;AAC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,CAAAA,EA/BDX,wBA+BCW,EAAAA,cAAAA,CAAAA,EAAAA,CAAAA,GAAAA,GAAAA,OAAAA,CAAAA,GAAAA,SAAAA,EAAAA,aAAAA,CAAAA,EA/BuFZ,iBA+BvFY,GAAAA,SAAAA;EAAkC/B,OAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAC7BA,OAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAAc,UAAA,CAAA,OAAA,EA7BtBoB,wBA6BsB,CAAA,EAAA,IAAA;wBA5BpBc,QAAQd;uCACOX;sCACDI;yBACbsB,YAAYtB;sCACCL,mBAAmByB;;;KACNV,6BAA6BE;;;;KAC7BD,2BAA2BC;0CACpCrB,iBAAiBF;kDACTwB,wBAAwBG;gDAC1BH,wBAAwBI;sCAClCT;;gBAEtBX;;oBAEIA,4CAA4CM,cAAce;oBAC1DrB,gCAAgCM,cAAcuB,QAAQR;oFACUxB,sBAAsBL;;;2BAG/EQ,0BAA0BO,2BAA2BF;;;;;;qEAMXgB,oBAAoB/B;wBACjE+B,8BAA8B/B,mBAAmBE;yBAChD6B,kCAAkC/B;8BAC7BA"}
@@ -14,6 +14,7 @@ import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
14
14
  import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
15
15
  import { iterateOverDiff } from "../utils/iterateOverDiff.js";
16
16
  import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
17
+ import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
17
18
  import { createEmptyRowBuffer } from "../utils/createEmptyRowBuffer.js";
18
19
  import { createNoNewlineElement } from "../utils/createNoNewlineElement.js";
19
20
  import { createSeparator } from "../utils/createSeparator.js";
@@ -42,10 +43,8 @@ var DiffHunksRenderer = class {
42
43
  if (workerManager?.isWorkingPool() !== true) this.highlighter = areThemesAttached(options.theme ?? DEFAULT_THEMES) ? getHighlighterIfLoaded() : void 0;
43
44
  }
44
45
  cleanUp() {
45
- this.highlighter = void 0;
46
- this.diff = void 0;
47
- this.renderCache = void 0;
48
- this.workerManager?.cleanUpPendingTasks(this);
46
+ this.recycle();
47
+ this.expandedHunks.clear();
49
48
  this.workerManager = void 0;
50
49
  this.onRenderUpdate = void 0;
51
50
  }
@@ -53,7 +52,9 @@ var DiffHunksRenderer = class {
53
52
  this.highlighter = void 0;
54
53
  this.diff = void 0;
55
54
  this.renderCache = void 0;
56
- this.workerManager?.cleanUpPendingTasks(this);
55
+ this.additionAnnotations = {};
56
+ this.deletionAnnotations = {};
57
+ this.workerManager?.cleanUpTasks(this);
57
58
  }
58
59
  setOptions(options) {
59
60
  this.options = options;
@@ -172,28 +173,31 @@ var DiffHunksRenderer = class {
172
173
  const { renderCache } = this;
173
174
  if (renderCache?.result == null) return {
174
175
  options,
175
- forceRender: true
176
+ forceHighlight: true
176
177
  };
177
- if (diff !== renderCache.diff || !areDiffRenderOptionsEqual(options, renderCache.options)) return {
178
+ if (!areDiffTargetsEqual(diff, renderCache.diff) || !areDiffRenderOptionsEqual(options, renderCache.options)) return {
178
179
  options,
179
- forceRender: true
180
+ forceHighlight: true
180
181
  };
181
182
  return {
182
183
  options,
183
- forceRender: false
184
+ forceHighlight: false
184
185
  };
185
186
  }
186
187
  renderDiff(diff = this.renderCache?.diff, renderRange = DEFAULT_RENDER_RANGE) {
187
188
  if (diff == null) return;
188
189
  const { expandUnchanged = false, collapsedContextThreshold } = this.getOptionsWithDefaults();
189
- const cache = this.workerManager?.getDiffResultCache(diff);
190
- if (cache != null && this.renderCache == null) this.renderCache = {
191
- diff,
192
- highlighted: true,
193
- renderRange: void 0,
194
- ...cache
195
- };
196
- const { options, forceRender } = this.getRenderOptions(diff);
190
+ let { options, forceHighlight } = this.getRenderOptions(diff);
191
+ const cache = this.getMatchingWorkerResultCache(diff, options);
192
+ if (cache != null && !this.hasHighlightedRenderCache(diff, options)) {
193
+ this.renderCache = {
194
+ diff,
195
+ highlighted: true,
196
+ renderRange: void 0,
197
+ ...cache
198
+ };
199
+ forceHighlight = false;
200
+ }
197
201
  const forcePlainText = isDiffMassive(diff, this.getTokenizeMaxLength());
198
202
  this.renderCache ??= {
199
203
  diff,
@@ -203,20 +207,20 @@ var DiffHunksRenderer = class {
203
207
  renderRange: void 0
204
208
  };
205
209
  if (this.workerManager?.isWorkingPool() === true) {
206
- if (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (diff !== this.renderCache.diff || !areRenderRangesEqual(this.renderCache.renderRange, renderRange))) {
210
+ if (forcePlainText || this.renderCache.result == null || !this.renderCache.highlighted && (!areDiffTargetsEqual(diff, this.renderCache.diff) || !areRenderRangesEqual(this.renderCache.renderRange, renderRange))) {
207
211
  this.renderCache.diff = diff;
208
212
  this.renderCache.options = options;
209
213
  this.renderCache.highlighted = false;
210
214
  this.renderCache.result = this.workerManager.getPlainDiffAST(diff, renderRange.startingLine, renderRange.totalLines, isDefaultRenderRange(renderRange) ? true : expandUnchanged ? true : this.expandedHunks, collapsedContextThreshold);
211
215
  this.renderCache.renderRange = renderRange;
212
216
  }
213
- if (renderRange.totalLines > 0 && !forcePlainText && (!this.renderCache.highlighted || forceRender)) this.workerManager.highlightDiffAST(this, diff);
217
+ if (renderRange.totalLines > 0 && !forcePlainText && (!this.renderCache.highlighted || forceHighlight)) this.workerManager.highlightDiffAST(this, diff);
214
218
  } else {
215
219
  this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
216
220
  const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
217
221
  const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLang);
218
222
  const canHighlight = !forcePlainText && hasLangs;
219
- if (this.highlighter != null && hasThemes && (forceRender || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
223
+ if (this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
220
224
  const { result, options: options$1 } = this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText || !hasLangs);
221
225
  this.renderCache = {
222
226
  diff,
@@ -272,7 +276,7 @@ var DiffHunksRenderer = class {
272
276
  }
273
277
  onHighlightSuccess(diff, result, options, highlighted = true) {
274
278
  if (this.renderCache == null) return;
275
- const triggerRenderUpdate = !this.renderCache.highlighted || !areDiffRenderOptionsEqual(this.renderCache.options, options) || this.renderCache.diff !== diff;
279
+ const triggerRenderUpdate = !this.renderCache.highlighted || !areDiffRenderOptionsEqual(this.renderCache.options, options) || !areDiffTargetsEqual(this.renderCache.diff, diff);
276
280
  this.renderCache = {
277
281
  diff,
278
282
  options,
@@ -282,6 +286,15 @@ var DiffHunksRenderer = class {
282
286
  };
283
287
  if (triggerRenderUpdate) this.onRenderUpdate?.();
284
288
  }
289
+ getMatchingWorkerResultCache(diff, options) {
290
+ const cache = this.workerManager?.getDiffResultCache(diff);
291
+ if (cache == null || !areDiffRenderOptionsEqual(options, cache.options)) return;
292
+ return cache;
293
+ }
294
+ hasHighlightedRenderCache(diff, options) {
295
+ const { renderCache } = this;
296
+ return renderCache?.result != null && renderCache.highlighted && areDiffTargetsEqual(diff, renderCache.diff) && areDiffRenderOptionsEqual(options, renderCache.options);
297
+ }
285
298
  onHighlightError(error) {
286
299
  console.error(error);
287
300
  }