@git-diff-view/react 0.0.23 → 0.0.25

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.
@@ -2,7 +2,7 @@
2
2
  import { NewLineSymbol, DiffLineType, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
3
3
  export * from '@git-diff-view/core';
4
4
  import * as React from 'react';
5
- import { useRef, useEffect, createContext, useContext, useLayoutEffect, useState, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
5
+ import { useState, useEffect, useRef, useLayoutEffect, createContext, useContext, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
6
6
  import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
7
7
  import { flushSync } from 'react-dom';
8
8
  import { createStore, ref } from 'reactivity-store';
@@ -214,6 +214,14 @@ const getSymbol = (symbol) => {
214
214
  }
215
215
  };
216
216
 
217
+ const useIsMounted = () => {
218
+ const [isMounted, setIsMounted] = useState(false);
219
+ useEffect(() => {
220
+ setIsMounted(true);
221
+ }, []);
222
+ return isMounted;
223
+ };
224
+
217
225
  const useUnmount = (cb, deps) => {
218
226
  const ref = useRef(cb);
219
227
  ref.current = cb;
@@ -221,19 +229,6 @@ const useUnmount = (cb, deps) => {
221
229
  useEffect(() => ref.current, deps);
222
230
  };
223
231
 
224
- var DiffModeEnum;
225
- (function (DiffModeEnum) {
226
- // github like
227
- DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
228
- // gitlab like
229
- DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
230
- DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
231
- DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
232
- })(DiffModeEnum || (DiffModeEnum = {}));
233
- const DiffViewContext = createContext(null);
234
- DiffViewContext.displayName = "DiffViewContext";
235
- const useDiffViewContext = () => useContext(DiffViewContext);
236
-
237
232
  const isClient = typeof window !== "undefined";
238
233
  const useSafeLayout = isClient ? useLayoutEffect : useEffect;
239
234
 
@@ -403,6 +398,10 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
403
398
  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, enableWrap: enableWrap }))));
404
399
  };
405
400
 
401
+ const DiffViewContext = createContext(null);
402
+ DiffViewContext.displayName = "DiffViewContext";
403
+ const useDiffViewContext = () => useContext(DiffViewContext);
404
+
406
405
  const DiffWidgetContext = createContext(null);
407
406
  DiffWidgetContext.displayName = "DiffWidgetContext";
408
407
  const useDiffWidgetContext = () => useContext(DiffWidgetContext);
@@ -871,12 +870,17 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
871
870
  backgroundColor: newLineNumberBG,
872
871
  color: `var(${plainLineNumberColorName})`,
873
872
  borderLeftColor: `var(${borderColorName})`,
873
+ borderLeftStyle: "solid",
874
874
  } },
875
875
  hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, 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 }) })),
876
876
  React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
877
877
  React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
878
878
  hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] z-[1] translate-x-[50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
879
- React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
879
+ React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
880
+ backgroundColor: `var(${emptyBGName})`,
881
+ borderLeftColor: `var(${borderColorName})`,
882
+ borderLeftStyle: "solid",
883
+ }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
880
884
  React.createElement("span", null, "\u2002")))));
881
885
  };
882
886
  const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
@@ -914,8 +918,12 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
914
918
  return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
915
919
  oldExtendRendered ? (React.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
916
920
  React.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }, newExtendRendered && React.createElement("span", null, "\u2002"))),
917
- newExtendRendered ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
918
- React.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 }, oldExtendRendered && React.createElement("span", null, "\u2002")))));
921
+ newExtendRendered ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
922
+ React.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: {
923
+ backgroundColor: `var(${emptyBGName})`,
924
+ borderLeftColor: `var(${borderColorName})`,
925
+ borderLeftStyle: "solid",
926
+ }, colSpan: 2 }, oldExtendRendered && React.createElement("span", null, "\u2002")))));
919
927
  };
920
928
  const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
921
929
  const { useDiffContext } = useDiffViewContext();
@@ -990,10 +998,11 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
990
998
  React.createElement("div", { className: "pl-[1.5em]", style: {
991
999
  color: `var(${hunkContentColorName})`,
992
1000
  } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
993
- React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
1001
+ React.createElement("td", { className: "diff-line-hunk-action relative z-[1] w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
994
1002
  backgroundColor: `var(${hunkLineNumberBGName})`,
995
1003
  color: `var(${plainLineNumberColorName})`,
996
1004
  borderLeftColor: `var(${borderColorName})`,
1005
+ borderLeftStyle: "solid",
997
1006
  } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
998
1007
  React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
999
1008
  React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
@@ -1050,8 +1059,12 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1050
1059
  return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
1051
1060
  oldWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
1052
1061
  React.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }, newWidgetRendered && React.createElement("span", null, "\u2002"))),
