@git-diff-view/react 0.0.30 → 0.0.31

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ import { Root } from 'hast';
3
4
  import { CSSProperties, ForwardedRef, ReactNode, RefObject } from 'react';
4
5
 
5
6
  declare class Cache$1<K, V> extends Map<K, V> {
@@ -276,8 +277,10 @@ export declare class DiffLine {
276
277
  changes?: IRange;
277
278
  diffChanges?: DiffRange;
278
279
  plainTemplate?: string;
280
+ plainTemplateMode?: "fast-diff" | "relative";
279
281
  syntaxTemplate?: string;
280
- constructor(text: string, type: DiffLineType, originalLineNumber: number | null, oldLineNumber: number | null, newLineNumber: number | null, noTrailingNewLine?: boolean, changes?: IRange, diffChanges?: DiffRange, plainTemplate?: string, syntaxTemplate?: string);
282
+ syntaxTemplateMode?: "fast-diff" | "relative";
283
+ constructor(text: string, type: DiffLineType, originalLineNumber: number | null, oldLineNumber: number | null, newLineNumber: number | null, noTrailingNewLine?: boolean, changes?: IRange, diffChanges?: DiffRange, plainTemplate?: string, plainTemplateMode?: "fast-diff" | "relative", syntaxTemplate?: string, syntaxTemplateMode?: "fast-diff" | "relative");
281
284
  withNoTrailingNewLine(noTrailingNewLine: boolean): DiffLine;
282
285
  isIncludeableLine(): boolean;
283
286
  equals(other: DiffLine): boolean;
@@ -426,6 +429,7 @@ export declare const checkCurrentLineIsHidden: (diffFile: DiffFile, lineNumber:
426
429
  unified: boolean;
427
430
  };
428
431
  export declare const checkDiffLineIncludeChange: (diffLine?: DiffLine) => boolean;
432
+ export declare const defaultTransform: (content: string) => string;
429
433
  export declare const disableCache: () => void;
430
434
  export declare const getCurrentComposeLength: () => number;
431
435
  export declare const getDiffRange: (additions: DiffLine[], deletions: DiffLine[], { getAdditionRaw, getDeletionRaw, getAdditionSyntax, getDeletionSyntax, }: {
@@ -434,12 +438,18 @@ export declare const getDiffRange: (additions: DiffLine[], deletions: DiffLine[]
434
438
  getAdditionSyntax: (lineNumber: number) => SyntaxLineWithTemplate;
435
439
  getDeletionSyntax: (lineNumber: number) => SyntaxLineWithTemplate;
436
440
  }) => void;
441
+ export declare const getEnableFastDiffTemplate: () => boolean;
437
442
  export declare const getLang: (fileName: string) => string;
438
443
  export declare const getPlainDiffTemplate: ({ diffLine, rawLine, operator, }: {
439
444
  diffLine: DiffLine;
440
445
  rawLine: string;
441
446
  operator: "add" | "del";
442
447
  }) => void;
448
+ export declare const getPlainDiffTemplateByFastDiff: ({ diffLine, rawLine, operator, }: {
449
+ diffLine: DiffLine;
450
+ rawLine: string;
451
+ operator: "add" | "del";
452
+ }) => void;
443
453
  export declare const getPlainLineTemplate: (line: string) => string;
444
454
  export declare const getSplitContentLines: (diffFile: DiffFile) => DiffSplitContentLineItem[];
445
455
  export declare const getSplitLines: (diffFile: DiffFile) => DiffSplitLineItem[];
@@ -448,6 +458,11 @@ export declare const getSyntaxDiffTemplate: ({ diffLine, syntaxLine, operator, }
448
458
  syntaxLine: SyntaxLineWithTemplate;
449
459
  operator: "add" | "del";
450
460
  }) => void;
461
+ export declare const getSyntaxDiffTemplateByFastDiff: ({ diffLine, syntaxLine, operator, }: {
462
+ diffLine: DiffLine;
463
+ syntaxLine: SyntaxLineWithTemplate;
464
+ operator: "add" | "del";
465
+ }) => void;
451
466
  export declare const getSyntaxLineTemplate: (line: SyntaxLine) => string;
452
467
  export declare const getUnifiedContentLine: (diffFile: DiffFile) => DiffUnifiedContentLineItem[];
453
468
  export declare const getUnifiedLines: (diffFile: DiffFile) => DiffUnifiedLineItem[];
@@ -496,6 +511,7 @@ export declare const processTransformForFile: (content: string) => string;
496
511
  */
497
512
  export declare const processTransformTemplateContent: (content: string) => string;
498
513
  export declare const resetDefaultComposeLength: () => void;
514
+ export declare const resetEnableFastDiffTemplate: () => void;
499
515
  /**
500
516
  * Resets all transformation functions to their default state and disables transformation.
501
517
  *
@@ -505,6 +521,7 @@ export declare const resetDefaultComposeLength: () => void;
505
521
  * ```
506
522
  */
507
523
  export declare const resetTransform: () => void;
524
+ export declare const setEnableFastDiffTemplate: (enable: boolean) => void;
508
525
  /**
509
526
  * ⚠️ **WARNING: DANGEROUS OPERATION** ⚠️
510
527
  *
@@ -617,7 +634,8 @@ export interface DiffRange {
617
634
  readonly range: {
618
635
  type: 1 | -1 | 0;
619
636
  str: string;
620
- location: number;
637
+ startIndex: number;
638
+ endIndex: number;
621
639
  length: number;
622
640
  }[];
623
641
  readonly hasLineChange?: boolean;
@@ -682,7 +700,7 @@ export interface UnifiedLineItem {
682
700
  isHidden?: boolean;
683
701
  _isHidden?: boolean;
684
702
  }
685
- export type DiffAST = ReturnType<typeof lowlight.highlight>;
703
+ export type DiffAST = Root;
686
704
  export type DiffHighlighter = {
687
705
  name: string;
688
706
  type: "class" | "style" | string;
@@ -780,7 +798,6 @@ export type SyntaxLine = {
780
798
  export type SyntaxLineWithTemplate = SyntaxLine & {
781
799
  template?: string;
782
800
  };
783
- // Generated by dts-bundle-generator v9.5.1
784
801
  export type SyntaxNode = {
785
802
  type: string;
786
803
  value: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "@git-diff-view/react",
4
4
  "author": "MrWangJustToDo",
5
5
  "license": "MIT",
6
- "version": "0.0.30",
6
+ "version": "0.0.31",
7
7
  "main": "index.js",
8
8
  "types": "index.d.ts",
9
9
  "files": [
@@ -61,7 +61,7 @@
61
61
  "react diff component"
62
62
  ],
63
63
  "dependencies": {
64
- "@git-diff-view/core": "^0.0.30",
64
+ "@git-diff-view/core": "^0.0.31",
65
65
  "@types/hast": "^3.0.0",
66
66
  "fast-diff": "^1.3.0",
67
67
  "highlight.js": "^11.11.0",
package/src/_com.css CHANGED
@@ -71,6 +71,10 @@ td {
71
71
  text-align: left;
72
72
  }
73
73
 
74
+ td {
75
+ padding: 0;
76
+ }
77
+
74
78
  .diff-line-old-num,
75
79
  .diff-line-new-num,
76
80
  .diff-line-num {
@@ -13,7 +13,6 @@ import { SplitSide } from "..";
13
13
 
14
14
  import { DiffSplitAddWidget } from "./DiffAddWidget";
15
15
  import { DiffContent } from "./DiffContent";
16
- // import { DiffContent_v2 } from "./DiffContent_v2";
17
16
  import { useDiffViewContext } from "./DiffViewContext";
18
17
  import { useDiffWidgetContext } from "./DiffWidgetContext";
19
18
 
@@ -13,7 +13,6 @@ import { SplitSide } from "..";
13
13
 
14
14
  import { DiffSplitAddWidget } from "./DiffAddWidget";
15
15
  import { DiffContent } from "./DiffContent";
16
- // import { DiffContent_v2 } from "./DiffContent_v2";
17
16
  import { useDiffViewContext } from "./DiffViewContext";
18
17
  import { useDiffWidgetContext } from "./DiffWidgetContext";
19
18
 
@@ -77,7 +76,10 @@ const InternalDiffSplitLine = ({
77
76
  <td
78
77
  className="diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top"
79
78
  data-side={SplitSide[SplitSide.old]}
80
- style={{ backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` }}
79
+ style={{
80
+ backgroundColor: oldLineNumberBG,
81
+ color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
82
+ }}
81
83
  >
82
84
  {hasDiff && enableAddWidget && (
83
85
  <DiffSplitAddWidget
@@ -51,7 +51,7 @@ const DiffSplitViewTable = ({
51
51
  <th scope="col">{SplitSide[side]} line content</th>
52
52
  </tr>
53
53
  </thead>
54
- <tbody className="diff-table-body leading-[1.4]" onMouseDownCapture={onMouseDown}>
54
+ <tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
55
55
  {lines.map((line) => (
56
56
  <Fragment key={line.index}>
57
57
  <DiffSplitHunkLine index={line.index} side={side} lineNumber={line.lineNumber} diffFile={diffFile} />
@@ -119,7 +119,7 @@ export const DiffSplitViewWrap = memo(({ diffFile }: { diffFile: DiffFile }) =>
119
119
  <th scope="col">new line content</th>
120
120
  </tr>
121
121
  </thead>
122
- <tbody className="diff-table-body leading-[1.4]" onMouseDownCapture={onMouseDown}>
122
+ <tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
123
123
  {lines.map((line) => (
124
124
  <Fragment key={line.index}>
125
125
  <DiffSplitHunkLine index={line.index} lineNumber={line.lineNumber} diffFile={diffFile} />
@@ -135,7 +135,7 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
135
135
  <th scope="col">line content</th>
136
136
  </tr>
137
137
  </thead>
138
- <tbody className="diff-table-body leading-[1.4]" onMouseDownCapture={onMouseDown}>
138
+ <tbody className="diff-table-body leading-[1.6]" onMouseDownCapture={onMouseDown}>
139
139
  {lines.map((item) => (
140
140
  <Fragment key={item.index}>
141
141
  <DiffUnifiedHunkLine index={item.index} lineNumber={item.lineNumber} diffFile={diffFile} />
@@ -299,19 +299,23 @@ const DiffViewWithRef = <T extends unknown>(
299
299
  useEffect(() => {
300
300
  if (!diffFile) return;
301
301
  diffFile.initTheme(diffViewTheme);
302
+
302
303
  diffFile.initRaw();
304
+
303
305
  diffFile.buildSplitDiffLines();
306
+
304
307
  diffFile.buildUnifiedDiffLines();
305
308
  }, [diffFile, diffViewTheme]);
306
309
 
307
310
  useEffect(() => {
308
311
  if (!diffFile) return;
309
-
312
+
310
313
  if (props.diffViewHighlight) {
311
314
  diffFile.initSyntax({ registerHighlighter });
312
- diffFile.notifyAll();
313
315
  }
314
- }, [diffFile, props.diffViewHighlight, registerHighlighter]);
316
+
317
+ diffFile.notifyAll();
318
+ }, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
315
319
 
316
320
  useEffect(() => {
317
321
  if (!diffFile) return;
@@ -326,7 +330,7 @@ const DiffViewWithRef = <T extends unknown>(
326
330
  const cb = diffFile.subscribe(init);
327
331
 
328
332
  return cb;
329
- }, [diffFile, diffViewTheme]);
333
+ }, [diffFile]);
330
334
 
331
335
  // fix react strict mode error
332
336
  useUnmount(() => (__DEV__ ? diffFile?._destroy?.() : diffFile?.clear?.()), [diffFile]);
@@ -55,6 +55,8 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
55
55
 
56
56
  const ref = useRef<HTMLStyleElement>();
57
57
 
58
+ const tempRef = useRef<SplitSide>();
59
+
58
60
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
59
61
 
60
62
  const { useDiffContext } = useDiffViewContext();
@@ -105,13 +107,19 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
105
107
  const state = ele.getAttribute("data-state");
106
108
  const side = ele.getAttribute("data-side");
107
109
  if (side) {
108
- setStyle(SplitSide[side]);
109
- removeAllSelection();
110
+ if (tempRef.current !== SplitSide[side]) {
111
+ tempRef.current = SplitSide[side];
112
+ setStyle(SplitSide[side]);
113
+ removeAllSelection();
114
+ }
110
115
  }
111
116
  if (state) {
112
117
  if (state === "extend" || state === "hunk" || state === "widget") {
113
- setStyle(undefined);
114
- removeAllSelection();
118
+ if (tempRef.current !== undefined) {
119
+ tempRef.current = undefined;
120
+ setStyle(undefined);
121
+ removeAllSelection();
122
+ }
115
123
  return;
116
124
  } else {
117
125
  return;
@@ -125,6 +133,16 @@ export const DiffSplitViewNormal = memo(({ diffFile }: { diffFile: DiffFile }) =
125
133
  return (
126
134
  <div className="split-diff-view split-diff-view-normal flex w-full basis-[50%]">
127
135
  <style data-select-style ref={ref} />
136
+ <style>
137
+ {`
138
+ .diff-tailwindcss-wrapper .diff-add-widget-wrapper.diff-add-widget-wrapper.diff-add-widget-wrapper {
139
+ transform: translate(-50%, -50%) !important;
140
+ }
141
+ .diff-tailwindcss-wrapper .diff-add-widget-wrapper.diff-add-widget-wrapper.diff-add-widget-wrapper:hover {
142
+ transform: translate(-50%, -50%) scale(1.1) !important;
143
+ }
144
+ `}
145
+ </style>
128
146
  <div
129
147
  className="old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden"
130
148
  ref={ref1}
@@ -155,6 +155,9 @@
155
155
  --tw-translate-y: -50%;
156
156
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
157
157
  }
158
+ .diff-tailwindcss-wrapper .transform {
159
+ transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
160
+ }
158
161
  .diff-tailwindcss-wrapper .cursor-pointer {
159
162
  cursor: pointer;
160
163
  }
@@ -247,9 +250,6 @@
247
250
  .diff-tailwindcss-wrapper .text-\[1\.2em\] {
248
251
  font-size: 1.2em;
249
252
  }
250
- .diff-tailwindcss-wrapper .leading-\[1\.4\] {
251
- line-height: 1.4;
252
- }
253
253
  .diff-tailwindcss-wrapper .leading-\[1\.6\] {
254
254
  line-height: 1.6;
255
255
  }
@@ -260,9 +260,6 @@
260
260
  .diff-tailwindcss-wrapper .opacity-\[0\.5\] {
261
261
  opacity: 0.5;
262
262
  }
263
- .diff-tailwindcss-wrapper .filter {
264
- filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
265
- }
266
263
  .diff-tailwindcss-wrapper .transition-transform {
267
264
  transition-property: transform;
268
265
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
@@ -335,6 +332,9 @@
335
332
  border-width: 0px;
336
333
  text-align: left;
337
334
  }
335
+ .diff-tailwindcss-wrapper td {
336
+ padding: 0;
337
+ }
338
338
  .diff-tailwindcss-wrapper .diff-line-old-num,
339
339
  .diff-tailwindcss-wrapper .diff-line-new-num,
340
340
  .diff-tailwindcss-wrapper .diff-line-num {
@@ -661,6 +661,9 @@ video {
661
661
  --tw-translate-y: -50%;
662
662
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
663
663
  }
664
+ .diff-tailwindcss-wrapper .transform {
665
+ transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
666
+ }
664
667
  .diff-tailwindcss-wrapper .cursor-pointer {
665
668
  cursor: pointer;
666
669
  }
@@ -753,9 +756,6 @@ video {
753
756
  .diff-tailwindcss-wrapper .text-\[1\.2em\] {
754
757
  font-size: 1.2em;
755
758
  }
756
- .diff-tailwindcss-wrapper .leading-\[1\.4\] {
757
- line-height: 1.4;
758
- }
759
759
  .diff-tailwindcss-wrapper .leading-\[1\.6\] {
760
760
  line-height: 1.6;
761
761
  }
@@ -766,9 +766,6 @@ video {
766
766
  .diff-tailwindcss-wrapper .opacity-\[0\.5\] {
767
767
  opacity: 0.5;
768
768
  }
769
- .diff-tailwindcss-wrapper .filter {
770
- filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
771
- }
772
769
  .diff-tailwindcss-wrapper .transition-transform {
773
770
  transition-property: transform;
774
771
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
@@ -841,6 +838,9 @@ video {
841
838
  border-width: 0px;
842
839
  text-align: left;
843
840
  }
841
+ .diff-tailwindcss-wrapper td {
842
+ padding: 0;
843
+ }
844
844
  .diff-tailwindcss-wrapper .diff-line-old-num,
845
845
  .diff-tailwindcss-wrapper .diff-line-new-num,
846
846
  .diff-tailwindcss-wrapper .diff-line-num {
@@ -1,338 +0,0 @@
1
- import { DiffLineType, type DiffFile, type DiffLine, type diffChanges, type SyntaxLine } from "@git-diff-view/core";
2
- import {
3
- addContentHighlightBGName,
4
- delContentHighlightBGName,
5
- diffFontSizeName,
6
- getSymbol,
7
- NewLineSymbol,
8
- } from "@git-diff-view/utils";
9
- import * as React from "react";
10
-
11
- import { getStyleObjectFromString } from "./DiffContent";
12
- import { DiffNoNewLine } from "./DiffNoNewLine";
13
-
14
- const RenderRange = ({
15
- str,
16
- startIndex,
17
- endIndex,
18
- ranges,
19
- isAdd,
20
- indexRef,
21
- }: {
22
- str: string;
23
- startIndex: number;
24
- endIndex: number;
25
- isAdd: boolean;
26
- ranges: ReturnType<typeof diffChanges>["addRange"]["range"];
27
- indexRef: { current: number };
28
- }) => {
29
- if (!str) return null;
30
-
31
- const index = indexRef.current;
32
-
33
- const range = ranges[index];
34
-
35
- if (!range || endIndex < range.location || range.location + range.length < startIndex) return str.replace("\n", "");
36
-
37
- const index1 = range.location - startIndex;
38
- const index2 = index1 < 0 ? 0 : index1;
39
- const str1 = str.slice(0, index2);
40
- const str2 = str.slice(index2, index1 + range.length);
41
- const str3 = str.slice(index1 + range.length);
42
- const isStart = str1.length || range.location === startIndex;
43
-
44
- const isEnd = str3.length || endIndex === range.location + range.length - 1;
45
-
46
- if (isEnd && str3.length) indexRef.current++;
47
-
48
- const isLast = str2.includes("\n");
49
-
50
- const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
51
-
52
- return (
53
- <span
54
- data-range-start={range.location}
55
- data-range-end={range.location + range.length}
56
- data-total={ranges.length}
57
- data-index={index}
58
- >
59
- <span data-start={startIndex} data-end={endIndex}>
60
- {str1}
61
- <span
62
- data-diff-highlight
63
- style={{
64
- backgroundColor: isAdd ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
65
- borderTopLeftRadius: isStart ? "0.2em" : undefined,
66
- borderBottomLeftRadius: isStart ? "0.2em" : undefined,
67
- borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
68
- borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
69
- }}
70
- >
71
- {_str2}
72
- </span>
73
- {/* 可能会出现一个node跨越多个range的情况 */}
74
- {RenderRange({
75
- str: str3,
76
- startIndex: startIndex + str1.length + str2.length,
77
- endIndex,
78
- ranges,
79
- isAdd,
80
- indexRef,
81
- })}
82
- </span>
83
- </span>
84
- );
85
- };
86
-
87
- // TODO
88
- const DiffSyntax = ({
89
- rawLine,
90
- diffLine,
91
- operator,
92
- syntaxLine,
93
- enableWrap,
94
- }: {
95
- rawLine: string;
96
- diffLine?: DiffLine;
97
- syntaxLine?: SyntaxLine;
98
- operator?: "add" | "del";
99
- enableWrap?: boolean;
100
- }) => {
101
- if (!syntaxLine) {
102
- return <DiffString rawLine={rawLine} diffLine={diffLine} operator={operator} />;
103
- }
104
-
105
- const diffRange = diffLine?.diffChanges;
106
-
107
- if (diffRange?.hasLineChange) {
108
- const isAdd = operator === "add";
109
-
110
- const targetRange = diffRange.range.filter((i) => i.type === (isAdd ? 1 : -1));
111
-
112
- const isNewLineSymbolChanged = diffRange.newLineSymbol;
113
-
114
- const newLineSymbol = getSymbol(isNewLineSymbolChanged);
115
-
116
- const hasNoTrailingNewLine = isNewLineSymbolChanged === NewLineSymbol.NEWLINE;
117
-
118
- const rangeIndexRef = { current: 0 };
119
-
120
- return (
121
- <span className="diff-line-syntax-raw">
122
- {syntaxLine.nodeList?.map(({ node, wrapper }, index) => {
123
- const range = targetRange[rangeIndexRef.current];
124
- if (!range || node.endIndex < range.location || range.location + range.length < node.startIndex) {
125
- return (
126
- <span
127
- key={index}
128
- data-start={node.startIndex}
129
- data-end={node.endIndex}
130
- className={wrapper?.properties?.className?.join(" ")}
131
- style={getStyleObjectFromString(wrapper?.properties?.style || "")}
132
- >
133
- {node.value.replace("\n", "")}
134
- </span>
135
- );
136
- } else {
137
- return (
138
- <span
139
- key={index}
140
- data-start={node.startIndex}
141
- data-end={node.endIndex}
142
- className={wrapper?.properties?.className?.join(" ")}
143
- style={getStyleObjectFromString(wrapper?.properties?.style || "")}
144
- >
145
- {/* 将组件转换为函数调用,避免同级渲染时后续组件的index没有正确更新的问题 */}
146
- {RenderRange({
147
- str: node.value,
148
- startIndex: node.startIndex,
149
- endIndex: node.endIndex,
150
- ranges: targetRange,
151
- isAdd,
152
- indexRef: rangeIndexRef,
153
- })}
154
- </span>
155
- );
156
- }
157
- })}
158
-
159
- {newLineSymbol && (
160
- <span
161
- data-newline-symbol
162
- data-diff-highlight
163
- className="rounded-[0.2em]"
164
- style={{
165
- backgroundColor: isAdd ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
166
- }}
167
- >
168
- {newLineSymbol}
169
- </span>
170
- )}
171
-
172
- {hasNoTrailingNewLine && (
173
- <span
174
- data-no-newline-at-end-of-file-symbol
175
- className={enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500"}
176
- style={{
177
- width: `var(${diffFontSizeName})`,
178
- height: `var(${diffFontSizeName})`,
179
- }}
180
- >
181
- <DiffNoNewLine />
182
- </span>
183
- )}
184
- </span>
185
- );
186
- }
187
-
188
- return (
189
- <span className="diff-line-syntax-raw">
190
- {syntaxLine?.nodeList?.map(({ node, wrapper }, index) => (
191
- <span
192
- key={index}
193
- data-start={node.startIndex}
194
- data-end={node.endIndex}
195
- className={wrapper?.properties?.className?.join(" ")}
196
- style={getStyleObjectFromString(wrapper?.properties?.style || "")}
197
- >
198
- {node.value}
199
- </span>
200
- ))}
201
- </span>
202
- );
203
- };
204
-
205
- // TODO
206
- const DiffString = ({
207
- rawLine,
208
- diffLine,
209
- operator,
210
- enableWrap,
211
- }: {
212
- rawLine: string;
213
- diffLine?: DiffLine;
214
- operator?: "add" | "del";
215
- enableWrap?: boolean;
216
- }) => {
217
- const diffRange = diffLine?.diffChanges;
218
-
219
- const isAdd = operator === "add";
220
-
221
- if (diffRange?.hasLineChange) {
222
- const targetRange = diffRange.range;
223
-
224
- const isNewLineSymbolChanged = diffRange.newLineSymbol;
225
-
226
- const newLineSymbol = getSymbol(isNewLineSymbolChanged);
227
-
228
- const hasNoTrailingNewLine = isNewLineSymbolChanged === NewLineSymbol.NEWLINE;
229
-
230
- return (
231
- <span className="diff-line-content-raw">
232
- {targetRange.map(({ type, str, location, length }, index) => {
233
- if (type === 0) {
234
- return <span key={index}>{str}</span>;
235
- } else {
236
- return (
237
- <span key={index} data-range-start={location} data-range-end={location + length}>
238
- <span
239
- data-diff-highlight
240
- className="rounded-[0.2em]"
241
- style={{
242
- backgroundColor: isAdd ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
243
- }}
244
- >
245
- {str}
246
- </span>
247
- </span>
248
- );
249
- }
250
- })}
251
-
252
- {newLineSymbol && (
253
- <span
254
- data-newline-symbol
255
- data-diff-highlight
256
- className="rounded-[0.2em]"
257
- style={{
258
- backgroundColor: isAdd ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
259
- }}
260
- >
261
- {newLineSymbol}
262
- </span>
263
- )}
264
-
265
- {hasNoTrailingNewLine && (
266
- <span
267
- data-no-newline-at-end-of-file-symbol
268
- className={enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500"}
269
- style={{
270
- width: `var(${diffFontSizeName})`,
271
- height: `var(${diffFontSizeName})`,
272
- }}
273
- >
274
- <DiffNoNewLine />
275
- </span>
276
- )}
277
- </span>
278
- );
279
- } else {
280
- return <span className="diff-line-content-raw">{rawLine}</span>;
281
- }
282
- };
283
-
284
- // TODO
285
- export const DiffContent_v2 = ({
286
- diffLine,
287
- rawLine,
288
- syntaxLine,
289
- enableWrap,
290
- enableHighlight,
291
- }: {
292
- rawLine: string;
293
- syntaxLine?: SyntaxLine;
294
- diffLine?: DiffLine;
295
- diffFile: DiffFile;
296
- enableWrap: boolean;
297
- enableHighlight: boolean;
298
- }) => {
299
- const isAdded = diffLine?.type === DiffLineType.Add;
300
-
301
- const isDelete = diffLine?.type === DiffLineType.Delete;
302
-
303
- const isMaxLineLengthToIgnoreSyntax = syntaxLine?.nodeList?.length > 150;
304
-
305
- return (
306
- <div
307
- className="diff-line-content-item pl-[2.0em]"
308
- // data-val={rawLine}
309
- style={{
310
- whiteSpace: enableWrap ? "pre-wrap" : "pre",
311
- wordBreak: enableWrap ? "break-all" : "initial",
312
- }}
313
- >
314
- <span
315
- data-operator={isAdded ? "+" : isDelete ? "-" : undefined}
316
- className="diff-line-content-operator ml-[-1.5em] inline-block w-[1.5em] select-none indent-[0.2em]"
317
- >
318
- {isAdded ? "+" : isDelete ? "-" : " "}
319
- </span>
320
- {enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (
321
- <DiffSyntax
322
- operator={isAdded ? "add" : isDelete ? "del" : undefined}
323
- rawLine={rawLine}
324
- diffLine={diffLine}
325
- syntaxLine={syntaxLine}
326
- enableWrap={enableWrap}
327
- />
328
- ) : (
329
- <DiffString
330
- operator={isAdded ? "add" : isDelete ? "del" : undefined}
331
- rawLine={rawLine}
332
- diffLine={diffLine}
333
- enableWrap={enableWrap}
334
- />
335
- )}
336
- </div>
337
- );
338
- };