@git-diff-view/react 0.0.27 → 0.0.29

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.
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { NewLineSymbol, DiffLineType, getSyntaxDiffTemplate, getSyntaxLineTemplate, getPlainDiffTemplate, getPlainLineTemplate, SplitSide, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
2
+ import { DiffLineType, getSyntaxDiffTemplate, getSyntaxLineTemplate, getPlainDiffTemplate, getPlainLineTemplate, SplitSide, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
3
3
  export * from '@git-diff-view/core';
4
4
  export { SplitSide } from '@git-diff-view/core';
5
5
  import * as React from 'react';
@@ -203,6 +203,15 @@ const memoFunc = (func) => {
203
203
  });
204
204
  };
205
205
 
206
+ var NewLineSymbol;
207
+ (function (NewLineSymbol) {
208
+ NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
209
+ NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
210
+ NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
211
+ NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
212
+ NewLineSymbol[NewLineSymbol["NORMAL"] = 5] = "NORMAL";
213
+ NewLineSymbol[NewLineSymbol["NULL"] = 6] = "NULL";
214
+ })(NewLineSymbol || (NewLineSymbol = {}));
206
215
  const getSymbol = (symbol) => {
207
216
  switch (symbol) {
208
217
  case NewLineSymbol.LF:
@@ -215,6 +224,15 @@ const getSymbol = (symbol) => {
215
224
  return "";
216
225
  }
217
226
  };
227
+ var DiffModeEnum;
228
+ (function (DiffModeEnum) {
229
+ // github like
230
+ DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
231
+ // gitlab like
232
+ DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
233
+ DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
234
+ DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
235
+ })(DiffModeEnum || (DiffModeEnum = {}));
218
236
 
219
237
  const useIsMounted = () => {
220
238
  const [isMounted, setIsMounted] = useState(false);
@@ -309,14 +327,14 @@ const getStyleObjectFromString = memoFunc((str) => {
309
327
  });
310
328
  return style;
311
329
  });
312
- const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
330
+ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, enableTemplate, }) => {
313
331
  const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
314
332
  if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
315
333
  const isNewLineSymbolChanged = changes.newLineSymbol;
316
- if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof getPlainDiffTemplate === "function") {
334
+ if (enableTemplate && !(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof getPlainDiffTemplate === "function") {
317
335
  getPlainDiffTemplate({ diffLine, rawLine, operator });
318
336
  }
319
- if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
337
+ if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate)) {
320
338
  return (React.createElement("span", { className: "diff-line-content-raw" },
321
339
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
322
340
  isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
@@ -349,27 +367,27 @@ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) =>
349
367
  React.createElement(DiffNoNewLine, null)))));
350
368
  }
351
369
  }
352
- if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
370
+ if (enableTemplate && plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
353
371
  plainLine.template = getPlainLineTemplate(plainLine.value);
354
372
  }
355
- if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
373
+ if (enableTemplate && (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
356
374
  return (React.createElement("span", { className: "diff-line-content-raw" },
357
375
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
358
376
  }
359
377
  return React.createElement("span", { className: "diff-line-content-raw" }, rawLine);
360
378
  };
361
- const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) => {
379
+ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, enableTemplate, }) => {
362
380
  var _a, _b;
363
381
  if (!syntaxLine) {
364
- return React.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
382
+ return (React.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator, enableWrap: enableWrap, enableTemplate: enableTemplate }));
365
383
  }
366
384
  const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
367
385
  if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
368
386
  const isNewLineSymbolChanged = changes.newLineSymbol;
369
- if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof getSyntaxDiffTemplate === "function") {
387
+ if (enableTemplate && !(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof getSyntaxDiffTemplate === "function") {
370
388
  getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
371
389
  }
372
- if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
390
+ if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate)) {
373
391
  return (React.createElement("span", { className: "diff-line-syntax-raw" },
374
392
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
375
393
  isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
@@ -420,10 +438,10 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
420
438
  React.createElement(DiffNoNewLine, null)))));
421
439
  }
422
440
  }
