@git-diff-view/react 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +97 -64
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +97 -64
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/esm/index.mjs +91 -58
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +20 -14
- package/package.json +4 -4
- package/src/components/DiffContent.tsx +27 -10
- package/src/components/DiffContent_v2.tsx +2 -8
- 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
|
@@ -221,18 +221,36 @@ const memoFunc = (func) => {
|
|
|
221
221
|
});
|
|
222
222
|
};
|
|
223
223
|
|
|
224
|
+
var NewLineSymbol;
|
|
225
|
+
(function (NewLineSymbol) {
|
|
226
|
+
NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
|
|
227
|
+
NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
|
|
228
|
+
NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
|
|
229
|
+
NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
|
|
230
|
+
NewLineSymbol[NewLineSymbol["NORMAL"] = 5] = "NORMAL";
|
|
231
|
+
NewLineSymbol[NewLineSymbol["NULL"] = 6] = "NULL";
|
|
232
|
+
})(NewLineSymbol || (NewLineSymbol = {}));
|
|
224
233
|
const getSymbol = (symbol) => {
|
|
225
234
|
switch (symbol) {
|
|
226
|
-
case
|
|
235
|
+
case NewLineSymbol.LF:
|
|
227
236
|
return "␊";
|
|
228
|
-
case
|
|
237
|
+
case NewLineSymbol.CR:
|
|
229
238
|
return "␍";
|
|
230
|
-
case
|
|
239
|
+
case NewLineSymbol.CRLF:
|
|
231
240
|
return "␍␊";
|
|
232
241
|
default:
|
|
233
242
|
return "";
|
|
234
243
|
}
|
|
235
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 = {}));
|
|
236
254
|
|
|
237
255
|
const useIsMounted = () => {
|
|
238
256
|
const [isMounted, setIsMounted] = React.useState(false);
|
|
@@ -327,17 +345,17 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
327
345
|
});
|
|
328
346
|
return style;
|
|
329
347
|
});
|
|
330
|
-
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
348
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, enableTemplate, }) => {
|
|
331
349
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
332
350
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
333
351
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
334
|
-
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") {
|
|
335
353
|
core.getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
336
354
|
}
|
|
337
|
-
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
355
|
+
if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate)) {
|
|
338
356
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
339
357
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
340
|
-
isNewLineSymbolChanged ===
|
|
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: {
|
|
341
359
|
width: `var(${diffFontSizeName})`,
|
|
342
360
|
height: `var(${diffFontSizeName})`,
|
|
343
361
|
} },
|
|
@@ -360,37 +378,37 @@ const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) =>
|
|
|
360
378
|
_str2,
|
|
361
379
|
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
362
380
|
str3),
|
|
363
|
-
isNewLineSymbolChanged ===
|
|
381
|
+
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: {
|
|
364
382
|
width: `var(${diffFontSizeName})`,
|
|
365
383
|
height: `var(${diffFontSizeName})`,
|
|
366
384
|
} },
|
|
367
385
|
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
368
386
|
}
|
|
369
387
|
}
|
|
370
|
-
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
388
|
+
if (enableTemplate && plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
371
389
|
plainLine.template = core.getPlainLineTemplate(plainLine.value);
|
|
372
390
|
}
|
|
373
|
-
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
391
|
+
if (enableTemplate && (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
374
392
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
375
393
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
376
394
|
}
|
|
377
395
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
378
396
|
};
|
|
379
|
-
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) => {
|
|
397
|
+
const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, enableTemplate, }) => {
|
|
380
398
|
var _a, _b;
|
|
381
399
|
if (!syntaxLine) {
|
|
382
|
-
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 }));
|
|
383
401
|
}
|
|
384
402
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
385
403
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
386
404
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
387
|
-
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") {
|
|
388
406
|
core.getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
389
407
|
}
|
|
390
|
-
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
408
|
+
if (enableTemplate && (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate)) {
|
|
391
409
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
392
410
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
393
|
-
isNewLineSymbolChanged ===
|
|
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: {
|
|
394
412
|
width: `var(${diffFontSizeName})`,
|
|
395
413
|
height: `var(${diffFontSizeName})`,
|
|
396
414
|
} },
|
|
@@ -431,17 +449,17 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
431
449
|
str3));
|
|
432
450
|
}
|
|
433
451
|
})),
|
|
434
|
-
isNewLineSymbolChanged ===
|
|
452
|
+
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: {
|
|
435
453
|
width: `var(${diffFontSizeName})`,
|
|
436
454
|
height: `var(${diffFontSizeName})`,
|
|
437
455
|
} },
|
|
438
456
|
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
439
457
|
}
|
|
440
458
|
}
|
|
441
|
-
if (!syntaxLine.template) {
|
|
459
|
+
if (enableTemplate && !syntaxLine.template) {
|
|
442
460
|
syntaxLine.template = core.getSyntaxLineTemplate(syntaxLine);
|
|
443
461
|
}
|
|
444
|
-
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
462
|
+
if (enableTemplate && (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template)) {
|
|
445
463
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
446
464
|
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
447
465
|
}
|
|
@@ -450,11 +468,12 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
450
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));
|
|
451
469
|
})));
|
|
452
470
|
};
|
|
453
|
-
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
454
|
-
var _a;
|
|
471
|
+
const DiffContent = ({ diffLine, diffFile, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
472
|
+
var _a, _b, _c;
|
|
455
473
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
|
|
456
474
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
|
|
457
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;
|
|
458
477
|
return (React__namespace.createElement("div", { className: "diff-line-content-item pl-[2.0em]",
|
|
459
478
|
// data-val={rawLine}
|
|
460
479
|
style: {
|
|
@@ -462,7 +481,7 @@ const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, ena
|
|
|
462
481
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
463
482
|
} },
|
|
464
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 ? "-" : " "),
|
|
465
|
-
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 }))));
|
|
466
485
|
};
|
|
467
486
|
|
|
468
487
|
const DiffViewContext = React.createContext(null);
|
|
@@ -481,7 +500,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
481
500
|
const newLine = diffFile.getSplitRightLine(index);
|
|
482
501
|
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
483
502
|
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
484
|
-
const hasContent = !!currentLine.lineNumber;
|
|
503
|
+
const hasContent = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.lineNumber);
|
|
485
504
|
const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
486
505
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
|
|
487
506
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
|
|
@@ -494,7 +513,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
494
513
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
495
514
|
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
496
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,
|
|
497
|
-
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: {
|
|
498
517
|
backgroundColor: lineNumberBG,
|
|
499
518
|
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
500
519
|
width: `var(${diffAsideWidthName})`,
|
|
@@ -504,7 +523,7 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddW
|
|
|
504
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 }) })),
|
|
505
524
|
React__namespace.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
506
525
|
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
507
|
-
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 },
|
|
508
527
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
509
528
|
};
|
|
510
529
|
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
@@ -780,7 +799,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
780
799
|
const { useDiffContext } = useDiffViewContext();
|
|
781
800
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
782
801
|
const newLine = diffFile.getSplitRightLine(index);
|
|
783
|
-
const widgetSide = useWidget.
|
|
802
|
+
const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
|
|
784
803
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
785
804
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
786
805
|
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
@@ -859,6 +878,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
859
878
|
const ref1 = React.useRef(null);
|
|
860
879
|
const ref2 = React.useRef(null);
|
|
861
880
|
const ref = React.useRef();
|
|
881
|
+
const tempRef = React.useRef();
|
|
862
882
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
863
883
|
const { useDiffContext } = useDiffViewContext();
|
|
864
884
|
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
@@ -902,13 +922,19 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
902
922
|
const state = ele.getAttribute("data-state");
|
|
903
923
|
const side = ele.getAttribute("data-side");
|
|
904
924
|
if (side) {
|
|
905
|
-
|
|
906
|
-
|
|
925
|
+
if (tempRef.current !== core.SplitSide[side]) {
|
|
926
|
+
tempRef.current = core.SplitSide[side];
|
|
927
|
+
setStyle(core.SplitSide[side]);
|
|
928
|
+
removeAllSelection();
|
|
929
|
+
}
|
|
907
930
|
}
|
|
908
931
|
if (state) {
|
|
909
932
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
910
|
-
|
|
911
|
-
|
|
933
|
+
if (tempRef.current !== undefined) {
|
|
934
|
+
tempRef.current = undefined;
|
|
935
|
+
setStyle(undefined);
|
|
936
|
+
removeAllSelection();
|
|
937
|
+
}
|
|
912
938
|
return;
|
|
913
939
|
}
|
|
914
940
|
else {
|
|
@@ -1152,7 +1178,7 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1152
1178
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1153
1179
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1154
1180
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1155
|
-
const widgetSide = useWidget.
|
|
1181
|
+
const widgetSide = useWidget.useShallowStableSelector((s) => s.widgetSide);
|
|
1156
1182
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1157
1183
|
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1158
1184
|
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
@@ -1195,6 +1221,7 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
1195
1221
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1196
1222
|
const { useDiffContext } = useDiffViewContext();
|
|
1197
1223
|
const ref = React.useRef(null);
|
|
1224
|
+
const tempRef = React.useRef();
|
|
1198
1225
|
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1199
1226
|
fontSize: s.fontSize,
|
|
1200
1227
|
enableAddWidget: s.enableAddWidget,
|
|
@@ -1231,13 +1258,19 @@ const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
|
1231
1258
|
const state = ele.getAttribute("data-state");
|
|
1232
1259
|
const side = ele.getAttribute("data-side");
|
|
1233
1260
|
if (side) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1261
|
+
if (tempRef.current !== core.SplitSide[side]) {
|
|
1262
|
+
tempRef.current = core.SplitSide[side];
|
|
1263
|
+
setStyle(core.SplitSide[side]);
|
|
1264
|
+
removeAllSelection();
|
|
1265
|
+
}
|
|
1236
1266
|
}
|
|
1237
1267
|
if (state) {
|
|
1238
1268
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1239
|
-
|
|
1240
|
-
|
|
1269
|
+
if (tempRef.current !== undefined) {
|
|
1270
|
+
tempRef.current = undefined;
|
|
1271
|
+
setStyle(undefined);
|
|
1272
|
+
removeAllSelection();
|
|
1273
|
+
}
|
|
1241
1274
|
return;
|
|
1242
1275
|
}
|
|
1243
1276
|
else {
|
|
@@ -1397,7 +1430,7 @@ DiffSplitView.displayName = "DiffSplitView";
|
|
|
1397
1430
|
|
|
1398
1431
|
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1399
1432
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1400
|
-
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: {
|
|
1401
1434
|
color: `var(${plainLineNumberColorName})`,
|
|
1402
1435
|
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1403
1436
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1414,7 +1447,7 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, l
|
|
|
1414
1447
|
};
|
|
1415
1448
|
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1416
1449
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1417
|
-
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: {
|
|
1418
1451
|
color: `var(${plainLineNumberColorName})`,
|
|
1419
1452
|
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1420
1453
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1461,7 +1494,7 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber, enableWrap,
|
|
|
1461
1494
|
}
|
|
1462
1495
|
else {
|
|
1463
1496
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1464
|
-
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: {
|
|
1465
1498
|
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1466
1499
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1467
1500
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1630,6 +1663,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1630
1663
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
1631
1664
|
const { useDiffContext } = useDiffViewContext();
|
|
1632
1665
|
const ref = React.useRef(null);
|
|
1666
|
+
const tempRef = React.useRef();
|
|
1633
1667
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1634
1668
|
useDiffContextRef.current = useDiffContext;
|
|
1635
1669
|
// performance optimization
|
|
@@ -1679,13 +1713,19 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1679
1713
|
const state = ele.getAttribute("data-state");
|
|
1680
1714
|
if (state) {
|
|
1681
1715
|
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1682
|
-
|
|
1683
|
-
|
|
1716
|
+
if (tempRef.current !== undefined) {
|
|
1717
|
+
tempRef.current = undefined;
|
|
1718
|
+
setStyle(undefined);
|
|
1719
|
+
removeAllSelection();
|
|
1720
|
+
}
|
|
1684
1721
|
return;
|
|
1685
1722
|
}
|
|
1686
1723
|
else {
|
|
1687
|
-
|
|
1688
|
-
|
|
1724
|
+
if (tempRef.current !== core.SplitSide.new) {
|
|
1725
|
+
tempRef.current = core.SplitSide.new;
|
|
1726
|
+
setStyle(core.SplitSide.new);
|
|
1727
|
+
removeAllSelection();
|
|
1728
|
+
}
|
|
1689
1729
|
return;
|
|
1690
1730
|
}
|
|
1691
1731
|
}
|
|
@@ -1720,19 +1760,9 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1720
1760
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1721
1761
|
|
|
1722
1762
|
core._cacheMap.name = "@git-diff-view/react";
|
|
1723
|
-
exports.DiffModeEnum = void 0;
|
|
1724
|
-
(function (DiffModeEnum) {
|
|
1725
|
-
// github like
|
|
1726
|
-
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
1727
|
-
// gitlab like
|
|
1728
|
-
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
1729
|
-
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1730
|
-
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1731
|
-
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1732
1763
|
const InternalDiffView = (props) => {
|
|
1733
|
-
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;
|
|
1734
1765
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1735
|
-
const wrapperRef = React.useRef();
|
|
1736
1766
|
// performance optimization
|
|
1737
1767
|
const useDiffContext = React.useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1738
1768
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1790,17 +1820,9 @@ const InternalDiffView = (props) => {
|
|
|
1790
1820
|
onAddWidgetClick,
|
|
1791
1821
|
onCreateUseWidgetHook,
|
|
1792
1822
|
]);
|
|
1793
|
-
React.useEffect(() => {
|
|
1794
|
-
const cb = diffFile.subscribe(() => {
|
|
1795
|
-
var _a, _b;
|
|
1796
|
-
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
|
|
1797
|
-
(_b = wrapperRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("data-highlighter", diffFile._getHighlighterName());
|
|
1798
|
-
});
|
|
1799
|
-
return cb;
|
|
1800
|
-
}, [diffFile]);
|
|
1801
1823
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1802
1824
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1803
|
-
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 },
|
|
1804
1826
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1805
1827
|
// @ts-ignore
|
|
1806
1828
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1827,6 +1849,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1827
1849
|
return null;
|
|
1828
1850
|
}, [data, _diffFile]);
|
|
1829
1851
|
const diffFileRef = React.useRef(diffFile);
|
|
1852
|
+
const wrapperRef = React.useRef();
|
|
1830
1853
|
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
1831
1854
|
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1832
1855
|
diffFileRef.current = diffFile;
|
|
@@ -1855,18 +1878,28 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1855
1878
|
diffFile.initSyntax({ registerHighlighter });
|
|
1856
1879
|
diffFile.notifyAll();
|
|
1857
1880
|
}
|
|
1858
|
-
}, [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]);
|
|
1859
1892
|
// fix react strict mode error
|
|
1860
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]);
|
|
1861
1894
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1862
1895
|
if (!diffFile)
|
|
1863
1896
|
return null;
|
|
1864
|
-
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 })));
|
|
1865
1898
|
};
|
|
1866
1899
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1867
1900
|
InnerDiffView.displayName = "DiffView";
|
|
1868
1901
|
const DiffView = InnerDiffView;
|
|
1869
|
-
const version = "0.0.
|
|
1902
|
+
const version = "0.0.29";
|
|
1870
1903
|
|
|
1871
1904
|
Object.defineProperty(exports, "SplitSide", {
|
|
1872
1905
|
enumerable: true,
|