@pierre/diffs 1.2.0-beta.2 → 1.2.0-beta.4

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 (81) hide show
  1. package/dist/components/CodeView.d.ts +16 -6
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +129 -27
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +3 -2
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +14 -5
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +3 -2
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +14 -5
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/FileStream.js +6 -3
  14. package/dist/components/FileStream.js.map +1 -1
  15. package/dist/components/VirtualizedFile.d.ts +1 -0
  16. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  17. package/dist/components/VirtualizedFile.js +18 -13
  18. package/dist/components/VirtualizedFile.js.map +1 -1
  19. package/dist/components/VirtualizedFileDiff.d.ts +1 -0
  20. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.js +19 -16
  22. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  23. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  24. package/dist/components/web-components.js +4 -0
  25. package/dist/components/web-components.js.map +1 -1
  26. package/dist/constants.d.ts +6 -3
  27. package/dist/constants.d.ts.map +1 -1
  28. package/dist/constants.js +11 -2
  29. package/dist/constants.js.map +1 -1
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.js +5 -5
  32. package/dist/managers/InteractionManager.d.ts +2 -8
  33. package/dist/managers/InteractionManager.d.ts.map +1 -1
  34. package/dist/managers/InteractionManager.js.map +1 -1
  35. package/dist/react/CodeView.d.ts +5 -1
  36. package/dist/react/CodeView.d.ts.map +1 -1
  37. package/dist/react/CodeView.js +75 -16
  38. package/dist/react/CodeView.js.map +1 -1
  39. package/dist/react/index.d.ts +2 -2
  40. package/dist/react/types.d.ts +2 -2
  41. package/dist/react/types.d.ts.map +1 -1
  42. package/dist/react/utils/useFileDiffInstance.d.ts +2 -2
  43. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  44. package/dist/react/utils/useFileDiffInstance.js +1 -1
  45. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  46. package/dist/react/utils/useFileInstance.d.ts +2 -2
  47. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  48. package/dist/react/utils/useFileInstance.js +1 -1
  49. package/dist/react/utils/useFileInstance.js.map +1 -1
  50. package/dist/react/utils/useUnresolvedFileInstance.d.ts +2 -2
  51. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  52. package/dist/react/utils/useUnresolvedFileInstance.js +1 -1
  53. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  54. package/dist/renderers/FileRenderer.js +1 -1
  55. package/dist/ssr/index.d.ts +2 -2
  56. package/dist/style.js +1 -1
  57. package/dist/style.js.map +1 -1
  58. package/dist/types.d.ts +23 -7
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/utils/areSelectionsEqual.d.ts +1 -1
  61. package/dist/utils/areSelectionsEqual.d.ts.map +1 -1
  62. package/dist/utils/areSelectionsEqual.js.map +1 -1
  63. package/dist/utils/cssWrappers.d.ts +3 -2
  64. package/dist/utils/cssWrappers.d.ts.map +1 -1
  65. package/dist/utils/cssWrappers.js +13 -2
  66. package/dist/utils/cssWrappers.js.map +1 -1
  67. package/dist/utils/getFiletypeFromFileName.js +16 -0
  68. package/dist/utils/getFiletypeFromFileName.js.map +1 -1
  69. package/dist/utils/parsePatchFiles.js +15 -0
  70. package/dist/utils/parsePatchFiles.js.map +1 -1
  71. package/dist/utils/scrollbarGutter.d.ts +6 -0
  72. package/dist/utils/scrollbarGutter.d.ts.map +1 -0
  73. package/dist/utils/scrollbarGutter.js +28 -0
  74. package/dist/utils/scrollbarGutter.js.map +1 -0
  75. package/dist/worker/WorkerPoolManager.js +1 -1
  76. package/dist/worker/WorkerPoolManager.js.map +1 -1
  77. package/dist/worker/worker-portable.js +26 -1
  78. package/dist/worker/worker-portable.js.map +1 -1
  79. package/dist/worker/worker.js +23 -0
  80. package/dist/worker/worker.js.map +1 -1
  81. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
 
4
- import { CodeView as CodeView$1 } from "../components/CodeView.js";
5
4
  import { areOptionsEqual } from "../utils/areOptionsEqual.js";
5
+ import { CodeView as CodeView$1 } from "../components/CodeView.js";
6
6
  import { areManagedSnapshotsEqual } from "../utils/areManagedSnapshotsEqual.js";
7
7
  import { renderDiffChildren } from "./utils/renderDiffChildren.js";
8
8
  import { renderFileChildren } from "./utils/renderFileChildren.js";
@@ -14,16 +14,21 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
14
 
15
15
  //#region src/react/CodeView.tsx
16
16
  const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