423
- if (!syntaxLine.template) {
441
+ if (enableTemplate && !syntaxLine.template) {
424
442
  syntaxLine.template = getSyntaxLineTemplate(syntaxLine);
425
443
  }
426
- if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
444
+ if (enableTemplate && (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template)) {
427
445
  return (React.createElement("span", { className: "diff-line-syntax-raw" },
428
446
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
429
447
  }
@@ -432,11 +450,12 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
432
450
  return (React.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
433
451
  })));
434
452
  };
435
- const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
436
- var _a;
453
+ const DiffContent = ({ diffLine, diffFile, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
454
+ var _a, _b, _c;
437
455
  const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Add;
438
456
  const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Delete;
439
457
  const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
458
+ const isEnableTemplate = (_c = (_b = diffFile.getIsEnableTemplate) === null || _b === void 0 ? void 0 : _b.call(diffFile)) !== null && _c !== void 0 ? _c : true;
440
459
  return (React.createElement("div", { className: "diff-line-content-item pl-[2.0em]",
441
460
  // data-val={rawLine}
442
461
  style: {
@@ -444,7 +463,7 @@ const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, ena
444
463
  wordBreak: enableWrap ? "break-all" : "initial",
445
464
  } },
446
465
  React.createElement("span", { "data-operator": isAdded ? "+" : isDelete ? "-" : undefined, className: "diff-line-content-operator ml-[-1.5em] inline-block w-[1.5em] select-none indent-[0.2em]" }, isAdded ? "+" : isDelete ? "-" : " "),
447
- enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, enableWrap: enableWrap }))));
466
+ enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap, enableTemplate: isEnableTemplate })) : (React.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, enableWrap: enableWrap, enableTemplate: isEnableTemplate }))));
448
467
  };
449
468
 
450
469
  const DiffViewContext = createContext(null);
@@ -463,7 +482,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
463
482
  const newLine = diffFile.getSplitRightLine(index);
464
483
  const currentLine = side === SplitSide.old ? oldLine : newLine;
465
484
  const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
466
- const hasContent = !!currentLine.lineNumber;
485
+ const hasContent = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.lineNumber);
467
486
  const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
468
487
  const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
469
488
  const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
@@ -476,7 +495,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
476
495
  const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
477
496
  const plainLine = getCurrentPlainLine(currentLine.lineNumber);
