@git-diff-view/react 0.0.28 → 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.
- package/dist/cjs/index.development.js +81 -57
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +81 -57
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/esm/index.mjs +81 -57
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +12 -6
- package/package.json +4 -4
- package/src/components/DiffContent.tsx +26 -9
- package/src/components/DiffContent_v2.tsx +1 -7
- package/src/components/DiffSplitContentLineNormal.tsx +4 -4
- package/src/components/DiffSplitViewNormal.tsx +12 -4
- package/src/components/DiffSplitViewWrap.tsx +12 -4
- package/src/components/DiffSplitWidgetLineNormal.tsx +1 -1
- package/src/components/DiffSplitWidgetLineWrap.tsx +1 -1
- package/src/components/DiffUnifiedContentLine.tsx +3 -3
- package/src/components/DiffUnifiedView.tsx +12 -4
- package/src/components/DiffView.tsx +26 -25
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +1 -1
|
@@ -242,6 +242,15 @@ const getSymbol = (symbol) => {
|
|
|
242
242
|
return "";
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
|
+
exports.DiffModeEnum = void 0;
|
|
246
|
+
(function (DiffModeEnum) {
|
|
247
|
+
// github like
|
|
248
|
+
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
249
|
+
// gitlab like
|
|
250
|
+
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
251
|
+
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
252
|
+
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
253
|
+
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
245
254
|
|
|
246
255
|
const useIsMounted = () => {
|
|
247
256
|
const [isMounted, setIsMounted] = React.useState(false);
|
|
@@ -336,14 +345,14 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
336
345
|
});
|
|
337
346
|
return style;
|
|
338
347
|
});
|
|
339
|
-
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
348
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, enableTemplate, }) => {
|
|
340
349
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
341
350
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
342
351
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
343
|
-
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof core.getPlainDiffTemplate === "function") {
|
|
352
|
+
if (enableTemplate && !(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof core.getPlainDiffTemplate === "function") {
|
|
344
353
|
core.getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
345
354
|
}
|
|
346
|
-
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
355
|
+
if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate)) {
|
|
347
356
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
348
357
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
349
358
|
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React__namespace.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: {
|
|
@@ -376,27 +385,27 @@ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) =>
|
|
|
376
385
|
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
377
386
|
}
|
|
378
387
|
}
|
|
379
|
-
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
388
|
+
if (enableTemplate && plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
380
389
|
plainLine.template = core.getPlainLineTemplate(plainLine.value);
|
|
381
390
|
}
|
|
382
|
-
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
391
|
+
if (enableTemplate && (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
383
392
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
384
393
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
385
394
|
}
|
|
386
395
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
387
396
|
};
|
|
388
|
-
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) => {
|
|
397
|
+
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, enableTemplate, }) => {
|
|
389
398
|
var _a, _b;
|
|
390
399
|
if (!syntaxLine) {
|
|
391
|
-
return React__namespace.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
|
|
400
|
+
return (React__namespace.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator, enableWrap: enableWrap, enableTemplate: enableTemplate }));
|
|
392
401
|
}
|
|
393
402
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
394
403
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
395
404
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
396
|
-
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof core.getSyntaxDiffTemplate === "function") {
|
|
405
|
+
if (enableTemplate && !(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof core.getSyntaxDiffTemplate === "function") {
|
|
397
406
|
core.getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
398
407
|
}
|
|
399
|
-
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
408
|
+
if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate)) {
|
|
400
409
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
401
410
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
402
411
|
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React__namespace.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: {
|
|
@@ -447,10 +456,10 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
447
456
|
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
448
457
|
}
|
|
449
458
|
}
|
|
450
|
-
if (!syntaxLine.template) {
|
|
459
|
+
if (enableTemplate && !syntaxLine.template) {
|
|
451
460
|
syntaxLine.template = core.getSyntaxLineTemplate(syntaxLine);
|
|
452
461
|
}
|
|
453
|
-
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
462
|
+
if (enableTemplate && (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template)) {
|
|
454
463
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
455
464
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
456
465
|
}
|
|
@@ -459,11 +468,12 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
459
468
|
return (React__namespace.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));
|
|
460
469
|
})));
|
|
461
470
|
};
|
|
462
|
-
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
463
|
-
var _a;
|
|
471
|
+
const DiffContent = ({ diffLine, diffFile, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
472
|
+
var _a, _b, _c;
|
|
464
473
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
|
|
465
474
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
|
|
466
475
|
const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
|
|
476
|
+
const isEnableTemplate = (_c = (_b = diffFile.getIsEnableTemplate) === null || _b === void 0 ? void 0 : _b.call(diffFile)) !== null && _c !== void 0 ? _c : true;
|
|
467
477
|
return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]",
|
|
468
478
|
// data-val={rawLine}
|
|
469
479
|
style: {
|
|
@@ -471,7 +481,7 @@ const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, ena
|
|
|
471
481
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
472
482
|
} },
|
|
473
483
|
React__namespace.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 ? "-" : " "),
|
|
474
|
-
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, plainLine: plainLine, enableWrap: enableWrap }))));
|
|
484
|
+
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React__namespace.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap, enableTemplate: isEnableTemplate })) : (React__namespace.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, enableWrap: enableWrap, enableTemplate: isEnableTemplate }))));
|
|
475
485
|
};
|
|
476
486
|
|
|
477
487
|
const DiffViewContext = React.createContext(null);
|
|
@@ -490,7 +500,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
490
500
|
const newLine = diffFile.getSplitRightLine(index);
|
|
491
501
|
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
492
502
|
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
493
|
-
const hasContent = !!currentLine.lineNumber;
|
|
503
|
+
const hasContent = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.lineNumber);
|
|
494
504
|
const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
495
505
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
|
|
496
506
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
|
|
@@ -503,7 +513,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
503
513
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
504
514
|
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
505
515
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff || !hasContent ? "diff" : "plain", "data-side": core.SplitSide[side], className: "diff-line" + (hasContent ? " group" : "") }, hasContent ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
506
|
-
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-num sticky left-0 w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
|
|
516
|
+
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-num sticky left-0 z-[1] w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
|
|
507
517
|
backgroundColor: lineNumberBG,
|
|
508
518
|
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
509
519
|
width: `var(${diffAsideWidthName})`,
|
|
@@ -513,7 +523,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
513
523
|
hasDiff && enableAddWidget && (React__namespace.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 }) })),
|
|
514
524
|
React__namespace.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
515
525
|
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
516
|
-
React__namespace.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, plainLine: plainLine, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
526
|
+
React__namespace.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__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
517
527
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
518
528
|
};
|
|
519
529
|
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
@@ -789,7 +799,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
789
799
|
const { useDiffContext } = useDiffViewContext();
|
|
790
800
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
791
801
|
const newLine = diffFile.getSplitRightLine(index);
|
|
792
|
-
const widgetSide = useWidget.
|
|
802
|
+
const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
|
|
793
803
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
794
804
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
795
805
|
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
@@ -868,6 +878,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
868
878
|
const ref1 = React.useRef(null);
|
|
869
879
|
const ref2 = React.useRef(null);
|
|
870
880
|
const ref = React.useRef();
|
|
881
|
+
const tempRef = React.useRef();
|
|
871
882
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
872
883
|
const { useDiffContext } = useDiffViewContext();
|
|
873
884
|
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
@@ -911,13 +922,19 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
911
922
|
const state = ele.getAttribute("data-state");
|
|
912
923
|
const side = ele.getAttribute("data-side");
|
|
913
924
|
if (side) {
|
|
914
|
-
|
|
915
|
-
|
|
925
|
+
if (tempRef.current !== core.SplitSide[side]) {
|
|
926
|
+
tempRef.current = core.SplitSide[side];
|
|
927
|
+
setStyle(core.SplitSide[side]);
|
|
928
|
+
removeAllSelection();
|
|
929
|
+
}
|
|
916
930
|
}
|
|
917
931
|
if (state) {
|
|
918
932
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
919
|
-
|
|
920
|
-
|
|
933
|
+
if (tempRef.current !== undefined) {
|
|
934
|
+
tempRef.current = undefined;
|
|
935
|
+
setStyle(undefined);
|
|
936
|
+
removeAllSelection();
|
|
937
|
+
}
|
|
921
938
|
return;
|
|
922
939
|
}
|
|
923
940
|
else {
|
|
@@ -1161,7 +1178,7 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1161
1178
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1162
1179
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1163
1180
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1164
|
-
const widgetSide = useWidget.
|
|
1181
|
+
const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
|
|
1165
1182
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1166
1183
|
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1167
1184
|
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
@@ -1204,6 +1221,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
1204
1221
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1205
1222
|
const { useDiffContext } = useDiffViewContext();
|
|
1206
1223
|
const ref = React.useRef(null);
|
|
1224
|
+
const tempRef = React.useRef();
|
|
1207
1225
|
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1208
1226
|
fontSize: s.fontSize,
|
|
1209
1227
|
enableAddWidget: s.enableAddWidget,
|
|
@@ -1240,13 +1258,19 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
1240
1258
|
const state = ele.getAttribute("data-state");
|
|
1241
1259
|
const side = ele.getAttribute("data-side");
|
|
1242
1260
|
if (side) {
|
|
1243
|
-
|
|
1244
|
-
|
|
1261
|
+
if (tempRef.current !== core.SplitSide[side]) {
|
|
1262
|
+
tempRef.current = core.SplitSide[side];
|
|
1263
|
+
setStyle(core.SplitSide[side]);
|
|
1264
|
+
removeAllSelection();
|
|
1265
|
+
}
|
|
1245
1266
|
}
|
|
1246
1267
|
if (state) {
|
|
1247
1268
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1248
|
-
|
|
1249
|
-
|
|
1269
|
+
if (tempRef.current !== undefined) {
|
|
1270
|
+
tempRef.current = undefined;
|
|
1271
|
+
setStyle(undefined);
|
|
1272
|
+
removeAllSelection();
|
|
1273
|
+
}
|
|
1250
1274
|
return;
|
|
1251
1275
|
}
|
|
1252
1276
|
else {
|
|
@@ -1406,7 +1430,7 @@ DiffSplitView.displayName = "DiffSplitView";
|
|
|
1406
1430
|
|
|
1407
1431
|
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1408
1432
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1409
|
-
React__namespace.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: {
|
|
1433
|
+
React__namespace.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: {
|
|
1410
1434
|
color: `var(${plainLineNumberColorName})`,
|
|
1411
1435
|
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1412
1436
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1423,7 +1447,7 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, l
|
|
|
1423
1447
|
};
|
|
1424
1448
|
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1425
1449
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1426
|
-
React__namespace.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: {
|
|
1450
|
+
React__namespace.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: {
|
|
1427
1451
|
color: `var(${plainLineNumberColorName})`,
|
|
1428
1452
|
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1429
1453
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1470,7 +1494,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber, enableWrap,
|
|
|
1470
1494
|
}
|
|
1471
1495
|
else {
|
|
1472
1496
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1473
|
-
React__namespace.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: {
|
|
1497
|
+
React__namespace.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: {
|
|
1474
1498
|
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1475
1499
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1476
1500
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1639,6 +1663,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1639
1663
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
1640
1664
|
const { useDiffContext } = useDiffViewContext();
|
|
1641
1665
|
const ref = React.useRef(null);
|
|
1666
|
+
const tempRef = React.useRef();
|
|
1642
1667
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1643
1668
|
useDiffContextRef.current = useDiffContext;
|
|
1644
1669
|
// performance optimization
|
|
@@ -1688,13 +1713,19 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1688
1713
|
const state = ele.getAttribute("data-state");
|
|
1689
1714
|
if (state) {
|
|
1690
1715
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1691
|
-
|
|
1692
|
-
|
|
1716
|
+
if (tempRef.current !== undefined) {
|
|
1717
|
+
tempRef.current = undefined;
|
|
1718
|
+
setStyle(undefined);
|
|
1719
|
+
removeAllSelection();
|
|
1720
|
+
}
|
|
1693
1721
|
return;
|
|
1694
1722
|
}
|
|
1695
1723
|
else {
|
|
1696
|
-
|
|
1697
|
-
|
|
1724
|
+
if (tempRef.current !== core.SplitSide.new) {
|
|
1725
|
+
tempRef.current = core.SplitSide.new;
|
|
1726
|
+
setStyle(core.SplitSide.new);
|
|
1727
|
+
removeAllSelection();
|
|
1728
|
+
}
|
|
1698
1729
|
return;
|
|
1699
1730
|
}
|
|
1700
1731
|
}
|
|
@@ -1729,19 +1760,9 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1729
1760
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1730
1761
|
|
|
1731
1762
|
core._cacheMap.name = "@git-diff-view/react";
|
|
1732
|
-
exports.DiffModeEnum = void 0;
|
|
1733
|
-
(function (DiffModeEnum) {
|
|
1734
|
-
// github like
|
|
1735
|
-
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
1736
|
-
// gitlab like
|
|
1737
|
-
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
1738
|
-
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1739
|
-
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1740
|
-
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1741
1763
|
const InternalDiffView = (props) => {
|
|
1742
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1764
|
+
const { diffFile, className, style, wrapperRef, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1743
1765
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1744
|
-
const wrapperRef = React.useRef();
|
|
1745
1766
|
// performance optimization
|
|
1746
1767
|
const useDiffContext = React.useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1747
1768
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1799,17 +1820,9 @@ const InternalDiffView = (props) => {
|
|
|
1799
1820
|
onAddWidgetClick,
|
|
1800
1821
|
onCreateUseWidgetHook,
|
|
1801
1822
|
]);
|
|
1802
|
-
React.useEffect(() => {
|
|
1803
|
-
const cb = diffFile.subscribe(() => {
|
|
1804
|
-
var _a, _b;
|
|
1805
|
-
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
|
|
1806
|
-
(_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
|
|
1807
|
-
});
|
|
1808
|
-
return cb;
|
|
1809
|
-
}, [diffFile]);
|
|
1810
1823
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1811
1824
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1812
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1825
|
+
React__namespace.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 },
|
|
1813
1826
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1814
1827
|
// @ts-ignore
|
|
1815
1828
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1836,6 +1849,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1836
1849
|
return null;
|
|
1837
1850
|
}, [data, _diffFile]);
|
|
1838
1851
|
const diffFileRef = React.useRef(diffFile);
|
|
1852
|
+
const wrapperRef = React.useRef();
|
|
1839
1853
|
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
1840
1854
|
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1841
1855
|
diffFileRef.current = diffFile;
|
|
@@ -1864,18 +1878,28 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1864
1878
|
diffFile.initSyntax({ registerHighlighter });
|
|
1865
1879
|
diffFile.notifyAll();
|
|
1866
1880
|
}
|
|
1867
|
-
}, [diffFile, props.diffViewHighlight, registerHighlighter
|
|
1881
|
+
}, [diffFile, props.diffViewHighlight, registerHighlighter]);
|
|
1882
|
+
React.useEffect(() => {
|
|
1883
|
+
const init = () => {
|
|
1884
|
+
var _a, _b;
|
|
1885
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
|
|
1886
|
+
(_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
|
|
1887
|
+
};
|
|
1888
|
+
init();
|
|
1889
|
+
const cb = diffFile.subscribe(init);
|
|
1890
|
+
return cb;
|
|
1891
|
+
}, [diffFile, diffViewTheme]);
|
|
1868
1892
|
// fix react strict mode error
|
|
1869
1893
|
useUnmount(() => { var _a; return ((_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile._destroy) === null || _a === void 0 ? void 0 : _a.call(diffFile) ); }, [diffFile]);
|
|
1870
1894
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1871
1895
|
if (!diffFile)
|
|
1872
1896
|
return null;
|
|
1873
|
-
return (React__namespace.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || exports.DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
1897
|
+
return (React__namespace.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, wrapperRef: wrapperRef, diffViewTheme: diffViewTheme, diffViewMode: restProps.diffViewMode || exports.DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
1874
1898
|
};
|
|
1875
1899
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1876
1900
|
InnerDiffView.displayName = "DiffView";
|
|
1877
1901
|
const DiffView = InnerDiffView;
|
|
1878
|
-
const version = "0.0.
|
|
1902
|
+
const version = "0.0.29";
|
|
1879
1903
|
|
|
1880
1904
|
Object.defineProperty(exports, "SplitSide", {
|
|
1881
1905
|
enumerable: true,
|