@git-diff-view/react 0.0.28 → 0.0.30

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.
@@ -224,6 +224,15 @@ const getSymbol = (symbol) => {
224
224
  return "";
225
225
  }
226
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 = {}));
227
236
 
228
237
  const useIsMounted = () => {
229
238
  const [isMounted, setIsMounted] = useState(false);
@@ -318,14 +327,14 @@ const getStyleObjectFromString = memoFunc((str) => {
318
327
  });
319
328
  return style;
320
329
  });
321
- const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
330
+ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, enableTemplate, }) => {
322
331
  const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
323
332
  if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
324
333
  const isNewLineSymbolChanged = changes.newLineSymbol;
325
- 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") {
326
335
  getPlainDiffTemplate({ diffLine, rawLine, operator });
327
336
  }
328
- if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
337
+ if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate)) {
329
338
  return (React.createElement("span", { className: "diff-line-content-raw" },
330
339
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
331
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: {
@@ -358,27 +367,27 @@ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) =>
358
367
  React.createElement(DiffNoNewLine, null)))));
359
368
  }
360
369
  }
361
- if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
370
+ if (enableTemplate && plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
362
371
  plainLine.template = getPlainLineTemplate(plainLine.value);
363
372
  }
364
- if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
373
+ if (enableTemplate && (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
365
374
  return (React.createElement("span", { className: "diff-line-content-raw" },
366
375
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
367
376
  }
368
377
  return React.createElement("span", { className: "diff-line-content-raw" }, rawLine);
369
378
  };
370
- const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) => {
379
+ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, enableTemplate, }) => {
371
380
  var _a, _b;
372
381
  if (!syntaxLine) {
373
- 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 }));
374
383
  }
375
384
  const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
376
385
  if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
377
386
  const isNewLineSymbolChanged = changes.newLineSymbol;
378
- 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") {
379
388
  getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
380
389
  }
381
- if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
390
+ if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate)) {
382
391
  return (React.createElement("span", { className: "diff-line-syntax-raw" },
383
392
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
384
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: {
@@ -429,10 +438,10 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
429
438
  React.createElement(DiffNoNewLine, null)))));
430
439
  }
431
440
  }
432
- if (!syntaxLine.template) {
441
+ if (enableTemplate && !syntaxLine.template) {
433
442
  syntaxLine.template = getSyntaxLineTemplate(syntaxLine);
434
443
  }
435
- if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
444
+ if (enableTemplate && (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template)) {
436
445
  return (React.createElement("span", { className: "diff-line-syntax-raw" },
437
446
  React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
438
447
  }
@@ -441,11 +450,12 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
441
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));
442
451
  })));
443
452
  };
444
- const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
445
- var _a;
453
+ const DiffContent = ({ diffLine, diffFile, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
454
+ var _a, _b, _c;
446
455
  const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Add;
447
456
  const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Delete;
448
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;
449
459
  return (React.createElement("div", { className: "diff-line-content-item pl-[2.0em]",
450
460
  // data-val={rawLine}
451
461
  style: {
@@ -453,7 +463,7 @@ const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, ena
453
463
  wordBreak: enableWrap ? "break-all" : "initial",
454
464
  } },
455
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 ? "-" : " "),
456
- 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 }))));
457
467
  };
458
468
 
459
469
  const DiffViewContext = createContext(null);
@@ -472,7 +482,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
472
482
  const newLine = diffFile.getSplitRightLine(index);
473
483
  const currentLine = side === SplitSide.old ? oldLine : newLine;
474
484
  const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
475
- const hasContent = !!currentLine.lineNumber;
485
+ const hasContent = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.lineNumber);
476
486
  const hasChange = checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
477
487
  const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
478
488
  const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
@@ -485,7 +495,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
485
495
  const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
486
496
  const plainLine = getCurrentPlainLine(currentLine.lineNumber);
487
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,
488
- 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: {
489
499
  backgroundColor: lineNumberBG,
490
500
  color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
491
501
  width: `var(${diffAsideWidthName})`,
@@ -495,7 +505,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
495
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 }) })),
496
506
  React.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
