@pierre/diffs 1.2.0-beta.5 → 1.2.0-beta.6
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 +3 -0
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +40 -1
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +1 -0
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +19 -6
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +6 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +75 -35
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.d.ts +7 -2
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.js +52 -16
- package/dist/managers/ResizeManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +1 -0
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +9 -0
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/constants.d.ts.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/computeVirtualFileMetrics.d.ts +11 -0
- package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -0
- package/dist/utils/{resolveVirtualFileMetrics.js → computeVirtualFileMetrics.js} +7 -10
- package/dist/utils/computeVirtualFileMetrics.js.map +1 -0
- package/dist/utils/detachString.d.ts +5 -0
- package/dist/utils/detachString.d.ts.map +1 -0
- package/dist/utils/detachString.js +19 -0
- package/dist/utils/detachString.js.map +1 -0
- package/dist/utils/parsePatchFiles.js +163 -56
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/worker/worker-portable.js +0 -1
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +0 -1
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/utils/resolveVirtualFileMetrics.d.ts +0 -10
- package/dist/utils/resolveVirtualFileMetrics.d.ts.map +0 -1
- package/dist/utils/resolveVirtualFileMetrics.js.map +0 -1
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["DIFFS_DEVELOPMENT_BUILD: boolean","COMMIT_METADATA_SPLIT: RegExp","GIT_DIFF_FILE_BREAK_REGEX: RegExp","UNIFIED_DIFF_FILE_BREAK_REGEX: RegExp","FILE_CONTEXT_BLOB: RegExp","HUNK_HEADER: RegExp","SPLIT_WITH_NEWLINES: RegExp","FILENAME_HEADER_REGEX: RegExp","FILENAME_HEADER_REGEX_GIT: RegExp","ALTERNATE_FILE_NAMES_GIT: RegExp","INDEX_LINE_METADATA: RegExp","MERGE_CONFLICT_START_MARKER_REGEX: RegExp","MERGE_CONFLICT_BASE_MARKER_REGEX: RegExp","MERGE_CONFLICT_SEPARATOR_MARKER_REGEX: RegExp","MERGE_CONFLICT_END_MARKER_REGEX: RegExp","DEFAULT_THEMES: ThemesType","DEFAULT_VIRTUAL_FILE_METRICS: VirtualFileMetrics","DEFAULT_CODE_VIEW_FILE_METRICS: VirtualFileMetrics","DEFAULT_CODE_VIEW_LAYOUT: CodeViewLayout","DEFAULT_SMOOTH_SCROLL_SETTINGS: SmoothScrollSettings","DEFAULT_EXPANDED_REGION: HunkExpansionRegion","DEFAULT_RENDER_RANGE: RenderRange","EMPTY_RENDER_RANGE: RenderRange"],"sources":["../src/constants.ts"],"sourcesContent":["import type {\n CodeViewLayout,\n HunkExpansionRegion,\n RenderRange,\n SmoothScrollSettings,\n ThemesType,\n VirtualFileMetrics,\n} from './types';\n\nexport const DIFFS_TAG_NAME = 'diffs-container' as const;\n\n// Keep this as a NODE_ENV read so app builds can hard-disable development-only\n// checks unless they are explicitly built for development.\nexport const DIFFS_DEVELOPMENT_BUILD: boolean = (() => {\n try {\n return process.env.NODE_ENV === 'development';\n } catch {\n return false;\n }\n})();\n\n// Misc patch/content parsing regexes\nexport const COMMIT_METADATA_SPLIT: RegExp = /(?=^From [a-f0-9]+ .+$)/m;\nexport const GIT_DIFF_FILE_BREAK_REGEX: RegExp = /(?=^diff --git)/gm;\nexport const UNIFIED_DIFF_FILE_BREAK_REGEX: RegExp = /(?=^---\\s+\\S)/gm;\nexport const FILE_CONTEXT_BLOB: RegExp = /(?=^@@ )/gm;\nexport const HUNK_HEADER: RegExp =\n /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(?: (.*))?/m;\nexport const SPLIT_WITH_NEWLINES: RegExp = /(?<=\\n)/;\nexport const FILENAME_HEADER_REGEX: RegExp = /^(---|\\+\\+\\+)\\s+([^\\t\\r\\n]+)/;\nexport const FILENAME_HEADER_REGEX_GIT: RegExp =\n /^(---|\\+\\+\\+)\\s+[ab]\\/([^\\t\\r\\n]+)/;\nexport const ALTERNATE_FILE_NAMES_GIT: RegExp =\n /^diff --git (?:\"a\\/(.+?)\"|a\\/(.+?)) (?:\"b\\/(.+?)\"|b\\/(.+?))$/;\nexport const INDEX_LINE_METADATA: RegExp =\n /^index ([0-9a-f]+)\\.\\.([0-9a-f]+)(?: (\\d+))?$/i;\n\nexport const MERGE_CONFLICT_START_MARKER_REGEX: RegExp = /^<{7,}(?:\\s.*)?$/;\nexport const MERGE_CONFLICT_BASE_MARKER_REGEX: RegExp = /^\\|{7,}(?:\\s.*)?$/;\nexport const MERGE_CONFLICT_SEPARATOR_MARKER_REGEX: RegExp = /^={7,}$/;\nexport const MERGE_CONFLICT_END_MARKER_REGEX: RegExp = /^>{7,}(?:\\s.*)?$/;\n\nexport const HEADER_PREFIX_SLOT_ID = 'header-prefix';\nexport const HEADER_METADATA_SLOT_ID = 'header-metadata';\nexport const CUSTOM_HEADER_SLOT_ID = 'header-custom';\n\nexport const DEFAULT_THEMES: ThemesType = {\n dark: 'pierre-dark',\n light: 'pierre-light',\n};\n\nexport const THEME_CSS_ATTRIBUTE = 'data-theme-css';\nexport const UNSAFE_CSS_ATTRIBUTE = 'data-unsafe-css';\nexport const CORE_CSS_ATTRIBUTE = 'data-core-css';\nexport const DIFFS_SCROLLBAR_MEASURE_ATTRIBUTE = 'data-diffs-scrollbar-measure';\nexport const DIFFS_SCROLLBAR_GUTTER_MEASURED_PROPERTY =\n '--diffs-scrollbar-gutter-measured';\n\nexport const DEFAULT_COLLAPSED_CONTEXT_THRESHOLD = 1;\nexport const DEFAULT_TOKENIZE_MAX_LENGTH = 100_000;\nexport const DEFAULT_VIRTUAL_FILE_METRICS: VirtualFileMetrics = {\n hunkLineCount: 50,\n lineHeight: 20,\n diffHeaderHeight: 44,\n
|
|
1
|
+
{"version":3,"file":"constants.js","names":["DIFFS_DEVELOPMENT_BUILD: boolean","COMMIT_METADATA_SPLIT: RegExp","GIT_DIFF_FILE_BREAK_REGEX: RegExp","UNIFIED_DIFF_FILE_BREAK_REGEX: RegExp","FILE_CONTEXT_BLOB: RegExp","HUNK_HEADER: RegExp","SPLIT_WITH_NEWLINES: RegExp","FILENAME_HEADER_REGEX: RegExp","FILENAME_HEADER_REGEX_GIT: RegExp","ALTERNATE_FILE_NAMES_GIT: RegExp","INDEX_LINE_METADATA: RegExp","MERGE_CONFLICT_START_MARKER_REGEX: RegExp","MERGE_CONFLICT_BASE_MARKER_REGEX: RegExp","MERGE_CONFLICT_SEPARATOR_MARKER_REGEX: RegExp","MERGE_CONFLICT_END_MARKER_REGEX: RegExp","DEFAULT_THEMES: ThemesType","DEFAULT_VIRTUAL_FILE_METRICS: VirtualFileMetrics","DEFAULT_CODE_VIEW_FILE_METRICS: VirtualFileMetrics","DEFAULT_CODE_VIEW_LAYOUT: CodeViewLayout","DEFAULT_SMOOTH_SCROLL_SETTINGS: SmoothScrollSettings","DEFAULT_EXPANDED_REGION: HunkExpansionRegion","DEFAULT_RENDER_RANGE: RenderRange","EMPTY_RENDER_RANGE: RenderRange"],"sources":["../src/constants.ts"],"sourcesContent":["import type {\n CodeViewLayout,\n HunkExpansionRegion,\n RenderRange,\n SmoothScrollSettings,\n ThemesType,\n VirtualFileMetrics,\n} from './types';\n\nexport const DIFFS_TAG_NAME = 'diffs-container' as const;\n\n// Keep this as a NODE_ENV read so app builds can hard-disable development-only\n// checks unless they are explicitly built for development.\nexport const DIFFS_DEVELOPMENT_BUILD: boolean = (() => {\n try {\n return process.env.NODE_ENV === 'development';\n } catch {\n return false;\n }\n})();\n\n// Misc patch/content parsing regexes\nexport const COMMIT_METADATA_SPLIT: RegExp = /(?=^From [a-f0-9]+ .+$)/m;\nexport const GIT_DIFF_FILE_BREAK_REGEX: RegExp = /(?=^diff --git)/gm;\nexport const UNIFIED_DIFF_FILE_BREAK_REGEX: RegExp = /(?=^---\\s+\\S)/gm;\nexport const FILE_CONTEXT_BLOB: RegExp = /(?=^@@ )/gm;\nexport const HUNK_HEADER: RegExp =\n /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@(?: (.*))?/m;\nexport const SPLIT_WITH_NEWLINES: RegExp = /(?<=\\n)/;\nexport const FILENAME_HEADER_REGEX: RegExp = /^(---|\\+\\+\\+)\\s+([^\\t\\r\\n]+)/;\nexport const FILENAME_HEADER_REGEX_GIT: RegExp =\n /^(---|\\+\\+\\+)\\s+[ab]\\/([^\\t\\r\\n]+)/;\nexport const ALTERNATE_FILE_NAMES_GIT: RegExp =\n /^diff --git (?:\"a\\/(.+?)\"|a\\/(.+?)) (?:\"b\\/(.+?)\"|b\\/(.+?))$/;\nexport const INDEX_LINE_METADATA: RegExp =\n /^index ([0-9a-f]+)\\.\\.([0-9a-f]+)(?: (\\d+))?$/i;\n\nexport const MERGE_CONFLICT_START_MARKER_REGEX: RegExp = /^<{7,}(?:\\s.*)?$/;\nexport const MERGE_CONFLICT_BASE_MARKER_REGEX: RegExp = /^\\|{7,}(?:\\s.*)?$/;\nexport const MERGE_CONFLICT_SEPARATOR_MARKER_REGEX: RegExp = /^={7,}$/;\nexport const MERGE_CONFLICT_END_MARKER_REGEX: RegExp = /^>{7,}(?:\\s.*)?$/;\n\nexport const HEADER_PREFIX_SLOT_ID = 'header-prefix';\nexport const HEADER_METADATA_SLOT_ID = 'header-metadata';\nexport const CUSTOM_HEADER_SLOT_ID = 'header-custom';\n\nexport const DEFAULT_THEMES: ThemesType = {\n dark: 'pierre-dark',\n light: 'pierre-light',\n};\n\nexport const THEME_CSS_ATTRIBUTE = 'data-theme-css';\nexport const UNSAFE_CSS_ATTRIBUTE = 'data-unsafe-css';\nexport const CORE_CSS_ATTRIBUTE = 'data-core-css';\nexport const DIFFS_SCROLLBAR_MEASURE_ATTRIBUTE = 'data-diffs-scrollbar-measure';\nexport const DIFFS_SCROLLBAR_GUTTER_MEASURED_PROPERTY =\n '--diffs-scrollbar-gutter-measured';\n\nexport const DEFAULT_COLLAPSED_CONTEXT_THRESHOLD = 1;\nexport const DEFAULT_TOKENIZE_MAX_LENGTH = 100_000;\nexport const DEFAULT_VIRTUAL_FILE_METRICS: VirtualFileMetrics = {\n hunkLineCount: 50,\n lineHeight: 20,\n diffHeaderHeight: 44,\n spacing: 8,\n};\n\nexport const DEFAULT_CODE_VIEW_FILE_METRICS: VirtualFileMetrics = {\n ...DEFAULT_VIRTUAL_FILE_METRICS,\n hunkLineCount: 1,\n};\n\nexport const DEFAULT_CODE_VIEW_LAYOUT: CodeViewLayout = {\n paddingTop: 8,\n paddingBottom: 8,\n gap: 8,\n};\n\nexport const DEFAULT_SMOOTH_SCROLL_SETTINGS: SmoothScrollSettings = {\n omega: 0.015,\n positionEpsilon: 0.5,\n velocityEpsilon: 0.05,\n};\n\nexport const DEFAULT_EXPANDED_REGION: HunkExpansionRegion = Object.freeze({\n fromStart: 0,\n fromEnd: 0,\n});\n\nexport const DEFAULT_RENDER_RANGE: RenderRange = {\n startingLine: 0,\n totalLines: Infinity,\n bufferBefore: 0,\n bufferAfter: 0,\n};\n\nexport const EMPTY_RENDER_RANGE: RenderRange = {\n startingLine: 0,\n totalLines: 0,\n bufferBefore: 0,\n bufferAfter: 0,\n};\n"],"mappings":";AASA,MAAa,iBAAiB;AAI9B,MAAaA,iCAA0C;AACrD,KAAI;AACF,SAAO,QAAQ,IAAI,aAAa;SAC1B;AACN,SAAO;;IAEP;AAGJ,MAAaC,wBAAgC;AAC7C,MAAaC,4BAAoC;AACjD,MAAaC,gCAAwC;AACrD,MAAaC,oBAA4B;AACzC,MAAaC,cACX;AACF,MAAaC,sBAA8B;AAC3C,MAAaC,wBAAgC;AAC7C,MAAaC,4BACX;AACF,MAAaC,2BACX;AACF,MAAaC,sBACX;AAEF,MAAaC,oCAA4C;AACzD,MAAaC,mCAA2C;AACxD,MAAaC,wCAAgD;AAC7D,MAAaC,kCAA0C;AAEvD,MAAa,wBAAwB;AACrC,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AAErC,MAAaC,iBAA6B;CACxC,MAAM;CACN,OAAO;CACR;AAED,MAAa,sBAAsB;AACnC,MAAa,uBAAuB;AACpC,MAAa,qBAAqB;AAClC,MAAa,oCAAoC;AACjD,MAAa,2CACX;AAEF,MAAa,sCAAsC;AACnD,MAAa,8BAA8B;AAC3C,MAAaC,+BAAmD;CAC9D,eAAe;CACf,YAAY;CACZ,kBAAkB;CAClB,SAAS;CACV;AAED,MAAaC,iCAAqD;CAChE,GAAG;CACH,eAAe;CAChB;AAED,MAAaC,2BAA2C;CACtD,YAAY;CACZ,eAAe;CACf,KAAK;CACN;AAED,MAAaC,iCAAuD;CAClE,OAAO;CACP,iBAAiB;CACjB,iBAAiB;CAClB;AAED,MAAaC,0BAA+C,OAAO,OAAO;CACxE,WAAW;CACX,SAAS;CACV,CAAC;AAEF,MAAaC,uBAAoC;CAC/C,cAAc;CACd,YAAY;CACZ,cAAc;CACd,aAAa;CACd;AAED,MAAaC,qBAAkC;CAC7C,cAAc;CACd,YAAY;CACZ,cAAc;CACd,aAAa;CACd"}
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,6 @@ import { prerenderHTMLIfNecessary } from "./utils/prerenderHTMLIfNecessary.js";
|
|
|
55
55
|
import { setPreNodeProperties } from "./utils/setWrapperNodeProps.js";
|
|
56
56
|
import { File } from "./components/File.js";
|
|
57
57
|
import { VirtualizedFile } from "./components/VirtualizedFile.js";
|
|
58
|
-
import { parseLineType } from "./utils/parseLineType.js";
|
|
59
58
|
import { parsePatchFiles, processFile, processPatch } from "./utils/parsePatchFiles.js";
|
|
60
59
|
import { parseDiffFromFile } from "./utils/parseDiffFromFile.js";
|
|
61
60
|
import { ScrollSyncManager } from "./managers/ScrollSyncManager.js";
|
|
@@ -96,6 +95,7 @@ import { createStyleElement, createThemeStyleElement } from "./utils/createStyle
|
|
|
96
95
|
import { diffAcceptRejectHunk } from "./utils/diffAcceptRejectHunk.js";
|
|
97
96
|
import { getLineEndingType } from "./utils/getLineEndingType.js";
|
|
98
97
|
import { getSingularPatch } from "./utils/getSingularPatch.js";
|
|
98
|
+
import { parseLineType } from "./utils/parseLineType.js";
|
|
99
99
|
import { setLanguageOverride } from "./utils/setLanguageOverride.js";
|
|
100
100
|
import { trimPatchContext } from "./utils/trimPatchContext.js";
|
|
101
101
|
import { codeToHtml, createCssVariablesTheme as createCSSVariablesTheme } from "shiki";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionManager.d.ts","names":["AnnotationSide","DiffLineEventBaseProps","DiffTokenEventBaseProps","ExpansionDirections","LineEventBaseProps","MergeConflictResolution","SelectedLineRange","SelectionSide","TokenEventBase","LogTypes","InteractionManagerMode","OnLineClickProps","PointerEvent","OnLineEnterLeaveProps","OnDiffLineClickProps","OnDiffLineEnterLeaveProps","SelectionWriteOptions","GetLineIndexUtility","EventClickProps","TMode","PointerEventEnterLeaveProps","OnTokenEventProps","GetHoveredLineResult","MergeConflictActionTarget","InteractionManagerBaseOptions","MouseEvent","InteractionManagerOptions","InteractionManager","HTMLPreElement","InteractionPluckOptions","HTMLElement","pluckInteractionOptions","enableTokenInteractionsOnWhitespace","enableGutterUtility","lineHoverHighlight","onGutterUtilityClick","onLineClick","onLineEnter","onLineLeave","onLineNumberClick","onTokenClick","onTokenEnter","onTokenLeave","renderGutterUtility","__debugPointerEvents","enableLineSelection","controlledSelection","onLineSelected","onLineSelectionStart","onLineSelectionChange","onLineSelectionEnd"],"sources":["../../src/managers/InteractionManager.d.ts"],"sourcesContent":["import type { AnnotationSide, DiffLineEventBaseProps, DiffTokenEventBaseProps, ExpansionDirections, LineEventBaseProps, MergeConflictResolution, SelectedLineRange, SelectionSide, TokenEventBase } from '../types';\nexport type LogTypes = 'click' | 'move' | 'both' | 'none';\nexport type InteractionManagerMode = 'file' | 'diff';\nexport interface OnLineClickProps extends LineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnLineEnterLeaveProps extends LineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnDiffLineClickProps extends DiffLineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnDiffLineEnterLeaveProps extends DiffLineEventBaseProps {\n event: PointerEvent;\n}\nexport interface SelectionWriteOptions {\n notify?: boolean;\n}\nexport type GetLineIndexUtility = (lineNumber: number, side?: SelectionSide) => [number, number] | undefined;\ntype EventClickProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? OnLineClickProps : OnDiffLineClickProps;\ntype PointerEventEnterLeaveProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? OnLineEnterLeaveProps : OnDiffLineEnterLeaveProps;\nexport type OnTokenEventProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? TokenEventBase : DiffTokenEventBaseProps;\nexport type GetHoveredLineResult<TMode extends InteractionManagerMode> = TMode extends 'file' ? {\n lineNumber: number;\n} : {\n lineNumber: number;\n side: AnnotationSide;\n};\nexport interface MergeConflictActionTarget {\n kind: 'merge-conflict-action';\n resolution: MergeConflictResolution;\n conflictIndex: number;\n}\nexport interface InteractionManagerBaseOptions<TMode extends InteractionManagerMode> {\n lineHoverHighlight?: 'disabled' | 'both' | 'number' | 'line';\n enableTokenInteractionsOnWhitespace?: boolean;\n enableGutterUtility?: boolean;\n onGutterUtilityClick?(range: SelectedLineRange): unknown;\n onLineClick?(props: EventClickProps<TMode>): unknown;\n onLineNumberClick?(props: EventClickProps<TMode>): unknown;\n onLineEnter?(props: PointerEventEnterLeaveProps<TMode>): unknown;\n onLineLeave?(props: PointerEventEnterLeaveProps<TMode>): unknown;\n onTokenClick?(props: OnTokenEventProps<TMode>, event: MouseEvent): unknown;\n onTokenEnter?(props: OnTokenEventProps<TMode>, event: PointerEvent): unknown;\n onTokenLeave?(props: OnTokenEventProps<TMode>, event: PointerEvent): unknown;\n __debugPointerEvents?: LogTypes;\n enableLineSelection?: boolean;\n controlledSelection?: boolean;\n onLineSelected?: (range: SelectedLineRange | null) => void;\n onLineSelectionStart?: (range: SelectedLineRange | null) => void;\n onLineSelectionChange?: (range: SelectedLineRange | null) => void;\n onLineSelectionEnd?: (range: SelectedLineRange | null) => void;\n getLineIndex?: GetLineIndexUtility;\n}\nexport interface InteractionManagerOptions<TMode extends InteractionManagerMode> extends InteractionManagerBaseOptions<TMode> {\n usesCustomGutterUtility?: boolean;\n onHunkExpand?(hunkIndex: number, direction: ExpansionDirections, expansionLineCountOverride?: number): unknown;\n onMergeConflictActionClick?(target: MergeConflictActionTarget): void;\n}\nexport declare class InteractionManager<TMode extends InteractionManagerMode> {\n private mode;\n private options;\n private hoveredLine;\n private hoveredToken;\n private pre;\n private gutterUtilityLine;\n private gutterUtilityContainer;\n private gutterUtilityButton;\n private gutterUtilitySlot;\n private interactiveLinesAttr;\n private interactiveLineNumbersAttr;\n private hasPointerListeners;\n private hasDocumentPointerListeners;\n private selectedRange;\n private proposedSelectedRange;\n private renderedSelectionRange;\n private selectionAnchor;\n private queuedSelectionRender;\n private pointerSession;\n constructor(mode: TMode, options: InteractionManagerOptions<TMode>);\n setOptions(options: InteractionManagerOptions<TMode>): void;\n cleanUp(): void;\n setup(pre: HTMLPreElement): void;\n setSelectionDirty(): void;\n isSelectionDirty(): boolean;\n setSelection(range: SelectedLineRange | null, options?: SelectionWriteOptions): void;\n getSelection(): SelectedLineRange | null;\n getHoveredLine: () => GetHoveredLineResult<TMode> | undefined;\n handlePointerClick: (event: MouseEvent) => void;\n handlePointerMove: (event: PointerEvent) => void;\n handlePointerLeave: (event: PointerEvent) => void;\n private handlePointerEvent;\n private syncPointerListeners;\n private updateInteractiveLineAttributes;\n private handlePointerDown;\n private startLineSelectionFromPointerDown;\n private startGutterSelectionFromPointerDown;\n private handleDocumentPointerMove;\n private handleDocumentPointerUp;\n private handleDocumentPointerCancel;\n private clearHoveredLine;\n private setHoveredLine;\n private clearHoveredToken;\n private setHoveredToken;\n private ensureGutterUtilityNode;\n private revealUtilityFromGutterPath;\n private placeUtility;\n private placeUtilityFromSelection;\n private showUtilityOnLine;\n private hideUtility;\n private currentSelectionEnds;\n private selectionEnds;\n private selectionPointRowIndex;\n private targetForSelectionPoint;\n private attachDocumentPointerListeners;\n private detachDocumentPointerListeners;\n private clearPointerSession;\n private clearPendingSingleLineState;\n private selectionInfoFromPath;\n private resolveSelectionInfo;\n private selectionPointFromPath;\n private resolveSelectionPoint;\n private resolveSelectionPath;\n private pathFromCoordinates;\n private pathFromEventPath;\n private pathFromElement;\n private pathFromAnnotationSlot;\n private hitTest;\n private getLineIndex;\n private getCurrentSelectionRange;\n private clearProposedSelection;\n private updateSelection;\n private getIndexesFromSelection;\n private renderSelection;\n private notifySelectionCommitted;\n private notifySelectionChangeDelta;\n private notifySelectionStart;\n private notifySelectionEnd;\n private toEventBaseProps;\n private toTokenEventBaseProps;\n private buildSelectedLineRange;\n private buildSelectionRange;\n private resolvePointerTarget;\n private isSplitDiff;\n private parseLineIndex;\n}\ntype InteractionPluckOptions<TMode extends InteractionManagerMode> = InteractionManagerBaseOptions<TMode> & {\n renderGutterUtility?(getHoveredRow: () => GetHoveredLineResult<TMode> | undefined): HTMLElement | null | undefined;\n};\nexport declare function pluckInteractionOptions<TMode extends InteractionManagerMode>({ enableTokenInteractionsOnWhitespace, enableGutterUtility, lineHoverHighlight, onGutterUtilityClick, onLineClick, onLineEnter, onLineLeave, onLineNumberClick, onTokenClick, onTokenEnter, onTokenLeave, renderGutterUtility, __debugPointerEvents, enableLineSelection, controlledSelection, onLineSelected, onLineSelectionStart, onLineSelectionChange, onLineSelectionEnd }: InteractionPluckOptions<TMode>, onHunkExpand?: (hunkIndex: number, direction: ExpansionDirections, expansionLineCountOverride?: number) => unknown, getLineIndex?: GetLineIndexUtility, onMergeConflictActionClick?: (target: MergeConflictActionTarget) => void): InteractionManagerOptions<TMode>;\nexport {};\n//# sourceMappingURL=InteractionManager.d.ts.map"],"mappings":";;;KACYS,QAAAA;KACAC,sBAAAA;AADAD,UAEKE,gBAAAA,SAAyBP,kBAFtB,CAAA;EACRM,KAAAA,EAEDE,YAFCF;AACZ;AAGiBG,UAAAA,qBAAAA,SAA8BT,kBAAAA,CAAAA;EAG9BU,KAAAA,EAFNF,YAEME;AAGjB;AAGiBE,UANAF,oBAAAA,SAA6Bb,sBAMR,CAAA;EAG1BgB,KAAAA,EARDL,YAQCK;AAAiG;AAC1EP,UAPlBK,yBAAAA,SAAkCd,sBAOhBS,CAAAA;EAA0BS,KAAAA,EANlDP,YAMkDO;;AAA0CL,UAJtFE,qBAAAA,CAIsFF;EAAoB,MAAA,CAAA,EAAA,OAAA;AAAA;AAC5EJ,KAFnCO,mBAAAA,GAEmCP,CAAAA,UAAAA,EAAAA,MAAAA,EAAAA,IAAAA,CAAAA,EAFeH,aAEfG,EAAAA,GAAAA,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA,GAAAA,SAAAA;KAD1CQ,eACoEC,CAAAA,cADtCT,sBACsCS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DiffTokenEventBaseProps","ExpansionDirections","LineEventBaseProps","MergeConflictResolution","SelectedLineRange","SelectionSide","TokenEventBase","LogTypes","InteractionManagerMode","OnLineClickProps","PointerEvent","OnLineEnterLeaveProps","OnDiffLineClickProps","OnDiffLineEnterLeaveProps","SelectionWriteOptions","GetLineIndexUtility","EventClickProps","TMode","PointerEventEnterLeaveProps","OnTokenEventProps","GetHoveredLineResult","MergeConflictActionTarget","InteractionManagerBaseOptions","MouseEvent","InteractionManagerOptions","InteractionManager","HTMLPreElement","InteractionPluckOptions","HTMLElement","pluckInteractionOptions","enableTokenInteractionsOnWhitespace","enableGutterUtility","lineHoverHighlight","onGutterUtilityClick","onLineClick","onLineEnter","onLineLeave","onLineNumberClick","onTokenClick","onTokenEnter","onTokenLeave","renderGutterUtility","__debugPointerEvents","enableLineSelection","controlledSelection","onLineSelected","onLineSelectionStart","onLineSelectionChange","onLineSelectionEnd"],"sources":["../../src/managers/InteractionManager.d.ts"],"sourcesContent":["import type { AnnotationSide, DiffLineEventBaseProps, DiffTokenEventBaseProps, ExpansionDirections, LineEventBaseProps, MergeConflictResolution, SelectedLineRange, SelectionSide, TokenEventBase } from '../types';\nexport type LogTypes = 'click' | 'move' | 'both' | 'none';\nexport type InteractionManagerMode = 'file' | 'diff';\nexport interface OnLineClickProps extends LineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnLineEnterLeaveProps extends LineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnDiffLineClickProps extends DiffLineEventBaseProps {\n event: PointerEvent;\n}\nexport interface OnDiffLineEnterLeaveProps extends DiffLineEventBaseProps {\n event: PointerEvent;\n}\nexport interface SelectionWriteOptions {\n notify?: boolean;\n}\nexport type GetLineIndexUtility = (lineNumber: number, side?: SelectionSide) => [number, number] | undefined;\ntype EventClickProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? OnLineClickProps : OnDiffLineClickProps;\ntype PointerEventEnterLeaveProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? OnLineEnterLeaveProps : OnDiffLineEnterLeaveProps;\nexport type OnTokenEventProps<TMode extends InteractionManagerMode> = TMode extends 'file' ? TokenEventBase : DiffTokenEventBaseProps;\nexport type GetHoveredLineResult<TMode extends InteractionManagerMode> = TMode extends 'file' ? {\n lineNumber: number;\n} : {\n lineNumber: number;\n side: AnnotationSide;\n};\nexport interface MergeConflictActionTarget {\n kind: 'merge-conflict-action';\n resolution: MergeConflictResolution;\n conflictIndex: number;\n}\nexport interface InteractionManagerBaseOptions<TMode extends InteractionManagerMode> {\n lineHoverHighlight?: 'disabled' | 'both' | 'number' | 'line';\n enableTokenInteractionsOnWhitespace?: boolean;\n enableGutterUtility?: boolean;\n onGutterUtilityClick?(range: SelectedLineRange): unknown;\n onLineClick?(props: EventClickProps<TMode>): unknown;\n onLineNumberClick?(props: EventClickProps<TMode>): unknown;\n onLineEnter?(props: PointerEventEnterLeaveProps<TMode>): unknown;\n onLineLeave?(props: PointerEventEnterLeaveProps<TMode>): unknown;\n onTokenClick?(props: OnTokenEventProps<TMode>, event: MouseEvent): unknown;\n onTokenEnter?(props: OnTokenEventProps<TMode>, event: PointerEvent): unknown;\n onTokenLeave?(props: OnTokenEventProps<TMode>, event: PointerEvent): unknown;\n __debugPointerEvents?: LogTypes;\n enableLineSelection?: boolean;\n controlledSelection?: boolean;\n onLineSelected?: (range: SelectedLineRange | null) => void;\n onLineSelectionStart?: (range: SelectedLineRange | null) => void;\n onLineSelectionChange?: (range: SelectedLineRange | null) => void;\n onLineSelectionEnd?: (range: SelectedLineRange | null) => void;\n getLineIndex?: GetLineIndexUtility;\n}\nexport interface InteractionManagerOptions<TMode extends InteractionManagerMode> extends InteractionManagerBaseOptions<TMode> {\n usesCustomGutterUtility?: boolean;\n onHunkExpand?(hunkIndex: number, direction: ExpansionDirections, expansionLineCountOverride?: number): unknown;\n onMergeConflictActionClick?(target: MergeConflictActionTarget): void;\n}\nexport declare class InteractionManager<TMode extends InteractionManagerMode> {\n private mode;\n private options;\n private hoveredLine;\n private hoveredToken;\n private pre;\n private gutterUtilityLine;\n private gutterUtilityContainer;\n private gutterUtilityButton;\n private gutterUtilitySlot;\n private interactiveLinesAttr;\n private interactiveLineNumbersAttr;\n private hasPointerListeners;\n private hasDocumentPointerListeners;\n private selectedRange;\n private proposedSelectedRange;\n private renderedSelectionRange;\n private selectionAnchor;\n private queuedSelectionRender;\n private pointerSession;\n constructor(mode: TMode, options: InteractionManagerOptions<TMode>);\n setOptions(options: InteractionManagerOptions<TMode>): void;\n cleanUp(): void;\n setup(pre: HTMLPreElement): void;\n setSelectionDirty(): void;\n isSelectionDirty(): boolean;\n setSelection(range: SelectedLineRange | null, options?: SelectionWriteOptions): void;\n getSelection(): SelectedLineRange | null;\n getHoveredLine: () => GetHoveredLineResult<TMode> | undefined;\n handlePointerClick: (event: MouseEvent) => void;\n handlePointerMove: (event: PointerEvent) => void;\n handlePointerLeave: (event: PointerEvent) => void;\n private handlePointerEvent;\n private syncPointerListeners;\n private updateInteractiveLineAttributes;\n private handlePointerDown;\n private startLineSelectionFromPointerDown;\n private startGutterSelectionFromPointerDown;\n private handleDocumentPointerMove;\n private handleDocumentPointerUp;\n private handleDocumentPointerCancel;\n private clearHoveredLine;\n private setHoveredLine;\n private clearHoveredToken;\n private setHoveredToken;\n private ensureGutterUtilityNode;\n private revealUtilityFromGutterPath;\n private placeUtility;\n private placeUtilityFromSelection;\n private showUtilityOnLine;\n private hideUtility;\n private currentSelectionEnds;\n private selectionEnds;\n private selectionPointRowIndex;\n private targetForSelectionPoint;\n private attachDocumentPointerListeners;\n private detachDocumentPointerListeners;\n private clearPointerSession;\n private clearPendingSingleLineState;\n private selectionInfoFromPath;\n private resolveSelectionInfo;\n private selectionPointFromPath;\n private resolveSelectionPoint;\n private resolveSelectionPath;\n private pathFromCoordinates;\n private pathFromEventPath;\n private pathFromElement;\n private pathFromAnnotationSlot;\n private hitTest;\n private getLineIndex;\n private getCurrentSelectionRange;\n private clearProposedSelection;\n private updateSelection;\n private getIndexesFromSelection;\n private renderSelection;\n private notifySelectionCommitted;\n private notifySelectionChangeDelta;\n private notifySelectionStart;\n private notifySelectionEnd;\n private toEventBaseProps;\n private toTokenEventBaseProps;\n private buildSelectedLineRange;\n private buildSelectionRange;\n private resolvePointerTarget;\n private isSplitDiff;\n private parseLineIndex;\n}\ntype InteractionPluckOptions<TMode extends InteractionManagerMode> = InteractionManagerBaseOptions<TMode> & {\n renderGutterUtility?(getHoveredRow: () => GetHoveredLineResult<TMode> | undefined): HTMLElement | null | undefined;\n};\nexport declare function pluckInteractionOptions<TMode extends InteractionManagerMode>({ enableTokenInteractionsOnWhitespace, enableGutterUtility, lineHoverHighlight, onGutterUtilityClick, onLineClick, onLineEnter, onLineLeave, onLineNumberClick, onTokenClick, onTokenEnter, onTokenLeave, renderGutterUtility, __debugPointerEvents, enableLineSelection, controlledSelection, onLineSelected, onLineSelectionStart, onLineSelectionChange, onLineSelectionEnd }: InteractionPluckOptions<TMode>, onHunkExpand?: (hunkIndex: number, direction: ExpansionDirections, expansionLineCountOverride?: number) => unknown, getLineIndex?: GetLineIndexUtility, onMergeConflictActionClick?: (target: MergeConflictActionTarget) => void): InteractionManagerOptions<TMode>;\nexport {};\n//# sourceMappingURL=InteractionManager.d.ts.map"],"mappings":";;;KACYS,QAAAA;KACAC,sBAAAA;AADAD,UAEKE,gBAAAA,SAAyBP,kBAFtB,CAAA;EACRM,KAAAA,EAEDE,YAFCF;AACZ;AAGiBG,UAAAA,qBAAAA,SAA8BT,kBAAAA,CAAAA;EAG9BU,KAAAA,EAFNF,YAEME;AAGjB;AAGiBE,UANAF,oBAAAA,SAA6Bb,sBAMR,CAAA;EAG1BgB,KAAAA,EARDL,YAQCK;AAAiG;AAC1EP,UAPlBK,yBAAAA,SAAkCd,sBAOhBS,CAAAA;EAA0BS,KAAAA,EANlDP,YAMkDO;;AAA0CL,UAJtFE,qBAAAA,CAIsFF;EAAoB,MAAA,CAAA,EAAA,OAAA;AAAA;AAC5EJ,KAFnCO,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;iBAEhEC,sCAAsCrB;;;;;;;;;;;;;;;;;;;;GAA0YmB,wBAAwBV,sDAAsDhB,qFAAqFc,2DAA2DM,qCAAqCG,0BAA0BP"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
//#region src/managers/ResizeManager.d.ts
|
|
2
2
|
declare class ResizeManager {
|
|
3
|
-
private resizeObserver;
|
|
3
|
+
private static resizeObserver;
|
|
4
|
+
private static managersByElement;
|
|
5
|
+
private static getResizeObserver;
|
|
6
|
+
private static handleSharedResizeEntries;
|
|
4
7
|
private observedNodes;
|
|
5
8
|
setup(pre: HTMLPreElement, disableAnnotations: boolean): void;
|
|
6
9
|
cleanUp(): void;
|
|
7
|
-
private
|
|
10
|
+
private observe;
|
|
11
|
+
private unobserve;
|
|
12
|
+
private handleResizeEntries;
|
|
8
13
|
private applyAnnotationUpdates;
|
|
9
14
|
private applyColumnUpdates;
|
|
10
15
|
private applyNewHeight;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResizeManager.d.ts","names":["ResizeManager","HTMLPreElement"],"sources":["../../src/managers/ResizeManager.d.ts"],"sourcesContent":["export declare class ResizeManager {\n private resizeObserver;\n private observedNodes;\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void;\n cleanUp(): void;\n private
|
|
1
|
+
{"version":3,"file":"ResizeManager.d.ts","names":["ResizeManager","HTMLPreElement"],"sources":["../../src/managers/ResizeManager.d.ts"],"sourcesContent":["export declare class ResizeManager {\n private static resizeObserver;\n private static managersByElement;\n private static getResizeObserver;\n private static handleSharedResizeEntries;\n private observedNodes;\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void;\n cleanUp(): void;\n private observe;\n private unobserve;\n private handleResizeEntries;\n private applyAnnotationUpdates;\n private applyColumnUpdates;\n private applyNewHeight;\n}\n//# sourceMappingURL=ResizeManager.d.ts.map"],"mappings":";cAAqBA,aAAAA;EAAAA,eAAAA,cAMNC;;;;;aAAAA"}
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
//#region src/managers/ResizeManager.ts
|
|
2
|
-
var ResizeManager = class {
|
|
3
|
-
resizeObserver;
|
|
2
|
+
var ResizeManager = class ResizeManager {
|
|
3
|
+
static resizeObserver;
|
|
4
|
+
static managersByElement = /* @__PURE__ */ new Map();
|
|
5
|
+
static getResizeObserver() {
|
|
6
|
+
const resizeObserver = ResizeManager.resizeObserver ?? new ResizeObserver(ResizeManager.handleSharedResizeEntries);
|
|
7
|
+
ResizeManager.resizeObserver = resizeObserver;
|
|
8
|
+
return resizeObserver;
|
|
9
|
+
}
|
|
10
|
+
static handleSharedResizeEntries(entries) {
|
|
11
|
+
const entriesByManager = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const manager = ResizeManager.managersByElement.get(entry.target);
|
|
14
|
+
if (manager == null) continue;
|
|
15
|
+
const managerEntries = entriesByManager.get(manager);
|
|
16
|
+
if (managerEntries == null) entriesByManager.set(manager, [entry]);
|
|
17
|
+
else managerEntries.push(entry);
|
|
18
|
+
}
|
|
19
|
+
for (const [manager, managerEntries] of entriesByManager) manager.handleResizeEntries(managerEntries);
|
|
20
|
+
}
|
|
4
21
|
observedNodes = /* @__PURE__ */ new Map();
|
|
5
22
|
setup(pre, disableAnnotations) {
|
|
6
|
-
this.resizeObserver ??= new ResizeObserver(this.handleResizeObserver);
|
|
7
23
|
const annotationUpdates = /* @__PURE__ */ new Set();
|
|
8
24
|
let columnCount = 0;
|
|
9
25
|
const observedNodes = new Map(this.observedNodes);
|
|
@@ -24,11 +40,11 @@ var ResizeManager = class {
|
|
|
24
40
|
observedNodes.delete(codeElement);
|
|
25
41
|
if (item.numberElement !== numberElement) {
|
|
26
42
|
if (item.numberElement != null) {
|
|
27
|
-
this.
|
|
43
|
+
this.unobserve(item.numberElement);
|
|
28
44
|
observedNodes.delete(item.numberElement);
|
|
29
45
|
}
|
|
30
46
|
if (numberElement != null) {
|
|
31
|
-
this.
|
|
47
|
+
this.observe(numberElement);
|
|
32
48
|
observedNodes.delete(numberElement);
|
|
33
49
|
this.observedNodes.set(numberElement, item);
|
|
34
50
|
}
|
|
@@ -47,10 +63,10 @@ var ResizeManager = class {
|
|
|
47
63
|
numberWidth: 0
|
|
48
64
|
};
|
|
49
65
|
this.observedNodes.set(codeElement, item);
|
|
50
|
-
this.
|
|
66
|
+
this.observe(codeElement);
|
|
51
67
|
if (numberElement != null) {
|
|
52
68
|
this.observedNodes.set(numberElement, item);
|
|
53
|
-
this.
|
|
69
|
+
this.observe(numberElement);
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
}
|
|
@@ -118,34 +134,54 @@ var ResizeManager = class {
|
|
|
118
134
|
this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);
|
|
119
135
|
this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);
|
|
120
136
|
this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
137
|
+
this.observe(pendingUpdate.child1);
|
|
138
|
+
this.observe(pendingUpdate.child2);
|
|
123
139
|
}
|
|
124
140
|
annotationUpdates.clear();
|
|
125
141
|
}
|
|
126
142
|
for (const [element, item] of observedNodes) {
|
|
127
|
-
this.
|
|
143
|
+
this.unobserve(element);
|
|
128
144
|
if (item.type === "code") cleanupStaleCodeItem(item);
|
|
129
145
|
else cleanupStaleAnnotationItem(item);
|
|
130
146
|
}
|
|
131
147
|
observedNodes.clear();
|
|
132
148
|
}
|
|
133
149
|
cleanUp() {
|
|
134
|
-
this.
|
|
150
|
+
for (const element of this.observedNodes.keys()) this.unobserve(element);
|
|
135
151
|
this.observedNodes.clear();
|
|
136
152
|
}
|
|
137
|
-
|
|
153
|
+
observe(element) {
|
|
154
|
+
const { managersByElement } = ResizeManager;
|
|
155
|
+
const owner = managersByElement.get(element);
|
|
156
|
+
if (owner === this) return;
|
|
157
|
+
else if (owner != null && owner !== this) throw new Error("ResizeManager.observe: element is already owned by another ResizeManager");
|
|
158
|
+
managersByElement.set(element, this);
|
|
159
|
+
ResizeManager.getResizeObserver().observe(element);
|
|
160
|
+
}
|
|
161
|
+
unobserve(element) {
|
|
162
|
+
const { managersByElement, resizeObserver } = ResizeManager;
|
|
163
|
+
const owner = managersByElement.get(element);
|
|
164
|
+
if (owner == null) return;
|
|
165
|
+
else if (owner !== this) throw new Error("ResizeManager.unobserve: element is owned by another ResizeManager");
|
|
166
|
+
managersByElement.delete(element);
|
|
167
|
+
resizeObserver?.unobserve(element);
|
|
168
|
+
if (resizeObserver != null && managersByElement.size === 0) {
|
|
169
|
+
resizeObserver.disconnect();
|
|
170
|
+
ResizeManager.resizeObserver = void 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
handleResizeEntries(entries) {
|
|
138
174
|
const codeUpdates = /* @__PURE__ */ new Map();
|
|
139
175
|
const annotationUpdates = /* @__PURE__ */ new Set();
|
|
140
176
|
for (const entry of entries) {
|
|
141
177
|
const { target, borderBoxSize, contentBoxSize } = entry;
|
|
142
178
|
if (!(target instanceof HTMLElement)) {
|
|
143
|
-
console.error("
|
|
179
|
+
console.error("ResizeManager.handleResizeEntries: Invalid element for ResizeObserver", entry);
|
|
144
180
|
continue;
|
|
145
181
|
}
|
|
146
182
|
const item = this.observedNodes.get(target);
|
|
147
183
|
if (item == null) {
|
|
148
|
-
console.error("
|
|
184
|
+
console.error("ResizeManager.handleResizeEntries: Not a valid observed node", entry);
|
|
149
185
|
continue;
|
|
150
186
|
}
|
|
151
187
|
if (item.type === "annotations") {
|
|
@@ -154,7 +190,7 @@ var ResizeManager = class {
|
|
|
154
190
|
if (target === item.column2.child) return item.column2;
|
|
155
191
|
})();
|
|
156
192
|
if (column == null) {
|
|
157
|
-
console.error(`
|
|
193
|
+
console.error(`ResizeManager.handleResizeEntries: Couldn't find a column for`, {
|
|
158
194
|
item,
|
|
159
195
|
target
|
|
160
196
|
});
|
|
@@ -174,7 +210,7 @@ var ResizeManager = class {
|
|
|
174
210
|
annotationUpdates.clear();
|
|
175
211
|
this.applyColumnUpdates(codeUpdates);
|
|
176
212
|
codeUpdates.clear();
|
|
177
|
-
}
|
|
213
|
+
}
|
|
178
214
|
applyAnnotationUpdates(annotationUpdates) {
|
|
179
215
|
for (const item of annotationUpdates) this.applyNewHeight(item, Math.max(item.column1.childHeight, item.column2.childHeight));
|
|
180
216
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResizeManager.js","names":["codeElement: HTMLElement | undefined","item: ObservedGridNodes | ObservedAnnotationNodes | undefined","codeUpdates: CodeUpdateMap","annotationUpdates: Set<ObservedAnnotationNodes>"],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n private resizeObserver: ResizeObserver | undefined;\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void {\n this.resizeObserver ??= new ResizeObserver(this.handleResizeObserver);\n const annotationUpdates = new Set<AnnotationSetup>();\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.resizeObserver.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.resizeObserver.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n };\n this.observedNodes.set(codeElement, item);\n this.resizeObserver.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.resizeObserver.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^\\d+,\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.resizeObserver.observe(pendingUpdate.child1);\n this.resizeObserver.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.resizeObserver.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n // Disconnect any existing observer and nodes\n this.resizeObserver?.disconnect();\n this.observedNodes.clear();\n }\n\n private handleResizeObserver = (entries: ResizeObserverEntry[]) => {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'FileDiff.handleResizeObserver: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'FileDiff.handleResizeObserver: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `FileDiff.handleResizeObserver: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n };\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (codeWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof nextCodeWidth === 'number' ? `${nextCodeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${nextNumberWidth === 0 ? 'auto' : `${nextNumberWidth}px`}`\n );\n }\n\n if (\n codeWidthChanged ||\n (numberWidthChanged && nextCodeWidth !== 'auto')\n ) {\n const targetWidth =\n typeof nextCodeWidth === 'number'\n ? Math.max(nextCodeWidth - nextNumberWidth, 0)\n : 0;\n item.codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n}\n"],"mappings":";AAiBA,IAAa,gBAAb,MAA2B;CACzB,AAAQ;CACR,AAAQ,gCAAgB,IAAI,KAGzB;CAEH,MAAM,KAAqB,oBAAmC;AAC5D,O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AAgB,KAAK,IAAI,WAAW,EAAE;AAC3C,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;AACD,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;;;;AAKP,SAAS,iBAAiB,YAAqC;CAC7D,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,WAAW,EAAE,EAAE;AACjD,QAAO,UAAU,IAAI,SAAS;;AAGhC,SAAS,mBAAmB,YAA4B;AACtD,QAAO,KAAK,IAAI,KAAK,KAAK,WAAW,EAAE,EAAE;;AAG3C,SAAS,qBAAqB,MAA+B;AAC3D,KAAI,KAAK,YAAY,aAAa;AAChC,OAAK,YAAY,MAAM,eAAe,+BAA+B;AACrE,OAAK,YAAY,MAAM,eAAe,8BAA8B;AACpE,OAAK,YAAY,MAAM,eAAe,uBAAuB;;;AAIjE,SAAS,2BAA2B,MAAqC;AACvE,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD;AAEH,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD"}
|
|
1
|
+
{"version":3,"file":"ResizeManager.js","names":["codeElement: HTMLElement | undefined","item: ObservedGridNodes | ObservedAnnotationNodes | undefined","codeUpdates: CodeUpdateMap","annotationUpdates: Set<ObservedAnnotationNodes>"],"sources":["../../src/managers/ResizeManager.ts"],"sourcesContent":["import type { ObservedAnnotationNodes, ObservedGridNodes } from '../types';\n\ninterface CodeColumnUpdate {\n codeInlineSize?: number;\n numberInlineSize?: number;\n measuredNumberInlineSize?: number;\n}\n\ntype CodeUpdateMap = Map<ObservedGridNodes, CodeColumnUpdate>;\n\ninterface AnnotationSetup {\n child1: HTMLElement;\n child2: HTMLElement;\n item: ObservedAnnotationNodes;\n newHeight: number;\n}\n\nexport class ResizeManager {\n // Shared static resizeObserver that all ResizeManagers use\n private static resizeObserver: ResizeObserver | undefined;\n private static managersByElement = new Map<Element, ResizeManager>();\n\n private static getResizeObserver(): ResizeObserver {\n const resizeObserver =\n ResizeManager.resizeObserver ??\n new ResizeObserver(ResizeManager.handleSharedResizeEntries);\n ResizeManager.resizeObserver = resizeObserver;\n return resizeObserver;\n }\n\n private static handleSharedResizeEntries(entries: ResizeObserverEntry[]) {\n // First we need to batch all elements by manager, so callbacks are\n // properly aligned with a per-instance ResizeManager\n const entriesByManager = new Map<ResizeManager, ResizeObserverEntry[]>();\n for (const entry of entries) {\n const manager = ResizeManager.managersByElement.get(entry.target);\n if (manager == null) {\n continue;\n }\n const managerEntries = entriesByManager.get(manager);\n if (managerEntries == null) {\n entriesByManager.set(manager, [entry]);\n } else {\n managerEntries.push(entry);\n }\n }\n\n for (const [manager, managerEntries] of entriesByManager) {\n manager.handleResizeEntries(managerEntries);\n }\n }\n\n private observedNodes = new Map<\n HTMLElement,\n ObservedAnnotationNodes | ObservedGridNodes\n >();\n\n setup(pre: HTMLPreElement, disableAnnotations: boolean): void {\n const annotationUpdates = new Set<AnnotationSetup>();\n let columnCount = 0;\n const observedNodes = new Map(this.observedNodes);\n this.observedNodes.clear();\n\n for (const element of pre.children) {\n if (columnCount === 2) {\n break;\n }\n const codeElement: HTMLElement | undefined = (() => {\n if (element instanceof HTMLElement && element.tagName === 'CODE') {\n return element;\n }\n return undefined;\n })();\n if (codeElement == null) {\n continue;\n }\n columnCount++;\n let item: ObservedGridNodes | ObservedAnnotationNodes | undefined =\n observedNodes.get(codeElement);\n if (item != null && item.type !== 'code') {\n throw new Error(\n 'ResizeManager.setup: somehow a code node is being used for an annotation, should be impossible'\n );\n }\n\n let numberElement = codeElement.firstElementChild;\n if (!(numberElement instanceof HTMLElement)) {\n numberElement = null;\n }\n if (item != null) {\n this.observedNodes.set(codeElement, item);\n observedNodes.delete(codeElement);\n if (item.numberElement !== numberElement) {\n if (item.numberElement != null) {\n this.unobserve(item.numberElement);\n observedNodes.delete(item.numberElement);\n }\n if (numberElement != null) {\n this.observe(numberElement);\n observedNodes.delete(numberElement);\n this.observedNodes.set(numberElement, item);\n }\n item.numberElement = numberElement;\n item.numberWidth = 0;\n } else if (item.numberElement != null) {\n observedNodes.delete(item.numberElement);\n this.observedNodes.set(item.numberElement, item);\n // If there is a resize, let the resize handler handle it...\n } else {\n item.numberWidth = 0;\n }\n } else {\n item = {\n type: 'code',\n codeElement,\n numberElement,\n codeWidth: 'auto',\n numberWidth: 0,\n };\n this.observedNodes.set(codeElement, item);\n this.observe(codeElement);\n if (numberElement != null) {\n this.observedNodes.set(numberElement, item);\n this.observe(numberElement);\n }\n }\n }\n\n if (columnCount > 1 && !disableAnnotations) {\n const annotationElements = pre.querySelectorAll(\n '[data-line-annotation*=\",\"]'\n );\n\n const elementMap = new Map<string, HTMLElement[]>();\n // Iterate through all the matched elements and organize them into pairs\n // based on the data-line-annotation attribute\n for (const element of annotationElements) {\n if (!(element instanceof HTMLElement)) {\n continue;\n }\n const lineAnnotation =\n element.getAttribute('data-line-annotation') ?? '';\n if (!/^\\d+,\\d+$/.test(lineAnnotation)) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Invalid element or annotation',\n { lineAnnotation, element }\n );\n continue;\n }\n let pairs = elementMap.get(lineAnnotation);\n if (pairs == null) {\n pairs = [];\n elementMap.set(lineAnnotation, pairs);\n }\n pairs.push(element);\n }\n\n for (const [key, pair] of elementMap) {\n if (pair.length !== 2) {\n console.error(\n 'DiffFileRenderer.setupResizeObserver: Bad Pair',\n key,\n pair\n );\n continue;\n }\n const [container1, container2] = pair;\n const child1 = container1.firstElementChild;\n const child2 = container2.firstElementChild;\n if (\n !(container1 instanceof HTMLElement) ||\n !(container2 instanceof HTMLElement) ||\n !(child1 instanceof HTMLElement) ||\n !(child2 instanceof HTMLElement)\n ) {\n continue;\n }\n\n let item = observedNodes.get(child1);\n\n if (item != null) {\n this.observedNodes.set(child1, item);\n this.observedNodes.set(child2, item);\n observedNodes.delete(child1);\n observedNodes.delete(child2);\n continue;\n }\n\n const child1Height = child1.getBoundingClientRect().height;\n const child2Height = child2.getBoundingClientRect().height;\n item = {\n type: 'annotations',\n column1: {\n container: container1,\n child: child1,\n childHeight: child1Height,\n },\n column2: {\n container: container2,\n child: child2,\n childHeight: child2Height,\n },\n currentHeight: 'auto',\n };\n annotationUpdates.add({\n child1,\n child2,\n item,\n newHeight: Math.max(child1Height, child2Height),\n });\n }\n\n // Measure all annotation heights first, then apply the paired min-height\n // styles after the read phase so setup does not bounce between layout\n // reads and writes for every annotation pair.\n for (const pendingUpdate of annotationUpdates) {\n this.applyNewHeight(pendingUpdate.item, pendingUpdate.newHeight);\n this.observedNodes.set(pendingUpdate.child1, pendingUpdate.item);\n this.observedNodes.set(pendingUpdate.child2, pendingUpdate.item);\n this.observe(pendingUpdate.child1);\n this.observe(pendingUpdate.child2);\n }\n annotationUpdates.clear();\n }\n\n // Cleanup any old nodes that might still be observed\n for (const [element, item] of observedNodes) {\n this.unobserve(element);\n if (item.type === 'code') {\n cleanupStaleCodeItem(item);\n } else {\n cleanupStaleAnnotationItem(item);\n }\n }\n observedNodes.clear();\n }\n\n cleanUp(): void {\n for (const element of this.observedNodes.keys()) {\n this.unobserve(element);\n }\n this.observedNodes.clear();\n }\n\n private observe(element: HTMLElement): void {\n const { managersByElement } = ResizeManager;\n const owner = managersByElement.get(element);\n // Already registered\n if (owner === this) {\n return;\n }\n // If we've already somehow registered with another manager, we in for a\n // world of pain, so complain loudly\n else if (owner != null && owner !== this) {\n throw new Error(\n 'ResizeManager.observe: element is already owned by another ResizeManager'\n );\n }\n managersByElement.set(element, this);\n ResizeManager.getResizeObserver().observe(element);\n }\n\n private unobserve(element: HTMLElement): void {\n const { managersByElement, resizeObserver } = ResizeManager;\n const owner = managersByElement.get(element);\n if (owner == null) {\n return;\n } else if (owner !== this) {\n throw new Error(\n 'ResizeManager.unobserve: element is owned by another ResizeManager'\n );\n }\n\n managersByElement.delete(element);\n resizeObserver?.unobserve(element);\n if (resizeObserver != null && managersByElement.size === 0) {\n resizeObserver.disconnect();\n ResizeManager.resizeObserver = undefined;\n }\n }\n\n private handleResizeEntries(entries: ResizeObserverEntry[]) {\n const codeUpdates: CodeUpdateMap = new Map();\n const annotationUpdates: Set<ObservedAnnotationNodes> = new Set();\n for (const entry of entries) {\n const { target, borderBoxSize, contentBoxSize } = entry;\n if (!(target instanceof HTMLElement)) {\n console.error(\n 'ResizeManager.handleResizeEntries: Invalid element for ResizeObserver',\n entry\n );\n continue;\n }\n const item = this.observedNodes.get(target);\n if (item == null) {\n console.error(\n 'ResizeManager.handleResizeEntries: Not a valid observed node',\n entry\n );\n continue;\n }\n if (item.type === 'annotations') {\n const column = (() => {\n if (target === item.column1.child) {\n return item.column1;\n }\n if (target === item.column2.child) {\n return item.column2;\n }\n return undefined;\n })();\n\n if (column == null) {\n console.error(\n `ResizeManager.handleResizeEntries: Couldn't find a column for`,\n { item, target }\n );\n continue;\n }\n\n column.childHeight = borderBoxSize[0].blockSize;\n annotationUpdates.add(item);\n } else if (item.type === 'code') {\n const update = codeUpdates.get(item) ?? {};\n const inlineSize = contentBoxSize[0].inlineSize;\n if (target === item.codeElement) {\n update.codeInlineSize = inlineSize;\n } else if (target === item.numberElement) {\n update.numberInlineSize = inlineSize;\n }\n codeUpdates.set(item, update);\n }\n }\n this.applyAnnotationUpdates(annotationUpdates);\n annotationUpdates.clear();\n this.applyColumnUpdates(codeUpdates);\n codeUpdates.clear();\n }\n\n private applyAnnotationUpdates(\n annotationUpdates: Set<ObservedAnnotationNodes>\n ) {\n for (const item of annotationUpdates) {\n this.applyNewHeight(\n item,\n Math.max(item.column1.childHeight, item.column2.childHeight)\n );\n }\n }\n\n private applyColumnUpdates = (queuedUpdates: CodeUpdateMap) => {\n for (const [item, update] of queuedUpdates) {\n const nextCodeWidth =\n update.codeInlineSize != null\n ? resolveCodeWidth(update.codeInlineSize)\n : item.codeWidth;\n const nextNumberWidth =\n update.numberInlineSize != null\n ? resolveNumberWidth(update.numberInlineSize)\n : item.numberWidth;\n const codeWidthChanged = nextCodeWidth !== item.codeWidth;\n const numberWidthChanged = nextNumberWidth !== item.numberWidth;\n\n if (!codeWidthChanged && !numberWidthChanged) {\n continue;\n }\n\n item.codeWidth = nextCodeWidth;\n item.numberWidth = nextNumberWidth;\n\n if (codeWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-width',\n `${typeof nextCodeWidth === 'number' ? `${nextCodeWidth}px` : 'auto'}`\n );\n }\n\n if (numberWidthChanged) {\n item.codeElement.style.setProperty(\n '--diffs-column-number-width',\n `${nextNumberWidth === 0 ? 'auto' : `${nextNumberWidth}px`}`\n );\n }\n\n if (\n codeWidthChanged ||\n (numberWidthChanged && nextCodeWidth !== 'auto')\n ) {\n const targetWidth =\n typeof nextCodeWidth === 'number'\n ? Math.max(nextCodeWidth - nextNumberWidth, 0)\n : 0;\n item.codeElement.style.setProperty(\n '--diffs-column-content-width',\n `${targetWidth > 0 ? `${targetWidth}px` : 'auto'}`\n );\n }\n }\n };\n\n private applyNewHeight(item: ObservedAnnotationNodes, newHeight: number) {\n if (newHeight !== item.currentHeight) {\n item.currentHeight = Math.max(newHeight, 0);\n item.column1.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n item.column2.container.style.setProperty(\n '--diffs-annotation-min-height',\n `${item.currentHeight}px`\n );\n }\n }\n}\n\nfunction resolveCodeWidth(inlineSize: number): number | 'auto' {\n const width = Math.max(Math.floor(inlineSize), 0);\n return width === 0 ? 'auto' : width;\n}\n\nfunction resolveNumberWidth(inlineSize: number): number {\n return Math.max(Math.ceil(inlineSize), 0);\n}\n\nfunction cleanupStaleCodeItem(item: ObservedGridNodes): void {\n if (item.codeElement.isConnected) {\n item.codeElement.style.removeProperty('--diffs-column-content-width');\n item.codeElement.style.removeProperty('--diffs-column-number-width');\n item.codeElement.style.removeProperty('--diffs-column-width');\n }\n}\n\nfunction cleanupStaleAnnotationItem(item: ObservedAnnotationNodes): void {\n if (item.column1.container.isConnected) {\n item.column1.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n if (item.column2.container.isConnected) {\n item.column2.container.style.removeProperty(\n '--diffs-annotation-min-height'\n );\n }\n}\n"],"mappings":";AAiBA,IAAa,gBAAb,MAAa,cAAc;CAEzB,OAAe;CACf,OAAe,oCAAoB,IAAI,KAA6B;CAEpE,OAAe,oBAAoC;EACjD,MAAM,iBACJ,cAAc,kBACd,IAAI,eAAe,cAAc,0BAA0B;AAC7D,gBAAc,iBAAiB;AAC/B,SAAO;;CAGT,OAAe,0BAA0B,SAAgC;EAGvE,MAAM,mCAAmB,IAAI,KAA2C;AACxE,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,UAAU,cAAc,kBAAkB,IAAI,MAAM,OAAO;AACjE,OAAI,WAAW,KACb;GAEF,MAAM,iBAAiB,iBAAiB,IAAI,QAAQ;AACpD,OAAI,kBAAkB,KACpB,kBAAiB,IAAI,SAAS,CAAC,MAAM,CAAC;OAEtC,gBAAe,KAAK,MAAM;;AAI9B,OAAK,MAAM,CAAC,SAAS,mBAAmB,iBACtC,SAAQ,oBAAoB,eAAe;;CAI/C,AAAQ,gCAAgB,IAAI,KAGzB;CAEH,MAAM,KAAqB,oBAAmC;EAC5D,MAAM,oCAAoB,IAAI,KAAsB;EACpD,IAAI,cAAc;EAClB,MAAM,gBAAgB,IAAI,IAAI,KAAK,cAAc;AACjD,OAAK,cAAc,OAAO;AAE1B,OAAK,MAAM,WAAW,IAAI,UAAU;AAClC,OAAI,gBAAgB,EAClB;GAEF,MAAMA,qBAA8C;AAClD,QAAI,mBAAmB,eAAe,QAAQ,YAAY,OACxD,QAAO;OAGP;AACJ,OAAI,eAAe,KACjB;AAEF;GACA,IAAIC,OACF,cAAc,IAAI,YAAY;AAChC,OAAI,QAAQ,QAAQ,KAAK,SAAS,OAChC,OAAM,IAAI,MACR,iGACD;GAGH,IAAI,gBAAgB,YAAY;AAChC,OAAI,EAAE,yBAAyB,aAC7B,iBAAgB;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Q,eAAe,MAA+B,WAAmB;AACvE,MAAI,cAAc,KAAK,eAAe;AACpC,QAAK,gBAAgB,KAAK,IAAI,WAAW,EAAE;AAC3C,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;AACD,QAAK,QAAQ,UAAU,MAAM,YAC3B,iCACA,GAAG,KAAK,cAAc,IACvB;;;;AAKP,SAAS,iBAAiB,YAAqC;CAC7D,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,WAAW,EAAE,EAAE;AACjD,QAAO,UAAU,IAAI,SAAS;;AAGhC,SAAS,mBAAmB,YAA4B;AACtD,QAAO,KAAK,IAAI,KAAK,KAAK,WAAW,EAAE,EAAE;;AAG3C,SAAS,qBAAqB,MAA+B;AAC3D,KAAI,KAAK,YAAY,aAAa;AAChC,OAAK,YAAY,MAAM,eAAe,+BAA+B;AACrE,OAAK,YAAY,MAAM,eAAe,8BAA8B;AACpE,OAAK,YAAY,MAAM,eAAe,uBAAuB;;;AAIjE,SAAS,2BAA2B,MAAqC;AACvE,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD;AAEH,KAAI,KAAK,QAAQ,UAAU,YACzB,MAAK,QAAQ,UAAU,MAAM,eAC3B,gCACD"}
|
package/dist/react/CodeView.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ interface CodeViewHandle<LAnnotation> {
|
|
|
34
34
|
addItems(items: readonly CodeViewItem<LAnnotation>[]): void;
|
|
35
35
|
getItem(id: string): CodeViewItem<LAnnotation> | undefined;
|
|
36
36
|
updateItem(item: CodeViewItem<LAnnotation>): boolean;
|
|
37
|
+
updateItemId(oldId: string, newId: string): boolean;
|
|
37
38
|
scrollTo(target: CodeViewScrollTarget): void;
|
|
38
39
|
setSelectedLines(selection: CodeViewLineSelection | null): void;
|
|
39
40
|
getSelectedLines(): CodeViewLineSelection | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.d.ts","names":["CSSProperties","ReactNode","Ref","CodeView","CodeViewClass","CodeViewItem","CodeViewLineSelection","CodeViewOptions","CodeViewScrollTarget","DiffLineAnnotation","GetHoveredLineResult","LineAnnotation","CodeViewGutterUtilityGetter","CodeViewBaseProps","LAnnotation","HTMLDivElement","ControlledCodeViewProps","UncontrolledCodeViewProps","CodeViewProps","CodeViewHandle","CodeViewComponent","React","JSX","Element"],"sources":["../../src/react/CodeView.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode, type Ref } from 'react';\nimport { CodeView as CodeViewClass, type CodeViewItem, type CodeViewLineSelection, type CodeViewOptions, type CodeViewScrollTarget, type DiffLineAnnotation, type GetHoveredLineResult, type LineAnnotation } from '../index';\ntype CodeViewGutterUtilityGetter = (() => GetHoveredLineResult<'file'> | undefined) | (() => GetHoveredLineResult<'diff'> | undefined);\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>, item: CodeViewItem<LAnnotation>): ReactNode;\n renderGutterUtility?(getHoveredLine: CodeViewGutterUtilityGetter, item: CodeViewItem<LAnnotation>): ReactNode;\n}\nexport interface ControlledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\nexport interface UncontrolledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\nexport type CodeViewProps<LAnnotation = undefined> = ControlledCodeViewProps<LAnnotation> | UncontrolledCodeViewProps<LAnnotation>;\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\ntype CodeViewComponent = <LAnnotation = undefined>(props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n}) => React.JSX.Element;\nexport declare const CodeView: CodeViewComponent;\nexport {};\n//# sourceMappingURL=CodeView.d.ts.map"],"mappings":";;;;;;;KAEKY,2BAAAA,UAAqCF,mDAAmDA;UACnFG;YACIN,gBAAgBO;;UAElBd;EAJPY,YAAAA,CAAAA,EAKcV,GALdU,CAKkBG,cALS,CAAA;EACtBF,iBAAAA,CAAAA,EAAiB,OAAAC;EACGA,aAAAA,CAAAA,EAKVR,qBALUQ,GAAAA,IAAAA;EAAhBP,qBAAAA,EAAAA,SAAAA,EAMwBD,qBANxBC,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAEFP,QAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAK6BI,UAL7BJ,CAK2Cc,WAL3Cd,CAAAA,CAAAA,EAAAA,IAAAA;EACWe,kBAAAA,EAAAA,IAAAA,EAKOV,YALPU,CAKoBD,WALpBC,CAAAA,CAAAA,EAKmCd,SALnCc;EAAJb,kBAAAA,EAAAA,IAAAA,EAMWG,YANXH,CAMwBY,WANxBZ,CAAAA,CAAAA,EAMuCD,SANvCC;EAECI,oBAAAA,EAAAA,IAAAA,EAKYD,YALZC,CAKyBQ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AA,OAAAA;EAAoDK,QAAAA,CAAAA,MAAAA,
|
|
1
|
+
{"version":3,"file":"CodeView.d.ts","names":["CSSProperties","ReactNode","Ref","CodeView","CodeViewClass","CodeViewItem","CodeViewLineSelection","CodeViewOptions","CodeViewScrollTarget","DiffLineAnnotation","GetHoveredLineResult","LineAnnotation","CodeViewGutterUtilityGetter","CodeViewBaseProps","LAnnotation","HTMLDivElement","ControlledCodeViewProps","UncontrolledCodeViewProps","CodeViewProps","CodeViewHandle","CodeViewComponent","React","JSX","Element"],"sources":["../../src/react/CodeView.d.ts"],"sourcesContent":["import { type CSSProperties, type ReactNode, type Ref } from 'react';\nimport { CodeView as CodeViewClass, type CodeViewItem, type CodeViewLineSelection, type CodeViewOptions, type CodeViewScrollTarget, type DiffLineAnnotation, type GetHoveredLineResult, type LineAnnotation } from '../index';\ntype CodeViewGutterUtilityGetter = (() => GetHoveredLineResult<'file'> | undefined) | (() => GetHoveredLineResult<'diff'> | undefined);\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>, item: CodeViewItem<LAnnotation>): ReactNode;\n renderGutterUtility?(getHoveredLine: CodeViewGutterUtilityGetter, item: CodeViewItem<LAnnotation>): ReactNode;\n}\nexport interface ControlledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\nexport interface UncontrolledCodeViewProps<LAnnotation> extends CodeViewBaseProps<LAnnotation> {\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\nexport type CodeViewProps<LAnnotation = undefined> = ControlledCodeViewProps<LAnnotation> | UncontrolledCodeViewProps<LAnnotation>;\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\ntype CodeViewComponent = <LAnnotation = undefined>(props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n}) => React.JSX.Element;\nexport declare const CodeView: CodeViewComponent;\nexport {};\n//# sourceMappingURL=CodeView.d.ts.map"],"mappings":";;;;;;;KAEKY,2BAAAA,UAAqCF,mDAAmDA;UACnFG;YACIN,gBAAgBO;;UAElBd;EAJPY,YAAAA,CAAAA,EAKcV,GALdU,CAKkBG,cALS,CAAA;EACtBF,iBAAAA,CAAAA,EAAiB,OAAAC;EACGA,aAAAA,CAAAA,EAKVR,qBALUQ,GAAAA,IAAAA;EAAhBP,qBAAAA,EAAAA,SAAAA,EAMwBD,qBANxBC,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAEFP,QAAAA,EAAAA,SAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAK6BI,UAL7BJ,CAK2Cc,WAL3Cd,CAAAA,CAAAA,EAAAA,IAAAA;EACWe,kBAAAA,EAAAA,IAAAA,EAKOV,YALPU,CAKoBD,WALpBC,CAAAA,CAAAA,EAKmCd,SALnCc;EAAJb,kBAAAA,EAAAA,IAAAA,EAMWG,YANXH,CAMw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A,SAAAA;EAAnBL,UAAAA,CAAAA,IAAAA,EAe3CJ,YAf2CI,CAe9BK,WAf8BL,CAAAA,CAAAA,EAAAA,OAAAA;EAAoDK,YAAAA,CAAAA,KAAAA,EAAAA,MAAAA,EAAAA,KAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;EAAbT,QAAAA,CAAAA,MAAAA,EAiBlFG,oBAjBkFH,CAAAA,EAAAA,IAAAA;EAA4BJ,gBAAAA,CAAAA,SAAAA,EAkBnGK,qBAlBmGL,GAAAA,IAAAA,CAAAA,EAAAA,IAAAA;EAC1FW,gBAAAA,EAAAA,EAkBjBN,qBAlBiBM,GAAAA,IAAAA;EAAgDE,kBAAAA,EAAAA,EAAAA,IAAAA;EAAbT,WAAAA,EAAAA,EAoBzDD,UApByDC,CAoB3CS,WApB2CT,CAAAA,GAAAA,SAAAA;;KAsBvEe,iBAAAA,GAtB4G,CAAA,cAAA,SAAA,CAAA,CAAA,KAAA,EAsBvDF,aAtBuD,CAsBzCJ,WAtByC,CAAA,GAAA;EAEhGE,GAAAA,CAAAA,EAqBPK,KAAAA,CAAMnB,GArBCc,CAqBGG,cArBoB,CAqBLL,WArBKA,CAAAA,CAAAA;CAAwCA,EAAAA,GAsB1EO,KAAAA,CAAMC,GAAAA,CAAIC,OAtBgET;AAC/CA,cAsBZX,QAtBYW,EAsBFM,iBAtBEN"}
|
package/dist/react/CodeView.js
CHANGED
|
@@ -160,6 +160,15 @@ function CodeViewInner(props, ref) {
|
|
|
160
160
|
}
|
|
161
161
|
return instance.updateItem(item);
|
|
162
162
|
},
|
|
163
|
+
updateItemId(oldId, newId) {
|
|
164
|
+
const { controlled: controlled$1, instance } = cachedDataRef.current;
|
|
165
|
+
assertUncontrolledCodeViewAction(controlled$1, "updateItemId");
|
|
166
|
+
if (instance == null) {
|
|
167
|
+
console.error("CodeView.updateItemId: no valid instance to update item id with", oldId, newId);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return instance.updateItemId(oldId, newId);
|
|
171
|
+
},
|
|
163
172
|
scrollTo(target) {
|
|
164
173
|
const { instance } = cachedDataRef.current;
|
|
165
174
|
if (instance == null) console.error("CodeView.scrollTo: no valid instance to scroll with", target);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.js","names":["CodeViewClass","slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined","controlled","snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined","SlotPortals"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type DiffLineAnnotation,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewRenderedItem<LAnnotation>[] | undefined;\n publish(snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {hasRenderers && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n controlledSelection,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n onSelectedLinesChange == null &&\n !controlledSelection\n ) {\n return options;\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n options.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n options.renderGutterUtility = noopRender;\n }\n\n return options;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: SlotPortalsProps<LAnnotation>) {\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const renderedItems = useSyncExternalStore<\n CodeViewRenderedItem<LAnnotation>[] | undefined\n >(subscribe, getSnapshot, getSnapshot);\n return renderedItems?.map((renderedItem) => {\n return createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n );\n });\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAoF9C,SAAS,mBACP,YAC4B;AAC5B,QAAO;EACL,UAAU;EACV,OAAO;EACP;EACA,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EAClB;;AAGH,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,oBAAoB,OACpB,cACA,OAAO,iBACP,UACA,uBACA,SACA,kBACA,oBACA,qBACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB;CACvC,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,gBAAgB,OACpB,mBAAgC,WAAW,CAC5C;CACD,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,0BAA0B,mBAC7B,cAA4C;AAC3C,0BAAwB,UAAU;GAErC;CACD,MAAM,sBAAsB,kBAAkB;CAE9C,MAAM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K,iBAAiB;AAC1C,SAAO,aACL,2BAA2B;GACzB;GACA;GACA;GACA;GACA;GACA;GACD,CAAC,EACF,aAAa,SACb,aAAa,GACd;GACD;EACF;AAEF,SAAS,2BAAwC,EAC/C,cACA,oBACA,oBACA,sBACA,kBACA,uBAC0D;AAC1D,KAAI,aAAa,SAAS,QAAQ;EAChC,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,UAAU,KAAK;GACf,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;QACG;EACL,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;;;AAIN,SAAS,aAAa"}
|
|
1
|
+
{"version":3,"file":"CodeView.js","names":["CodeViewClass","slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined","controlled","snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined","SlotPortals"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type DiffLineAnnotation,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewRenderedItem<LAnnotation>[] | undefined;\n publish(snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n if (!hasHeaderRenderers && !hasAnnotationRenderer && !hasGutterRenderer) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {hasRenderers && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewRenderedItem<LAnnotation>[] | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n onSelectedLinesChange,\n controlledSelection,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n onSelectedLinesChange == null &&\n !controlledSelection\n ) {\n return options;\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n options.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n options.renderGutterUtility = noopRender;\n }\n\n return options;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: SlotPortalsProps<LAnnotation>) {\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const renderedItems = useSyncExternalStore<\n CodeViewRenderedItem<LAnnotation>[] | undefined\n >(subscribe, getSnapshot, getSnapshot);\n return renderedItems?.map((renderedItem) => {\n return createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n );\n });\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAqF9C,SAAS,mBACP,YAC4B;AAC5B,QAAO;EACL,UAAU;EACV,OAAO;EACP;EACA,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EAClB;;AAGH,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,oBAAoB,OACpB,cACA,OAAO,iBACP,UACA,uBACA,SACA,kBACA,oBACA,qBACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB;CACvC,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,gBAAgB,OACpB,mBAAgC,WAAW,CAC5C;CACD,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,0BAA0B,mBAC7B,cAA4C;AAC3C,0BAAwB,UAAU;GAErC;CACD,MAAM,sBAAsB,kBAAkB;CAE9C,MAAM,iBAAiB,cAEnB,6BAA6B;EAC3B;EACA;EACA;EACA,uBACE,yBAAyB,OAAO,0BAA0B;EAC5D;EACD,CAAC,EACJ;EACE;EACA;EACA;EACA;EACA;EACA;EACD,CACF;CAED,MAAM,CAAC,oBAAoB,eACzB,wBAAw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W,aAAa,YAAY,EAChB,KAAK,iBAAiB;AAC1C,SAAO,aACL,2BAA2B;GACzB;GACA;GACA;GACA;GACA;GACA;GACD,CAAC,EACF,aAAa,SACb,aAAa,GACd;GACD;EACF;AAEF,SAAS,2BAAwC,EAC/C,cACA,oBACA,oBACA,sBACA,kBACA,uBAC0D;AAC1D,KAAI,aAAa,SAAS,QAAQ;EAChC,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,UAAU,KAAK;GACf,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;QACG;EACL,MAAM,EAAE,MAAM,aAAa;AAC3B,SAAO,mBAAmB;GACxB,MAAM,KAAK;GACX,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,oBACE,sBAAsB,aAAa,mBAAmB,KAAK,GAAG;GAChE,sBACE,wBAAwB,aACd,qBAAqB,KAAK,GAChC;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,KAAK,GAClD;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,KAAK,GAC7D;GACN,gBAAgB,SAAS;GAC1B,CAAC;;;AAIN,SAAS,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":["CSSProperties","GutterUtilitySlotStyles","MergeConflictSlotStyles","noopRender"],"sources":["../../src/react/constants.d.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nexport declare const GutterUtilitySlotStyles: CSSProperties;\nexport declare const MergeConflictSlotStyles: CSSProperties;\nexport declare function noopRender(): null;\n//# sourceMappingURL=constants.d.ts.map"],"mappings":";;;cACqBC,yBAAyBD;cACzBE,yBAAyBF;AADzBC,iBAEGE,UAAAA,CAAAA,CAFmC,EAAA,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":["CSSProperties","GutterUtilitySlotStyles","MergeConflictSlotStyles","noopRender"],"sources":["../../src/react/constants.d.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\nexport declare const GutterUtilitySlotStyles: CSSProperties;\nexport declare const MergeConflictSlotStyles: CSSProperties;\nexport declare function noopRender(): null;\n//# sourceMappingURL=constants.d.ts.map"],"mappings":";;;cACqBC,yBAAyBD;cACzBE,yBAAyBF;AADzBC,iBAEGE,UAAAA,CAAAA,CAFmC,EAAA,IAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -583,8 +583,9 @@ interface VirtualFileMetrics {
|
|
|
583
583
|
lineHeight: number;
|
|
584
584
|
/** Height reserved for the file or diff header region. */
|
|
585
585
|
diffHeaderHeight: number;
|
|
586
|
-
/** Height reserved for each collapsed-context separator row.
|
|
587
|
-
|
|
586
|
+
/** Height reserved for each collapsed-context separator row. Only set this
|
|
587
|
+
* if you customized the size of hunk separators via unsafeCSS */
|
|
588
|
+
hunkSeparatorHeight?: number;
|
|
588
589
|
/** Vertical spacing used around hunks and file-level padding. You should not
|
|
589
590
|
* change this from the default if you aren't applying custom CSS */
|
|
590
591
|
spacing: number;
|