@pierre/diffs 1.4.1 → 1.4.2
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 +4 -4
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +8 -6
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +3 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/FileDiff.d.ts +9 -37
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +15 -12
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts +1 -0
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -1
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +2 -8
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +11 -9
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +2 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +11 -9
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +1 -5
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts +0 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/components/web-components.d.ts.map +1 -1
- package/dist/components/web-components.js +2 -1
- package/dist/components/web-components.js.map +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/editor/EditStateManager.d.ts +0 -1
- package/dist/editor/EditStateManager.d.ts.map +1 -1
- package/dist/editor/EditStateManager.js.map +1 -1
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +0 -1
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -1
- package/dist/editor/command.d.ts +2 -1
- package/dist/editor/command.d.ts.map +1 -1
- package/dist/editor/editPrediction.d.ts +3 -2
- package/dist/editor/editPrediction.d.ts.map +1 -1
- package/dist/editor/editPrediction.js +11 -11
- package/dist/editor/editPrediction.js.map +1 -1
- package/dist/editor/editStack.d.ts +0 -1
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +1 -5
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +24 -19
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js.map +1 -1
- package/dist/editor/languages.d.ts +0 -1
- package/dist/editor/languages.d.ts.map +1 -1
- package/dist/editor/languages.js +1 -1
- package/dist/editor/languages.js.map +1 -1
- package/dist/editor/lineAnnotations.d.ts +0 -1
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +2 -1
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +0 -1
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js +5 -3
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +0 -1
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/pieceTable.d.ts +0 -1
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/platform.d.ts +1 -5
- package/dist/editor/platform.d.ts.map +1 -1
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/popover.d.ts +12 -12
- package/dist/editor/popover.d.ts.map +1 -1
- package/dist/editor/popover.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +0 -1
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +16 -12
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +0 -1
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +0 -1
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/sprite.d.ts.map +1 -1
- package/dist/editor/textDocument.d.ts +0 -1
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts +0 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -1
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +1 -11
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +8 -4
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/types.d.ts +0 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +11 -7
- package/dist/editor/utils.js.map +1 -1
- package/dist/highlighter/languages/areLanguagesAttached.d.ts +0 -1
- package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts +1 -0
- package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/cleanUpResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/constants.d.ts +1 -1
- package/dist/highlighter/languages/constants.d.ts.map +1 -1
- package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -0
- package/dist/highlighter/languages/getResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -0
- package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/hasResolvedLanguages.d.ts +0 -1
- package/dist/highlighter/languages/hasResolvedLanguages.d.ts.map +1 -1
- package/dist/highlighter/languages/registerCustomLanguage.d.ts +0 -1
- package/dist/highlighter/languages/registerCustomLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/resolveLanguage.d.ts +1 -0
- package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
- package/dist/highlighter/languages/resolveLanguages.d.ts +1 -0
- package/dist/highlighter/languages/resolveLanguages.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +1 -6
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/themes/areThemesAttached.d.ts +0 -1
- package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.d.ts +0 -1
- package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/constants.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +0 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.d.ts +0 -1
- package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.d.ts +0 -1
- package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts +0 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveTheme.d.ts +0 -1
- package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/resolveThemes.d.ts +0 -1
- package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
- package/dist/highlighter/themes/themeResolution.d.ts +0 -1
- package/dist/highlighter/themes/themeResolution.d.ts.map +1 -1
- package/dist/highlighter/themes/themeResolver.d.ts +0 -1
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/managers/InteractionManager.d.ts +2 -26
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +1 -3
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.d.ts +1 -4
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ScrollSyncManager.d.ts.map +1 -1
- package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +0 -1
- package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
- package/dist/node_modules/.pnpm/@types_unist@3.0.3/node_modules/@types/unist/index.d.ts.map +1 -1
- package/dist/react/CodeView.d.ts +9 -1
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +39 -33
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +2 -5
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/File.d.ts +1 -23
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +13 -12
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +1 -23
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +13 -12
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +1 -24
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +13 -12
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +1 -23
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +13 -12
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +1 -18
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js +15 -14
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/Virtualizer.d.ts +1 -9
- package/dist/react/Virtualizer.d.ts.map +1 -1
- package/dist/react/Virtualizer.js.map +1 -1
- package/dist/react/WorkerPoolContext.d.ts +2 -6
- package/dist/react/WorkerPoolContext.d.ts.map +1 -1
- package/dist/react/constants.d.ts +0 -1
- package/dist/react/constants.d.ts.map +1 -1
- package/dist/react/jsx.d.ts +1 -0
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +1 -1
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/assignRef.d.ts +6 -0
- package/dist/react/utils/assignRef.d.ts.map +1 -0
- package/dist/react/utils/assignRef.js +9 -0
- package/dist/react/utils/assignRef.js.map +1 -0
- package/dist/react/utils/renderDiffChildren.d.ts +1 -16
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +1 -13
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/templateRender.d.ts +0 -1
- package/dist/react/utils/templateRender.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +2 -18
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +31 -17
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +2 -16
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +8 -4
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useStableCallback.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -12
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +4 -9
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +28 -21
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +1 -0
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +3 -9
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/shiki-stream/stream.d.ts +0 -1
- package/dist/shiki-stream/stream.d.ts.map +1 -1
- package/dist/shiki-stream/stream.js.map +1 -1
- package/dist/shiki-stream/tokenizer.d.ts +0 -1
- package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/types.d.ts +0 -1
- package/dist/shiki-stream/types.d.ts.map +1 -1
- package/dist/sprite.d.ts.map +1 -1
- package/dist/ssr/FileDiffReact.d.ts +1 -8
- package/dist/ssr/FileDiffReact.d.ts.map +1 -1
- package/dist/ssr/FileDiffReact.js +8 -3
- package/dist/ssr/FileDiffReact.js.map +1 -1
- package/dist/ssr/preloadDiffs.d.ts +6 -34
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadFile.d.ts +1 -6
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts +1 -5
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/renderHTML.d.ts +0 -1
- package/dist/ssr/renderHTML.d.ts.map +1 -1
- package/dist/string-import.d.ts.map +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/annotationHelpers.d.ts +0 -1
- package/dist/utils/annotationHelpers.d.ts.map +1 -1
- package/dist/utils/appendItems.d.ts.map +1 -1
- package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -1
- package/dist/utils/areDiffLineAnnotationsEqual.d.ts +0 -1
- package/dist/utils/areDiffLineAnnotationsEqual.d.ts.map +1 -1
- package/dist/utils/areDiffRenderOptionsEqual.d.ts +0 -1
- package/dist/utils/areDiffRenderOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areDiffTargetsEqual.d.ts +0 -1
- package/dist/utils/areDiffTargetsEqual.d.ts.map +1 -1
- package/dist/utils/areFileRenderOptionsEqual.d.ts +0 -1
- package/dist/utils/areFileRenderOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areFileTargetsEqual.d.ts +0 -1
- package/dist/utils/areFileTargetsEqual.d.ts.map +1 -1
- package/dist/utils/areFilesEqual.d.ts +0 -1
- package/dist/utils/areFilesEqual.d.ts.map +1 -1
- package/dist/utils/areHunkDataEqual.d.ts +0 -1
- package/dist/utils/areHunkDataEqual.d.ts.map +1 -1
- package/dist/utils/areLineAnnotationsEqual.d.ts +0 -1
- package/dist/utils/areLineAnnotationsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts +0 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areMergeConflictActionsEqual.d.ts +0 -1
- package/dist/utils/areMergeConflictActionsEqual.d.ts.map +1 -1
- package/dist/utils/areObjectsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +1 -0
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/arePrePropertiesEqual.d.ts +0 -1
- package/dist/utils/arePrePropertiesEqual.d.ts.map +1 -1
- package/dist/utils/areRenderRangesEqual.d.ts +0 -1
- package/dist/utils/areRenderRangesEqual.d.ts.map +1 -1
- package/dist/utils/areSelectionPointsEqual.d.ts +0 -1
- package/dist/utils/areSelectionPointsEqual.d.ts.map +1 -1
- package/dist/utils/areSelectionsEqual.d.ts +0 -1
- package/dist/utils/areSelectionsEqual.d.ts.map +1 -1
- package/dist/utils/areThemesEqual.d.ts +0 -1
- package/dist/utils/areThemesEqual.d.ts.map +1 -1
- package/dist/utils/areVirtualWindowSpecsEqual.d.ts +0 -1
- package/dist/utils/areVirtualWindowSpecsEqual.d.ts.map +1 -1
- package/dist/utils/areWorkerStatsEqual.d.ts +1 -0
- package/dist/utils/areWorkerStatsEqual.d.ts.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -1
- package/dist/utils/cleanLastNewline.d.ts.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +0 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
- package/dist/utils/composeCacheKey.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts +1 -11
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeFileOffsets.d.ts.map +1 -1
- package/dist/utils/computeFileOffsets.js +9 -8
- package/dist/utils/computeFileOffsets.js.map +1 -1
- package/dist/utils/computeVirtualFileMetrics.d.ts +0 -1
- package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -1
- package/dist/utils/createAnnotationElement.d.ts +0 -1
- package/dist/utils/createAnnotationElement.d.ts.map +1 -1
- package/dist/utils/createAnnotationWrapperNode.d.ts.map +1 -1
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -1
- package/dist/utils/createContentColumn.d.ts +0 -1
- package/dist/utils/createContentColumn.d.ts.map +1 -1
- package/dist/utils/createEmptyRowBuffer.d.ts +0 -1
- package/dist/utils/createEmptyRowBuffer.d.ts.map +1 -1
- package/dist/utils/createFileHeaderElement.d.ts +1 -6
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createGutterUtilityContentNode.d.ts.map +1 -1
- package/dist/utils/createGutterUtilityElement.d.ts +0 -1
- package/dist/utils/createGutterUtilityElement.d.ts.map +1 -1
- package/dist/utils/createNoNewlineElement.d.ts +0 -1
- package/dist/utils/createNoNewlineElement.d.ts.map +1 -1
- package/dist/utils/createPreElement.d.ts +1 -11
- package/dist/utils/createPreElement.d.ts.map +1 -1
- package/dist/utils/createRowNodes.d.ts.map +1 -1
- package/dist/utils/createSeparator.d.ts +1 -10
- package/dist/utils/createSeparator.d.ts.map +1 -1
- package/dist/utils/createSeparator.js +12 -10
- package/dist/utils/createSeparator.js.map +1 -1
- package/dist/utils/createSpanNodeFromToken.d.ts +0 -1
- package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
- package/dist/utils/createSpanNodeFromToken.js +2 -1
- package/dist/utils/createSpanNodeFromToken.js.map +1 -1
- package/dist/utils/createStyleElement.d.ts +0 -1
- package/dist/utils/createStyleElement.d.ts.map +1 -1
- package/dist/utils/createTransformerWithState.d.ts +0 -1
- package/dist/utils/createTransformerWithState.d.ts.map +1 -1
- package/dist/utils/createUnsafeCSSStyleNode.d.ts.map +1 -1
- package/dist/utils/createWindowFromScrollPosition.d.ts +1 -9
- package/dist/utils/createWindowFromScrollPosition.d.ts.map +1 -1
- package/dist/utils/cssWrappers.d.ts +0 -1
- package/dist/utils/cssWrappers.d.ts.map +1 -1
- package/dist/utils/cssWrappers.js +5 -3
- package/dist/utils/cssWrappers.js.map +1 -1
- package/dist/utils/detachString.d.ts.map +1 -1
- package/dist/utils/diffAcceptRejectHunk.d.ts +0 -1
- package/dist/utils/diffAcceptRejectHunk.d.ts.map +1 -1
- package/dist/utils/editSessionAnnotations.d.ts +0 -1
- package/dist/utils/editSessionAnnotations.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.d.ts +0 -1
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/formatCSSVariablePrefix.d.ts.map +1 -1
- package/dist/utils/getDiffFileInput.d.ts +1 -5
- package/dist/utils/getDiffFileInput.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts +0 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts +0 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts +0 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/getHighlighterOptions.d.ts +1 -5
- package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
- package/dist/utils/getHighlighterOptions.js +1 -1
- package/dist/utils/getHighlighterOptions.js.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.d.ts +1 -6
- package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
- package/dist/utils/getHunkSeparatorSlotName.d.ts +0 -1
- package/dist/utils/getHunkSeparatorSlotName.d.ts.map +1 -1
- package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -1
- package/dist/utils/getIconForType.d.ts +0 -1
- package/dist/utils/getIconForType.d.ts.map +1 -1
- package/dist/utils/getLineAnnotationName.d.ts +0 -1
- package/dist/utils/getLineAnnotationName.d.ts.map +1 -1
- package/dist/utils/getLineEndingType.d.ts.map +1 -1
- package/dist/utils/getLineNodes.d.ts +0 -1
- package/dist/utils/getLineNodes.d.ts.map +1 -1
- package/dist/utils/getMergeConflictActionSlotName.d.ts +1 -5
- package/dist/utils/getMergeConflictActionSlotName.d.ts.map +1 -1
- package/dist/utils/getMergeConflictLineTypes.d.ts +0 -1
- package/dist/utils/getMergeConflictLineTypes.d.ts.map +1 -1
- package/dist/utils/getOrCreateCodeNode.d.ts +1 -7
- package/dist/utils/getOrCreateCodeNode.d.ts.map +1 -1
- package/dist/utils/getSingularPatch.d.ts +0 -1
- package/dist/utils/getSingularPatch.d.ts.map +1 -1
- package/dist/utils/getThemes.d.ts +0 -1
- package/dist/utils/getThemes.d.ts.map +1 -1
- package/dist/utils/getTotalLineCountFromHunks.d.ts +0 -1
- package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
- package/dist/utils/guardWebKitScrollDuringRebuild.d.ts.map +1 -1
- package/dist/utils/hast_utils.d.ts +2 -12
- package/dist/utils/hast_utils.d.ts.map +1 -1
- package/dist/utils/hostTheme.d.ts +1 -5
- package/dist/utils/hostTheme.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +0 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/includesFileAnnotations.d.ts +0 -1
- package/dist/utils/includesFileAnnotations.d.ts.map +1 -1
- package/dist/utils/isDefaultRenderRange.d.ts +0 -1
- package/dist/utils/isDefaultRenderRange.d.ts.map +1 -1
- package/dist/utils/isDiffPlainText.d.ts +0 -1
- package/dist/utils/isDiffPlainText.d.ts.map +1 -1
- package/dist/utils/isFilePlainText.d.ts +0 -1
- package/dist/utils/isFilePlainText.d.ts.map +1 -1
- package/dist/utils/isGutterUtilityPath.d.ts.map +1 -1
- package/dist/utils/isStyleNode.d.ts.map +1 -1
- package/dist/utils/isWorkerContext.d.ts.map +1 -1
- package/dist/utils/iterateOverDiff.d.ts +1 -10
- package/dist/utils/iterateOverDiff.d.ts.map +1 -1
- package/dist/utils/iterateOverDiff.js +5 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/lineAnnotationIdentity.d.ts +0 -1
- package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -1
- package/dist/utils/normalizeDiffResolution.d.ts +0 -1
- package/dist/utils/normalizeDiffResolution.d.ts.map +1 -1
- package/dist/utils/parseDiffDecorations.d.ts +2 -13
- package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +0 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +2 -1
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parseLineType.d.ts +0 -1
- package/dist/utils/parseLineType.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts +0 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +0 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +8 -5
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/utils/prefersReducedMotion.d.ts.map +1 -1
- package/dist/utils/prerenderHTMLIfNecessary.d.ts.map +1 -1
- package/dist/utils/processLine.d.ts +0 -1
- package/dist/utils/processLine.d.ts.map +1 -1
- package/dist/utils/realignChangeContent.d.ts +0 -1
- package/dist/utils/realignChangeContent.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts +1 -8
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts +1 -11
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/resolveConflict.d.ts +0 -1
- package/dist/utils/resolveConflict.d.ts.map +1 -1
- package/dist/utils/resolveRegion.d.ts +0 -1
- package/dist/utils/resolveRegion.d.ts.map +1 -1
- package/dist/utils/roundToDevicePixel.d.ts.map +1 -1
- package/dist/utils/scrollbarGutter.d.ts.map +1 -1
- package/dist/utils/scrollbarGutter.js +2 -1
- package/dist/utils/scrollbarGutter.js.map +1 -1
- package/dist/utils/setLanguageOverride.d.ts +0 -1
- package/dist/utils/setLanguageOverride.d.ts.map +1 -1
- package/dist/utils/setWrapperNodeProps.d.ts +1 -11
- package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
- package/dist/utils/setWrapperNodeProps.js +1 -3
- package/dist/utils/setWrapperNodeProps.js.map +1 -1
- package/dist/utils/shouldUseTokenTransformer.d.ts +0 -1
- package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
- package/dist/utils/splitFileContents.d.ts.map +1 -1
- package/dist/utils/trimPatchContext.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +0 -1
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.d.ts +10 -55
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/wrapTokenFragments.d.ts +0 -1
- package/dist/utils/wrapTokenFragments.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +2 -17
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +8 -5
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/getOrCreateWorkerPoolSingleton.d.ts +1 -5
- package/dist/worker/getOrCreateWorkerPoolSingleton.d.ts.map +1 -1
- package/dist/worker/types.d.ts +0 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.d.ts +1 -1
- package/dist/worker/worker-portable.js +113 -354
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.d.ts +1 -1
- package/dist/worker/worker.js +14 -11
- package/dist/worker/worker.js.map +1 -1
- package/package.json +4 -5
|
@@ -47,21 +47,13 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
47
47
|
return decision;
|
|
48
48
|
});
|
|
49
49
|
const onEditComplete = _onEditComplete != null ? handleOnEditComplete : void 0;
|
|
50
|
-
const effectiveFileDiff =
|
|
51
|
-
|
|
52
|
-
const { current: accepted } = acceptedCache;
|
|
53
|
-
const filePair = accepted?.filePair;
|
|
54
|
-
if (accepted != null && filePair != null) {
|
|
55
|
-
if (isSameFilePair(oldFile, newFile, filePair.stale) || isSameFilePair(oldFile, newFile, filePair.installed)) return filePair.fileDiff;
|
|
56
|
-
accepted.filePair = null;
|
|
57
|
-
}
|
|
58
|
-
return parseDiffFromFile(oldFile ?? null, newFile ?? null, options?.parseDiffOptions);
|
|
59
|
-
}, [
|
|
50
|
+
const effectiveFileDiff = useEffectiveFileDiff({
|
|
51
|
+
acceptedCache,
|
|
60
52
|
fileDiff,
|
|
61
|
-
oldFile,
|
|
62
53
|
newFile,
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
oldFile,
|
|
55
|
+
parseDiffOptions: options?.parseDiffOptions
|
|
56
|
+
});
|
|
65
57
|
const instanceRef = useRef(null);
|
|
66
58
|
const disposeEditorRef = useRef(null);
|
|
67
59
|
const getEditor = useStableCallback(() => {
|
|
@@ -137,6 +129,24 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
137
129
|
getAnnotationSlotName: useCallback((annotation) => instanceRef.current?.getAnnotationSlotName(annotation) ?? getLineAnnotationName(annotation), [])
|
|
138
130
|
};
|
|
139
131
|
}
|
|
132
|
+
function useEffectiveFileDiff({ acceptedCache, fileDiff, newFile, oldFile, parseDiffOptions }) {
|
|
133
|
+
return useMemo(() => {
|
|
134
|
+
if (fileDiff != null) return fileDiff;
|
|
135
|
+
const { current: accepted } = acceptedCache;
|
|
136
|
+
const filePair = accepted?.filePair;
|
|
137
|
+
if (accepted != null && filePair != null) {
|
|
138
|
+
if (isSameFilePair(oldFile, newFile, filePair.stale) || isSameFilePair(oldFile, newFile, filePair.installed)) return filePair.fileDiff;
|
|
139
|
+
accepted.filePair = null;
|
|
140
|
+
}
|
|
141
|
+
return parseDiffFromFile(oldFile ?? null, newFile ?? null, parseDiffOptions);
|
|
142
|
+
}, [
|
|
143
|
+
acceptedCache,
|
|
144
|
+
fileDiff,
|
|
145
|
+
oldFile,
|
|
146
|
+
newFile,
|
|
147
|
+
parseDiffOptions
|
|
148
|
+
]);
|
|
149
|
+
}
|
|
140
150
|
function isSameFilePair(oldFile, newFile, filePair) {
|
|
141
151
|
return areFileTargetsEqual(oldFile ?? void 0, filePair.oldFile ?? void 0) && areFileTargetsEqual(newFile ?? void 0, filePair.newFile ?? void 0);
|
|
142
152
|
}
|
|
@@ -148,11 +158,15 @@ function resolveAcceptedValues(fileDiff, lineAnnotations, acceptedCache) {
|
|
|
148
158
|
};
|
|
149
159
|
const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;
|
|
150
160
|
let resolvedFileDiff = fileDiff;
|
|
151
|
-
if (acceptedDiff != null)
|
|
152
|
-
|
|
161
|
+
if (acceptedDiff != null) {
|
|
162
|
+
if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) resolvedFileDiff = acceptedDiff.installed;
|
|
163
|
+
else accepted.fileDiff = null;
|
|
164
|
+
}
|
|
153
165
|
let resolvedAnnotations = lineAnnotations;
|
|
154
|
-
if (acceptedAnnotations != null)
|
|
155
|
-
|
|
166
|
+
if (acceptedAnnotations != null) {
|
|
167
|
+
if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
|
|
168
|
+
else accepted.annotations = null;
|
|
169
|
+
}
|
|
156
170
|
if (accepted.fileDiff == null && accepted.annotations == null && accepted.filePair == null) acceptedCache.current = null;
|
|
157
171
|
return {
|
|
158
172
|
fileDiff: resolvedFileDiff,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n // File-pair inputs parse here. While the file props still match the pair\n // from acceptance time (stale) or the completion event's files (installed),\n // the parse is the accepted diff itself; any other pair clears the record\n // and parses fresh.\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n options?.parseDiffOptions\n );\n }, [fileDiff, oldFile, newFile, options?.parseDiffOptions]);\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n return {\n fileDiff: effectiveFileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Render the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its slot — filePair settles in\n// the parse memo instead — and the ref clears once all three have.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n fileDiff: FileDiffMetadata;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { fileDiff, lineAnnotations };\n }\n const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;\n let resolvedFileDiff = fileDiff;\n if (acceptedDiff != null) {\n if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) {\n resolvedFileDiff = acceptedDiff.installed;\n } else {\n accepted.fileDiff = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return { fileDiff: resolvedFileDiff, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>):\n | FileDiffOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAiD9C,SAAgB,oBAAwC,EACtD,UACA,SACA,SACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIyB;CACzC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;CACzD,MAAM,qBAAqB,mBACxB,UACC,gBAAgB,KAAK,CACzB;CACA,MAAM,eAAe,iBAAiB,OAAO,qBAAqB,KAAA;CAKlE,MAAM,gBAAgB,OAA+C,IAAI;CACzE,MAAM,uBAAuB,mBAC1B,UAAyD;EACxD,MAAM,WAAW,kBAAkB,KAAK,KAAK;EAC7C,IAAI,aAAa,UACf,cAAc,UAAU;GACtB,UAAU;IACR,WAAW,MAAM;IACjB,OAAO,MAAM;GACf;GACA,UACE,YAAY,OACR;IACE,UAAU,MAAM;IAChB,WAAW;KAAE,SAAS,MAAM;KAAS,SAAS,MAAM;IAAQ;IAC5D,OAAO;KAAE,SAAS,WAAW;KAAM,SAAS,WAAW;IAAK;GAC9D,IACA;GACN,aAAa;IACX,WAAW,MAAM;IACjB,OAAO,MAAM;GACf;EACF;EAEF,OAAO;CACT,CACF;CACA,MAAM,iBACJ,mBAAmB,OAAO,uBAAuB,KAAA;CAKnD,MAAM,oBAAoB,cAAc;EACtC,IAAI,YAAY,MACd,OAAO;EAET,MAAM,EAAE,SAAS,aAAa;EAC9B,MAAM,WAAW,UAAU;EAC3B,IAAI,YAAY,QAAQ,YAAY,MAAM;GACxC,IACE,eAAe,SAAS,SAAS,SAAS,KAAK,KAC/C,eAAe,SAAS,SAAS,SAAS,SAAS,GAEnD,OAAO,SAAS;GAElB,SAA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AAkB,iBAAiB;CAAoB;AAC5E;AAWA,SAAS,qBAAyC,EAChD,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n // File-pair inputs parse here. While the file props still match the pair\n // from acceptance time (stale) or the completion event's files (installed),\n // the parse is the accepted diff itself; any other pair clears the record\n // and parses fresh.\n const effectiveFileDiff = useEffectiveFileDiff({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions: options?.parseDiffOptions,\n });\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n return {\n fileDiff: effectiveFileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\ninterface UseEffectiveFileDiffProps<LAnnotation, Caret> {\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>;\n fileDiff: FileDiffMetadata | undefined;\n newFile: FileContents | null | undefined;\n oldFile: FileContents | null | undefined;\n parseDiffOptions: FileDiffOptions<LAnnotation, Caret>['parseDiffOptions'];\n}\n\n// Resolves the diff the instance renders: the `fileDiff` prop when given;\n// otherwise the accepted edit's cached diff while the file props still name the\n// pair it was accepted against; otherwise a fresh parse of the file props. A\n// cached pair that no longer matches is dropped on the way. Kept in its own hook\n// because the render-time ref read and write are deliberate; the boundary lets\n// the calling hook stay compilable.\nfunction useEffectiveFileDiff<LAnnotation, Caret>({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions,\n}: UseEffectiveFileDiffProps<LAnnotation, Caret>): FileDiffMetadata {\n /* oxlint-disable react/immutability react/refs -- accepted edit output must\n * replace stale file-pair props during render */\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n parseDiffOptions\n );\n }, [acceptedCache, fileDiff, oldFile, newFile, parseDiffOptions]);\n /* oxlint-enable react/immutability react/refs */\n\n return effectiveFileDiff;\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Render the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its slot — filePair settles in\n// the parse memo instead — and the ref clears once all three have.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n fileDiff: FileDiffMetadata;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { fileDiff, lineAnnotations };\n }\n const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;\n let resolvedFileDiff = fileDiff;\n if (acceptedDiff != null) {\n if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) {\n resolvedFileDiff = acceptedDiff.installed;\n } else {\n accepted.fileDiff = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return { fileDiff: resolvedFileDiff, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>):\n | FileDiffOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAiD9C,SAAgB,oBAAwC,EACtD,UACA,SACA,SACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIyB;CACzC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;CACzD,MAAM,qBAAqB,mBACxB,UACC,gBAAgB,KAAK,CACzB;CACA,MAAM,eAAe,iBAA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UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
|
|
@@ -2,6 +2,7 @@ import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } f
|
|
|
2
2
|
import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
|
|
3
3
|
import { FileEditChangeHandler, FileEditCompleteHandler, FileOptions } from "../../components/File.js";
|
|
4
4
|
import { EditorOptions } from "../../editor/editor.js";
|
|
5
|
+
import "../../edit/index.js";
|
|
5
6
|
//#region src/react/utils/useFileInstance.d.ts
|
|
6
7
|
interface UseFileInstanceProps<LAnnotation, Caret> {
|
|
7
8
|
file: FileContents;
|
|
@@ -24,22 +25,7 @@ interface UseFileInstanceReturn<LAnnotation> {
|
|
|
24
25
|
getHoveredLine(): GetHoveredLineResult<'file'> | undefined;
|
|
25
26
|
getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;
|
|
26
27
|
}
|
|
27
|
-
declare function useFileInstance<LAnnotation, Caret>({
|
|
28
|
-
file,
|
|
29
|
-
options,
|
|
30
|
-
editorOptions,
|
|
31
|
-
editStateKey,
|
|
32
|
-
lineAnnotations,
|
|
33
|
-
selectedLines,
|
|
34
|
-
prerenderedHTML,
|
|
35
|
-
metrics,
|
|
36
|
-
hasGutterRenderUtility,
|
|
37
|
-
hasCustomHeader,
|
|
38
|
-
disableWorkerPool,
|
|
39
|
-
edit,
|
|
40
|
-
onEditChange: _onEditChange,
|
|
41
|
-
onEditComplete: _onEditComplete
|
|
42
|
-
}: UseFileInstanceProps<LAnnotation, Caret>): UseFileInstanceReturn<LAnnotation>;
|
|
28
|
+
declare function useFileInstance<LAnnotation, Caret>({ file, options, editorOptions, editStateKey, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit, onEditChange: _onEditChange, onEditComplete: _onEditComplete }: UseFileInstanceProps<LAnnotation, Caret>): UseFileInstanceReturn<LAnnotation>;
|
|
43
29
|
//#endregion
|
|
44
30
|
export { useFileInstance };
|
|
45
31
|
//# sourceMappingURL=useFileInstance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;;UAgDU,qBAAqB,aAAa;EAC1C,MAAM;EACN,SAAS,YAAY,aAAa;EAClC,eAAe,sBAAsB,aAAa;EAClD;EACA,iBAAiB,eAAe;EAChC,eAAe;EACf;EACA,UAAU;EACV;EACA;EACA;EACA;EACA,eAAe,sBAAsB,aAAa;EAClD,iBAAiB,wBAAwB,aAAa;;UAG9C,sBAAsB;EAC9B,IAAI,MAAM;EACV,kBAAkB;EAClB,sBAAsB,YAAY,eAAe;;iBAGnC,gBAAgB,aAAa,SAC3C,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBACf,qBACD,aACA,SACE,sBAAsB"}
|
|
@@ -116,11 +116,15 @@ function resolveAcceptedValues(file, lineAnnotations, acceptedCache) {
|
|
|
116
116
|
};
|
|
117
117
|
const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;
|
|
118
118
|
let resolvedFile = file;
|
|
119
|
-
if (acceptedFiles != null)
|
|
120
|
-
|
|
119
|
+
if (acceptedFiles != null) {
|
|
120
|
+
if (areFileTargetsEqual(file, acceptedFiles.stale)) resolvedFile = acceptedFiles.installed;
|
|
121
|
+
else accepted.file = null;
|
|
122
|
+
}
|
|
121
123
|
let resolvedAnnotations = lineAnnotations;
|
|
122
|
-
if (acceptedAnnotations != null)
|
|
123
|
-
|
|
124
|
+
if (acceptedAnnotations != null) {
|
|
125
|
+
if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
|
|
126
|
+
else accepted.annotations = null;
|
|
127
|
+
}
|
|
124
128
|
if (accepted.file == null && accepted.annotations == null) acceptedCache.current = null;
|
|
125
129
|
return {
|
|
126
130
|
file: resolvedFile,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport {\n File,\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n type FileOptions,\n} from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedCompletion<LAnnotation> {\n file: {\n installed: FileContents;\n stale: FileContents;\n } | null;\n annotations: {\n installed: LineAnnotation<LAnnotation>[] | undefined;\n stale: LineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileInstanceProps<LAnnotation, Caret> {\n file: FileContents;\n options: FileOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileInstanceReturn<LAnnotation> {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileInstance<LAnnotation, Caret>({\n file,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileInstanceProps<\n LAnnotation,\n Caret\n>): UseFileInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its file on the instance immediately,\n // but the file/lineAnnotations props stay pre-edit until the owner's state\n // update lands. This holds the accepted values so the renders in between do\n // not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n file: { installed: event.file, stale: event.originalFile },\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n const instanceRef = useRef<\n File<LAnnotation, Caret> | VirtualizedFile<LAnnotation, Caret> | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('File: EditContext is not attached');\n }\n return createEditor('file', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n file,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n file: resolved.file,\n lineAnnotations: resolved.lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: LineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n return { ref, getHoveredLine, getAnnotationSlotName };\n}\n\n// Return the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its half, and the ref clears once\n// both halves have.\nfunction resolveAcceptedValues<LAnnotation>(\n file: FileContents,\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n file: FileContents;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { file, lineAnnotations };\n }\n const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;\n let resolvedFile = file;\n if (acceptedFiles != null) {\n if (areFileTargetsEqual(file, acceptedFiles.stale)) {\n resolvedFile = acceptedFiles.installed;\n } else {\n accepted.file = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (accepted.file == null && accepted.annotations == null) {\n acceptedCache.current = null;\n }\n return { file: resolvedFile, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileOptionsProps<LAnnotation, Caret> {\n options: FileOptions<LAnnotation, Caret> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n onEditChange: FileEditChangeHandler<LAnnotation, Caret> | undefined;\n onEditComplete: FileEditCompleteHandler<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileOptionsProps<LAnnotation, Caret>):\n | FileOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: File<LAnnotation, Caret>,\n getEditor: () => Editor<'file', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAoC9C,SAAgB,gBAAoC,EAClD,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIqB;CACrC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;CACzD,MAAM,qBAAqB,mBACxB,UACC,gBAAgB,KAAK,CACzB;CACA,MAAM,eAAe,iBAAiB,OAAO,qBAAqB,KAAA;CAKlE,MAAM,gBAAgB,OAA+C,IAAI;C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CAAoB;AACpE;AAWA,SAAS,iBAAqC,EAC5C,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport {\n File,\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n type FileOptions,\n} from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedCompletion<LAnnotation> {\n file: {\n installed: FileContents;\n stale: FileContents;\n } | null;\n annotations: {\n installed: LineAnnotation<LAnnotation>[] | undefined;\n stale: LineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileInstanceProps<LAnnotation, Caret> {\n file: FileContents;\n options: FileOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileInstanceReturn<LAnnotation> {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileInstance<LAnnotation, Caret>({\n file,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileInstanceProps<\n LAnnotation,\n Caret\n>): UseFileInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its file on the instance immediately,\n // but the file/lineAnnotations props stay pre-edit until the owner's state\n // update lands. This holds the accepted values so the renders in between do\n // not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n file: { installed: event.file, stale: event.originalFile },\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n const instanceRef = useRef<\n File<LAnnotation, Caret> | VirtualizedFile<LAnnotation, Caret> | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('File: EditContext is not attached');\n }\n return createEditor('file', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n file,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n file: resolved.file,\n lineAnnotations: resolved.lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: LineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n return { ref, getHoveredLine, getAnnotationSlotName };\n}\n\n// Return the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its half, and the ref clears once\n// both halves have.\nfunction resolveAcceptedValues<LAnnotation>(\n file: FileContents,\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n file: FileContents;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { file, lineAnnotations };\n }\n const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;\n let resolvedFile = file;\n if (acceptedFiles != null) {\n if (areFileTargetsEqual(file, acceptedFiles.stale)) {\n resolvedFile = acceptedFiles.installed;\n } else {\n accepted.file = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (accepted.file == null && accepted.annotations == null) {\n acceptedCache.current = null;\n }\n return { file: resolvedFile, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileOptionsProps<LAnnotation, Caret> {\n options: FileOptions<LAnnotation, Caret> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n onEditChange: FileEditChangeHandler<LAnnotation, Caret> | undefined;\n onEditComplete: FileEditCompleteHandler<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileOptionsProps<LAnnotation, Caret>):\n | FileOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: File<LAnnotation, Caret>,\n getEditor: () => Editor<'file', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAoC9C,SAAgB,gBAAoC,EAClD,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIqB;CACrC,MAAM,oBA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e,cAAc;OAE7B,SAAS,OAAO;CAEpB;CACA,IAAI,sBAAsB;CAC1B,IAAI,uBAAuB,MAAM;EAC/B,IAAI,oBAAoB,oBAAoB,OAC1C,sBAAsB,oBAAoB;OAE1C,SAAS,cAAc;CAE3B;CACA,IAAI,SAAS,QAAQ,QAAQ,SAAS,eAAe,MACnD,cAAc,UAAU;CAE1B,OAAO;EAAE,MAAM;EAAc,iBAAiB;CAAoB;AACpE;AAWA,SAAS,iBAAqC,EAC5C,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableCallback.d.ts","names":[],"sources":["../../../src/react/utils/useStableCallback.ts"],"mappings":";iBAGgB,
|
|
1
|
+
{"version":3,"file":"useStableCallback.d.ts","names":[],"sources":["../../../src/react/utils/useStableCallback.ts"],"mappings":";iBAGgB,kBAAkB,cAAc,qBAC9C,UAAU,IACT"}
|
|
@@ -3,7 +3,6 @@ import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
|
|
|
3
3
|
import { MergeConflictDiffAction } from "../../utils/parseMergeConflictDiffFromFile.js";
|
|
4
4
|
import { UnresolvedFile } from "../../components/UnresolvedFile.js";
|
|
5
5
|
import { UnresolvedFileReactOptions } from "../UnresolvedFile.js";
|
|
6
|
-
|
|
7
6
|
//#region src/react/utils/useUnresolvedFileInstance.d.ts
|
|
8
7
|
interface UseUnresolvedFileInstanceProps<LAnnotation> {
|
|
9
8
|
file: FileContents;
|
|
@@ -24,17 +23,7 @@ interface UseUnresolvedFileInstanceReturn<LAnnotation> {
|
|
|
24
23
|
getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;
|
|
25
24
|
getInstance(): UnresolvedFile<LAnnotation> | undefined;
|
|
26
25
|
}
|
|
27
|
-
declare function useUnresolvedFileInstance<LAnnotation>({
|
|
28
|
-
file,
|
|
29
|
-
options,
|
|
30
|
-
lineAnnotations,
|
|
31
|
-
selectedLines,
|
|
32
|
-
prerenderedHTML,
|
|
33
|
-
hasConflictUtility,
|
|
34
|
-
hasGutterRenderUtility,
|
|
35
|
-
hasCustomHeader,
|
|
36
|
-
disableWorkerPool
|
|
37
|
-
}: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;
|
|
26
|
+
declare function useUnresolvedFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, hasConflictUtility, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;
|
|
38
27
|
//#endregion
|
|
39
28
|
export { useUnresolvedFileInstance };
|
|
40
29
|
//# sourceMappingURL=useUnresolvedFileInstance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnresolvedFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnresolvedFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"mappings":";;;;;;UAoCU,+BAA+B;EACvC,MAAM;EACN,UAAU,2BAA2B;EACrC,iBAAiB,mBAAmB;EACpC,eAAe;EACf;EACA;EACA;EACA;EACA;;UAGQ,gCAAgC;EACxC,UAAU;EACV,UAAU;EACV,YAAY;EACZ,IAAI,MAAM;EACV,kBAAkB;EAClB,eAAe,eAAe;;iBAGhB,0BAA0B,eACxC,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBACC,+BAA+B,eAAe,gCAAgC"}
|
|
@@ -2,8 +2,8 @@ import { Element, ElementContent, Properties } from "../node_modules/.pnpm/@type
|
|
|
2
2
|
import { BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HighlightedToken, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
|
|
3
3
|
import { TextDocument } from "../editor/textDocument.js";
|
|
4
4
|
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
|
|
5
|
+
import "../worker/index.js";
|
|
5
6
|
import { DiffLineMetadata } from "../utils/iterateOverDiff.js";
|
|
6
|
-
|
|
7
7
|
//#region src/renderers/DiffHunksRenderer.d.ts
|
|
8
8
|
interface DiffHunksRendererOptions extends BaseDiffOptions {
|
|
9
9
|
headerRenderMode?: FileHeaderRenderMode;
|
|
@@ -82,7 +82,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
82
82
|
private expandedHunks;
|
|
83
83
|
private deletionAnnotations;
|
|
84
84
|
private additionAnnotations;
|
|
85
|
-
private
|
|
85
|
+
private computedLangs;
|
|
86
86
|
private renderCache;
|
|
87
87
|
private pendingHighlightResult;
|
|
88
88
|
private pendingStructuralRows;
|
|
@@ -139,13 +139,8 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
139
139
|
private applySessionDocumentChange;
|
|
140
140
|
private applyRecomputePreservingSessionType;
|
|
141
141
|
private markEditSessionPass;
|
|
142
|
-
protected getUnifiedLineDecoration({
|
|
143
|
-
|
|
144
|
-
}: UnifiedLineDecorationProps): LineDecoration;
|
|
145
|
-
protected getSplitLineDecoration({
|
|
146
|
-
side,
|
|
147
|
-
type
|
|
148
|
-
}: SplitLineDecorationProps): LineDecoration;
|
|
142
|
+
protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;
|
|
143
|
+
protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;
|
|
149
144
|
private createAnnotationElement;
|
|
150
145
|
protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;
|
|
151
146
|
protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;;UAoJiB,
|
|
1
|
+
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;;UAoJiB,iCAAiC;EAChD,mBAAmB;;UAGJ,6CAA6C,KAC5D;EAGA,kBAAkB;;UAGH;EACf;EACA,UAAU;EACV;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;;UAUL;EACf;EACA;EACA;EACA;EACA;EACA,eAAe;EACf,eAAe;;UAGA;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,UAAU;;UAGK;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,SAAS;EACT,QAAQ;;UAGO;EACf,UAAU;EACV,kBAAkB;EAClB,mBAAmB;EACnB,oBAAoB;EACpB,qBAAqB;EACrB,oBAAoB;EACpB,qBAAqB;EACrB,UAAU;EACV;EACA,SAAS;EACT,eAAe;EACf;EACA;EACA;EACA;EACA;EACA;;cAKW,kBAAkB;EAgCpB,SAAS;UACR;UAGA;UACA;WApCD;UAED;UAIA;UAEA;UAEA;UACA;UAEA;UACA;UAGA;UAGA;UAQA;EAER,YACS,UAAS,0BACR,sBACN,YAAY,mBAAmB,yBAEzB,8CACA,gBAAgB;EASnB;EAOA;;;;;;;;;;EAmBA,iBACL,MAAM,kBACN,eAAe;;EAgEV;;;;EAQA;;;;;;;;;;EAiBA,4BAA4B;UAqC3B;MA4BG,aAAa;EAIjB;EAMA,WAAW,SAAS;EAIpB,aAAa,SAAS,QAAQ;EAI9B,WACL,eACA,WAAW,qBACX;EA0BK,gBAAgB,oBAAoB;EAIpC,uBAAuB,YAAY;;EAKnC,oBACL,eAAe,YAAY;EAKtB,mBACL,iBAAiB,mBAAmB;;;;;;;EAyB/B,kBACL,YAAY,YAAY,MAAM,oBAC9B,6BACA;UA+HM;EAUD,oBACL,cAAc,0BAA0B;UA8DlC;UAeA;UAaA;YAOE,2BACR,YACC,6BAA6B;YAStB,yBACR,MACA,QACC,2BAA2B;UAetB;YAKU,iCAChB,KAAK,wBACF;YAGa,+BAChB,KAAK,wBACF;YAEK,0BAA0B;EAiDvB,yBAAyB,QAAQ;EAYvC,QAAQ,MAAM;UAmCb;EAQD,2BAA2B,KAChC;UAeM;;;;;;EA2CD,qBAAqB,MAAM,mBAAmB;UAwB7C;EAiCD,WACL,OAAM,8BACN,cAAa,cACZ;EAiJU,YACX,MAAM,kBACN,cAAa,cACZ,QAAQ;YAMD,iBACR,gBACA,oBACA,mBAAmB,sBAClB;UAeW;UAuBN;EA2CD,mBACL,MAAM,kBACN,QAAQ,kBACR,SAAS,mBACT;UAQM;UAqCA;UAgBA;UAuBA;EAaD,iBAAiB;UAIhB;UAIA;EAgjBD,cACL,6CACA,QAAQ,oBACP;EAyBI,cACL,QAAQ,mBACR,WAAU,mBACT;EAkDI,eACL,QAAQ,mBACR,eAAc;EAKT,kBACL,UAAU,kBACV;UAqBM;UAiEA;UA+DA;UASA"}
|
|
@@ -42,7 +42,7 @@ var DiffHunksRenderer = class {
|
|
|
42
42
|
expandedHunks = /* @__PURE__ */ new Map();
|
|
43
43
|
deletionAnnotations = {};
|
|
44
44
|
additionAnnotations = {};
|
|
45
|
-
|
|
45
|
+
computedLangs = ["text"];
|
|
46
46
|
renderCache;
|
|
47
47
|
pendingHighlightResult;
|
|
48
48
|
pendingStructuralRows;
|
|
@@ -279,18 +279,21 @@ var DiffHunksRenderer = class {
|
|
|
279
279
|
else hastLines[line] = row;
|
|
280
280
|
}
|
|
281
281
|
let regionsChanged = false;
|
|
282
|
-
if (changedAdditionLines.length > 0)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
282
|
+
if (changedAdditionLines.length > 0) {
|
|
283
|
+
if (this.editSessionActive) {
|
|
284
|
+
if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
285
|
+
this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
286
|
+
regionsChanged = true;
|
|
287
|
+
} else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
|
|
288
|
+
this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
|
|
289
|
+
regionsChanged = true;
|
|
290
|
+
} else {
|
|
291
|
+
const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
|
|
292
|
+
this.applyExpansionRemap(change);
|
|
293
|
+
regionsChanged = change != null;
|
|
294
|
+
}
|
|
295
|
+
} else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
292
296
|
}
|
|
293
|
-
else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
|
|
294
297
|
result.baseThemeType = themeType;
|
|
295
298
|
renderCache.isDirty = true;
|
|
296
299
|
return regionsChanged;
|
|
@@ -380,7 +383,7 @@ var DiffHunksRenderer = class {
|
|
|
380
383
|
};
|
|
381
384
|
}
|
|
382
385
|
async initializeHighlighter() {
|
|
383
|
-
this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.
|
|
386
|
+
this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLangs, {
|
|
384
387
|
theme: this.getLocalHighlightTheme(),
|
|
385
388
|
preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
|
|
386
389
|
}));
|
|
@@ -404,7 +407,7 @@ var DiffHunksRenderer = class {
|
|
|
404
407
|
if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
|
|
405
408
|
if (this.renderCache.result == null && !massiveDiff) this.workerManager.highlightDiffAST(this, this.diff);
|
|
406
409
|
} else if (this.highlighter == null) {
|
|
407
|
-
this.
|
|
410
|
+
this.computedLangs = getDiffLanguages(diff);
|
|
408
411
|
this.initializeHighlighter();
|
|
409
412
|
}
|
|
410
413
|
}
|
|
@@ -514,10 +517,10 @@ var DiffHunksRenderer = class {
|
|
|
514
517
|
}
|
|
515
518
|
if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) this.workerManager.highlightDiffAST(this, diff);
|
|
516
519
|
} else {
|
|
517
|
-
this.
|
|
520
|
+
this.computedLangs = getDiffLanguages(diff);
|
|
518
521
|
this.highlighter ??= getHighlighterIfLoaded();
|
|
519
522
|
const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
|
|
520
|
-
const hasLangs = this.highlighter != null && areLanguagesAttached(this.
|
|
523
|
+
const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLangs);
|
|
521
524
|
const canHighlight = !forcePlainText && hasLangs;
|
|
522
525
|
if (canRenderDiff && this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
|
|
523
526
|
const { result, options } = this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText || !hasLangs);
|
|
@@ -555,9 +558,9 @@ var DiffHunksRenderer = class {
|
|
|
555
558
|
}
|
|
556
559
|
async asyncHighlight(diff) {
|
|
557
560
|
const forcePlainText = isDiffMassive(diff, this.getTokenizeMaxLength());
|
|
558
|
-
this.
|
|
561
|
+
this.computedLangs = forcePlainText ? ["text"] : getDiffLanguages(diff);
|
|
559
562
|
const hasThemes = this.highlighter != null && areThemesAttached(this.getLocalHighlightTheme());
|
|
560
|
-
const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.
|
|
563
|
+
const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLangs);
|
|
561
564
|
if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
|
|
562
565
|
return this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText);
|
|
563
566
|
}
|
|
@@ -666,9 +669,7 @@ var DiffHunksRenderer = class {
|
|
|
666
669
|
case "deletions":
|
|
667
670
|
context.deletionsGutterAST.children.push(element);
|
|
668
671
|
break;
|
|
669
|
-
case "additions":
|
|
670
|
-
context.additionsGutterAST.children.push(element);
|
|
671
|
-
break;
|
|
672
|
+
case "additions": context.additionsGutterAST.children.push(element);
|
|
672
673
|
}
|
|
673
674
|
}
|
|
674
675
|
};
|
|
@@ -1250,6 +1251,12 @@ function getEditorDocumentLines(textDocument) {
|
|
|
1250
1251
|
for (let line = 0; line < textDocument.lineCount; line++) lines.push(textDocument.getLineText(line, true));
|
|
1251
1252
|
return lines;
|
|
1252
1253
|
}
|
|
1254
|
+
function getDiffLanguages(diff) {
|
|
1255
|
+
if (diff.lang != null) return [diff.lang];
|
|
1256
|
+
const deletionLang = getFiletypeFromFileName(diff.prevName ?? diff.name);
|
|
1257
|
+
const additionLang = getFiletypeFromFileName(diff.name);
|
|
1258
|
+
return deletionLang === additionLang ? [additionLang] : [deletionLang, additionLang];
|
|
1259
|
+
}
|
|
1253
1260
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
1254
1261
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
1255
1262
|
}
|