1053
- newWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})` } },
1054
- React.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 }, oldWidgetRendered && React.createElement("span", null, "\u2002")))));
1062
+ newWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
1063
+ React.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: {
1064
+ backgroundColor: `var(${emptyBGName})`,
1065
+ borderLeftColor: `var(${borderColorName})`,
1066
+ borderLeftStyle: "solid",
1067
+ }, colSpan: 2 }, oldWidgetRendered && React.createElement("span", null, "\u2002")))));
1055
1068
  };
1056
1069
  // TODO! improve performance
1057
1070
  const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
@@ -1395,7 +1408,7 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
1395
1408
  });
1396
1409
  }, [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
1397
1410
  const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
1398
- if (!hasExtend || !unifiedItem || unifiedItem.isHidden || !unifiedItem.diff)
1411
+ if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
1399
1412
  return null;
1400
1413
  return (React.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
1401
1414
  };
@@ -1419,13 +1432,13 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1419
1432
  width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1420
1433
  maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1421
1434
  minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1422
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
1423
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
1424
- React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
1435
+ } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
1436
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
1437
+ React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
1425
1438
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
1426
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
1439
+ React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
1427
1440
  React.createElement(ExpandDown, { className: "fill-current" })),
1428
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
1441
+ React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
1429
1442
  React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
1430
1443
  React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
1431
1444
  React.createElement("div", { className: "pl-[1.5em]", style: {
@@ -1553,9 +1566,19 @@ var SplitSide;
1553
1566
  SplitSide[SplitSide["old"] = 1] = "old";
1554
1567
  SplitSide[SplitSide["new"] = 2] = "new";
1555
1568
  })(SplitSide || (SplitSide = {}));
1569
+ var DiffModeEnum;
1570
+ (function (DiffModeEnum) {
1571
+ // github like
1572
+ DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
1573
+ // gitlab like
1574
+ DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
1575
+ DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
1576
+ DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
1577
+ })(DiffModeEnum || (DiffModeEnum = {}));
1556
1578
  const _InternalDiffView = (props) => {
1557
1579
  const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
1558
1580
  const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
1581
+ const isMounted = useIsMounted();
1559
1582
  const wrapperRef = useRef();
1560
1583
  // performance optimization
1561
1584
  const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
@@ -1596,12 +1619,12 @@ const _InternalDiffView = (props) => {
1596
1619
  }, [diffFile]);
1597
1620
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1598
1621
  return (React.createElement(DiffViewContext.Provider, { value: value },
1599
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.23", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1622
+ React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.25", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1600
1623
  React.createElement("div", { className: "diff-style-root", style: {
1601
1624
  // @ts-ignore
1602
1625
  [diffFontSizeName]: diffViewFontSize + "px",
1603
1626
  } },
1604
- React.createElement("div", { suppressHydrationWarning: true, id: `diff-root${diffFileId}`, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & DiffModeEnum.Split ? (React.createElement(DiffSplitView, { diffFile: diffFile })) : (React.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
1627
+ React.createElement("div", { id: isMounted ? `diff-root${diffFileId}` : undefined, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & DiffModeEnum.Split ? (React.createElement(DiffSplitView, { diffFile: diffFile })) : (React.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
1605
1628
  };
1606
1629
  const InternalDiffView = memo(_InternalDiffView);
1607
1630
  const DiffViewWithRef = (props, ref) => {
@@ -1661,7 +1684,7 @@ const DiffViewWithRef = (props, ref) => {
1661
1684
  const InnerDiffView = forwardRef(DiffViewWithRef);
1662
1685
  InnerDiffView.displayName = "DiffView";
1663
1686
  const DiffView = InnerDiffView;
1664
- const version = "0.0.23";
1687
+ const version = "0.0.25";
1665
1688
 
1666
- export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
1689
+ export { DiffModeEnum, DiffView, SplitSide, version };
1667
1690
  //# sourceMappingURL=index.mjs.map