@pierre/diffs 1.3.0-beta.6 → 1.3.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +90 -5
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +291 -38
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +1 -0
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +20 -6
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +38 -23
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +144 -61
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +3 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +4 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +6 -8
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +13 -5
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +192 -55
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +2 -0
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js +16 -3
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/command.d.ts +1 -1
- package/dist/editor/command.d.ts.map +1 -1
- package/dist/editor/command.js +8 -0
- package/dist/editor/command.js.map +1 -1
- package/dist/editor/editor.d.ts +10 -3
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +325 -135
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +84 -12
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +5 -3
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js +35 -12
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +8 -0
- package/dist/editor/matchBrackets.d.ts.map +1 -0
- package/dist/editor/matchBrackets.js +146 -0
- package/dist/editor/matchBrackets.js.map +1 -0
- package/dist/editor/popover.d.ts +45 -0
- package/dist/editor/popover.d.ts.map +1 -0
- package/dist/editor/popover.js +145 -0
- package/dist/editor/popover.js.map +1 -0
- package/dist/editor/selection.d.ts +14 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +142 -41
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +20 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js +41 -10
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/textDocument.d.ts +2 -0
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +22 -6
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +25 -7
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenzier.d.ts +6 -7
- package/dist/editor/tokenzier.d.ts.map +1 -1
- package/dist/editor/tokenzier.js +83 -34
- package/dist/editor/tokenzier.js.map +1 -1
- package/dist/editor/utils.d.ts +3 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +14 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +6 -4
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +0 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.d.ts +10 -2
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.js +33 -13
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +25 -1
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +76 -17
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditorContext.d.ts +2 -2
- package/dist/react/EditorContext.d.ts.map +1 -1
- package/dist/react/EditorContext.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +3 -4
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/utils/useFileDiffInstance.js +14 -15
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +45 -23
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +2 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +58 -38
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +11 -10
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +14 -6
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/types.d.ts +100 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/applyLineTextWithNewline.d.ts +5 -0
- package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -0
- package/dist/utils/applyLineTextWithNewline.js +11 -0
- package/dist/utils/applyLineTextWithNewline.js.map +1 -0
- package/dist/utils/areHunkDataEqual.js +1 -1
- package/dist/utils/areHunkDataEqual.js.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts +2 -2
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js +5 -0
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts +5 -0
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
- package/dist/utils/awaitWithTimeout.js +15 -0
- package/dist/utils/awaitWithTimeout.js.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.js +16 -0
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +8 -1
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts +5 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js +19 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js.map +1 -0
- package/dist/utils/createPreElement.js +0 -1
- package/dist/utils/createPreElement.js.map +1 -1
- package/dist/utils/getDiffFileInput.d.ts +14 -0
- package/dist/utils/getDiffFileInput.d.ts.map +1 -0
- package/dist/utils/getDiffFileInput.js +24 -0
- package/dist/utils/getDiffFileInput.js.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +2 -0
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +10 -0
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
- package/dist/utils/hydratePartialDiff.js +140 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +3 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +26 -5
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +0 -1
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +5 -1
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +48 -4
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +7 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +78 -15
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/index.d.ts +2 -2
- package/dist/worker/types.d.ts +7 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +5 -3
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +5 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResizeManager.js","names":[],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n // Shared static resizeObserver that all ResizeManagers use\n private static resizeObserver: ResizeObserver | undefined;\n private static managersByElement = new Map<Element, ResizeManager>();\n\n private static getResizeObserver(): ResizeObserver {\n const resizeObserver =\n ResizeManager.resizeObserver ??\n new ResizeObserver(ResizeManager.handleSharedResizeEntries);\n ResizeManager.resizeObserver = resizeObserver;\n return resizeObserver;\n }\n\n private static handleSharedResizeEntries(entries: ResizeObserverEntry[]) {\n // First we need to batch all elements by manager, so callbacks are\n // properly aligned with a per-instance ResizeManager\n const entriesByManager = new Map<ResizeManager, ResizeObserverEntry[]>();\n for (const entry of entries) {\n const manager = ResizeManager.managersByElement.get(entry.target);\n if (manager == null) {\n continue;\n }\n const managerEntries = entriesByManager.get(manager);\n if (managerEntries == null) {\n entriesByManager.set(manager, [entry]);\n } else {\n managerEntries.push(entry);\n }\n }\n\n for (const [manager, managerEntries] of entriesByManager) {\n manager.handleResizeEntries(managerEntries);\n }\n }\n\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void {\n const annotationUpdates = new Set<AnnotationSetup>();\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n };\n this.observedNodes.set(codeElement, item);\n this.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^-?\\d+,-?\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.observe(pendingUpdate.child1);\n this.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n for (const element of this.observedNodes.keys()) {\n this.unobserve(element);\n }\n this.observedNodes.clear();\n }\n\n private observe(element: HTMLElement): void {\n const { managersByElement } = ResizeManager;\n const owner = managersByElement.get(element);\n // Already registered\n if (owner === this) {\n return;\n }\n // If we've already somehow registered with another manager, we in for a\n // world of pain, so complain loudly\n else if (owner != null && owner !== this) {\n throw new Error(\n 'ResizeManager.observe: element is already owned by another ResizeManager'\n );\n }\n managersByElement.set(element, this);\n ResizeManager.getResizeObserver().observe(element);\n }\n\n private unobserve(element: HTMLElement): void {\n const { managersByElement, resizeObserver } = ResizeManager;\n const owner = managersByElement.get(element);\n if (owner == null) {\n return;\n } else if (owner !== this) {\n throw new Error(\n 'ResizeManager.unobserve: element is owned by another ResizeManager'\n );\n }\n\n managersByElement.delete(element);\n resizeObserver?.unobserve(element);\n if (resizeObserver != null && managersByElement.size === 0) {\n resizeObserver.disconnect();\n ResizeManager.resizeObserver = undefined;\n }\n }\n\n private handleResizeEntries(entries: ResizeObserverEntry[]) {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'ResizeManager.handleResizeEntries: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'ResizeManager.handleResizeEntries: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `ResizeManager.handleResizeEntries: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n }\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (codeWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof nextCodeWidth === 'number' ? `${nextCodeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${nextNumberWidth === 0 ? 'auto' : `${nextNumberWidth}px`}`\n );\n }\n\n if (\n codeWidthChanged ||\n (numberWidthChanged && nextCodeWidth !== 'auto')\n ) {\n const targetWidth =\n typeof nextCodeWidth === 'number'\n ? Math.max(nextCodeWidth - nextNumberWidth, 0)\n : 0;\n item.codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removePro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GAAG,cAAc,IAAI,GAAG,YAAY,MAAM,QAC5C;GACF;EACF;CACF;CAEA,eAAuB,MAA+B,WAAmB;EACvE,IAAI,cAAc,KAAK,eAAe;GACpC,KAAK,gBAAgB,KAAK,IAAI,WAAW,CAAC;GAC1C,KAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,GACxB;GACA,KAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,GACxB;EACF;CACF;AACF;AAEA,SAAS,iBAAiB,YAAqC;CAC7D,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,UAAU,GAAG,CAAC;CAChD,OAAO,UAAU,IAAI,SAAS;AAChC;AAEA,SAAS,mBAAmB,YAA4B;CACtD,OAAO,KAAK,IAAI,KAAK,KAAK,UAAU,GAAG,CAAC;AAC1C;AAEA,SAAS,qBAAqB,MAA+B;CAC3D,IAAI,KAAK,YAAY,aAAa;EAChC,KAAK,YAAY,MAAM,eAAe,8BAA8B;EACpE,KAAK,YAAY,MAAM,eAAe,6BAA6B;EACnE,KAAK,YAAY,MAAM,eAAe,sBAAsB;CAC9D;AACF;AAEA,SAAS,2BAA2B,MAAqC;CACvE,IAAI,KAAK,QAAQ,UAAU,aACzB,KAAK,QAAQ,UAAU,MAAM,eAC3B,+BACF;CAEF,IAAI,KAAK,QAAQ,UAAU,aACzB,KAAK,QAAQ,UAAU,MAAM,eAC3B,+BACF;AAEJ"}
|
|
1
|
+
{"version":3,"file":"ResizeManager.js","names":[],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ninterface CodeColumnVariableChanges {\n codeWidthChanged: boolean;\n numberWidthChanged: boolean;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\nexport type ResizeManagerColumnVariableMode = 'apply' | 'measure';\n\nexport interface ResizeManagerSetupOptions {\n disableAnnotations: boolean;\n columnVariables?: ResizeManagerColumnVariableMode;\n}\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n // Shared static resizeObserver that all ResizeManagers use\n private static resizeObserver: ResizeObserver | undefined;\n private static managersByElement = new Map<Element, ResizeManager>();\n\n private static getResizeObserver(): ResizeObserver {\n const resizeObserver =\n ResizeManager.resizeObserver ??\n new ResizeObserver(ResizeManager.handleSharedResizeEntries);\n ResizeManager.resizeObserver = resizeObserver;\n return resizeObserver;\n }\n\n private static handleSharedResizeEntries(entries: ResizeObserverEntry[]) {\n // First we need to batch all elements by manager, so callbacks are\n // properly aligned with a per-instance ResizeManager\n const entriesByManager = new Map<ResizeManager, ResizeObserverEntry[]>();\n for (const entry of entries) {\n const manager = ResizeManager.managersByElement.get(entry.target);\n if (manager == null) {\n continue;\n }\n const managerEntries = entriesByManager.get(manager);\n if (managerEntries == null) {\n entriesByManager.set(manager, [entry]);\n } else {\n managerEntries.push(entry);\n }\n }\n\n for (const [manager, managerEntries] of entriesByManager) {\n manager.handleResizeEntries(managerEntries);\n }\n }\n\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(\n pre: HTMLPreElement,\n { disableAnnotations, columnVariables = 'apply' }: ResizeManagerSetupOptions\n ): void {\n const annotationUpdates = new Set<AnnotationSetup>();\n const applyColumnVariables = columnVariables === 'apply';\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n syncColumnVariableMode(item, applyColumnVariables);\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n applyColumnVariables,\n };\n this.observedNodes.set(codeElement, item);\n this.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^-?\\d+,-?\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.observe(pendingUpdate.child1);\n this.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n for (const element of this.observedNodes.keys()) {\n this.unobserve(element);\n }\n this.observedNodes.clear();\n }\n\n private observe(element: HTMLElement): void {\n const { managersByElement } = ResizeManager;\n const owner = managersByElement.get(element);\n // Already registered\n if (owner === this) {\n return;\n }\n // If we've already somehow registered with another manager, we in for a\n // world of pain, so complain loudly\n else if (owner != null && owner !== this) {\n throw new Error(\n 'ResizeManager.observe: element is already owned by another ResizeManager'\n );\n }\n managersByElement.set(element, this);\n ResizeManager.getResizeObserver().observe(element);\n }\n\n private unobserve(element: HTMLElement): void {\n const { managersByElement, resizeObserver } = ResizeManager;\n const owner = managersByElement.get(element);\n if (owner == null) {\n return;\n } else if (owner !== this) {\n throw new Error(\n 'ResizeManager.unobserve: element is owned by another ResizeManager'\n );\n }\n\n managersByElement.delete(element);\n resizeObserver?.unobserve(element);\n if (resizeObserver != null && managersByElement.size === 0) {\n resizeObserver.disconnect();\n ResizeManager.resizeObserver = undefined;\n }\n }\n\n private handleResizeEntries(entries: ResizeObserverEntry[]) {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'ResizeManager.handleResizeEntries: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'ResizeManager.handleResizeEntries: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `ResizeManager.handleResizeEntries: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n }\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (item.applyColumnVariables) {\n applyCodeColumnVariables(item, {\n codeWidthChanged,\n numberWidthChanged,\n });\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction syncColumnVariableMode(\n item: ObservedGridNodes,\n applyColumnVariables: boolean\n): void {\n if (item.applyColumnVariables === applyColumnVariables) {\n return;\n }\n\n item.applyColumnVariables = applyColumnVariables;\n if (applyColumnVariables) {\n applyCodeColumnVariables(item, {\n codeWidthChanged: true,\n numberWidthChanged: true,\n });\n } else {\n removeCodeColumnVariables(item);\n }\n}\n\nfunction applyCodeColumnVariables(\n item: ObservedGridNodes,\n { codeWidthChanged, numberWidthChanged }: CodeColumnVariableChanges\n): void {\n const { codeElement, codeWidth, numberWidth } = item;\n if (codeWidthChanged) {\n codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof codeWidth === 'number' ? `${codeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${numberWidth === 0 ? 'auto' : `${numberWidth}px`}`\n );\n }\n\n if (codeWidthChanged || (numberWidthChanged && codeWidth !== 'auto')) {\n const targetWidth =\n typeof codeWidth === 'number' ? Math.max(codeWidth - numberWidth, 0) : 0;\n codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n}\n\nfunction removeCodeColumnVariables(item: ObservedGridNodes): void {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n removeCodeColumnVariables(item);\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n}\n"],"mappings":";AA6BA,IAAa,gBAAb,MAAa,cAAc;CAEzB,OAAe;CACf,OAAe,oCAAoB,IAAI,IAA4B;CAEnE,OAAe,oBAAoC;EACjD,MAAM,iBACJ,cAAc,kBACd,IAAI,eAAe,cAAc,yBAAyB;EAC5D,cAAc,iBAAiB;EAC/B,OAAO;CACT;CAEA,OAAe,0BAA0B,SAAgC;EAGvE,MAAM,mCAAmB,IAAI,IAA0C;EACvE,KAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,U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;CAC5B,IAAI,sBACF,yBAAyB,MAAM;EAC7B,kBAAkB;EAClB,oBAAoB;CACtB,CAAC;MAED,0BAA0B,IAAI;AAElC;AAEA,SAAS,yBACP,MACA,EAAE,kBAAkB,sBACd;CACN,MAAM,EAAE,aAAa,WAAW,gBAAgB;CAChD,IAAI,kBACF,YAAY,MAAM,YAChB,wBACA,GAAG,OAAO,cAAc,WAAW,GAAG,UAAU,MAAM,QACxD;CAGF,IAAI,oBACF,YAAY,MAAM,YAChB,+BACA,GAAG,gBAAgB,IAAI,SAAS,GAAG,YAAY,KACjD;CAGF,IAAI,oBAAqB,sBAAsB,cAAc,QAAS;EACpE,MAAM,cACJ,OAAO,cAAc,WAAW,KAAK,IAAI,YAAY,aAAa,CAAC,IAAI;EACzE,YAAY,MAAM,YAChB,gCACA,GAAG,cAAc,IAAI,GAAG,YAAY,MAAM,QAC5C;CACF;AACF;AAEA,SAAS,0BAA0B,MAA+B;CAChE,KAAK,YAAY,MAAM,eAAe,8BAA8B;CACpE,KAAK,YAAY,MAAM,eAAe,6BAA6B;CACnE,KAAK,YAAY,MAAM,eAAe,sBAAsB;AAC9D;AAEA,SAAS,qBAAqB,MAA+B;CAC3D,IAAI,KAAK,YAAY,aACnB,0BAA0B,IAAI;AAElC;AAEA,SAAS,2BAA2B,MAAqC;CACvE,IAAI,KAAK,QAAQ,UAAU,aACzB,KAAK,QAAQ,UAAU,MAAM,eAC3B,+BACF;CAEF,IAAI,KAAK,QAAQ,UAAU,aACzB,KAAK,QAAQ,UAAU,MAAM,eAC3B,+BACF;AAEJ"}
|
package/dist/react/CodeView.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CodeViewItem, CodeViewScrollTarget, DiffLineAnnotation, LineAnnotation } from "../types.js";
|
|
1
|
+
import { CodeViewCreateEditorOptions, CodeViewItem, CodeViewScrollTarget, DiffLineAnnotation, DiffsEditorHost, FileContents, LineAnnotation } from "../types.js";
|
|
2
2
|
import { GetHoveredLineResult } from "../managers/InteractionManager.js";
|
|
3
3
|
import { CodeView as CodeView$1, CodeViewLineSelection, CodeViewOptions } from "../components/CodeView.js";
|
|
4
4
|
import { CSSProperties, ReactNode, Ref } from "react";
|
|
@@ -14,6 +14,29 @@ interface CodeViewBaseProps<LAnnotation> {
|
|
|
14
14
|
selectedLines?: CodeViewLineSelection | null;
|
|
15
15
|
onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;
|
|
16
16
|
onScroll?(scrollTop: number, viewer: CodeView$1<LAnnotation>): void;
|
|
17
|
+
/** Render a non-virtualized node at the very start of the scroll content,
|
|
18
|
+
* before the first item. Always rendered; scrolls with the content. */
|
|
19
|
+
renderCodeViewHeader?(): ReactNode;
|
|
20
|
+
/** Render a non-virtualized node at the very end of the scroll content, after
|
|
21
|
+
* the last item. Always rendered; scrolls with the content. */
|
|
22
|
+
renderCodeViewFooter?(): ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Enables editing for items with `edit: true`. Pass the given options into
|
|
25
|
+
* the editor constructor — `new Editor(options)` from `@pierre/diffs/editor`
|
|
26
|
+
* — so document changes route to `onItemEditChange` and
|
|
27
|
+
* `onItemEditComplete`. CodeView owns the returned editor's lifecycle.
|
|
28
|
+
*/
|
|
29
|
+
createEditor?(options: CodeViewCreateEditorOptions<LAnnotation>): DiffsEditorHost<LAnnotation> | undefined;
|
|
30
|
+
/** Called with the owning item on every edited-document change. */
|
|
31
|
+
onItemEditChange?(item: CodeViewItem<LAnnotation>, file: FileContents, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Called once with the final contents when an item's edit session ends
|
|
34
|
+
* (edit turned off, item removed or collapsed). Not called for sessions
|
|
35
|
+
* that produced no changes. Committing is user-space: make one combined
|
|
36
|
+
* item write carrying the new file/fileDiff (with a fresh `cacheKey`,
|
|
37
|
+
* since the contents changed) along with `edit: false`.
|
|
38
|
+
*/
|
|
39
|
+
onItemEditComplete?(item: CodeViewItem<LAnnotation>, file: FileContents, lineAnnotations?: DiffLineAnnotation<LAnnotation>[]): void;
|
|
17
40
|
renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;
|
|
18
41
|
renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;
|
|
19
42
|
renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;
|
|
@@ -39,6 +62,7 @@ interface CodeViewHandle<LAnnotation> {
|
|
|
39
62
|
setSelectedLines(selection: CodeViewLineSelection | null): void;
|
|
40
63
|
getSelectedLines(): CodeViewLineSelection | null;
|
|
41
64
|
clearSelectedLines(): void;
|
|
65
|
+
getEditor(id: string): DiffsEditorHost<LAnnotation> | undefined;
|
|
42
66
|
getInstance(): CodeView$1<LAnnotation> | undefined;
|
|
43
67
|
}
|
|
44
68
|
type CodeViewComponent = <LAnnotation = undefined>(props: CodeViewProps<LAnnotation> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.d.ts","names":[],"sources":["../../src/react/CodeView.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"CodeView.d.ts","names":[],"sources":["../../src/react/CodeView.tsx"],"mappings":";;;;;;KA6CK,2BAAA,UACM,oBAAA,+BACA,oBAAoB;AAAA,UAErB,iBAAA;EACR,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,YAAA,GAAe,GAAA,CAAI,cAAA;EACnB,iBAAA;EACA,aAAA,GAAgB,qBAAA;EAChB,qBAAA,EAAuB,SAAA,EAAW,qBAAA;EAClC,QAAA,EAAU,SAAA,UAAmB,MAAA,EAAQ,UAAA,CAAc,WAAA;EAR3C;;EAWR,oBAAA,KAAyB,SAAA;EAVC;;EAa1B,oBAAA,KAAyB,SAAA;EAVN;;;;;;EAiBnB,YAAA,EACE,OAAA,EAAS,2BAAA,CAA4B,WAAA,IACpC,eAAA,CAAgB,WAAA;EATM;EAWzB,gBAAA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SAAA,EAAW,qBAAA;EAC5B,gBAAA,IAAoB,qBAAA;EACpB,kBAAA;EACA,SAAA,CAAU,EAAA,WAAa,eAAA,CAAgB,WAAA;EACvC,WAAA,IAAe,UAAA,CAAc,WAAA;AAAA;AAAA,KAG1B,iBAAA,6BACH,KAAA,EAAO,aAAA,CAAc,WAAA;EACnB,GAAA,GAAM,KAAA,CAAM,GAAA,CAAI,cAAA,CAAe,WAAA;AAAA,MAE9B,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA,cAqcF,QAAA,EAAwC,iBAAiB"}
|
package/dist/react/CodeView.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { areManagedSnapshotsEqual } from "../utils/areManagedSnapshotsEqual.js";
|
|
2
3
|
import { areOptionsEqual } from "../utils/areOptionsEqual.js";
|
|
3
4
|
import { CodeView as CodeView$1 } from "../components/CodeView.js";
|
|
4
|
-
import { areManagedSnapshotsEqual } from "../utils/areManagedSnapshotsEqual.js";
|
|
5
5
|
import { renderDiffChildren } from "./utils/renderDiffChildren.js";
|
|
6
6
|
import { renderFileChildren } from "./utils/renderFileChildren.js";
|
|
7
7
|
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
@@ -22,7 +22,7 @@ function createDefaultCache(controlled) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
function CodeViewInner(props, ref) {
|
|
25
|
-
const { className, containerRef, disableWorkerPool = false, initialItems, items: controlledItems, onScroll, onSelectedLinesChange, options, renderAnnotation, renderCustomHeader, renderGutterUtility, renderHeaderFilenameSuffix, renderHeaderMetadata, renderHeaderPrefix, selectedLines, style } = props;
|
|
25
|
+
const { className, containerRef, createEditor, disableWorkerPool = false, initialItems, items: controlledItems, onItemEditChange, onItemEditComplete, onScroll, onSelectedLinesChange, options, renderAnnotation, renderCodeViewFooter, renderCodeViewHeader, renderCustomHeader, renderGutterUtility, renderHeaderFilenameSuffix, renderHeaderMetadata, renderHeaderPrefix, selectedLines, style } = props;
|
|
26
26
|
const controlled = controlledItems !== void 0;
|
|
27
27
|
const poolManager = useContext(WorkerPoolContext);
|
|
28
28
|
const cachedDataRef = useRef(createDefaultCache(controlled));
|
|
@@ -31,23 +31,45 @@ function CodeViewInner(props, ref) {
|
|
|
31
31
|
const hasGutterRenderer = renderGutterUtility != null;
|
|
32
32
|
const hasHeaderRenderers = hasCustomHeader || renderHeaderPrefix != null || renderHeaderFilenameSuffix != null || renderHeaderMetadata != null;
|
|
33
33
|
const hasRenderers = hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;
|
|
34
|
+
const hasCodeViewHeader = renderCodeViewHeader != null;
|
|
35
|
+
const hasCodeViewFooter = renderCodeViewFooter != null;
|
|
34
36
|
const emitSelectedLinesChange = useStableCallback((selection) => {
|
|
35
37
|
onSelectedLinesChange?.(selection);
|
|
36
38
|
});
|
|
37
39
|
const controlledSelection = selectedLines !== void 0;
|
|
40
|
+
const stableCreateEditor = useStableCallback((editorOptions) => createEditor?.(editorOptions));
|
|
41
|
+
const emitItemEditChange = useStableCallback((item, file, lineAnnotations) => {
|
|
42
|
+
onItemEditChange?.(item, file, lineAnnotations);
|
|
43
|
+
});
|
|
44
|
+
const emitItemEditComplete = useStableCallback((item, file, lineAnnotations) => {
|
|
45
|
+
onItemEditComplete?.(item, file, lineAnnotations);
|
|
46
|
+
});
|
|
38
47
|
const managedOptions = useMemo(() => createManagedCodeViewOptions({
|
|
39
48
|
options,
|
|
40
49
|
hasCustomHeader,
|
|
41
50
|
hasGutterRenderer,
|
|
51
|
+
hasCodeViewHeader,
|
|
52
|
+
hasCodeViewFooter,
|
|
42
53
|
onSelectedLinesChange: onSelectedLinesChange != null ? emitSelectedLinesChange : void 0,
|
|
43
|
-
controlledSelection
|
|
54
|
+
controlledSelection,
|
|
55
|
+
createEditor: createEditor != null ? stableCreateEditor : void 0,
|
|
56
|
+
onItemEditChange: onItemEditChange != null ? emitItemEditChange : void 0,
|
|
57
|
+
onItemEditComplete: onItemEditComplete != null ? emitItemEditComplete : void 0
|
|
44
58
|
}), [
|
|
45
59
|
options,
|
|
46
60
|
hasCustomHeader,
|
|
47
61
|
hasGutterRenderer,
|
|
62
|
+
hasCodeViewHeader,
|
|
63
|
+
hasCodeViewFooter,
|
|
48
64
|
onSelectedLinesChange,
|
|
49
65
|
emitSelectedLinesChange,
|
|
50
|
-
controlledSelection
|
|
66
|
+
controlledSelection,
|
|
67
|
+
createEditor,
|
|
68
|
+
stableCreateEditor,
|
|
69
|
+
onItemEditChange,
|
|
70
|
+
emitItemEditChange,
|
|
71
|
+
onItemEditComplete,
|
|
72
|
+
emitItemEditComplete
|
|
51
73
|
]);
|
|
52
74
|
const [slotContentStore] = useState(() => createSlotContentStore());
|
|
53
75
|
const [, forceUpdate] = useState({});
|
|
@@ -71,7 +93,7 @@ function CodeViewInner(props, ref) {
|
|
|
71
93
|
});
|
|
72
94
|
});
|
|
73
95
|
const slotCoordinator = useMemo(() => {
|
|
74
|
-
if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) return;
|
|
96
|
+
if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer && !hasCodeViewHeader && !hasCodeViewFooter) return;
|
|
75
97
|
else return {
|
|
76
98
|
hasHeaderRenderers,
|
|
77
99
|
hasAnnotationRenderer,
|
|
@@ -82,7 +104,9 @@ function CodeViewInner(props, ref) {
|
|
|
82
104
|
onSnapshotChange,
|
|
83
105
|
hasAnnotationRenderer,
|
|
84
106
|
hasGutterRenderer,
|
|
85
|
-
hasHeaderRenderers
|
|
107
|
+
hasHeaderRenderers,
|
|
108
|
+
hasCodeViewHeader,
|
|
109
|
+
hasCodeViewFooter
|
|
86
110
|
]);
|
|
87
111
|
useIsometricEffect(() => {
|
|
88
112
|
return onScroll != null ? cachedDataRef.current.instance?.subscribeToScroll(onScroll) : void 0;
|
|
@@ -194,6 +218,14 @@ function CodeViewInner(props, ref) {
|
|
|
194
218
|
emitSelectedLinesChange(null);
|
|
195
219
|
}
|
|
196
220
|
},
|
|
221
|
+
getEditor(id) {
|
|
222
|
+
const { instance } = cachedDataRef.current;
|
|
223
|
+
if (instance == null) {
|
|
224
|
+
console.error("CodeView.getEditor: no valid instance exists", id);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
return instance.getEditor(id);
|
|
228
|
+
},
|
|
197
229
|
getInstance() {
|
|
198
230
|
return cachedDataRef.current.instance;
|
|
199
231
|
}
|
|
@@ -202,14 +234,16 @@ function CodeViewInner(props, ref) {
|
|
|
202
234
|
ref: nodeRef,
|
|
203
235
|
className,
|
|
204
236
|
style
|
|
205
|
-
}), hasRenderers && /* @__PURE__ */ jsx(SlotPortals, {
|
|
237
|
+
}), (hasRenderers || hasCodeViewHeader || hasCodeViewFooter) && /* @__PURE__ */ jsx(SlotPortals, {
|
|
206
238
|
managedContentStore: slotContentStore,
|
|
207
239
|
renderCustomHeader,
|
|
208
240
|
renderHeaderPrefix,
|
|
209
241
|
renderHeaderFilenameSuffix,
|
|
210
242
|
renderHeaderMetadata,
|
|
211
243
|
renderAnnotation,
|
|
212
|
-
renderGutterUtility
|
|
244
|
+
renderGutterUtility,
|
|
245
|
+
renderCodeViewHeader,
|
|
246
|
+
renderCodeViewFooter
|
|
213
247
|
})] });
|
|
214
248
|
}
|
|
215
249
|
const CodeView = forwardRef(CodeViewInner);
|
|
@@ -248,31 +282,56 @@ function createSlotContentStore() {
|
|
|
248
282
|
}
|
|
249
283
|
};
|
|
250
284
|
}
|
|
251
|
-
function createManagedCodeViewOptions({ options, hasCustomHeader, hasGutterRenderer, onSelectedLinesChange, controlledSelection }) {
|
|
252
|
-
if (!hasCustomHeader && !hasGutterRenderer && onSelectedLinesChange == null && !controlledSelection) return options;
|
|
285
|
+
function createManagedCodeViewOptions({ options, hasCustomHeader, hasGutterRenderer, hasCodeViewHeader, hasCodeViewFooter, onSelectedLinesChange, controlledSelection, createEditor, onItemEditChange, onItemEditComplete }) {
|
|
286
|
+
if (!hasCustomHeader && !hasGutterRenderer && !hasCodeViewHeader && !hasCodeViewFooter && onSelectedLinesChange == null && !controlledSelection && createEditor == null && onItemEditChange == null && onItemEditComplete == null) return options ?? {};
|
|
253
287
|
options = {
|
|
254
288
|
...options,
|
|
255
289
|
controlledSelection,
|
|
256
290
|
onSelectedLinesChange
|
|
257
291
|
};
|
|
292
|
+
if (createEditor != null) options.createEditor = createEditor;
|
|
293
|
+
if (onItemEditChange != null) options.onItemEditChange = onItemEditChange;
|
|
294
|
+
if (onItemEditComplete != null) options.onItemEditComplete = onItemEditComplete;
|
|
258
295
|
if (hasCustomHeader) options.renderCustomHeader = noopRender;
|
|
259
296
|
if (hasGutterRenderer) options.renderGutterUtility = noopRender;
|
|
297
|
+
if (hasCodeViewHeader) options.renderCodeViewHeader = noopRender;
|
|
298
|
+
if (hasCodeViewFooter) options.renderCodeViewFooter = noopRender;
|
|
260
299
|
return options;
|
|
261
300
|
}
|
|
262
|
-
const SlotPortals = memo(function SlotPortals({ managedContentStore, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, renderGutterUtility }) {
|
|
301
|
+
const SlotPortals = memo(function SlotPortals({ managedContentStore, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, renderGutterUtility, renderCodeViewHeader, renderCodeViewFooter }) {
|
|
302
|
+
"use no memo";
|
|
263
303
|
const subscribe = useStableCallback((listener) => managedContentStore.subscribe(listener));
|
|
264
304
|
const getSnapshot = useStableCallback(() => managedContentStore.getSnapshot());
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
305
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
306
|
+
let itemKeys = "";
|
|
307
|
+
for (const item of snapshot?.items ?? []) itemKeys += `${item.id}:${item.version}:${item.type}`;
|
|
308
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
309
|
+
useMemo(() => {
|
|
310
|
+
return snapshot?.items?.map((renderedItem) => createPortal(renderCodeViewItemChildren({
|
|
311
|
+
renderedItem,
|
|
312
|
+
renderCustomHeader,
|
|
313
|
+
renderHeaderPrefix,
|
|
314
|
+
renderHeaderFilenameSuffix,
|
|
315
|
+
renderHeaderMetadata,
|
|
316
|
+
renderAnnotation,
|
|
317
|
+
renderGutterUtility
|
|
318
|
+
}), renderedItem.element, renderedItem.id));
|
|
319
|
+
}, [
|
|
268
320
|
renderCustomHeader,
|
|
269
321
|
renderHeaderPrefix,
|
|
270
322
|
renderHeaderFilenameSuffix,
|
|
271
323
|
renderHeaderMetadata,
|
|
272
324
|
renderAnnotation,
|
|
273
|
-
renderGutterUtility
|
|
274
|
-
|
|
275
|
-
|
|
325
|
+
renderGutterUtility,
|
|
326
|
+
itemKeys
|
|
327
|
+
]),
|
|
328
|
+
useMemo(() => {
|
|
329
|
+
return renderCodeViewHeader != null && snapshot?.header != null ? createPortal(renderCodeViewHeader(), snapshot.header) : null;
|
|
330
|
+
}, [renderCodeViewHeader, snapshot?.header]),
|
|
331
|
+
useMemo(() => {
|
|
332
|
+
return renderCodeViewFooter != null && snapshot?.footer != null ? createPortal(renderCodeViewFooter(), snapshot.footer) : null;
|
|
333
|
+
}, [renderCodeViewFooter, snapshot?.footer])
|
|
334
|
+
] });
|
|
276
335
|
});
|
|
277
336
|
function renderCodeViewItemChildren({ renderedItem, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, renderGutterUtility }) {
|
|
278
337
|
if (renderedItem.type === "diff") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.js","names":["CodeViewClass"],"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 renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewRenderedItem<LAnnotation>[] | undefined;\n publish(snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {hasRenderers && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\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 renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\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 renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\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 renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : 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 renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : 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;AAsF9C,SAAS,mBACP,YAC4B;CAC5B,OAAO;EACL,UAAU,KAAA;EACV,OAAO,KAAA;EACP;EACA,gBAAgB,KAAA;EAChB,kBAAkB;EAClB,iBAAiB,KAAA;CACnB;AACF;AAEA,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,oBAAoB,OACpB,cACA,OAAO,iBACP,UACA,uBACA,SACA,kBACA,oBACA,qBACA,4BACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB,KAAA;CACvC,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,gBAAgB,OACpB,mBAAgC,UAAU,CAC5C;CACA,MAAM,kBAAkB,sBAAsB;CA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qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH,OAAO;EACL,MAAM,EAAE,MAAM,aAAa;EAC3B,OAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,4BACE,8BAA8B,aACpB,2BAA2B,IAAI,IACrC,KAAA;GACN,sBACE,wBAAwB,aACd,qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
|
|
1
|
+
{"version":3,"file":"CodeView.js","names":["CodeViewClass"],"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 CodeViewCreateEditorOptions,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type CodeViewSlotSnapshot,\n type DiffLineAnnotation,\n type DiffsEditorHost,\n type FileContents,\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 /** Render a non-virtualized node at the very start of the scroll content,\n * before the first item. Always rendered; scrolls with the content. */\n renderCodeViewHeader?(): ReactNode;\n /** Render a non-virtualized node at the very end of the scroll content, after\n * the last item. Always rendered; scrolls with the content. */\n renderCodeViewFooter?(): ReactNode;\n /**\n * Enables editing for items with `edit: true`. Pass the given options into\n * the editor constructor — `new Editor(options)` from `@pierre/diffs/editor`\n * — so document changes route to `onItemEditChange` and\n * `onItemEditComplete`. CodeView owns the returned editor's lifecycle.\n */\n createEditor?(\n options: CodeViewCreateEditorOptions<LAnnotation>\n ): DiffsEditorHost<LAnnotation> | undefined;\n /** Called with the owning item on every edited-document change. */\n onItemEditChange?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void;\n /**\n * Called once with the final contents when an item's edit session ends\n * (edit turned off, item removed or collapsed). Not called for sessions\n * that produced no changes. Committing is user-space: make one combined\n * item write carrying the new file/fileDiff (with a fresh `cacheKey`,\n * since the contents changed) along with `edit: false`.\n */\n onItemEditComplete?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getEditor(id: string): DiffsEditorHost<LAnnotation> | undefined;\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(): CodeViewSlotSnapshot<LAnnotation> | undefined;\n publish(snapshot: CodeViewSlotSnapshot<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 createEditor,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onItemEditChange,\n onItemEditComplete,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCodeViewFooter,\n renderCodeViewHeader,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const hasCodeViewHeader = renderCodeViewHeader != null;\n const hasCodeViewFooter = renderCodeViewFooter != null;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n // Stable identities for the editor callbacks so inline props don't churn\n // managedOptions (a changed options object forces a full item re-render).\n const stableCreateEditor = useStableCallback(\n (editorOptions: CodeViewCreateEditorOptions<LAnnotation>) =>\n createEditor?.(editorOptions)\n );\n const emitItemEditChange = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditChange?.(item, file, lineAnnotations);\n }\n );\n const emitItemEditComplete = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditComplete?.(item, file, lineAnnotations);\n }\n );\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n createEditor: createEditor != null ? stableCreateEditor : undefined,\n onItemEditChange:\n onItemEditChange != null ? emitItemEditChange : undefined,\n onItemEditComplete:\n onItemEditComplete != null ? emitItemEditComplete : undefined,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n createEditor,\n stableCreateEditor,\n onItemEditChange,\n emitItemEditChange,\n onItemEditComplete,\n emitItemEditComplete,\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: CodeViewSlotSnapshot<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 // A coordinator is needed whenever React portals anything — per-item\n // slots and codeview header and footer\n if (\n !hasHeaderRenderers &&\n !hasAnnotationRenderer &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter\n ) {\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 hasCodeViewHeader,\n hasCodeViewFooter,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getEditor(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getEditor: no valid instance exists', id);\n return undefined;\n }\n\n return instance.getEditor(id);\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 || hasCodeViewHeader || hasCodeViewFooter) && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n renderCodeViewHeader={renderCodeViewHeader}\n renderCodeViewFooter={renderCodeViewFooter}\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: CodeViewSlotSnapshot<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 hasCodeViewHeader: boolean;\n hasCodeViewFooter: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n createEditor: CodeViewOptions<LAnnotation>['createEditor'];\n onItemEditChange: CodeViewOptions<LAnnotation>['onItemEditChange'];\n onItemEditComplete: CodeViewOptions<LAnnotation>['onItemEditComplete'];\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n controlledSelection,\n createEditor,\n onItemEditChange,\n onItemEditComplete,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter &&\n onSelectedLinesChange == null &&\n !controlledSelection &&\n createEditor == null &&\n onItemEditChange == null &&\n onItemEditComplete == null\n ) {\n return options ?? {};\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // Prop-level editor callbacks win over their options-object counterparts,\n // but an absent prop must not clobber a value provided via `options`.\n if (createEditor != null) {\n options.createEditor = createEditor;\n }\n if (onItemEditChange != null) {\n options.onItemEditChange = onItemEditChange;\n }\n if (onItemEditComplete != null) {\n options.onItemEditComplete = onItemEditComplete;\n }\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 // The imperative CodeView adapters use these callbacks' presence to create the\n // header/footer host elements. React portals the actual content into them (via\n // the slot snapshot), so these placeholders intentionally return nothing.\n if (hasCodeViewHeader) {\n options.renderCodeViewHeader = noopRender;\n }\n if (hasCodeViewFooter) {\n options.renderCodeViewFooter = 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 renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\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 renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n renderCodeViewHeader: CodeViewBaseProps<LAnnotation>['renderCodeViewHeader'];\n renderCodeViewFooter: CodeViewBaseProps<LAnnotation>['renderCodeViewFooter'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderCodeViewHeader,\n renderCodeViewFooter,\n}: SlotPortalsProps<LAnnotation>) {\n 'use no memo';\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const snapshot = useSyncExternalStore<\n CodeViewSlotSnapshot<LAnnotation> | undefined\n >(subscribe, getSnapshot, getSnapshot);\n let itemKeys = '';\n for (const item of snapshot?.items ?? []) {\n itemKeys += `${item.id}:${item.version}:${item.type}`;\n }\n // NOTE(amadeus): And just like that, the react compiler do be failing us\n // lol... we need to pre-render everything for items, headers and footers to\n // not trigger needless renders while scrolling\n const renderedItems = useMemo(\n () => {\n return snapshot?.items?.map((renderedItem) =>\n createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n )\n );\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n itemKeys,\n ]\n );\n const renderedHeader = useMemo(() => {\n return renderCodeViewHeader != null && snapshot?.header != null\n ? createPortal(renderCodeViewHeader(), snapshot.header)\n : null;\n }, [renderCodeViewHeader, snapshot?.header]);\n const renderedFooter = useMemo(() => {\n return renderCodeViewFooter != null && snapshot?.footer != null\n ? createPortal(renderCodeViewFooter(), snapshot.footer)\n : null;\n }, [renderCodeViewFooter, snapshot?.footer]);\n return (\n <>\n {renderedItems}\n {renderedHeader}\n {renderedFooter}\n </>\n );\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\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 renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : 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 renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : 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":";;;;;;;;;;;;AA0CA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAwH9C,SAAS,mBACP,YAC4B;CAC5B,OAAO;EACL,UAAU,KAAA;EACV,OAAO,KAAA;EACP;EACA,gBAAgB,KAAA;EAChB,kBAAkB;EAClB,iBAAiB,KAAA;CACnB;AACF;AAEA,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,cACA,oBAAoB,OACpB,cACA,OAAO,iBACP,kBACA,oBACA,UACA,uBACA,SACA,kBACA,sBACA,sBACA,oBACA,qBACA,4BACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB,KAAA;CACvC,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,gBAAgB,OACpB,mBAAgC,UAAU,CAC5C;CACA,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,8BAA8B,QAC9B,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,0BAA0B,mBAC7B,cAA4C;EAC3C,wBAAwB,SAAS;CACnC,CACF;CACA,MAAM,sBAAsB,kBAAkB,KAAA;CAI9C,MAAM,qBAAqB,mBACxB,kBACC,eAAe,aAAa,CAChC;CACA,MAAM,qBAAqB,mBAEvB,MACA,MACA,oBACG;EACH,mBAAmB,MAAM,MAAM,eAAe;CAChD,CACF;CACA,MAAM,uBAAuB,mBAEzB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AAC;CACH,OAAO;EACL,MAAM,EAAE,MAAM,aAAa;EAC3B,OAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,IAAI,IAAI,KAAA;GAChE,4BACE,8BAA8B,aACpB,2BAA2B,IAAI,IACrC,KAAA;GACN,sBACE,wBAAwB,aACd,qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
|
|
@@ -2,12 +2,12 @@ import { Editor } from "../editor/editor.js";
|
|
|
2
2
|
import { Context, PropsWithChildren } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/react/EditorContext.d.ts
|
|
5
|
-
declare const EditorContext: Context<Editor<
|
|
5
|
+
declare const EditorContext: Context<Editor<any> | undefined>;
|
|
6
6
|
declare function EditorProvider({
|
|
7
7
|
children,
|
|
8
8
|
editor
|
|
9
9
|
}: PropsWithChildren<{
|
|
10
|
-
editor: Editor<
|
|
10
|
+
editor: Editor<any>;
|
|
11
11
|
}>): React.JSX.Element;
|
|
12
12
|
declare function useEditor<LAnnotation>(): Editor<LAnnotation> | undefined;
|
|
13
13
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContext.d.ts","names":[],"sources":["../../src/react/EditorContext.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"EditorContext.d.ts","names":[],"sources":["../../src/react/EditorContext.tsx"],"mappings":";;;;cAQa,aAAA,EAAe,OAAO,CAAC,MAAA;AAAA,iBAIpB,cAAA;EACd,QAAA;EACA;AAAA,GACC,iBAAA;EAAoB,MAAA,EAAQ,MAAA;AAAA,KAAiB,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA,iBAW1C,SAAA,iBAA0B,MAAM,CAAC,WAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContext.js","names":[],"sources":["../../src/react/EditorContext.tsx"],"sourcesContent":["'use client';\n\nimport type { Context, PropsWithChildren } from 'react';\nimport { createContext, useContext, useEffect } from 'react';\n\nimport { Editor } from '../editor';\n\nexport const EditorContext: Context<Editor<
|
|
1
|
+
{"version":3,"file":"EditorContext.js","names":[],"sources":["../../src/react/EditorContext.tsx"],"sourcesContent":["// oxlint-disable typescript/no-explicit-any\n'use client';\n\nimport type { Context, PropsWithChildren } from 'react';\nimport { createContext, useContext, useEffect } from 'react';\n\nimport type { Editor } from '../editor';\n\nexport const EditorContext: Context<Editor<any> | undefined> = createContext<\n Editor<any> | undefined\n>(undefined);\n\nexport function EditorProvider({\n children,\n editor,\n}: PropsWithChildren<{ editor: Editor<any> }>): React.JSX.Element {\n useEffect(() => {\n return () => {\n editor.cleanUp();\n };\n }, [editor]);\n return (\n <EditorContext.Provider value={editor}>{children}</EditorContext.Provider>\n );\n}\n\nexport function useEditor<LAnnotation>(): Editor<LAnnotation> | undefined {\n return useContext(EditorContext);\n}\n"],"mappings":";;;;AAQA,MAAa,gBAAkD,cAE7D,KAAA,CAAS;AAEX,SAAgB,eAAe,EAC7B,UACA,UACgE;CAChE,gBAAgB;EACd,aAAa;GACX,OAAO,QAAQ;EACjB;CACF,GAAG,CAAC,MAAM,CAAC;CACX,OACE,oBAAC,cAAc,UAAf;EAAwB,OAAO;EAAS;CAAiC,CAAA;AAE7E;AAEA,SAAgB,YAA0D;CACxE,OAAO,WAAW,aAAa;AACjC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { FileContents } from "../types.js";
|
|
1
|
+
import { DiffFileInput, FileContents } from "../types.js";
|
|
2
2
|
import { DiffBasePropsReact } from "./types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/react/MultiFileDiff.d.ts
|
|
5
|
-
interface
|
|
6
|
-
oldFile: FileContents;
|
|
7
|
-
newFile: FileContents;
|
|
5
|
+
interface MultiFileDiffBaseProps<LAnnotation> extends DiffBasePropsReact<LAnnotation> {
|
|
8
6
|
disableWorkerPool?: boolean;
|
|
9
7
|
contentEditable?: boolean;
|
|
10
8
|
}
|
|
9
|
+
type MultiFileDiffProps<LAnnotation> = MultiFileDiffBaseProps<LAnnotation> & DiffFileInput;
|
|
11
10
|
declare function MultiFileDiff<LAnnotation = undefined>({
|
|
12
11
|
oldFile,
|
|
13
12
|
newFile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFileDiff.d.ts","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"MultiFileDiff.d.ts","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"mappings":";;;;UAcU,sBAAA,sBAEA,kBAAkB,CAAC,WAAA;EAC3B,iBAAA;EACA,eAAA;AAAA;AAAA,KAGU,kBAAA,gBACV,sBAAA,CAAuB,WAAA,IAAe,aAAA;AAAA,iBAExB,aAAA;EACd,OAAA;EACA,OAAA;EACA,OAAA;EACA,OAAA;EACA,eAAA;EACA,aAAA;EACA,SAAA;EACA,KAAA;EACA,eAAA;EACA,gBAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,mBAAA;EACA,iBAAA;EACA;AAAA,GACC,kBAAA,CAAmB,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileContents } from '../types';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileContents };\n\
|
|
1
|
+
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { DiffFileInput, FileContents } from '../types';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileContents };\n\ninterface MultiFileDiffBaseProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n disableWorkerPool?: boolean;\n contentEditable?: boolean;\n}\n\nexport type MultiFileDiffProps<LAnnotation> =\n MultiFileDiffBaseProps<LAnnotation> & DiffFileInput;\n\nexport function MultiFileDiff<LAnnotation = undefined>({\n oldFile,\n newFile,\n options,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n contentEditable = false,\n}: MultiFileDiffProps<LAnnotation>): React.JSX.Element {\n const fileDiff = useMemo(() => {\n return parseDiffFromFile(oldFile, newFile, options?.parseDiffOptions);\n }, [oldFile, newFile, options?.parseDiffOptions]);\n const { ref, getHoveredLine } = useFileDiffInstance({\n fileDiff,\n options,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n contentEditable,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,cAAuC,EACrD,SACA,SACA,SACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,kBAAkB,SACmC;CACrD,MAAM,WAAW,cAAc;EAC7B,OAAO,kBAAkB,SAAS,SAAS,SAAS,gBAAgB;CACtE,GAAG;EAAC;EAAS;EAAS,SAAS;CAAgB,CAAC;CAChD,MAAM,EAAE,KAAK,mBAAmB,oBAAoB;EAClD;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;CACF,CAAC;CAYD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAbY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
|