478
497
  return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff || !hasContent ? "diff" : "plain", "data-side": SplitSide[side], className: "diff-line" + (hasContent ? " group" : "") }, hasContent ? (React.createElement(React.Fragment, null,
479
- React.createElement("td", { className: `diff-line-${SplitSide[side]}-num sticky left-0 w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
498
+ React.createElement("td", { className: `diff-line-${SplitSide[side]}-num sticky left-0 z-[1] w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
480
499
  backgroundColor: lineNumberBG,
481
500
  color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
482
501
  width: `var(${diffAsideWidthName})`,
@@ -486,7 +505,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
486
505
  hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
487
506
  React.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
488
507
  React.createElement("td", { className: `diff-line-${SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
489
- React.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, plainLine: plainLine, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: `diff-line-${SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
508
+ React.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: (currentLine === null || currentLine === void 0 ? void 0 : currentLine.value) || "", diffLine: currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff, plainLine: plainLine, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: `diff-line-${SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
490
509
  React.createElement("span", null, "\u2002")))));
491
510
  };
492
511
  const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
@@ -762,7 +781,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
762
781
  const { useDiffContext } = useDiffViewContext();
763
782
  const oldLine = diffFile.getSplitLeftLine(index);
764
783
  const newLine = diffFile.getSplitRightLine(index);
765
- const widgetSide = useWidget.getReadonlyState().widgetSide;
784
+ const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
766
785
  const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
767
786
  const setWidget = useWidget.getReadonlyState().setWidget;
768
787
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
@@ -841,6 +860,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
841
860
  const ref1 = useRef(null);
842
861
  const ref2 = useRef(null);
843
862
  const ref = useRef();
863
+ const tempRef = useRef();
844
864
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
845
865
  const { useDiffContext } = useDiffViewContext();
846
866
  const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
@@ -884,13 +904,19 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
884
904
  const state = ele.getAttribute("data-state");
885
905
  const side = ele.getAttribute("data-side");
886
906
  if (side) {
887
- setStyle(SplitSide[side]);
888
- removeAllSelection();
907
+ if (tempRef.current !== SplitSide[side]) {
908
+ tempRef.current = SplitSide[side];
909
+ setStyle(SplitSide[side]);
910
+ removeAllSelection();
911
+ }
889
912
  }
890
913
  if (state) {
891
914
  if (state === "extend" || state === "hunk" || state === "widget") {
892
- setStyle(undefined);
893
- removeAllSelection();
915
+ if (tempRef.current !== undefined) {
916
+ tempRef.current = undefined;
917
+ setStyle(undefined);
918
+ removeAllSelection();
919
+ }
894
920
  return;
895
921
  }
896
922
  else {
@@ -1134,7 +1160,7 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1134
1160
  const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
1135
1161
  const oldLine = diffFile.getSplitLeftLine(index);
1136
1162
  const newLine = diffFile.getSplitRightLine(index);
1137
- const widgetSide = useWidget.getReadonlyState().widgetSide;
1163
+ const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
1138
1164
  const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
1139
1165
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
1140
1166
  const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
@@ -1177,6 +1203,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1177
1203
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
1178
1204
  const { useDiffContext } = useDiffViewContext();
1179
1205
  const ref = useRef(null);
1206
+ const tempRef = useRef();
1180
1207
  const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
1181
1208
  fontSize: s.fontSize,
1182
1209
  enableAddWidget: s.enableAddWidget,
@@ -1213,13 +1240,19 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1213
1240
  const state = ele.getAttribute("data-state");
1214
1241
  const side = ele.getAttribute("data-side");
1215
1242
  if (side) {
1216
- setStyle(SplitSide[side]);
1217
- removeAllSelection();
1243
+ if (tempRef.current !== SplitSide[side]) {
1244
+ tempRef.current = SplitSide[side];
1245
+ setStyle(SplitSide[side]);
1246
+ removeAllSelection();
1247
+ }
1218
1248
  }
1219
1249
  if (state) {
1220
1250
  if (state === "extend" || state === "hunk" || state === "widget") {
1221
- setStyle(undefined);
1222
- removeAllSelection();
1251
+ if (tempRef.current !== undefined) {
1252
+ tempRef.current = undefined;
1253
+ setStyle(undefined);
1254
+ removeAllSelection();
1255
+ }
1223
1256
  return;
1224
1257
  }
1225
1258
  else {
@@ -1379,7 +1412,7 @@ DiffSplitView.displayName = "DiffSplitView";
1379
1412
 
1380
1413
  const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1381
1414
  return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1382
- React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1415
+ React.createElement("td", { className: "diff-line-num sticky left-0 z-[1] w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1383
1416
  color: `var(${plainLineNumberColorName})`,
1384
1417
  backgroundColor: `var(${delLineNumberBGName})`,
1385
1418
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1396,7 +1429,7 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, l
1396
1429
  };
1397
1430
  const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1398
1431
  return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1399
- React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1432
+ React.createElement("td", { className: "diff-line-num sticky left-0 z-[1] w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1400
1433
  color: `var(${plainLineNumberColorName})`,
1401
1434
  backgroundColor: `var(${addLineNumberBGName})`,
1402
1435
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1443,7 +1476,7 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber, enableWrap, enable
1443
1476
  }
1444
1477
  else {
1445
1478
  return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
1446
- React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1479
+ React.createElement("td", { className: "diff-line-num sticky left-0 z-[1] w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
1447
1480
  color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
1448
1481
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1449
1482
  maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1612,6 +1645,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1612
1645
  const DiffUnifiedView = memo(({ diffFile }) => {
1613
1646
  const { useDiffContext } = useDiffViewContext();
1614
1647
  const ref = useRef(null);
1648
+ const tempRef = useRef();
1615
1649
  const useDiffContextRef = useRef(useDiffContext);
1616
1650
  useDiffContextRef.current = useDiffContext;
1617
1651
  // performance optimization
@@ -1661,13 +1695,19 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1661
1695
  const state = ele.getAttribute("data-state");
1662
1696
  if (state) {
1663
1697
  if (state === "extend" || state === "hunk" || state === "widget") {
1664
- setStyle(undefined);
1665
- removeAllSelection();
1698
+ if (tempRef.current !== undefined) {
1699
+ tempRef.current = undefined;
1700
+ setStyle(undefined);
1701
+ removeAllSelection();
1702
+ }
1666
1703
  return;
1667
1704
  }
1668
1705
  else {
1669
- setStyle(SplitSide.new);
1670
- removeAllSelection();
1706
+ if (tempRef.current !== SplitSide.new) {
1707
+ tempRef.current = SplitSide.new;
1708
+ setStyle(SplitSide.new);
1709
+ removeAllSelection();
1710
+ }
1671
1711
  return;
1672
1712
  }
1673
1713
  }
@@ -1702,19 +1742,9 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1702
1742
  DiffUnifiedView.displayName = "DiffUnifiedView";
1703
1743
 
1704
1744
  _cacheMap.name = "@git-diff-view/react";
1705
- var DiffModeEnum;
1706
- (function (DiffModeEnum) {
1707
- // github like
1708
- DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
1709
- // gitlab like
1710
- DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
1711
- DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
1712
- DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
1713
- })(DiffModeEnum || (DiffModeEnum = {}));
1714
1745
  const InternalDiffView = (props) => {
1715
- const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
1746
+ const { diffFile, className, style, wrapperRef, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
1716
1747
  const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
1717
- const wrapperRef = useRef();
1718
1748
  // performance optimization
1719
1749
  const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
1720
1750
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1772,17 +1802,9 @@ const InternalDiffView = (props) => {
1772
1802
  onAddWidgetClick,
1773
1803
  onCreateUseWidgetHook,
1774
1804
  ]);
1775
- useEffect(() => {
1776
- const cb = diffFile.subscribe(() => {
1777
- var _a, _b;
1778
- (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
1779
- (_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
1780
- });
1781
- return cb;
1782
- }, [diffFile]);
1783
1805
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1784
1806
  return (React.createElement(DiffViewContext.Provider, { value: value },
1785
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.27", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1807
+ React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.29", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1786
1808
  React.createElement("div", { className: "diff-style-root", style: {
1787
1809
  // @ts-ignore
1788
1810
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -1809,6 +1831,7 @@ const DiffViewWithRef = (props, ref) => {
1809
1831
  return null;
1810
1832
  }, [data, _diffFile]);
1811
1833
  const diffFileRef = useRef(diffFile);
1834
+ const wrapperRef = useRef();
1812
1835
  if (diffFileRef.current && diffFileRef.current !== diffFile) {
1813
1836
  (_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
1814
1837
  diffFileRef.current = diffFile;
@@ -1837,18 +1860,28 @@ const DiffViewWithRef = (props, ref) => {
1837
1860
  diffFile.initSyntax({ registerHighlighter });
1838
1861
  diffFile.notifyAll();
1839
1862
  }
1840
- }, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
1863
+ }, [diffFile, props.diffViewHighlight, registerHighlighter]);
1864
+ useEffect(() => {
1865
+ const init = () => {
1866
+ var _a, _b;
1867
+ (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
1868
+ (_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
1869
+ };
1870
+ init();
1871
+ const cb = diffFile.subscribe(init);
1872
+ return cb;
1873
+ }, [diffFile, diffViewTheme]);
1841
1874
  // fix react strict mode error
1842
1875
  useUnmount(() => { var _a, _b; return (process.env.NODE_ENV === "development" ? (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile._destroy) === null || _a === void 0 ? void 0 : _a.call(diffFile) : (_b = diffFile === null || diffFile === void 0 ? void 0 : diffFile.clear) === null || _b === void 0 ? void 0 : _b.call(diffFile)); }, [diffFile]);
1843
1876
  useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
1844
1877
  if (!diffFile)
1845
1878
  return null;
1846
- return (React.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
1879
+ return (React.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, wrapperRef: wrapperRef, diffViewTheme: diffViewTheme, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
1847
1880
  };
1848
1881
  const InnerDiffView = forwardRef(DiffViewWithRef);
1849
1882
  InnerDiffView.displayName = "DiffView";
1850
1883
  const DiffView = InnerDiffView;
1851
- const version = "0.0.27";
1884
+ const version = "0.0.29";
1852
1885
 
1853
1886
  export { DiffModeEnum, DiffView, version };
1854
1887
  //# sourceMappingURL=index.mjs.map