497
507
  React.createElement("td", { className: `diff-line-${SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
498
- 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 },
499
509
  React.createElement("span", null, "\u2002")))));
500
510
  };
501
511
  const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
@@ -771,7 +781,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
771
781
  const { useDiffContext } = useDiffViewContext();
772
782
  const oldLine = diffFile.getSplitLeftLine(index);
773
783
  const newLine = diffFile.getSplitRightLine(index);
774
- const widgetSide = useWidget.getReadonlyState().widgetSide;
784
+ const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
775
785
  const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
776
786
  const setWidget = useWidget.getReadonlyState().setWidget;
777
787
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
@@ -850,6 +860,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
850
860
  const ref1 = useRef(null);
851
861
  const ref2 = useRef(null);
852
862
  const ref = useRef();
863
+ const tempRef = useRef();
853
864
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
854
865
  const { useDiffContext } = useDiffViewContext();
855
866
  const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
@@ -893,13 +904,19 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
893
904
  const state = ele.getAttribute("data-state");
894
905
  const side = ele.getAttribute("data-side");
895
906
  if (side) {
896
- setStyle(SplitSide[side]);
897
- removeAllSelection();
907
+ if (tempRef.current !== SplitSide[side]) {
908
+ tempRef.current = SplitSide[side];
909
+ setStyle(SplitSide[side]);
910
+ removeAllSelection();
911
+ }
898
912
  }
899
913
  if (state) {
900
914
  if (state === "extend" || state === "hunk" || state === "widget") {
901
- setStyle(undefined);
902
- removeAllSelection();
915
+ if (tempRef.current !== undefined) {
916
+ tempRef.current = undefined;
917
+ setStyle(undefined);
918
+ removeAllSelection();
919
+ }
903
920
  return;
904
921
  }
905
922
  else {
@@ -1143,7 +1160,7 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1143
1160
  const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
1144
1161
  const oldLine = diffFile.getSplitLeftLine(index);
1145
1162
  const newLine = diffFile.getSplitRightLine(index);
1146
- const widgetSide = useWidget.getReadonlyState().widgetSide;
1163
+ const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
1147
1164
  const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
1148
1165
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
1149
1166
  const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
@@ -1186,6 +1203,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1186
1203
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
1187
1204
  const { useDiffContext } = useDiffViewContext();
1188
1205
  const ref = useRef(null);
1206
+ const tempRef = useRef();
1189
1207
  const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
1190
1208
  fontSize: s.fontSize,
1191
1209
  enableAddWidget: s.enableAddWidget,
@@ -1222,13 +1240,19 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1222
1240
  const state = ele.getAttribute("data-state");
1223
1241
  const side = ele.getAttribute("data-side");
1224
1242
  if (side) {
1225
- setStyle(SplitSide[side]);
1226
- removeAllSelection();
1243
+ if (tempRef.current !== SplitSide[side]) {
1244
+ tempRef.current = SplitSide[side];
1245
+ setStyle(SplitSide[side]);
1246
+ removeAllSelection();
1247
+ }
1227
1248
  }
1228
1249
  if (state) {
1229
1250
  if (state === "extend" || state === "hunk" || state === "widget") {
1230
- setStyle(undefined);
1231
- removeAllSelection();
1251
+ if (tempRef.current !== undefined) {
1252
+ tempRef.current = undefined;
1253
+ setStyle(undefined);
1254
+ removeAllSelection();
1255
+ }
1232
1256
  return;
1233
1257
  }
1234
1258
  else {
@@ -1388,7 +1412,7 @@ DiffSplitView.displayName = "DiffSplitView";
1388
1412
 
1389
1413
  const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1390
1414
  return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1391
- 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: {
1392
1416
  color: `var(${plainLineNumberColorName})`,
1393
1417
  backgroundColor: `var(${delLineNumberBGName})`,
1394
1418
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1405,7 +1429,7 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, l
1405
1429
  };
1406
1430
  const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1407
1431
  return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1408
- 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: {
1409
1433
  color: `var(${plainLineNumberColorName})`,
1410
1434
  backgroundColor: `var(${addLineNumberBGName})`,
1411
1435
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1452,7 +1476,7 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber, enableWrap, enable
1452
1476
  }
1453
1477
  else {
1454
1478
  return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
1455
- 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: {
1456
1480
  color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
1457
1481
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1458
1482
  maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
@@ -1621,6 +1645,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1621
1645
  const DiffUnifiedView = memo(({ diffFile }) => {
1622
1646
  const { useDiffContext } = useDiffViewContext();
1623
1647
  const ref = useRef(null);
1648
+ const tempRef = useRef();
1624
1649
  const useDiffContextRef = useRef(useDiffContext);
1625
1650
  useDiffContextRef.current = useDiffContext;
1626
1651
  // performance optimization
@@ -1670,13 +1695,19 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1670
1695
  const state = ele.getAttribute("data-state");
1671
1696
  if (state) {
1672
1697
  if (state === "extend" || state === "hunk" || state === "widget") {
1673
- setStyle(undefined);
1674
- removeAllSelection();
1698
+ if (tempRef.current !== undefined) {
1699
+ tempRef.current = undefined;
1700
+ setStyle(undefined);
1701
+ removeAllSelection();
1702
+ }
1675
1703
  return;
1676
1704
  }
1677
1705
  else {
1678
- setStyle(SplitSide.new);
1679
- removeAllSelection();
1706
+ if (tempRef.current !== SplitSide.new) {
1707
+ tempRef.current = SplitSide.new;
1708
+ setStyle(SplitSide.new);
1709
+ removeAllSelection();
1710
+ }
1680
1711
  return;
1681
1712
  }
1682
1713
  }
@@ -1711,19 +1742,9 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1711
1742
  DiffUnifiedView.displayName = "DiffUnifiedView";
1712
1743
 
1713
1744
  _cacheMap.name = "@git-diff-view/react";
1714
- var DiffModeEnum;
1715
- (function (DiffModeEnum) {
1716
- // github like
1717
- DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
1718
- // gitlab like
1719
- DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
1720
- DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
1721
- DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
1722
- })(DiffModeEnum || (DiffModeEnum = {}));
1723
1745
  const InternalDiffView = (props) => {
1724
- 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;
1725
1747
  const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
1726
- const wrapperRef = useRef();
1727
1748
  // performance optimization
1728
1749
  const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
1729
1750
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1781,17 +1802,9 @@ const InternalDiffView = (props) => {
1781
1802
  onAddWidgetClick,
1782
1803
  onCreateUseWidgetHook,
1783
1804
  ]);
1784
- useEffect(() => {
1785
- const cb = diffFile.subscribe(() => {
1786
- var _a, _b;
1787
- (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
1788
- (_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
1789
- });
1790
- return cb;
1791
- }, [diffFile]);
1792
1805
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1793
1806
  return (React.createElement(DiffViewContext.Provider, { value: value },
1794
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.28", "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.30", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1795
1808
  React.createElement("div", { className: "diff-style-root", style: {
1796
1809
  // @ts-ignore
1797
1810
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -1818,6 +1831,7 @@ const DiffViewWithRef = (props, ref) => {
1818
1831
  return null;
1819
1832
  }, [data, _diffFile]);
1820
1833
  const diffFileRef = useRef(diffFile);
1834
+ const wrapperRef = useRef();
1821
1835
  if (diffFileRef.current && diffFileRef.current !== diffFile) {
1822
1836
  (_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
1823
1837
  diffFileRef.current = diffFile;
@@ -1846,18 +1860,30 @@ const DiffViewWithRef = (props, ref) => {
1846
1860
  diffFile.initSyntax({ registerHighlighter });
1847
1861
  diffFile.notifyAll();
1848
1862
  }
1849
- }, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
1863
+ }, [diffFile, props.diffViewHighlight, registerHighlighter]);
1864
+ useEffect(() => {
1865
+ if (!diffFile)
1866
+ return;
1867
+ const init = () => {
1868
+ var _a, _b;
1869
+ (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
1870
+ (_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
1871
+ };
1872
+ init();
1873
+ const cb = diffFile.subscribe(init);
1874
+ return cb;
1875
+ }, [diffFile, diffViewTheme]);
1850
1876
  // fix react strict mode error
1851
1877
  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]);
1852
1878
  useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
1853
1879
  if (!diffFile)
1854
1880
  return null;
1855
- return (React.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
1881
+ 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 })));
1856
1882
  };
1857
1883
  const InnerDiffView = forwardRef(DiffViewWithRef);
1858
1884
  InnerDiffView.displayName = "DiffView";
1859
1885
  const DiffView = InnerDiffView;
1860
- const version = "0.0.28";
1886
+ const version = "0.0.30";
1861
1887
 
1862
1888
  export { DiffModeEnum, DiffView, version };
1863
1889
  //# sourceMappingURL=index.mjs.map