@git-diff-view/react 0.0.24 → 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.
- package/dist/cjs/index.development.js +51 -30
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +51 -30
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +662 -0
- package/dist/css/diff-view.css +1150 -5
- package/dist/esm/index.mjs +53 -30
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +12 -113
- package/package.json +7 -6
- package/styles/diff-view-pure.css +662 -0
- package/styles/diff-view.css +1168 -0
|
@@ -233,6 +233,14 @@ const getSymbol = (symbol) => {
|
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
+
const useIsMounted = () => {
|
|
237
|
+
const [isMounted, setIsMounted] = React.useState(false);
|
|
238
|
+
React.useEffect(() => {
|
|
239
|
+
setIsMounted(true);
|
|
240
|
+
}, []);
|
|
241
|
+
return isMounted;
|
|
242
|
+
};
|
|
243
|
+
|
|
236
244
|
const useUnmount = (cb, deps) => {
|
|
237
245
|
const ref = React.useRef(cb);
|
|
238
246
|
ref.current = cb;
|
|
@@ -409,6 +417,10 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
409
417
|
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React__namespace.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React__namespace.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, enableWrap: enableWrap }))));
|
|
410
418
|
};
|
|
411
419
|
|
|
420
|
+
const DiffViewContext = React.createContext(null);
|
|
421
|
+
DiffViewContext.displayName = "DiffViewContext";
|
|
422
|
+
const useDiffViewContext = () => React.useContext(DiffViewContext);
|
|
423
|
+
|
|
412
424
|
const DiffWidgetContext = React.createContext(null);
|
|
413
425
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
414
426
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
@@ -500,19 +512,6 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
500
512
|
return width;
|
|
501
513
|
};
|
|
502
514
|
|
|
503
|
-
exports.DiffModeEnum = void 0;
|
|
504
|
-
(function (DiffModeEnum) {
|
|
505
|
-
// github like
|
|
506
|
-
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
507
|
-
// gitlab like
|
|
508
|
-
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
509
|
-
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
510
|
-
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
511
|
-
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
512
|
-
const DiffViewContext = React.createContext(null);
|
|
513
|
-
DiffViewContext.displayName = "DiffViewContext";
|
|
514
|
-
const useDiffViewContext = () => React.useContext(DiffViewContext);
|
|
515
|
-
|
|
516
515
|
// TODO
|
|
517
516
|
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
518
517
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -890,12 +889,17 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
890
889
|
backgroundColor: newLineNumberBG,
|
|
891
890
|
color: `var(${plainLineNumberColorName})`,
|
|
892
891
|
borderLeftColor: `var(${borderColorName})`,
|
|
892
|
+
borderLeftStyle: "solid",
|
|
893
893
|
} },
|
|
894
894
|
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.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 }) })),
|
|
895
895
|
React__namespace.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
896
896
|
React__namespace.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": exports.SplitSide[exports.SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
897
897
|
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: exports.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 }) })),
|
|
898
|
-
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
898
|
+
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
899
|
+
backgroundColor: `var(${emptyBGName})`,
|
|
900
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
901
|
+
borderLeftStyle: "solid",
|
|
902
|
+
}, "data-side": exports.SplitSide[exports.SplitSide.new], colSpan: 2 },
|
|
899
903
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
900
904
|
};
|
|
901
905
|
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -933,8 +937,12 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
933
937
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
934
938
|
oldExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
935
939
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }, newExtendRendered && React__namespace.createElement("span", null, "\u2002"))),
|
|
936
|
-
newExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})
|
|
937
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
940
|
+
newExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
|
|
941
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
942
|
+
backgroundColor: `var(${emptyBGName})`,
|
|
943
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
944
|
+
borderLeftStyle: "solid",
|
|
945
|
+
}, colSpan: 2 }, oldExtendRendered && React__namespace.createElement("span", null, "\u2002")))));
|
|
938
946
|
};
|
|
939
947
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
940
948
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1009,10 +1017,11 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1009
1017
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
1010
1018
|
color: `var(${hunkContentColorName})`,
|
|
1011
1019
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
|
|
1012
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
|
|
1020
|
+
React__namespace.createElement("td", { className: "diff-line-hunk-action relative z-[1] w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
|
|
1013
1021
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
1014
1022
|
color: `var(${plainLineNumberColorName})`,
|
|
1015
1023
|
borderLeftColor: `var(${borderColorName})`,
|
|
1024
|
+
borderLeftStyle: "solid",
|
|
1016
1025
|
} }, couldExpand ? (isFirstLine ? (React__namespace.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) },
|
|
1017
1026
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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) },
|
|
1018
1027
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.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) },
|
|
@@ -1069,8 +1078,12 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1069
1078
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1070
1079
|
oldWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
1071
1080
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }, newWidgetRendered && React__namespace.createElement("span", null, "\u2002"))),
|
|
1072
|
-
newWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})
|
|
1073
|
-
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
1081
|
+
newWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
|
|
1082
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
1083
|
+
backgroundColor: `var(${emptyBGName})`,
|
|
1084
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
1085
|
+
borderLeftStyle: "solid",
|
|
1086
|
+
}, colSpan: 2 }, oldWidgetRendered && React__namespace.createElement("span", null, "\u2002")))));
|
|
1074
1087
|
};
|
|
1075
1088
|
// TODO! improve performance
|
|
1076
1089
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1414,7 +1427,7 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1414
1427
|
});
|
|
1415
1428
|
}, [unifiedItem.oldLineNumber, unifiedItem.newLineNumber]));
|
|
1416
1429
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
1417
|
-
if (!hasExtend || !unifiedItem || unifiedItem.isHidden
|
|
1430
|
+
if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
|
|
1418
1431
|
return null;
|
|
1419
1432
|
return (React__namespace.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1420
1433
|
};
|
|
@@ -1438,13 +1451,13 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1438
1451
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1439
1452
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1440
1453
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1441
|
-
} }, couldExpand ? (isFirstLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]
|
|
1442
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]
|
|
1443
|
-
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]
|
|
1454
|
+
} }, couldExpand ? (isFirstLine ? (React__namespace.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) },
|
|
1455
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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) },
|
|
1456
|
+
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.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) },
|
|
1444
1457
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
1445
|
-
React__namespace.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1458
|
+
React__namespace.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) },
|
|
1446
1459
|
React__namespace.createElement(ExpandDown, { className: "fill-current" })),
|
|
1447
|
-
React__namespace.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1460
|
+
React__namespace.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) },
|
|
1448
1461
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
1449
1462
|
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1450
1463
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -1572,9 +1585,19 @@ exports.SplitSide = void 0;
|
|
|
1572
1585
|
SplitSide[SplitSide["old"] = 1] = "old";
|
|
1573
1586
|
SplitSide[SplitSide["new"] = 2] = "new";
|
|
1574
1587
|
})(exports.SplitSide || (exports.SplitSide = {}));
|
|
1588
|
+
exports.DiffModeEnum = void 0;
|
|
1589
|
+
(function (DiffModeEnum) {
|
|
1590
|
+
// github like
|
|
1591
|
+
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
1592
|
+
// gitlab like
|
|
1593
|
+
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
1594
|
+
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1595
|
+
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1596
|
+
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1575
1597
|
const _InternalDiffView = (props) => {
|
|
1576
1598
|
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1577
1599
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1600
|
+
const isMounted = useIsMounted();
|
|
1578
1601
|
const wrapperRef = React.useRef();
|
|
1579
1602
|
// performance optimization
|
|
1580
1603
|
const useDiffContext = React.useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
@@ -1615,12 +1638,12 @@ const _InternalDiffView = (props) => {
|
|
|
1615
1638
|
}, [diffFile]);
|
|
1616
1639
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1617
1640
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1618
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1641
|
+
React__namespace.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 },
|
|
1619
1642
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1620
1643
|
// @ts-ignore
|
|
1621
1644
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
1622
1645
|
} },
|
|
1623
|
-
React__namespace.createElement("div", {
|
|
1646
|
+
React__namespace.createElement("div", { id: isMounted ? `diff-root${diffFileId}` : undefined, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & exports.DiffModeEnum.Split ? (React__namespace.createElement(DiffSplitView, { diffFile: diffFile })) : (React__namespace.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
|
|
1624
1647
|
};
|
|
1625
1648
|
const InternalDiffView = React.memo(_InternalDiffView);
|
|
1626
1649
|
const DiffViewWithRef = (props, ref) => {
|
|
@@ -1680,11 +1703,9 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1680
1703
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1681
1704
|
InnerDiffView.displayName = "DiffView";
|
|
1682
1705
|
const DiffView = InnerDiffView;
|
|
1683
|
-
const version = "0.0.
|
|
1706
|
+
const version = "0.0.25";
|
|
1684
1707
|
|
|
1685
1708
|
exports.DiffView = DiffView;
|
|
1686
|
-
exports.DiffViewContext = DiffViewContext;
|
|
1687
|
-
exports.useDiffViewContext = useDiffViewContext;
|
|
1688
1709
|
exports.version = version;
|
|
1689
1710
|
Object.keys(core).forEach(function (k) {
|
|
1690
1711
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|