@pierre/diffs 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/components/AdvancedVirtualizedFileDiff.d.ts.map +1 -1
  2. package/dist/components/File.d.ts.map +1 -1
  3. package/dist/components/FileDiff.d.ts +4 -4
  4. package/dist/components/FileDiff.d.ts.map +1 -1
  5. package/dist/components/FileDiff.js.map +1 -1
  6. package/dist/components/UnresolvedFile.d.ts +18 -9
  7. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  8. package/dist/components/UnresolvedFile.js +199 -57
  9. package/dist/components/UnresolvedFile.js.map +1 -1
  10. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  11. package/dist/constants.d.ts +5 -1
  12. package/dist/constants.d.ts.map +1 -1
  13. package/dist/constants.js +5 -1
  14. package/dist/constants.js.map +1 -1
  15. package/dist/index.d.ts +7 -6
  16. package/dist/index.js +5 -4
  17. package/dist/react/UnresolvedFile.d.ts +3 -1
  18. package/dist/react/UnresolvedFile.d.ts.map +1 -1
  19. package/dist/react/UnresolvedFile.js.map +1 -1
  20. package/dist/react/index.d.ts +2 -2
  21. package/dist/react/jsx.d.ts.map +1 -1
  22. package/dist/react/utils/renderDiffChildren.d.ts +1 -1
  23. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  24. package/dist/react/utils/renderDiffChildren.js +6 -4
  25. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  26. package/dist/react/utils/useUnresolvedFileInstance.d.ts +5 -4
  27. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  28. package/dist/react/utils/useUnresolvedFileInstance.js +15 -12
  29. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  30. package/dist/renderers/DiffHunksRenderer.d.ts +15 -7
  31. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  32. package/dist/renderers/DiffHunksRenderer.js +9 -7
  33. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  34. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +11 -16
  35. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  36. package/dist/renderers/UnresolvedFileHunksRenderer.js +68 -75
  37. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  38. package/dist/ssr/index.d.ts +2 -2
  39. package/dist/ssr/preloadDiffs.d.ts +2 -2
  40. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  41. package/dist/ssr/preloadDiffs.js +4 -3
  42. package/dist/ssr/preloadDiffs.js.map +1 -1
  43. package/dist/style.js +1 -1
  44. package/dist/style.js.map +1 -1
  45. package/dist/types.d.ts +41 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/utils/areMergeConflictActionsEqual.js +1 -1
  48. package/dist/utils/areMergeConflictActionsEqual.js.map +1 -1
  49. package/dist/utils/diffAcceptRejectHunk.d.ts +3 -2
  50. package/dist/utils/diffAcceptRejectHunk.d.ts.map +1 -1
  51. package/dist/utils/diffAcceptRejectHunk.js +24 -89
  52. package/dist/utils/diffAcceptRejectHunk.js.map +1 -1
  53. package/dist/utils/getMergeConflictActionSlotName.d.ts +4 -6
  54. package/dist/utils/getMergeConflictActionSlotName.d.ts.map +1 -1
  55. package/dist/utils/getMergeConflictActionSlotName.js +2 -2
  56. package/dist/utils/getMergeConflictActionSlotName.js.map +1 -1
  57. package/dist/utils/getMergeConflictLineTypes.d.ts +1 -2
  58. package/dist/utils/getMergeConflictLineTypes.d.ts.map +1 -1
  59. package/dist/utils/getMergeConflictLineTypes.js +7 -12
  60. package/dist/utils/getMergeConflictLineTypes.js.map +1 -1
  61. package/dist/utils/normalizeDiffResolution.d.ts +7 -0
  62. package/dist/utils/normalizeDiffResolution.d.ts.map +1 -0
  63. package/dist/utils/normalizeDiffResolution.js +11 -0
  64. package/dist/utils/normalizeDiffResolution.js.map +1 -0
  65. package/dist/utils/parseMergeConflictDiffFromFile.d.ts +16 -12
  66. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  67. package/dist/utils/parseMergeConflictDiffFromFile.js +474 -117
  68. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  69. package/dist/utils/resolveConflict.d.ts +7 -0
  70. package/dist/utils/resolveConflict.d.ts.map +1 -0
  71. package/dist/utils/resolveConflict.js +23 -0
  72. package/dist/utils/resolveConflict.js.map +1 -0
  73. package/dist/utils/resolveRegion.d.ts +14 -0
  74. package/dist/utils/resolveRegion.d.ts.map +1 -0
  75. package/dist/utils/resolveRegion.js +215 -0
  76. package/dist/utils/resolveRegion.js.map +1 -0
  77. package/dist/utils/trimPatchContext.js +19 -20
  78. package/dist/utils/trimPatchContext.js.map +1 -1
  79. package/dist/worker/{wasm-BlUZCxHM.js → wasm-BaDzIkIn.js} +2 -2
  80. package/dist/worker/wasm-BaDzIkIn.js.map +1 -0
  81. package/dist/worker/worker-portable.js +4880 -4810
  82. package/dist/worker/worker-portable.js.map +1 -1
  83. package/dist/worker/worker.js.map +1 -1
  84. package/package.json +2 -1
  85. package/dist/utils/resolveMergeConflict.d.ts +0 -7
  86. package/dist/utils/resolveMergeConflict.d.ts.map +0 -1
  87. package/dist/utils/resolveMergeConflict.js +0 -30
  88. package/dist/utils/resolveMergeConflict.js.map +0 -1
  89. package/dist/worker/wasm-BlUZCxHM.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { FileContents, FileDiffMetadata, MergeConflictActionPayload, MergeConflictResolution } from "../types.js";
1
+ import { FileContents, FileDiffMetadata, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictResolution } from "../types.js";
2
2
  import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