17
- const DEFAULT_CACHE = {
18
- instance: void 0,
19
- items: void 0,
20
- managedOptions: void 0,
21
- disableFlushSync: false,
22
- slotCoordinator: void 0
23
- };
24
- function CodeViewInner({ className, containerRef, disableWorkerPool = false, items, onScroll, onSelectedLinesChange, options, renderAnnotation, renderCustomHeader, renderGutterUtility, renderHeaderMetadata, renderHeaderPrefix, selectedLines, style }, ref) {
17
+ function createDefaultCache(controlled) {
18
+ return {
19
+ instance: void 0,
20
+ items: void 0,
21
+ controlled,
22
+ managedOptions: void 0,
23
+ disableFlushSync: false,
24
+ slotCoordinator: void 0
25
+ };
26
+ }
27
+ function CodeViewInner(props, ref) {
28
+ const { className, containerRef, disableWorkerPool = false, initialItems, items: controlledItems, onScroll, onSelectedLinesChange, options, renderAnnotation, renderCustomHeader, renderGutterUtility, renderHeaderMetadata, renderHeaderPrefix, selectedLines, style } = props;
29
+ const controlled = controlledItems !== void 0;
25
30
  const poolManager = useContext(WorkerPoolContext);
26
- const cachedDataRef = useRef({ ...DEFAULT_CACHE });
31
+ const cachedDataRef = useRef(createDefaultCache(controlled));
27
32
  const hasCustomHeader = renderCustomHeader != null;
28
33
  const hasAnnotationRenderer = renderAnnotation != null;
29
34
  const hasGutterRenderer = renderGutterUtility != null;
@@ -53,7 +58,7 @@ function CodeViewInner({ className, containerRef, disableWorkerPool = false, ite
53
58
  if (cachedDataRef.current.instance != null && (node == null || node !== cachedDataRef.current.instance.getContainerElement())) {
54
59
  cachedDataRef.current.instance.cleanUp();
55
60
  slotContentStore.publish(void 0);
56
- cachedDataRef.current = { ...DEFAULT_CACHE };
61
+ cachedDataRef.current = createDefaultCache(controlled);
57
62
  }
58
63
  if (node != null && node !== cachedDataRef.current.instance?.getContainerElement()) {
59
64
  cachedDataRef.current.instance = new CodeView$1(managedOptions, !disableWorkerPool ? poolManager : void 0, true);
@@ -86,7 +91,7 @@ function CodeViewInner({ className, containerRef, disableWorkerPool = false, ite
86
91
  return onScroll != null ? cachedDataRef.current.instance?.subscribeToScroll(onScroll) : void 0;
87
92
  });
88
93
  useIsometricEffect(() => {
89
- const { instance, items: prevItems, managedOptions: prevManagedOptions, slotCoordinator: prevSlotCoordinator } = cachedDataRef.current;
94
+ const { instance, controlled: prevControlled, items: prevItems, managedOptions: prevManagedOptions, slotCoordinator: prevSlotCoordinator } = cachedDataRef.current;
90
95
  if (instance == null) return;
91
96
  try {
92
97
  cachedDataRef.current.disableFlushSync = true;
@@ -96,10 +101,27 @@ function CodeViewInner({ className, containerRef, disableWorkerPool = false, ite
96
101
  instance.setOptions(managedOptions);
97
102
  shouldRender = true;
98
103
  }
99
- if (items !== prevItems) {
100
- cachedDataRef.current.items = items;
101
- instance.setItems(items);
102
- shouldRender = true;
104
+ if (prevControlled !== controlled) {
105
+ console.error("CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.");
106
+ return;
107
+ }
108
+ if (controlled) {
109
+ if (controlledItems !== prevItems) if (areItemListsEqual(prevItems, controlledItems)) cachedDataRef.current.items = controlledItems;
110
+ else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {
111
+ cachedDataRef.current.items = controlledItems;
112
+ instance.addItems(controlledItems.slice(prevItems.length));
113
+ } else {
114
+ cachedDataRef.current.items = controlledItems;
115
+ instance.setItems(controlledItems);
116
+ shouldRender = true;
117
+ }
118
+ } else if (prevItems == null) {
119
+ const seedItems = initialItems ?? [];
120
+ cachedDataRef.current.items = seedItems;
121
+ if (seedItems.length > 0) {
122
+ instance.setItems(seedItems);
123
+ shouldRender = true;
124
+ }
103
125
  }
104
126
  if (selectedLines !== void 0) instance.setSelectedLines(selectedLines, { notify: false });
105
127
  const slotPublish = instance.setSlotCoordinator(slotCoordinator);
@@ -116,6 +138,28 @@ function CodeViewInner({ className, containerRef, disableWorkerPool = false, ite
116
138
  }
117
139
  });
118
140
  useImperativeHandle(ref, () => ({
141
+ addItems(items) {
142
+ const { controlled: controlled$1, instance } = cachedDataRef.current;
143
+ assertUncontrolledCodeViewAction(controlled$1, "addItems");
144
+ if (instance == null) console.error("CodeView.addItems: no valid instance to append items with", items);
145
+ else instance.addItems(items);
146
+ },
147
+ getItem(id) {
148
+ const { instance } = cachedDataRef.current;
149
+ if (instance == null) {
150
+ console.error("CodeView.getItem: no valid instance exists", id);
151
+ return;
152
+ } else return instance.getItem(id);
153
+ },
154
+ updateItem(item) {
155
+ const { controlled: controlled$1, instance } = cachedDataRef.current;
156
+ assertUncontrolledCodeViewAction(controlled$1, "updateItem");
157
+ if (instance == null) {
158
+ console.error("CodeView.updateItem: no valid instance to update item with", item);
159
+ return false;
160
+ }
161
+ return instance.updateItem(item);
162
+ },
119
163
  scrollTo(target) {
120
164
  const { instance } = cachedDataRef.current;
121
165
  if (instance == null) console.error("CodeView.scrollTo: no valid instance to scroll with", target);
@@ -162,6 +206,21 @@ function CodeViewInner({ className, containerRef, disableWorkerPool = false, ite
162
206
  })] });
163
207
  }
164
208
  const CodeView = forwardRef(CodeViewInner);
209
+ function isAppendOnlyItemUpdate(previousItems, nextItems) {
210
+ if (previousItems == null || nextItems.length <= previousItems.length) return false;
211
+ if (previousItems.length === 0) return true;
212
+ for (let index = 0; index < previousItems.length; index++) if (nextItems[index] !== previousItems[index]) return false;
213
+ return true;
214
+ }
215
+ function areItemListsEqual(previousItems, nextItems) {
216
+ if (previousItems == null || previousItems.length !== nextItems.length) return false;
217
+ for (let index = 0; index < previousItems.length; index++) if (previousItems[index] !== nextItems[index]) return false;
218
+ return true;
219
+ }
220
+ function assertUncontrolledCodeViewAction(controlled, action) {
221
+ if (!controlled) return;
222
+ throw new Error(`CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`);
223
+ }
165
224
  function createSlotContentStore() {
166
225
  let snapshot;
167
226
  const listeners = /* @__PURE__ */ new Set();
@@ -1 +1 @@
1
- {"version":3,"file":"CodeView.js","names":["CodeViewClass","slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined","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 // FIXME(amadeus): Replace this with a data structure that can do\n // mutation-like changes for super massive diffs\n // initialItems?: readonly CodeViewItem<LAnnotation>[];\n // items?: never;\n items: readonly CodeViewItem<LAnnotation>[];\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\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 managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nconst DEFAULT_CACHE = {\n instance: undefined,\n items: undefined,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n} as const;\n\nfunction CodeViewInner<LAnnotation = undefined>(\n {\n className,\n containerRef,\n disableWorkerPool = false,\n items,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n }: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>({\n ...DEFAULT_CACHE,\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 = { ...DEFAULT_CACHE };\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 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 (items !== prevItems) {\n cachedDataRef.current.items = items;\n instance.setItems(items);\n shouldRender = true;\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 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 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;AAiF9C,MAAM,gBAAgB;CACpB,UAAU;CACV,OAAO;CACP,gBAAgB;CAChB,kBAAkB;CAClB,iBAAiB;CAClB;AAED,SAAS,cACP,EACE,WACA,cACA,oBAAoB,OACpB,OACA,UACA,uBACA,SACA,kBACA,oBACA,qBACA,sBACA,oBACA,eACA,SAEF,KACmB;CACnB,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,gBAAgB,OAAmC,EACvD,GAAG,eACJ,CAAC;CACF,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,0BAA0B,mBAC7B,cAA4C;AAC3C,0BAAwB,UAAU;GAErC;CACD,MAAM,sBAAsB,kBAAkB;CAE9C,MAAM,iBAAiB,cAEnB,6BAA6B;EAC3B;EACA;EACA;EACA,uBACE,yBAAyB,OAAO,0BAA0B;EAC5D;EACD,CAAC,EACJ;EACE;EACA;EACA;EACA;EACA;EACA;EACD,CACF;CAED,MAAM,CAAC,oBAAoB,eACzB,wBAAwB,CACzB;CACD,MAAM,GAAG,eA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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;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 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,WAAW,cAAc,YAAY;AAoF9C,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,cACA,oBAAoB,OACpB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B,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,4 +1,4 @@
1
- import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewItemVersion, CodeViewLineScrollTarget, CodeViewMetrics, CodeViewPositionScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
1
+ import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewItemVersion, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
2
2
  import { WorkerInitializationRenderOptions, WorkerPoolOptions } from "../worker/types.js";
3
3
  import { FileOptions } from "../components/File.js";
4
4
  import { CodeView, CodeViewHandle, CodeViewProps, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
@@ -17,4 +17,4 @@ import { templateRender } from "./utils/templateRender.js";
17
17
  import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
18
18
  import { useFileInstance } from "./utils/useFileInstance.js";
19
19
  import { useStableCallback } from "./utils/useStableCallback.js";
20
- export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeView, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewItemVersion, CodeViewLineScrollTarget, CodeViewMetrics, CodeViewPositionScrollTarget, CodeViewProps, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffMetadata, FileDiffProps, FileHeaderRenderMode, FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
20
+ export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeView, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewItemVersion, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffMetadata, FileDiffProps, FileHeaderRenderMode, FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
@@ -1,5 +1,5 @@
1
- import { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, VirtualFileMetrics } from "../types.js";
2
- import { GetHoveredLineResult, SelectedLineRange } from "../managers/InteractionManager.js";
1
+ import { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from "../types.js";
2
+ import { GetHoveredLineResult } from "../managers/InteractionManager.js";
3
3
  import { FileOptions } from "../components/File.js";
4
4
  import { FileDiffOptions } from "../components/FileDiff.js";
5
5
  import { CSSProperties, ReactNode } from "react";
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":["CSSProperties","ReactNode","FileOptions","FileDiffOptions","GetHoveredLineResult","SelectedLineRange","DiffLineAnnotation","FileContents","FileDiffMetadata","LineAnnotation","VirtualFileMetrics","DiffBasePropsReact","LAnnotation","FileProps"],"sources":["../../src/react/types.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\nimport type { FileOptions } from '../components/File';\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { GetHoveredLineResult, SelectedLineRange } from '../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, VirtualFileMetrics } from '../types';\nexport interface DiffBasePropsReact<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n metrics?: VirtualFileMetrics;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n selectedLines?: SelectedLineRange | null;\n renderAnnotation?(annotations: DiffLineAnnotation<LAnnotation>): ReactNode;\n renderCustomHeader?(fileDiff: FileDiffMetadata): ReactNode;\n renderHeaderPrefix?(fileDiff: FileDiffMetadata): ReactNode;\n renderHeaderMetadata?(fileDiff: FileDiffMetadata): ReactNode;\n renderGutterUtility?(getHoveredLine: () => GetHoveredLineResult<'diff'> | undefined): ReactNode;\n className?: string;\n style?: CSSProperties;\n prerenderedHTML?: string;\n}\nexport interface FileProps<LAnnotation> {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n metrics?: VirtualFileMetrics;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n selectedLines?: SelectedLineRange | null;\n renderAnnotation?(annotations: LineAnnotation<LAnnotation>): ReactNode;\n renderCustomHeader?(file: FileContents): ReactNode;\n renderHeaderPrefix?(file: FileContents): ReactNode;\n renderHeaderMetadata?(file: FileContents): ReactNode;\n renderGutterUtility?(getHoveredLine: () => GetHoveredLineResult<'file'> | undefined): ReactNode;\n className?: string;\n style?: CSSProperties;\n prerenderedHTML?: string;\n disableWorkerPool?: boolean;\n}\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;;;UAKiBW;YACHR,gBAAgBS;EADbD,OAAAA,CAAAA,EAEHD,kBAFqBE;EACLA,eAAAA,CAAAA,EAERN,kBAFQM,CAEWA,WAFXA,CAAAA,EAAAA;EAAhBT,aAAAA,CAAAA,EAGME,iBAHNF,GAAAA,IAAAA;EACAO,gBAAAA,EAAAA,WAAAA,EAGqBJ,kBAHrBI,CAGwCE,WAHxCF,CAAAA,CAAAA,EAGuDT,SAHvDS;EAC2BE,kBAAAA,EAAAA,QAAAA,EAGPJ,gBAHOI,CAAAA,EAGYX,SAHZW;EAAnBN,kBAAAA,EAAAA,QAAAA,EAIYE,gBAJZF,CAAAA,EAI+BL,SAJ/BK;EACFD,oBAAAA,EAAAA,QAAAA,EAIgBG,gBAJhBH,CAAAA,EAImCJ,SAJnCI;EACkCO,mBAAAA,EAAAA,cAAAA,EAAAA,GAAAA,GAIPR,oBAJOQ,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA,CAAAA,EAIoCX,SAJpCW;EAAnBN,SAAAA,CAAAA,EAAAA,MAAAA;EAAkCL,KAAAA,CAAAA,EAMzDD,aANyDC;EACnCO,eAAAA,CAAAA,EAAAA,MAAAA;;AACAA,UAOjBK,SAPiBL,CAAAA,WAAAA,CAAAA,CAAAA;EAAmBP,IAAAA,EAQ3CM,YAR2CN;EACjBO,OAAAA,CAAAA,EAQtBN,WARsBM,CAQVI,WARUJ,CAAAA;EAAmBP,OAAAA,CAAAA,EASzCS,kBATyCT;EACRG,eAAAA,CAAAA,EASzBK,cATyBL,CASVQ,WATUR,CAAAA,EAAAA;EAA2CH,aAAAA,CAAAA,EAUtEI,iBAVsEJ,GAAAA,IAAAA;EAE9ED,gBAAAA,EAAAA,WAAAA,EASuBS,cATvBT,CASsCY,WATtCZ,CAAAA,CAAAA,EASqDC,SATrDD;EAAa,kBAAA,EAAA,IAAA,EAUKO,YAVL,CAAA,EAUoBN,SAVpB;EAGRY,kBAAS,EAAAD,IAAAA,EAQIL,YARJ,CAAA,EAQmBN,SARnB;EAChBM,oBAAAA,EAAAA,IAAAA,EAQsBA,YARtBA,CAAAA,EAQqCN,SARrCM;EACgBK,mBAAAA,EAAAA,cAAAA,EAAAA,GAAAA,GAQqBR,oBARrBQ,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA,CAAAA,EAQgEX,SARhEW;EAAZV,SAAAA,CAAAA,EAAAA,MAAAA;EACAQ,KAAAA,CAAAA,EASFV,aATEU;EACuBE,eAAAA,CAAAA,EAAAA,MAAAA;EAAfH,iBAAAA,CAAAA,EAAAA,OAAAA"}
1
+ {"version":3,"file":"types.d.ts","names":["CSSProperties","ReactNode","FileOptions","FileDiffOptions","GetHoveredLineResult","DiffLineAnnotation","FileContents","FileDiffMetadata","LineAnnotation","SelectedLineRange","VirtualFileMetrics","DiffBasePropsReact","LAnnotation","FileProps"],"sources":["../../src/react/types.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode } from 'react';\nimport type { FileOptions } from '../components/File';\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { GetHoveredLineResult } from '../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from '../types';\nexport interface DiffBasePropsReact<LAnnotation> {\n options?: FileDiffOptions<LAnnotation>;\n metrics?: VirtualFileMetrics;\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[];\n selectedLines?: SelectedLineRange | null;\n renderAnnotation?(annotations: DiffLineAnnotation<LAnnotation>): ReactNode;\n renderCustomHeader?(fileDiff: FileDiffMetadata): ReactNode;\n renderHeaderPrefix?(fileDiff: FileDiffMetadata): ReactNode;\n renderHeaderMetadata?(fileDiff: FileDiffMetadata): ReactNode;\n renderGutterUtility?(getHoveredLine: () => GetHoveredLineResult<'diff'> | undefined): ReactNode;\n className?: string;\n style?: CSSProperties;\n prerenderedHTML?: string;\n}\nexport interface FileProps<LAnnotation> {\n file: FileContents;\n options?: FileOptions<LAnnotation>;\n metrics?: VirtualFileMetrics;\n lineAnnotations?: LineAnnotation<LAnnotation>[];\n selectedLines?: SelectedLineRange | null;\n renderAnnotation?(annotations: LineAnnotation<LAnnotation>): ReactNode;\n renderCustomHeader?(file: FileContents): ReactNode;\n renderHeaderPrefix?(file: FileContents): ReactNode;\n renderHeaderMetadata?(file: FileContents): ReactNode;\n renderGutterUtility?(getHoveredLine: () => GetHoveredLineResult<'file'> | undefined): ReactNode;\n className?: string;\n style?: CSSProperties;\n prerenderedHTML?: string;\n disableWorkerPool?: boolean;\n}\n//# sourceMappingURL=types.d.ts.map"],"mappings":";;;;;;;UAKiBW;YACHR,gBAAgBS;EADbD,OAAAA,CAAAA,EAEHD,kBAFqBE;EACLA,eAAAA,CAAAA,EAERP,kBAFQO,CAEWA,WAFXA,CAAAA,EAAAA;EAAhBT,aAAAA,CAAAA,EAGMM,iBAHNN,GAAAA,IAAAA;EACAO,gBAAAA,EAAAA,WAAAA,EAGqBL,kBAHrBK,CAGwCE,WAHxCF,CAAAA,CAAAA,EAGuDT,SAHvDS;EAC2BE,kBAAAA,EAAAA,QAAAA,EAGPL,gBAHOK,CAAAA,EAGYX,SAHZW;EAAnBP,kBAAAA,EAAAA,QAAAA,EAIYE,gBAJZF,CAAAA,EAI+BJ,SAJ/BI;EACFI,oBAAAA,EAAAA,QAAAA,EAIgBF,gBAJhBE,CAAAA,EAImCR,SAJnCQ;EACkCG,mBAAAA,EAAAA,cAAAA,EAAAA,GAAAA,GAIPR,oBAJOQ,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA,CAAAA,EAIoCX,SAJpCW;EAAnBP,SAAAA,CAAAA,EAAAA,MAAAA;EAAkCJ,KAAAA,CAAAA,EAMzDD,aANyDC;EACnCM,eAAAA,CAAAA,EAAAA,MAAAA;;AACAA,UAOjBM,SAPiBN,CAAAA,WAAAA,CAAAA,CAAAA;EAAmBN,IAAAA,EAQ3CK,YAR2CL;EACjBM,OAAAA,CAAAA,EAQtBL,WARsBK,CAQVK,WARUL,CAAAA;EAAmBN,OAAAA,CAAAA,EASzCS,kBATyCT;EACRG,eAAAA,CAAAA,EASzBI,cATyBJ,CASVQ,WATUR,CAAAA,EAAAA;EAA2CH,aAAAA,CAAAA,EAUtEQ,iBAVsER,GAAAA,IAAAA;EAE9ED,gBAAAA,EAAAA,WAAAA,EASuBQ,cATvBR,CASsCY,WATtCZ,CAAAA,CAAAA,EASqDC,SATrDD;EAAa,kBAAA,EAAA,IAAA,EAUKM,YAVL,CAAA,EAUoBL,SAVpB;EAGRY,kBAAS,EAAAD,IAAAA,EAQIN,YARJ,CAAA,EAQmBL,SARnB;EAChBK,oBAAAA,EAAAA,IAAAA,EAQsBA,YARtBA,CAAAA,EAQqCL,SARrCK;EACgBM,mBAAAA,EAAAA,cAAAA,EAAAA,GAAAA,GAQqBR,oBARrBQ,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA,CAAAA,EAQgEX,SARhEW;EAAZV,SAAAA,CAAAA,EAAAA,MAAAA;EACAQ,KAAAA,CAAAA,EASFV,aATEU;EACuBE,eAAAA,CAAAA,EAAAA,MAAAA;EAAfJ,iBAAAA,CAAAA,EAAAA,OAAAA"}
@@ -1,5 +1,5 @@
1
- import { DiffLineAnnotation, FileDiffMetadata, VirtualFileMetrics } from "../../types.js";
2
- import { GetHoveredLineResult, SelectedLineRange } from "../../managers/InteractionManager.js";
1
+ import { DiffLineAnnotation, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
+ import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileDiffOptions } from "../../components/FileDiff.js";
4
4
 
5
5
  //#region src/react/utils/useFileDiffInstance.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.d.ts","names":["FileDiffOptions","GetHoveredLineResult","SelectedLineRange","DiffLineAnnotation","FileDiffMetadata","VirtualFileMetrics","UseFileDiffInstanceProps","LAnnotation","UseFileDiffInstanceReturn","HTMLElement","useFileDiffInstance","fileDiff","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useFileDiffInstance.d.ts"],"sourcesContent":["import { type FileDiffOptions } from '../../components/FileDiff';\nimport type { GetHoveredLineResult, SelectedLineRange } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileDiffMetadata, VirtualFileMetrics } from '../../types';\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\nexport declare function useFileDiffInstance<LAnnotation>({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileDiffInstance.d.ts.map"],"mappings":";;;;;UAGUM;YACIF;EADJE,OAAAA,EAEGN,eAFHM,CAEmBC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBH,eAAAA,EAEOD,kBAFPC,CAE0BG,WAF1BH,CAAAA,EAAAA,GAAAA,SAAAA;EACeG,aAAAA,EAEVL,iBAFUK,GAAAA,IAAAA,GAAAA,SAAAA;EAAhBP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAC2BO,OAAAA,CAAAA,EAG1BF,kBAH0BE;EAAnBJ,sBAAAA,EAAAA,OAAAA;EACFD,eAAAA,EAAAA,OAAAA;EAELG,iBAAAA,EAAAA,OAAAA;;AAAkB,UAKtBG,yBAAAA,CAAyB;EAIXE,GAAAA,CAAAA,IAAAA,EAHVD,WAGUC,GAAmB,IAAA,CAAAH,EAAAA,IAAAA;EAAgBI,cAAAA,EAAAA,EAFrCV,oBAEqCU,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;;AAAmBE,iBAAtDH,mBAAsDG,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,QAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA;AAAAA,CAAAA,EAAwHP,wBAAxHO,CAAiJN,WAAjJM,CAAAA,CAAAA,EAAgKL,yBAAhKK"}
1
+ {"version":3,"file":"useFileDiffInstance.d.ts","names":["FileDiffOptions","GetHoveredLineResult","DiffLineAnnotation","FileDiffMetadata","SelectedLineRange","VirtualFileMetrics","UseFileDiffInstanceProps","LAnnotation","UseFileDiffInstanceReturn","HTMLElement","useFileDiffInstance","fileDiff","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useFileDiffInstance.d.ts"],"sourcesContent":["import { type FileDiffOptions } from '../../components/FileDiff';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from '../../types';\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\nexport declare function useFileDiffInstance<LAnnotation>({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileDiffInstance.d.ts.map"],"mappings":";;;;;UAGUM;YACIH;EADJG,OAAAA,EAEGN,eAFHM,CAEmBC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBJ,eAAAA,EAEOD,kBAFPC,CAE0BI,WAF1BJ,CAAAA,EAAAA,GAAAA,SAAAA;EACeI,aAAAA,EAEVH,iBAFUG,GAAAA,IAAAA,GAAAA,SAAAA;EAAhBP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAC2BO,OAAAA,CAAAA,EAG1BF,kBAH0BE;EAAnBL,sBAAAA,EAAAA,OAAAA;EACFE,eAAAA,EAAAA,OAAAA;EAELC,iBAAAA,EAAAA,OAAAA;;AAAkB,UAKtBG,yBAAAA,CAAyB;EAIXE,GAAAA,CAAAA,IAAAA,EAHVD,WAGUC,GAAmB,IAAA,CAAAH,EAAAA,IAAAA;EAAgBI,cAAAA,EAAAA,EAFrCV,oBAEqCU,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;;AAAmBE,iBAAtDH,mBAAsDG,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,QAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA;AAAAA,CAAAA,EAAwHP,wBAAxHO,CAAiJN,WAAjJM,CAAAA,CAAAA,EAAgKL,yBAAhKK"}
@@ -1,6 +1,6 @@
1
+ import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
1
2
  import { FileDiff } from "../../components/FileDiff.js";
2
3
  import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
3
- import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
4
4
  import { noopRender } from "../constants.js";
5
5
  import { useStableCallback } from "./useStableCallback.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type {\n GetHoveredLineResult,\n SelectedLineRange,\n} from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\n }\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,qBACmE;CACnE,MAAM,oBAAoB,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,kBAAsC;AACnE,MAAI,iBAAiB,MAAM;AACzB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,mFACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,wEACD;AAEH,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;EACvB,MAAM,EAAE,SAAS,aAAa;AAC9B,MAAI,YAAY,KAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,WAAW;AAClE,WAAS,WAAW,WAAW;AAC/B,EAAK,SAAS,OAAO;GACnB;GACA;GACA;GACD,CAAC;AACF,MAAI,kBAAkB,OACpB,UAAS,iBAAiB,cAAc;GAE1C;AAQF,QAAO;EAAE;EAAK,gBANS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EAEwB;;AAUhC,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,0BAGY;AACZ,KAAI,CAAC,uBAAuB,CAAC,0BAA0B,CAAC,gBACtD,QAAO;AAET,QAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
1
+ {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\n }\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,qBACmE;CACnE,MAAM,oBAAoB,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,kBAAsC;AACnE,MAAI,iBAAiB,MAAM;AACzB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,mFACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,wEACD;AAEH,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;EACvB,MAAM,EAAE,SAAS,aAAa;AAC9B,MAAI,YAAY,KAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,WAAW;AAClE,WAAS,WAAW,WAAW;AAC/B,EAAK,SAAS,OAAO;GACnB;GACA;GACA;GACD,CAAC;AACF,MAAI,kBAAkB,OACpB,UAAS,iBAAiB,cAAc;GAE1C;AAQF,QAAO;EAAE;EAAK,gBANS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EAEwB;;AAUhC,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,0BAGY;AACZ,KAAI,CAAC,uBAAuB,CAAC,0BAA0B,CAAC,gBACtD,QAAO;AAET,QAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
@@ -1,5 +1,5 @@
1
- import { FileContents, LineAnnotation, VirtualFileMetrics } from "../../types.js";
2
- import { GetHoveredLineResult, SelectedLineRange } from "../../managers/InteractionManager.js";
1
+ import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
+ import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileOptions } from "../../components/File.js";
4
4
 
5
5
  //#region src/react/utils/useFileInstance.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.d.ts","names":["FileOptions","GetHoveredLineResult","SelectedLineRange","FileContents","LineAnnotation","VirtualFileMetrics","UseFileInstanceProps","LAnnotation","UseFileInstanceReturn","HTMLElement","useFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useFileInstance.d.ts"],"sourcesContent":["import { type FileOptions } from '../../components/File';\nimport type { GetHoveredLineResult, SelectedLineRange } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation, VirtualFileMetrics } from '../../types';\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\nexport declare function useFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileInstance.d.ts.map"],"mappings":";;;;;UAGUM;QACAH;EADAG,OAAAA,EAEGN,WAFHM,CAEeC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBJ,eAAAA,EAEWC,cAFXD,CAE0BI,WAF1BJ,CAAAA,EAAAA,GAAAA,SAAAA;EACeI,aAAAA,EAENL,iBAFMK,GAAAA,IAAAA,GAAAA,SAAAA;EAAZP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACuBO,OAAAA,CAAAA,EAGtBF,kBAHsBE;EAAfH,sBAAAA,EAAAA,OAAAA;EACFF,eAAAA,EAAAA,OAAAA;EAELG,iBAAAA,EAAAA,OAAAA;;AAAkB,UAKtBG,qBAAAA,CAAqB;EAIPE,GAAAA,CAAAA,IAAAA,EAHVD,WAGyB,GAAA,IAAAF,CAAAA,EAAAA,IAAAA;EAAgBI,cAAAA,EAAAA,EAFjCV,oBAEiCU,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;;AAAeE,iBAA9CH,eAA8CG,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,IAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA;AAAAA,CAAAA,EAAwHP,oBAAxHO,CAA6IN,WAA7IM,CAAAA,CAAAA,EAA4JL,qBAA5JK"}
1
+ {"version":3,"file":"useFileInstance.d.ts","names":["FileOptions","GetHoveredLineResult","FileContents","LineAnnotation","SelectedLineRange","VirtualFileMetrics","UseFileInstanceProps","LAnnotation","UseFileInstanceReturn","HTMLElement","useFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useFileInstance.d.ts"],"sourcesContent":["import { type FileOptions } from '../../components/File';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from '../../types';\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\nexport declare function useFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileInstance.d.ts.map"],"mappings":";;;;;UAGUM;QACAJ;EADAI,OAAAA,EAEGN,WAFHM,CAEeC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBL,eAAAA,EAEWC,cAFXD,CAE0BK,WAF1BL,CAAAA,EAAAA,GAAAA,SAAAA;EACeK,aAAAA,EAENH,iBAFMG,GAAAA,IAAAA,GAAAA,SAAAA;EAAZP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACuBO,OAAAA,CAAAA,EAGtBF,kBAHsBE;EAAfJ,sBAAAA,EAAAA,OAAAA;EACFC,eAAAA,EAAAA,OAAAA;EAELC,iBAAAA,EAAAA,OAAAA;;AAAkB,UAKtBG,qBAAAA,CAAqB;EAIPE,GAAAA,CAAAA,IAAAA,EAHVD,WAGyB,GAAA,IAAAF,CAAAA,EAAAA,IAAAA;EAAgBI,cAAAA,EAAAA,EAFjCV,oBAEiCU,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;;AAAeE,iBAA9CH,eAA8CG,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,IAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA;AAAAA,CAAAA,EAAwHP,oBAAxHO,CAA6IN,WAA7IM,CAAAA,CAAAA,EAA4JL,qBAA5JK"}
@@ -1,6 +1,6 @@
1
+ import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
1
2
  import { File } from "../../components/File.js";
2
3
  import { VirtualizedFile } from "../../components/VirtualizedFile.js";
3
- import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
4
4
  import { noopRender } from "../constants.js";
5
5
  import { useStableCallback } from "./useStableCallback.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type {\n GetHoveredLineResult,\n SelectedLineRange,\n} from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\n }\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,qBAC2D;CAC3D,MAAM,oBAAoB,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,SAA6B;AAC1D,MAAI,QAAQ,MAAM;AAChB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,oEACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MAAM,qDAAqD;AAEvE,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;AACvB,MAAI,YAAY,WAAW,KAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,WACD;AACD,cAAY,QAAQ,WAAW,WAAW;AAC1C,EAAK,YAAY,QAAQ,OAAO;GAAE;GAAM;GAAiB;GAAa,CAAC;AACvE,MAAI,kBAAkB,OACpB,aAAY,QAAQ,iBAAiB,cAAc;GAErD;AAOF,QAAO;EAAE;EAAK,gBALS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EACwB;;AAUhC,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,0BAC2E;AAC3E,KAAI,CAAC,uBAAuB,CAAC,0BAA0B,CAAC,gBACtD,QAAO;AAET,QAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
1
+ {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\n }\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,qBAC2D;CAC3D,MAAM,oBAAoB,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,SAA6B;AAC1D,MAAI,QAAQ,MAAM;AAChB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,oEACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MAAM,qDAAqD;AAEvE,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;AACvB,MAAI,YAAY,WAAW,KAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,WACD;AACD,cAAY,QAAQ,WAAW,WAAW;AAC1C,EAAK,YAAY,QAAQ,OAAO;GAAE;GAAM;GAAiB;GAAa,CAAC;AACvE,MAAI,kBAAkB,OACpB,aAAY,QAAQ,iBAAiB,cAAc;GAErD;AAOF,QAAO;EAAE;EAAK,gBALS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EACwB;;AAUhC,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,0BAC2E;AAC3E,KAAI,CAAC,uBAAuB,CAAC,0BAA0B,CAAC,gBACtD,QAAO;AAET,QAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
@@ -1,5 +1,5 @@
1
- import { DiffLineAnnotation, FileContents, FileDiffMetadata, MergeConflictMarkerRow } from "../../types.js";
2
- import { GetHoveredLineResult, SelectedLineRange } from "../../managers/InteractionManager.js";
1
+ import { DiffLineAnnotation, FileContents, FileDiffMetadata, MergeConflictMarkerRow, SelectedLineRange } from "../../types.js";
2
+ import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { MergeConflictDiffAction } from "../../utils/parseMergeConflictDiffFromFile.js";
4
4
  import { UnresolvedFile } from "../../components/UnresolvedFile.js";
5
5
  import { UnresolvedFileReactOptions } from "../UnresolvedFile.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useUnresolvedFileInstance.d.ts","names":["UnresolvedFile","GetHoveredLineResult","SelectedLineRange","DiffLineAnnotation","FileContents","FileDiffMetadata","MergeConflictMarkerRow","MergeConflictDiffAction","UnresolvedFileReactOptions","UseUnresolvedFileInstanceProps","LAnnotation","UseUnresolvedFileInstanceReturn","HTMLElement","useUnresolvedFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","hasConflictUtility","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.d.ts"],"sourcesContent":["import { UnresolvedFile } from '../../components/UnresolvedFile';\nimport type { GetHoveredLineResult, SelectedLineRange } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileContents, FileDiffMetadata, MergeConflictMarkerRow } from '../../types';\nimport { type MergeConflictDiffAction } from '../../utils/parseMergeConflictDiffFromFile';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\nexport declare function useUnresolvedFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, hasConflictUtility, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;\nexport {};\n//# sourceMappingURL=useUnresolvedFileInstance.d.ts.map"],"mappings":";;;;;;;UAKUS;QACAL;EADAK,OAAAA,CAAAA,EAEID,0BAF0B,CAECE,WAFDA,CAAAA;EAC9BN,eAAAA,EAEWD,kBAFXC,CAE8BM,WAF9BN,CAAAA,EAAAA,GAAAA,SAAAA;EAC+BM,aAAAA,EAEtBR,iBAFsBQ,GAAAA,IAAAA,GAAAA,SAAAA;EAA3BF,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAC0BE,kBAAAA,EAAAA,OAAAA;EAAnBP,sBAAAA,EAAAA,OAAAA;EACFD,eAAAA,EAAAA,OAAAA;EAAiB,iBAAA,EAAA,OAAA;AAAA;UAO1BS,+BACIN,CAAAA,WAAAA,CAAAA,CAAAA;EACAE,QAAAA,EADAF,gBACAE;EACED,OAAAA,EAAAA,CADFC,uBACED,GAAAA,SAAAA,CAAAA,EAAAA;EACFM,UAAAA,EADEN,sBACFM,EAAAA;EACQX,GAAAA,CAAAA,IAAAA,EADRW,WACQX,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EACYS,cAAAA,EAAAA,EADZT,oBACYS,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;EAAfV,WAAAA,EAAAA,EAAAA,cAAAA,CAAeU,WAAfV,CAAAA,GAAAA,SAAAA;;AAEKa,iBAAAA,yBAAyBH,CAAAA,WAAA,CAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,eAAA;EAAA,aAAA;EAAA,eAAA;EAAA,kBAAA;EAAA,sBAAA;EAAA,eAAA;EAAA;AAAA,CAAA,EAAkKD,8BAAlK,CAAiMC,WAAjM,CAAA,CAAA,EAAgNC,+BAAhN,CAAgPD,WAAhP,CAAA"}
1
+ {"version":3,"file":"useUnresolvedFileInstance.d.ts","names":["UnresolvedFile","GetHoveredLineResult","DiffLineAnnotation","FileContents","FileDiffMetadata","MergeConflictMarkerRow","SelectedLineRange","MergeConflictDiffAction","UnresolvedFileReactOptions","UseUnresolvedFileInstanceProps","LAnnotation","UseUnresolvedFileInstanceReturn","HTMLElement","useUnresolvedFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","hasConflictUtility","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.d.ts"],"sourcesContent":["import { UnresolvedFile } from '../../components/UnresolvedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileContents, FileDiffMetadata, MergeConflictMarkerRow, SelectedLineRange } from '../../types';\nimport { type MergeConflictDiffAction } from '../../utils/parseMergeConflictDiffFromFile';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\nexport declare function useUnresolvedFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, hasConflictUtility, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;\nexport {};\n//# sourceMappingURL=useUnresolvedFileInstance.d.ts.map"],"mappings":";;;;;;;UAKUS;QACAN;EADAM,OAAAA,CAAAA,EAEID,0BAF0B,CAECE,WAFDA,CAAAA;EAC9BP,eAAAA,EAEWD,kBAFXC,CAE8BO,WAF9BP,CAAAA,EAAAA,GAAAA,SAAAA;EAC+BO,aAAAA,EAEtBJ,iBAFsBI,GAAAA,IAAAA,GAAAA,SAAAA;EAA3BF,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EAC0BE,kBAAAA,EAAAA,OAAAA;EAAnBR,sBAAAA,EAAAA,OAAAA;EACFI,eAAAA,EAAAA,OAAAA;EAAiB,iBAAA,EAAA,OAAA;AAAA;UAO1BK,+BACIP,CAAAA,WAAAA,CAAAA,CAAAA;EACAG,QAAAA,EADAH,gBACAG;EACEF,OAAAA,EAAAA,CADFE,uBACEF,GAAAA,SAAAA,CAAAA,EAAAA;EACFO,UAAAA,EADEP,sBACFO,EAAAA;EACQX,GAAAA,CAAAA,IAAAA,EADRW,WACQX,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EACYS,cAAAA,EAAAA,EADZT,oBACYS,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;EAAfV,WAAAA,EAAAA,EAAAA,cAAAA,CAAeU,WAAfV,CAAAA,GAAAA,SAAAA;;AAEKa,iBAAAA,yBAAyBH,CAAAA,WAAA,CAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,eAAA;EAAA,aAAA;EAAA,eAAA;EAAA,kBAAA;EAAA,sBAAA;EAAA,eAAA;EAAA;AAAA,CAAA,EAAkKD,8BAAlK,CAAiMC,WAAjM,CAAA,CAAA,EAAgNC,+BAAhN,CAAgPD,WAAhP,CAAA"}
@@ -1,6 +1,6 @@
1
+ import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
1
2
  import { parseMergeConflictDiffFromFile } from "../../utils/parseMergeConflictDiffFromFile.js";
2
3
  import { UnresolvedFile } from "../../components/UnresolvedFile.js";
3
- import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
4
4
  import { noopRender } from "../constants.js";
5
5
  import { useStableCallback } from "./useStableCallback.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
@@ -1 +1 @@
1
- {"version":3,"file":"useUnresolvedFileInstance.js","names":["fileDiff","actions","markerRows","UnresolvedFileClass"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n UnresolvedFile,\n UnresolvedFile as UnresolvedFileClass,\n type UnresolvedFileOptions,\n} from '../../components/UnresolvedFile';\nimport type {\n GetHoveredLineResult,\n SelectedLineRange,\n} from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MergeConflictActionPayload,\n MergeConflictMarkerRow,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport {\n type MergeConflictDiffAction,\n parseMergeConflictDiffFromFile,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { noopRender } from '../constants';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\n\nexport function useUnresolvedFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation> {\n const [{ fileDiff, actions, markerRows }, setState] = useState(() => {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n return { fileDiff, actions, markerRows };\n });\n // UnresolvedFile is intentionally uncontrolled in React. Keep an internal\n // source-of-truth file so sequential conflict actions apply to the latest\n // resolved contents rather than the initial prop value.\n const onMergeConflictAction = useStableCallback(\n (\n payload: MergeConflictActionPayload,\n instance: UnresolvedFile<LAnnotation>\n ) => {\n setState((prevState) => {\n const { fileDiff, actions, markerRows } =\n instance.resolveConflict(\n payload.conflict.conflictIndex,\n payload.resolution,\n prevState.fileDiff\n ) ?? {};\n if (fileDiff == null || actions == null || markerRows == null) {\n return prevState;\n } else {\n return { fileDiff, actions, markerRows };\n }\n });\n }\n );\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<UnresolvedFileClass<LAnnotation> | null>(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useUnresolvedFileInstance: An instance should not already exist when a node is created'\n );\n }\n instanceRef.current = new UnresolvedFileClass(\n mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n void instanceRef.current.hydrate({\n fileDiff,\n actions,\n markerRows,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useUnresolvedFileInstance: A UnresolvedFile instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const instance = instanceRef.current;\n const newOptions = mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n fileDiff,\n actions,\n markerRows,\n lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n const getInstance = useCallback(() => {\n return instanceRef.current ?? undefined;\n }, []);\n\n return { ref, getHoveredLine, fileDiff, actions, markerRows, getInstance };\n}\n\ninterface MergeUnresolvedOptionsProps<LAnnotation> {\n options: UnresolvedFileReactOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n onMergeConflictAction: UnresolvedFileOptions<LAnnotation>['onMergeConflictAction'];\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeUnresolvedOptions<LAnnotation>({\n options,\n controlledSelection,\n onMergeConflictAction,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeUnresolvedOptionsProps<LAnnotation>): UnresolvedFileOptions<LAnnotation> {\n return {\n ...options,\n controlledSelection,\n onMergeConflictAction,\n hunkSeparators:\n options?.hunkSeparators === 'custom'\n ? noopRender\n : options?.hunkSeparators,\n // Add a placeholder type for the custom render\n mergeConflictActionsType:\n hasConflictUtility || options?.mergeConflictActionsType === 'custom'\n ? noopRender\n : options?.mergeConflictActionsType,\n renderCustomHeader: hasCustomHeader ? noopRender : undefined,\n renderGutterUtility: hasGutterRenderUtility ? noopRender : undefined,\n };\n}\n"],"mappings":";;;;;;;;;AAmCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAuB9C,SAAgB,0BAAuC,EACrD,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBAC4F;CAC5F,MAAM,CAAC,EAAE,UAAU,SAAS,cAAc,YAAY,eAAe;EACnE,MAAM,EAAE,sBAAU,oBAAS,6BAAe,+BACxC,MACA,SAAS,gBACV;AACD,SAAO;GAAE;GAAU;GAAS;GAAY;GACxC;CAIF,MAAM,wBAAw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W;KAC7B,EAAE,CAAC;EAEoE;;AAY5E,SAAS,uBAAoC,EAC3C,SACA,qBACA,uBACA,oBACA,iBACA,0BAC+E;AAC/E,QAAO;EACL,GAAG;EACH;EACA;EACA,gBACE,SAAS,mBAAmB,WACxB,aACA,SAAS;EAEf,0BACE,sBAAsB,SAAS,6BAA6B,WACxD,aACA,SAAS;EACf,oBAAoB,kBAAkB,aAAa;EACnD,qBAAqB,yBAAyB,aAAa;EAC5D"}
1
+ {"version":3,"file":"useUnresolvedFileInstance.js","names":["fileDiff","actions","markerRows","UnresolvedFileClass"],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport {\n UnresolvedFile,\n UnresolvedFile as UnresolvedFileClass,\n type UnresolvedFileOptions,\n} from '../../components/UnresolvedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n MergeConflictActionPayload,\n MergeConflictMarkerRow,\n SelectedLineRange,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport {\n type MergeConflictDiffAction,\n parseMergeConflictDiffFromFile,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { noopRender } from '../constants';\nimport type { UnresolvedFileReactOptions } from '../UnresolvedFile';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseUnresolvedFileInstanceProps<LAnnotation> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseUnresolvedFileInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance(): UnresolvedFile<LAnnotation> | undefined;\n}\n\nexport function useUnresolvedFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation> {\n const [{ fileDiff, actions, markerRows }, setState] = useState(() => {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n return { fileDiff, actions, markerRows };\n });\n // UnresolvedFile is intentionally uncontrolled in React. Keep an internal\n // source-of-truth file so sequential conflict actions apply to the latest\n // resolved contents rather than the initial prop value.\n const onMergeConflictAction = useStableCallback(\n (\n payload: MergeConflictActionPayload,\n instance: UnresolvedFile<LAnnotation>\n ) => {\n setState((prevState) => {\n const { fileDiff, actions, markerRows } =\n instance.resolveConflict(\n payload.conflict.conflictIndex,\n payload.resolution,\n prevState.fileDiff\n ) ?? {};\n if (fileDiff == null || actions == null || markerRows == null) {\n return prevState;\n } else {\n return { fileDiff, actions, markerRows };\n }\n });\n }\n );\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<UnresolvedFileClass<LAnnotation> | null>(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useUnresolvedFileInstance: An instance should not already exist when a node is created'\n );\n }\n instanceRef.current = new UnresolvedFileClass(\n mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n void instanceRef.current.hydrate({\n fileDiff,\n actions,\n markerRows,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useUnresolvedFileInstance: A UnresolvedFile instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const instance = instanceRef.current;\n const newOptions = mergeUnresolvedOptions({\n controlledSelection,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n onMergeConflictAction,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n fileDiff,\n actions,\n markerRows,\n lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n const getInstance = useCallback(() => {\n return instanceRef.current ?? undefined;\n }, []);\n\n return { ref, getHoveredLine, fileDiff, actions, markerRows, getInstance };\n}\n\ninterface MergeUnresolvedOptionsProps<LAnnotation> {\n options: UnresolvedFileReactOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n onMergeConflictAction: UnresolvedFileOptions<LAnnotation>['onMergeConflictAction'];\n hasConflictUtility: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeUnresolvedOptions<LAnnotation>({\n options,\n controlledSelection,\n onMergeConflictAction,\n hasConflictUtility,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeUnresolvedOptionsProps<LAnnotation>): UnresolvedFileOptions<LAnnotation> {\n return {\n ...options,\n controlledSelection,\n onMergeConflictAction,\n hunkSeparators:\n options?.hunkSeparators === 'custom'\n ? noopRender\n : options?.hunkSeparators,\n // Add a placeholder type for the custom render\n mergeConflictActionsType:\n hasConflictUtility || options?.mergeConflictActionsType === 'custom'\n ? noopRender\n : options?.mergeConflictActionsType,\n renderCustomHeader: hasCustomHeader ? noopRender : undefined,\n renderGutterUtility: hasGutterRenderUtility ? noopRender : undefined,\n };\n}\n"],"mappings":";;;;;;;;;AAiCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAuB9C,SAAgB,0BAAuC,EACrD,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBAC4F;CAC5F,MAAM,CAAC,EAAE,UAAU,SAAS,cAAc,YAAY,eAAe;EACnE,MAAM,EAAE,sBAAU,oBAAS,6BAAe,+BACxC,MACA,SAAS,gBACV;AACD,SAAO;GAAE;GAAU;GAAS;GAAY;GACxC;CAIF,MAAM,wBAAwB,mBAE1B,SACA,aACG;AACH,YAAU,cAAc;GACtB,MAAM,EAAE,sBAAU,oBAAS,6BACzB,SAAS,gBACP,QAAQ,SAAS,eACjB,QAAQ,YACR,UAAU,SACX,IAAI,EAAE;AACT,OAAIA,cAAY,QAAQC,aAAW,QAAQC,gBAAc,KACvD,QAAO;OAEP,QAAO;IAAE;IAAU;IAAS;IAAY;IAE1C;GAEL;CACD,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAAgD,KAAK;CACzE,MAAM,MAAM,mBAAmB,kBAAsC;AACnE,MAAI,iBAAiB,MAAM;AACzB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,yFACD;AAEH,eAAY,UAAU,IAAIC,eACxB,uBAAuB;IACrB;IACA;IACA;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AACD,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,oFACD;AAEH,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;AACvB,MAAI,YAAY,WAAW,KAAM;EACjC,MAAM,WAAW,YAAY;EAC7B,MAAM,aAAa,uBAAuB;GACxC;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,WAAW;AAClE,WAAS,WAAW,WAAW;AAC/B,EAAK,SAAS,OAAO;GACnB;GACA;GACA;GACA;GACA;GACD,CAAC;AACF,MAAI,kBAAkB,OACpB,UAAS,iBAAiB,cAAc;GAE1C;AAYF,QAAO;EAAE;EAAK,gBAVS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EAMwB;EAAU;EAAS;EAAY,aAJzC,kBAAkB;AACpC,UAAO,YAAY,WAAW;KAC7B,EAAE,CAAC;EAEoE;;AAY5E,SAAS,uBAAoC,EAC3C,SACA,qBACA,uBACA,oBACA,iBACA,0BAC+E;AAC/E,QAAO;EACL,GAAG;EACH;EACA;EACA,gBACE,SAAS,mBAAmB,WACxB,aACA,SAAS;EAEf,0BACE,sBAAsB,SAAS,6BAA6B,WACxD,aACA,SAAS;EACf,oBAAoB,kBAAkB,aAAa;EACnD,qBAAqB,yBAAyB,aAAa;EAC5D"}
@@ -1,4 +1,5 @@
1
1
  import { DEFAULT_RENDER_RANGE, DEFAULT_THEMES, DEFAULT_TOKENIZE_MAX_LENGTH } from "../constants.js";
2
+ import { areThemesEqual } from "../utils/areThemesEqual.js";
2
3
  import { iterateOverFile } from "../utils/iterateOverFile.js";
3
4
  import { createGutterGap, createGutterItem, createGutterWrapper, createHastElement } from "../utils/hast_utils.js";
4
5
  import { areLanguagesAttached } from "../highlighter/languages/areLanguagesAttached.js";
@@ -7,7 +8,6 @@ import { getThemes } from "../utils/getThemes.js";
7
8
  import { areThemesAttached } from "../highlighter/themes/areThemesAttached.js";
8
9
  import { hasResolvedThemes } from "../highlighter/themes/hasResolvedThemes.js";
9
10
  import { areRenderRangesEqual } from "../utils/areRenderRangesEqual.js";
10
- import { areThemesEqual } from "../utils/areThemesEqual.js";
11
11
  import { createAnnotationElement } from "../utils/createAnnotationElement.js";
12
12
  import { createContentColumn } from "../utils/createContentColumn.js";
13
13
  import { createFileHeaderElement } from "../utils/createFileHeaderElement.js";