3
3
  import "../worker/index.js";
4
4
  import { HunksRenderResult } from "../renderers/DiffHunksRenderer.js";
@@ -9,27 +9,34 @@ import { FileDiff, FileDiffOptions, FileDiffRenderProps } from "./FileDiff.js";
9
9
  //#region src/components/UnresolvedFile.d.ts
10
10
  type RenderMergeConflictActions<LAnnotation> = (action: MergeConflictDiffAction, instance: UnresolvedFile<LAnnotation>) => HTMLElement | DocumentFragment | null | undefined;
11
11
  type MergeConflictActionsTypeOption<LAnnotation> = 'none' | 'default' | RenderMergeConflictActions<LAnnotation>;
12
- interface UnresolvedFileOptions<LAnnotation> extends FileDiffOptions<LAnnotation> {
12
+ interface UnresolvedFileOptions<LAnnotation> extends Omit<FileDiffOptions<LAnnotation>, 'diffStyle'> {
13
13
  onPostRender?(node: HTMLElement, instance: UnresolvedFile<LAnnotation>): unknown;
14
14
  mergeConflictActionsType?: MergeConflictActionsTypeOption<LAnnotation>;
15
15
  onMergeConflictAction?(payload: MergeConflictActionPayload, instance: UnresolvedFile<LAnnotation>): void;
16
16
  onMergeConflictResolve?(file: FileContents, payload: MergeConflictActionPayload): void;
17
+ maxContextLines?: number;
17
18
  }
18
19
  interface UnresolvedFileRenderProps<LAnnotation> extends Omit<FileDiffRenderProps<LAnnotation>, 'oldFile' | 'newFile'> {
19
20
  file?: FileContents;
20
- actions?: MergeConflictDiffAction[];
21
+ actions?: (MergeConflictDiffAction | undefined)[];
22
+ markerRows?: MergeConflictMarkerRow[];
21
23
  }
22
24
  interface UnresolvedFileHydrationProps<LAnnotation> extends Omit<UnresolvedFileRenderProps<LAnnotation>, 'file'> {
23
25
  file?: FileContents;
24
- fileDiff?: FileDiffMetadata;
25
- actions?: MergeConflictDiffAction[];
26
26
  fileContainer: HTMLElement;
27
27
  prerenderedHTML?: string;
28
28
  }
29
29
  interface GetOrComputeDiffProps {
30
30
  file: FileContents | undefined;
31
31
  fileDiff: FileDiffMetadata | undefined;
32
- actions: MergeConflictDiffAction[] | undefined;
32
+ actions: (MergeConflictDiffAction | undefined)[] | undefined;
33
+ markerRows: MergeConflictMarkerRow[] | undefined;
34
+ }
35
+ interface ResolveConflictReturn {
36
+ file: FileContents;
37
+ fileDiff: FileDiffMetadata;
38
+ actions: (MergeConflictDiffAction | undefined)[];
39
+ markerRows: MergeConflictMarkerRow[];
33
40
  }
34
41
  type UnresolvedFileDataCache = GetOrComputeDiffProps;
35
42
  declare class UnresolvedFile<LAnnotation = undefined> extends FileDiff<LAnnotation> {
@@ -37,6 +44,7 @@ declare class UnresolvedFile<LAnnotation = undefined> extends FileDiff<LAnnotati
37
44
  readonly __id: string;
38
45
  protected computedCache: UnresolvedFileDataCache;
39
46
  private conflictActions;
47
+ private markerRows;
40
48
  private conflictActionCache;
41
49
  constructor(options?: UnresolvedFileOptions<LAnnotation>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);
42
50
  setOptions(options: UnresolvedFileOptions<LAnnotation> | undefined): void;
@@ -48,14 +56,15 @@ declare class UnresolvedFile<LAnnotation = undefined> extends FileDiff<LAnnotati
48
56
  hydrate(props: UnresolvedFileHydrationProps<LAnnotation>): void;
49
57
  rerender(): void;
50
58
  render(props?: UnresolvedFileRenderProps<LAnnotation>): boolean;
51
- resolveConflict(conflictIndex: number, resolution: MergeConflictResolution, file?: FileContents | undefined): FileContents | undefined;
59
+ resolveConflict(conflictIndex: number, resolution: MergeConflictResolution, fileDiff?: FileDiffMetadata | undefined): ResolveConflictReturn | undefined;
52
60
  private resolveConflictAndRender;
53
- private setActiveMergeConflictActions;
61
+ private setActiveMergeConflictState;
54
62
  private handleMergeConflictActionClick;
55
63
  private renderMergeConflictActionSlots;
56
64
  private renderMergeConflictAction;
57
65
  private clearMergeConflictActionCache;
58
66
  }
67
+ declare function getUnresolvedDiffHunksRendererOptions<LAnnotation>(options?: UnresolvedFileOptions<LAnnotation>, baseOptions?: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRendererOptions;
59
68
  //#endregion
60
- export { MergeConflictActionsTypeOption, RenderMergeConflictActions, UnresolvedFile, UnresolvedFileHydrationProps, UnresolvedFileOptions, UnresolvedFileRenderProps };
69
+ export { MergeConflictActionsTypeOption, RenderMergeConflictActions, UnresolvedFile, UnresolvedFileHydrationProps, UnresolvedFileOptions, UnresolvedFileRenderProps, getUnresolvedDiffHunksRendererOptions };
61
70
  //# sourceMappingURL=UnresolvedFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnresolvedFile.d.ts","names":["HunksRenderResult","UnresolvedFileHunksRenderer","UnresolvedFileHunksRendererOptions","FileContents","FileDiffMetadata","MergeConflictActionPayload","MergeConflictResolution","MergeConflictDiffAction","WorkerPoolManager","FileDiff","FileDiffOptions","FileDiffRenderProps","RenderMergeConflictActions","LAnnotation","UnresolvedFile","HTMLElement","DocumentFragment","MergeConflictActionsTypeOption","UnresolvedFileOptions","UnresolvedFileRenderProps","Omit","UnresolvedFileHydrationProps","GetOrComputeDiffProps","UnresolvedFileDataCache","HTMLPreElement"],"sources":["../../src/components/UnresolvedFile.d.ts"],"sourcesContent":["import type { HunksRenderResult } from '../renderers/DiffHunksRenderer';\nimport { UnresolvedFileHunksRenderer, type UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type { FileContents, FileDiffMetadata, MergeConflictActionPayload, MergeConflictResolution } from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { WorkerPoolManager } from '../worker';\nimport { FileDiff, type FileDiffOptions, type FileDiffRenderProps } from './FileDiff';\nexport type RenderMergeConflictActions<LAnnotation> = (action: MergeConflictDiffAction, instance: UnresolvedFile<LAnnotation>) => HTMLElement | DocumentFragment | null | undefined;\nexport type MergeConflictActionsTypeOption<LAnnotation> = 'none' | 'default' | RenderMergeConflictActions<LAnnotation>;\nexport interface UnresolvedFileOptions<LAnnotation> extends FileDiffOptions<LAnnotation> {\n onPostRender?(node: HTMLElement, instance: UnresolvedFile<LAnnotation>): unknown;\n mergeConflictActionsType?: MergeConflictActionsTypeOption<LAnnotation>;\n onMergeConflictAction?(payload: MergeConflictActionPayload, instance: UnresolvedFile<LAnnotation>): void;\n onMergeConflictResolve?(file: FileContents, payload: MergeConflictActionPayload): void;\n}\nexport interface UnresolvedFileRenderProps<LAnnotation> extends Omit<FileDiffRenderProps<LAnnotation>, 'oldFile' | 'newFile'> {\n file?: FileContents;\n actions?: MergeConflictDiffAction[];\n}\nexport interface UnresolvedFileHydrationProps<LAnnotation> extends Omit<UnresolvedFileRenderProps<LAnnotation>, 'file'> {\n file?: FileContents;\n fileDiff?: FileDiffMetadata;\n actions?: MergeConflictDiffAction[];\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\ninterface GetOrComputeDiffProps {\n file: FileContents | undefined;\n fileDiff: FileDiffMetadata | undefined;\n actions: MergeConflictDiffAction[] | undefined;\n}\ntype UnresolvedFileDataCache = GetOrComputeDiffProps;\nexport declare class UnresolvedFile<LAnnotation = undefined> extends FileDiff<LAnnotation> {\n options: UnresolvedFileOptions<LAnnotation>;\n readonly __id: string;\n protected computedCache: UnresolvedFileDataCache;\n private conflictActions;\n private conflictActionCache;\n constructor(options?: UnresolvedFileOptions<LAnnotation>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);\n setOptions(options: UnresolvedFileOptions<LAnnotation> | undefined): void;\n protected createHunksRenderer(options: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRenderer<LAnnotation>;\n protected getHunksRendererOptions(options: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRendererOptions;\n protected applyPreNodeAttributes(pre: HTMLPreElement, result: HunksRenderResult): void;\n cleanUp(): void;\n private getOrComputeDiff;\n hydrate(props: UnresolvedFileHydrationProps<LAnnotation>): void;\n rerender(): void;\n render(props?: UnresolvedFileRenderProps<LAnnotation>): boolean;\n resolveConflict(conflictIndex: number, resolution: MergeConflictResolution, file?: FileContents | undefined): FileContents | undefined;\n private resolveConflictAndRender;\n private setActiveMergeConflictActions;\n private handleMergeConflictActionClick;\n private renderMergeConflictActionSlots;\n private renderMergeConflictAction;\n private clearMergeConflictActionCache;\n}\nexport {};\n//# sourceMappingURL=UnresolvedFile.d.ts.map"],"mappings":";;;;;;;;;KAMYY,mDAAmDL,mCAAmCO,eAAeD,iBAAiBE,cAAcC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,UAAA,EAsBwBhB,uBAtBxB,EAAA,IAAA,CAAA,EAsBwDH,YAtBxD,GAAA,SAAA,CAAA,EAsBmFA,YAtBnF,GAAA,SAAA;EACrBA,QAAAA,wBAAAA;EACIC,QAAAA,6BAAAA;EACDG,QAAAA,8BAAAA;EAAuB,QAAA,8BAAA;EAE/BgB,QAAAA,yBAAuB;EACPT,QAAAA,6BAAcD"}
1
+ {"version":3,"file":"UnresolvedFile.d.ts","names":["HunksRenderResult","UnresolvedFileHunksRenderer","UnresolvedFileHunksRendererOptions","FileContents","FileDiffMetadata","MergeConflictActionPayload","MergeConflictMarkerRow","MergeConflictResolution","MergeConflictDiffAction","WorkerPoolManager","FileDiff","FileDiffOptions","FileDiffRenderProps","RenderMergeConflictActions","LAnnotation","UnresolvedFile","HTMLElement","DocumentFragment","MergeConflictActionsTypeOption","UnresolvedFileOptions","Omit","UnresolvedFileRenderProps","UnresolvedFileHydrationProps","GetOrComputeDiffProps","ResolveConflictReturn","UnresolvedFileDataCache","HTMLPreElement","getUnresolvedDiffHunksRendererOptions"],"sources":["../../src/components/UnresolvedFile.d.ts"],"sourcesContent":["import type { HunksRenderResult } from '../renderers/DiffHunksRenderer';\nimport { UnresolvedFileHunksRenderer, type UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type { FileContents, FileDiffMetadata, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictResolution } from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { WorkerPoolManager } from '../worker';\nimport { FileDiff, type FileDiffOptions, type FileDiffRenderProps } from './FileDiff';\nexport type RenderMergeConflictActions<LAnnotation> = (action: MergeConflictDiffAction, instance: UnresolvedFile<LAnnotation>) => HTMLElement | DocumentFragment | null | undefined;\nexport type MergeConflictActionsTypeOption<LAnnotation> = 'none' | 'default' | RenderMergeConflictActions<LAnnotation>;\nexport interface UnresolvedFileOptions<LAnnotation> extends Omit<FileDiffOptions<LAnnotation>, 'diffStyle'> {\n onPostRender?(node: HTMLElement, instance: UnresolvedFile<LAnnotation>): unknown;\n mergeConflictActionsType?: MergeConflictActionsTypeOption<LAnnotation>;\n onMergeConflictAction?(payload: MergeConflictActionPayload, instance: UnresolvedFile<LAnnotation>): void;\n onMergeConflictResolve?(file: FileContents, payload: MergeConflictActionPayload): void;\n maxContextLines?: number;\n}\nexport interface UnresolvedFileRenderProps<LAnnotation> extends Omit<FileDiffRenderProps<LAnnotation>, 'oldFile' | 'newFile'> {\n file?: FileContents;\n actions?: (MergeConflictDiffAction | undefined)[];\n markerRows?: MergeConflictMarkerRow[];\n}\nexport interface UnresolvedFileHydrationProps<LAnnotation> extends Omit<UnresolvedFileRenderProps<LAnnotation>, 'file'> {\n file?: FileContents;\n fileContainer: HTMLElement;\n prerenderedHTML?: string;\n}\ninterface GetOrComputeDiffProps {\n file: FileContents | undefined;\n fileDiff: FileDiffMetadata | undefined;\n actions: (MergeConflictDiffAction | undefined)[] | undefined;\n markerRows: MergeConflictMarkerRow[] | undefined;\n}\ninterface ResolveConflictReturn {\n file: FileContents;\n fileDiff: FileDiffMetadata;\n actions: (MergeConflictDiffAction | undefined)[];\n markerRows: MergeConflictMarkerRow[];\n}\ntype UnresolvedFileDataCache = GetOrComputeDiffProps;\nexport declare class UnresolvedFile<LAnnotation = undefined> extends FileDiff<LAnnotation> {\n options: UnresolvedFileOptions<LAnnotation>;\n readonly __id: string;\n protected computedCache: UnresolvedFileDataCache;\n private conflictActions;\n private markerRows;\n private conflictActionCache;\n constructor(options?: UnresolvedFileOptions<LAnnotation>, workerManager?: WorkerPoolManager | undefined, isContainerManaged?: boolean);\n setOptions(options: UnresolvedFileOptions<LAnnotation> | undefined): void;\n protected createHunksRenderer(options: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRenderer<LAnnotation>;\n protected getHunksRendererOptions(options: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRendererOptions;\n protected applyPreNodeAttributes(pre: HTMLPreElement, result: HunksRenderResult): void;\n cleanUp(): void;\n private getOrComputeDiff;\n hydrate(props: UnresolvedFileHydrationProps<LAnnotation>): void;\n rerender(): void;\n render(props?: UnresolvedFileRenderProps<LAnnotation>): boolean;\n resolveConflict(conflictIndex: number, resolution: MergeConflictResolution, fileDiff?: FileDiffMetadata | undefined): ResolveConflictReturn | undefined;\n private resolveConflictAndRender;\n private setActiveMergeConflictState;\n private handleMergeConflictActionClick;\n private renderMergeConflictActionSlots;\n private renderMergeConflictAction;\n private clearMergeConflictActionCache;\n}\nexport declare function getUnresolvedDiffHunksRendererOptions<LAnnotation>(options?: UnresolvedFileOptions<LAnnotation>, baseOptions?: UnresolvedFileOptions<LAnnotation>): UnresolvedFileHunksRendererOptions;\nexport {};\n//# sourceMappingURL=UnresolvedFile.d.ts.map"],"mappings":";;;;;;;;;KAMYa,mDAAmDL,mCAAmCO,eAAeD,iBAAiBE,cAAcC;KACpIC,mEAAmEL,2BAA2BC;UACzFK,2CAA2CC,KAAKT,gBAAgBG;EAFrED,YAAAA,EAAAA,IAAAA,EAGYG,WAHc,EAAA,QAAAF,EAGSC,cAHT,CAGwBD,WAHxB,CAAA,CAAA,EAAA,OAAA;EAAyBN,wBAAAA,CAAAA,EAIhCU,8BAJgCV,CAIDM,WAJCN,CAAAA;EAAkDM,qBAAAA,EAAAA,OAAAA,EAK7ET,0BAL6ES,EAAAA,QAAAA,EAKvCC,cALuCD,CAKxBA,WALwBA,CAAAA,CAAAA,EAAAA,IAAAA;EAAfC,sBAAAA,EAAAA,IAAAA,EAMhEZ,YANgEY,EAAAA,OAAAA,EAMzCV,0BANyCU,CAAAA,EAAAA,IAAAA;EAAgCC,eAAAA,CAAAA,EAAAA,MAAAA;;AAA8B,UAS/IK,yBAT+I,CAAA,WAAA,CAAA,SAShGD,IATgG,CAS3FR,mBAT2F,CASvEE,WATuE,CAAA,EAAA,SAAA,GAAA,SAAA,CAAA,CAAA;EACpJI,IAAAA,CAAAA,EASDf,YATCe;EACKC,O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A,CAAAA,OAAAA,CAAAA,EAwBwEA,qBAxBxEA,CAwB8FL,WAxB9FK,CAAAA,EAAAA,WAAAA,CAAAA,EAwB0HA,qBAxB1HA,CAwBgJL,WAxBhJK,CAAAA,CAAAA,EAwB+JjB,kCAxB/JiB"}
@@ -1,13 +1,15 @@
1
- import { DEFAULT_THEMES } from "../constants.js";
1
+ import { DEFAULT_THEMES, UNSAFE_CSS_ATTRIBUTE } from "../constants.js";
2
2
  import { pluckInteractionOptions } from "../managers/InteractionManager.js";
3
+ import { splitFileContents } from "../utils/splitFileContents.js";
3
4
  import { areFilesEqual } from "../utils/areFilesEqual.js";
4
5
  import { createAnnotationWrapperNode } from "../utils/createAnnotationWrapperNode.js";
6
+ import { prerenderHTMLIfNecessary } from "../utils/prerenderHTMLIfNecessary.js";
5
7
  import { FileDiff } from "./FileDiff.js";
6
8
  import { getMergeConflictActionSlotName } from "../utils/getMergeConflictActionSlotName.js";
7
- import { getMergeConflictActionAnchor, parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.js";
9
+ import { buildMergeConflictMarkerRows, getMergeConflictActionAnchor, parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.js";
8
10
  import { UnresolvedFileHunksRenderer } from "../renderers/UnresolvedFileHunksRenderer.js";
9
11
  import { areMergeConflictActionsEqual } from "../utils/areMergeConflictActionsEqual.js";
10
- import { resolveMergeConflict } from "../utils/resolveMergeConflict.js";
12
+ import { resolveConflict } from "../utils/resolveConflict.js";
11
13
 
12
14
  //#region src/components/UnresolvedFile.ts
13
15
  let instanceId = -1;
@@ -16,9 +18,11 @@ var UnresolvedFile = class extends FileDiff {
16
18
  computedCache = {
17
19
  file: void 0,
18
20
  fileDiff: void 0,
19
- actions: void 0
21
+ actions: void 0,
22
+ markerRows: void 0
20
23
  };
21
24
  conflictActions = [];
25
+ markerRows = [];
22
26
  conflictActionCache = /* @__PURE__ */ new Map();
23
27
  constructor(options = { theme: DEFAULT_THEMES }, workerManager, isContainerManaged = false) {
24
28
  super(void 0, workerManager, isContainerManaged);
@@ -37,11 +41,7 @@ var UnresolvedFile = class extends FileDiff {
37
41
  return new UnresolvedFileHunksRenderer(this.getHunksRendererOptions(options), this.handleHighlightRender, this.workerManager);
38
42
  }
39
43
  getHunksRendererOptions(options) {
40
- return {
41
- ...this.options,
42
- hunkSeparators: typeof options.hunkSeparators === "function" ? "custom" : options.hunkSeparators,
43
- mergeConflictActionsType: typeof options.mergeConflictActionsType === "function" ? "custom" : options.mergeConflictActionsType
44
- };
44
+ return getUnresolvedDiffHunksRendererOptions(options, this.options);
45
45
  }
46
46
  applyPreNodeAttributes(pre, result) {
47
47
  super.applyPreNodeAttributes(pre, result, { "data-has-merge-conflict": "" });
@@ -51,73 +51,124 @@ var UnresolvedFile = class extends FileDiff {
51
51
  this.computedCache = {
52
52
  file: void 0,
53
53
  fileDiff: void 0,
54
- actions: void 0
54
+ actions: void 0,
55
+ markerRows: void 0
55
56
  };
56
57
  this.conflictActions = [];
57
58
  super.cleanUp();
58
59
  }
59
- getOrComputeDiff({ file, fileDiff, actions }) {
60
- wrapper: if (this.options.onMergeConflictAction != null) {
61
- if (fileDiff != null !== (actions != null)) throw new Error("UnresolvedFile.getOrComputeDiff: fileDiff and actions must be passed together");
62
- if (fileDiff != null && actions != null) {
60
+ getOrComputeDiff({ file, fileDiff, actions, markerRows }) {
61
+ const { maxContextLines, onMergeConflictAction } = this.options;
62
+ wrapper: if (onMergeConflictAction != null) {
63
+ const hasFileDiff = fileDiff != null;
64
+ if (hasFileDiff !== (actions != null) || hasFileDiff !== (markerRows != null)) throw new Error("UnresolvedFile.getOrComputeDiff: fileDiff, actions, and markerRows must be passed together");
65
+ if (fileDiff != null && actions != null && markerRows != null) {
63
66
  this.computedCache = {
64
67
  file: file ?? this.computedCache.file,
65
68
  fileDiff,
66
- actions
69
+ actions,
70
+ markerRows
67
71
  };
68
72
  break wrapper;
69
73
  } else if (file != null || this.computedCache.file != null) {
74
+ if (file != null && this.computedCache.file != null && !areFilesEqual(file, this.computedCache.file) && this.computedCache.fileDiff != null && this.computedCache.actions != null) throw new Error("UnresolvedFile.getOrComputeDiff: file can only be used to initialize unresolved state once. Pass fileDiff and actions for subsequent updates.");
70
75
  file ??= this.computedCache.file;
71
76
  if (file == null) throw new Error("UnresolvedFile.getOrComputeDiff: file is null, should be impossible");
72
77
  if (!areFilesEqual(file, this.computedCache.file) || this.computedCache.fileDiff == null || this.computedCache.actions == null) {
73
- const computed = parseMergeConflictDiffFromFile(file);
78
+ const computed = parseMergeConflictDiffFromFile(file, maxContextLines);
74
79
  this.computedCache = {
75
80
  file,
76
81
  fileDiff: computed.fileDiff,
77
- actions: computed.actions
82
+ actions: computed.actions,
83
+ markerRows: computed.markerRows
78
84
  };
79
85
  }
80
86
  fileDiff = this.computedCache.fileDiff;
81
87
  actions = this.computedCache.actions;
88
+ markerRows = this.computedCache.markerRows;
82
89
  break wrapper;
83
90
  } else {
84
91
  fileDiff = this.computedCache.fileDiff;
85
92
  actions = this.computedCache.actions;
93
+ markerRows = this.computedCache.markerRows;
86
94
  break wrapper;
87
95
  }
88
96
  } else {
89
- if (fileDiff != null || actions != null) throw new Error("UnresolvedFile.getOrComputeDiff: fileDiff and actions are only usable in controlled mode, you must pass in `onMergeConflictAction`");
97
+ if (fileDiff != null || actions != null || markerRows != null) throw new Error("UnresolvedFile.getOrComputeDiff: fileDiff, actions, and markerRows are only usable in controlled mode, you must pass in `onMergeConflictAction`");
98
+ if (file != null && this.computedCache.file != null && !areFilesEqual(file, this.computedCache.file)) throw new Error("UnresolvedFile.getOrComputeDiff: uncontrolled unresolved files parse the file only once. Later updates must come from the cached diff state.");
90
99
  this.computedCache.file ??= file;
91
100
  if (this.computedCache.fileDiff == null && this.computedCache.file != null) {
92
- const computed = parseMergeConflictDiffFromFile(this.computedCache.file);
101
+ const computed = parseMergeConflictDiffFromFile(this.computedCache.file, maxContextLines);
93
102
  this.computedCache.fileDiff = computed.fileDiff;
94
103
  this.computedCache.actions = computed.actions;
104
+ this.computedCache.markerRows = computed.markerRows;
95
105
  }
96
106
  fileDiff = this.computedCache.fileDiff;
97
107
  actions = this.computedCache.actions;
108
+ markerRows = this.computedCache.markerRows;
98
109
  break wrapper;
99
110
  }
100
- if (fileDiff == null || actions == null) return;
111
+ if (fileDiff == null || actions == null || markerRows == null) return;
101
112
  return {
102
113
  fileDiff,
103
- actions
114
+ actions,
115
+ markerRows
104
116
  };
105
117
  }
106
118
  hydrate(props) {
107
- const { file, fileDiff, actions, lineAnnotations, preventEmit = false,...rest } = props;
119
+ const { file, fileDiff, actions, markerRows, lineAnnotations, fileContainer, prerenderedHTML, preventEmit = false } = props;
108
120
  const source = this.getOrComputeDiff({
109
121
  file,
110
122
  fileDiff,
111
- actions
123
+ actions,
124
+ markerRows
112
125
  });
126
+ const { overflow = "scroll" } = this.options;
113
127
  if (source == null) return;
114
- this.setActiveMergeConflictActions(source.actions);
115
- super.hydrate({
116
- ...rest,
117
- fileDiff: source.fileDiff,
118
- lineAnnotations,
128
+ prerenderHTMLIfNecessary(fileContainer, prerenderedHTML);
129
+ for (const element of fileContainer.shadowRoot?.children ?? []) {
130
+ if (element instanceof SVGElement) {
131
+ this.spriteSVG = element;
132
+ continue;
133
+ }
134
+ if (!(element instanceof HTMLElement)) continue;
135
+ if (element instanceof HTMLPreElement) {
136
+ this.pre = element;
137
+ for (const code of element.children) {
138
+ if (!(code instanceof HTMLElement) || code.tagName.toLowerCase() !== "code") continue;
139
+ if ("deletions" in code.dataset) this.codeDeletions = code;
140
+ if ("additions" in code.dataset) this.codeAdditions = code;
141
+ if ("unified" in code.dataset) this.codeUnified = code;
142
+ }
143
+ continue;
144
+ }
145
+ if ("diffsHeader" in element.dataset) {
146
+ this.headerElement = element;
147
+ continue;
148
+ }
149
+ if (element instanceof HTMLStyleElement && element.hasAttribute(UNSAFE_CSS_ATTRIBUTE)) {
150
+ this.unsafeCSSStyle = element;
151
+ continue;
152
+ }
153
+ }
154
+ if (this.pre != null) this.syncCodeNodesFromPre(this.pre);
155
+ this.setActiveMergeConflictState(source.actions, source.markerRows);
156
+ if (this.pre == null) this.render({
157
+ ...props,
119
158
  preventEmit: true
120
159
  });
160
+ else {
161
+ this.fileContainer = fileContainer;
162
+ delete this.pre.dataset.dehydrated;
163
+ this.lineAnnotations = lineAnnotations ?? this.lineAnnotations;
164
+ this.fileDiff = source.fileDiff;
165
+ this.hunksRenderer.hydrate(this.fileDiff);
166
+ this.renderAnnotations();
167
+ this.renderGutterUtility();
168
+ this.injectUnsafeCSS();
169
+ this.interactionManager.setup(this.pre);
170
+ this.resizeManager.setup(this.pre, overflow === "wrap");
171
+ }
121
172
  this.renderMergeConflictActionSlots();
122
173
  if (!preventEmit) this.emitPostRender();
123
174
  }
@@ -129,27 +180,30 @@ var UnresolvedFile = class extends FileDiff {
129
180
  });
130
181
  }
131
182
  render(props = {}) {
132
- let { file, fileDiff, actions, lineAnnotations, preventEmit = false,...rest } = props;
183
+ let { file, fileDiff, actions, markerRows, lineAnnotations, preventEmit = false,...rest } = props;
133
184
  const source = this.getOrComputeDiff({
134
185
  file,
135
186
  fileDiff,
136
- actions
187
+ actions,
188
+ markerRows
137
189
  });
138
190
  if (source == null) return false;
139
- this.setActiveMergeConflictActions(source.actions);
191
+ this.setActiveMergeConflictState(source.actions, source.markerRows);
140
192
  const didRender = super.render({
141
193
  ...rest,
142
194
  fileDiff: source.fileDiff,
143
195
  lineAnnotations,
144
196
  preventEmit: true
145
197
  });
146
- this.renderMergeConflictActionSlots();
147
- if (didRender && !preventEmit) this.emitPostRender();
198
+ if (didRender) {
199
+ this.renderMergeConflictActionSlots();
200
+ if (!preventEmit) this.emitPostRender();
201
+ }
148
202
  return didRender;
149
203
  }
150
- resolveConflict(conflictIndex, resolution, file = this.computedCache.file) {
204
+ resolveConflict(conflictIndex, resolution, fileDiff = this.computedCache.fileDiff) {
151
205
  const action = this.conflictActions[conflictIndex];
152
- if (file == null || action == null) return;
206
+ if (fileDiff == null || action == null) return;
153
207
  if (action.conflictIndex !== conflictIndex) {
154
208
  console.error({
155
209
  conflictIndex,
@@ -157,15 +211,20 @@ var UnresolvedFile = class extends FileDiff {
157
211
  });
158
212
  throw new Error("UnresolvedFile.resolveConflict: conflictIndex and conflictAction don't match");
159
213
  }
160
- const contents = resolveMergeConflict(file.contents, {
161
- resolution,
162
- conflict: action.conflict
214
+ const newFileDiff = resolveConflict(fileDiff, action, resolution);
215
+ const previousFile = this.computedCache.file;
216
+ const { file, actions, markerRows } = rebuildFileAndActions({
217
+ fileDiff: newFileDiff,
218
+ previousActions: this.conflictActions,
219
+ resolvedConflictIndex: conflictIndex,
220
+ previousFile,
221
+ resolution
163
222
  });
164
- if (contents === file.contents) return;
165
223
  return {
166
- ...file,
167
- contents,
168
- cacheKey: file.cacheKey != null ? `${file.cacheKey}:mc-${conflictIndex}-${resolution}` : void 0
224
+ file,
225
+ fileDiff: newFileDiff,
226
+ actions,
227
+ markerRows
169
228
  };
170
229
  }
171
230
  resolveConflictAndRender(conflictIndex, resolution) {
@@ -182,18 +241,23 @@ var UnresolvedFile = class extends FileDiff {
182
241
  resolution,
183
242
  conflict: action.conflict
184
243
  };
185
- const nextFile = this.resolveConflict(conflictIndex, resolution);
186
- if (nextFile == null) return;
187
- this.computedCache.file = nextFile;
188
- this.computedCache.fileDiff = void 0;
189
- this.computedCache.actions = void 0;
190
- this.render();
191
- this.options.onMergeConflictResolve?.(nextFile, payload);
192
- return nextFile;
244
+ const { file, fileDiff, actions, markerRows } = this.resolveConflict(conflictIndex, resolution) ?? {};
245
+ if (file == null || fileDiff == null || actions == null || markerRows == null) return;
246
+ this.computedCache = {
247
+ file,
248
+ fileDiff,
249
+ actions,
250
+ markerRows
251
+ };
252
+ this.setActiveMergeConflictState(actions, markerRows);
253
+ if (this.workerManager != null) this.hunksRenderer.renderDiff(fileDiff);
254
+ else this.render({ forceRender: true });
255
+ this.options.onMergeConflictResolve?.(file, payload);
193
256
  }
194
- setActiveMergeConflictActions(actions) {
257
+ setActiveMergeConflictState(actions = this.conflictActions, markerRows = this.markerRows) {
195
258
  this.conflictActions = actions;
196
- if (this.hunksRenderer instanceof UnresolvedFileHunksRenderer) this.hunksRenderer.setConflictActions(this.options.mergeConflictActionsType === "none" ? [] : actions);
259
+ this.markerRows = markerRows;
260
+ if (this.computedCache.fileDiff != null && this.hunksRenderer instanceof UnresolvedFileHunksRenderer) this.hunksRenderer.setConflictState(this.options.mergeConflictActionsType === "none" ? [] : actions, markerRows, this.computedCache.fileDiff);
197
261
  }
198
262
  handleMergeConflictActionClick = (target) => {
199
263
  const action = this.conflictActions[target.conflictIndex];
@@ -216,7 +280,8 @@ var UnresolvedFile = class extends FileDiff {
216
280
  this.resolveConflictAndRender(target.conflictIndex, target.resolution);
217
281
  };
218
282
  renderMergeConflictActionSlots() {
219
- if (this.isContainerManaged || this.fileContainer == null || typeof this.options.mergeConflictActionsType !== "function" || this.conflictActions.length === 0) {
283
+ const { fileDiff } = this.computedCache;
284
+ if (this.isContainerManaged || this.fileContainer == null || typeof this.options.mergeConflictActionsType !== "function" || this.conflictActions.length === 0 || fileDiff == null) {
220
285
  this.clearMergeConflictActionCache();
221
286
  return;
222
287
  }
@@ -231,12 +296,12 @@ var UnresolvedFile = class extends FileDiff {
231
296
  });
232
297
  throw new Error("UnresolvedFile.renderMergeConflictActionSlots: conflictIndex and conflictAction don't match");
233
298
  }
234
- const anchor = getMergeConflictActionAnchor(action);
299
+ const anchor = getMergeConflictActionAnchor(action, fileDiff);
235
300
  if (anchor == null) continue;
236
301
  const conflictIndex = action.conflictIndex;
237
302
  const slotName = getMergeConflictActionSlotName({
238
- side: anchor.side,
239
- lineNumber: anchor.lineNumber,
303
+ hunkIndex: anchor.hunkIndex,
304
+ lineIndex: anchor.lineIndex,
240
305
  conflictIndex
241
306
  });
242
307
  const id = `${actionIndex}-${slotName}`;
@@ -278,7 +343,84 @@ var UnresolvedFile = class extends FileDiff {
278
343
  this.conflictActionCache.clear();
279
344
  }
280
345
  };
346
+ function rebuildFileAndActions({ fileDiff, previousActions, resolvedConflictIndex, previousFile, resolution }) {
347
+ const resolvedAction = previousActions[resolvedConflictIndex];
348
+ if (resolvedAction == null) throw new Error("rebuildFileAndActions: missing resolved action for unresolved file rebuild");
349
+ const actions = updateConflictActionsAfterResolution(previousActions, resolvedConflictIndex, resolvedAction, resolution);
350
+ const markerRows = buildMergeConflictMarkerRows(fileDiff, actions);
351
+ return {
352
+ file: rebuildUnresolvedFile({
353
+ fileDiff,
354
+ resolvedAction,
355
+ resolvedConflictIndex,
356
+ previousFile,
357
+ resolution
358
+ }),
359
+ actions,
360
+ markerRows
361
+ };
362
+ }
363
+ function rebuildUnresolvedFile({ resolvedAction, resolvedConflictIndex, previousFile, fileDiff, resolution }) {
364
+ const lines = splitFileContents(previousFile?.contents ?? "");
365
+ const { conflict } = resolvedAction;
366
+ const replacementLines = getResolvedConflictReplacementLines(lines, conflict, resolution);
367
+ const contents = [
368
+ ...lines.slice(0, conflict.startLineIndex),
369
+ ...replacementLines,
370
+ ...lines.slice(conflict.endLineIndex + 1)
371
+ ].join("");
372
+ return {
373
+ name: previousFile?.name ?? fileDiff.name,
374
+ contents,
375
+ cacheKey: previousFile?.cacheKey != null ? `${previousFile.cacheKey}:mc-${resolvedConflictIndex}-${resolution}` : void 0
376
+ };
377
+ }
378
+ function getResolvedConflictReplacementLines(lines, conflict, resolution) {
379
+ const currentLines = lines.slice(conflict.startLineIndex + 1, conflict.baseMarkerLineIndex ?? conflict.separatorLineIndex);
380
+ const incomingLines = lines.slice(conflict.separatorLineIndex + 1, conflict.endLineIndex);
381
+ if (resolution === "current") return currentLines;
382
+ if (resolution === "incoming") return incomingLines;
383
+ return [...currentLines, ...incomingLines];
384
+ }
385
+ function updateConflictActionsAfterResolution(previousActions, resolvedConflictIndex, resolvedAction, resolution) {
386
+ const lineDelta = getResolvedConflictLineDelta(resolvedAction.conflict, resolution);
387
+ return previousActions.map((action, index) => {
388
+ if (index === resolvedConflictIndex) return;
389
+ if (action == null) return;
390
+ if (action.conflict.startLineIndex > resolvedAction.conflict.endLineIndex) return {
391
+ ...action,
392
+ conflict: shiftMergeConflictRegion(action.conflict, lineDelta)
393
+ };
394
+ return action;
395
+ });
396
+ }
397
+ function getResolvedConflictLineDelta(conflict, resolution) {
398
+ const currentLineCount = (conflict.baseMarkerLineIndex ?? conflict.separatorLineIndex) - conflict.startLineIndex - 1;
399
+ const incomingLineCount = conflict.endLineIndex - conflict.separatorLineIndex - 1;
400
+ return (resolution === "current" ? currentLineCount : resolution === "incoming" ? incomingLineCount : currentLineCount + incomingLineCount) - (conflict.endLineIndex - conflict.startLineIndex + 1);
401
+ }
402
+ function shiftMergeConflictRegion(conflict, lineDelta) {
403
+ return {
404
+ ...conflict,
405
+ startLineIndex: conflict.startLineIndex + lineDelta,
406
+ startLineNumber: conflict.startLineNumber + lineDelta,
407
+ separatorLineIndex: conflict.separatorLineIndex + lineDelta,
408
+ separatorLineNumber: conflict.separatorLineNumber + lineDelta,
409
+ endLineIndex: conflict.endLineIndex + lineDelta,
410
+ endLineNumber: conflict.endLineNumber + lineDelta,
411
+ baseMarkerLineIndex: conflict.baseMarkerLineIndex != null ? conflict.baseMarkerLineIndex + lineDelta : void 0,
412
+ baseMarkerLineNumber: conflict.baseMarkerLineNumber != null ? conflict.baseMarkerLineNumber + lineDelta : void 0
413
+ };
414
+ }
415
+ function getUnresolvedDiffHunksRendererOptions(options, baseOptions) {
416
+ return {
417
+ ...baseOptions,
418
+ ...options,
419
+ hunkSeparators: typeof options?.hunkSeparators === "function" ? "custom" : options?.hunkSeparators,
420
+ mergeConflictActionsType: typeof options?.mergeConflictActionsType === "function" ? "custom" : options?.mergeConflictActionsType
421
+ };
422
+ }
281
423
 
282
424
  //#endregion
283
- export { UnresolvedFile };
425
+ export { UnresolvedFile, getUnresolvedDiffHunksRendererOptions };
284
426
  //# sourceMappingURL=UnresolvedFile.js.map