@git-diff-view/react 0.0.25 → 0.0.26
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 +139 -104
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +139 -104
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +1 -1
- package/dist/css/diff-view.css +2 -2
- package/dist/esm/index.mjs +140 -105
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +21 -7
- package/package.json +6 -6
- package/styles/diff-view-pure.css +1 -1
- package/styles/diff-view.css +2 -2
|
@@ -84,7 +84,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
87
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
87
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
88
88
|
return (state.set(receiver, value)), value;
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -207,7 +207,7 @@ const syncScroll = (left, right) => {
|
|
|
207
207
|
const diffFontSizeName = "--diff-font-size--";
|
|
208
208
|
const diffAsideWidthName = "--diff-aside-width--";
|
|
209
209
|
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
210
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
211
211
|
const memoFunc = (func) => {
|
|
212
212
|
const cache = {};
|
|
213
213
|
return ((key) => {
|
|
@@ -425,7 +425,7 @@ const DiffWidgetContext = React.createContext(null);
|
|
|
425
425
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
426
426
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
427
427
|
|
|
428
|
-
const
|
|
428
|
+
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
429
429
|
var _a, _b;
|
|
430
430
|
const getCurrentSyntaxLine = side === exports.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
431
431
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
@@ -466,13 +466,13 @@ const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
466
466
|
const currentLine = getCurrentLine(index);
|
|
467
467
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
468
468
|
return null;
|
|
469
|
-
return React__namespace.createElement(
|
|
469
|
+
return React__namespace.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
470
470
|
};
|
|
471
471
|
|
|
472
472
|
const useDomWidth = ({ selector, enable }) => {
|
|
473
473
|
const [width, setWidth] = React.useState(0);
|
|
474
474
|
const { useDiffContext } = useDiffViewContext();
|
|
475
|
-
const id = useDiffContext
|
|
475
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
476
476
|
React.useEffect(() => {
|
|
477
477
|
if (enable) {
|
|
478
478
|
const container = document.querySelector(`#diff-root${id}`);
|
|
@@ -508,86 +508,95 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
508
508
|
typedWrapper.setAttribute("data-observe", "height");
|
|
509
509
|
return () => cleanCb();
|
|
510
510
|
}
|
|
511
|
-
}, [selector, enable, id]);
|
|
511
|
+
}, [selector, enable, id, mounted]);
|
|
512
512
|
return width;
|
|
513
513
|
};
|
|
514
514
|
|
|
515
|
-
// TODO
|
|
516
515
|
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
517
516
|
const { useDiffContext } = useDiffViewContext();
|
|
518
|
-
const id = useDiffContext
|
|
517
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
519
518
|
React.useEffect(() => {
|
|
520
519
|
if (enable) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
const
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
520
|
+
const container = document.querySelector(`#diff-root${id}`);
|
|
521
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
522
|
+
const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
|
|
523
|
+
if (elements.length === 2 && wrappers.length === 2) {
|
|
524
|
+
const ele1 = elements[0];
|
|
525
|
+
const ele2 = elements[1];
|
|
526
|
+
const wrapper1 = wrappers[0];
|
|
527
|
+
const wrapper2 = wrappers[1];
|
|
528
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
529
|
+
const typedTarget = target;
|
|
530
|
+
const cb = () => {
|
|
531
|
+
ele1.style.height = "auto";
|
|
532
|
+
ele2.style.height = "auto";
|
|
533
|
+
const rect1 = ele1.getBoundingClientRect();
|
|
534
|
+
const rect2 = ele2.getBoundingClientRect();
|
|
535
|
+
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
536
|
+
wrapper1.style.height = maxHeight + "px";
|
|
537
|
+
wrapper2.style.height = maxHeight + "px";
|
|
538
|
+
wrapper1.setAttribute("data-sync-height", String(maxHeight));
|
|
539
|
+
wrapper2.setAttribute("data-sync-height", String(maxHeight));
|
|
540
|
+
};
|
|
541
|
+
cb();
|
|
542
|
+
const cleanCb = () => {
|
|
543
|
+
var _a;
|
|
544
|
+
typedTarget.__observeCallback.delete(cb);
|
|
545
|
+
if (typedTarget.__observeCallback.size === 0) {
|
|
546
|
+
(_a = typedTarget.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
547
|
+
typedTarget.removeAttribute("data-observe");
|
|
548
|
+
delete typedTarget.__observeCallback;
|
|
549
|
+
delete typedTarget.__observeInstance;
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
if (typedTarget.__observeCallback) {
|
|
553
|
+
typedTarget.__observeCallback.add(cb);
|
|
554
|
+
return () => cleanCb();
|
|
552
555
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
556
|
+
typedTarget.__observeCallback = new Set();
|
|
557
|
+
typedTarget.__observeCallback.add(cb);
|
|
558
|
+
const observer = new ResizeObserver(() => typedTarget.__observeCallback.forEach((cb) => cb()));
|
|
559
|
+
typedTarget.__observeInstance = observer;
|
|
560
|
+
observer.observe(target);
|
|
561
|
+
target.setAttribute("data-observe", "height");
|
|
562
|
+
return () => cleanCb();
|
|
563
|
+
}
|
|
558
564
|
}
|
|
559
|
-
}, [selector, enable, side, id, wrapper]);
|
|
565
|
+
}, [selector, enable, side, id, wrapper, mounted]);
|
|
560
566
|
};
|
|
561
567
|
|
|
562
|
-
const
|
|
568
|
+
const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
563
569
|
const { useDiffContext } = useDiffViewContext();
|
|
564
570
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
565
571
|
const newLine = diffFile.getSplitRightLine(index);
|
|
566
572
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
567
573
|
const currentExtend = side === exports.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
574
|
+
const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
|
|
568
575
|
const currentLineNumber = side === exports.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
569
|
-
const
|
|
576
|
+
const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
|
|
577
|
+
const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
|
|
578
|
+
((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
|
|
570
579
|
const currentExtendRendered = hasExtend &&
|
|
571
580
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
572
581
|
diffFile,
|
|
573
582
|
side,
|
|
574
583
|
lineNumber: currentLineNumber,
|
|
575
|
-
data: currentExtend.data,
|
|
584
|
+
data: currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data,
|
|
576
585
|
onUpdate: diffFile.notifyAll,
|
|
577
586
|
}));
|
|
578
587
|
useSyncHeight({
|
|
579
588
|
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
580
589
|
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
581
|
-
side: exports.SplitSide[side],
|
|
590
|
+
side: exports.SplitSide[currentSideHasExtend ? side : otherSide],
|
|
582
591
|
enable: hasExtend && typeof renderExtendLine === "function",
|
|
583
592
|
});
|
|
584
593
|
const width = useDomWidth({
|
|
585
594
|
selector: side === exports.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
586
|
-
enable:
|
|
595
|
+
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
587
596
|
});
|
|
588
597
|
if (!renderExtendLine)
|
|
589
598
|
return null;
|
|
590
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": exports.SplitSide[side], className: "diff-line diff-line-extend" },
|
|
599
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": exports.SplitSide[side], className: "diff-line diff-line-extend" }, currentSideHasExtend ? (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
591
600
|
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": exports.SplitSide[side], className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 && currentExtendRendered))) : (React__namespace.createElement("td", { className: `diff-line-extend-${exports.SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
592
601
|
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": exports.SplitSide[side] })))));
|
|
593
602
|
};
|
|
@@ -609,7 +618,7 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
609
618
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
610
619
|
if (!currentIsShow)
|
|
611
620
|
return null;
|
|
612
|
-
return (React__namespace.createElement(
|
|
621
|
+
return (React__namespace.createElement(InternalDiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
613
622
|
};
|
|
614
623
|
|
|
615
624
|
const ExpandDown = ({ className }) => {
|
|
@@ -625,7 +634,7 @@ const ExpandAll = ({ className }) => {
|
|
|
625
634
|
React__namespace.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
626
635
|
};
|
|
627
636
|
|
|
628
|
-
const
|
|
637
|
+
const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
629
638
|
var _a;
|
|
630
639
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
631
640
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -649,9 +658,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
649
658
|
minWidth: `var(${diffAsideWidthName})`,
|
|
650
659
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
651
660
|
} }, 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) },
|
|
652
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () =>
|
|
653
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
654
|
-
} },
|
|
661
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip relative 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) },
|
|
655
662
|
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) },
|
|
656
663
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
657
664
|
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.onSplitHunkExpand("down", index) },
|
|
@@ -664,7 +671,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
664
671
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
665
672
|
React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
666
673
|
};
|
|
667
|
-
const
|
|
674
|
+
const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
668
675
|
var _a;
|
|
669
676
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
670
677
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -687,9 +694,7 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
687
694
|
minWidth: `var(${diffAsideWidthName})`,
|
|
688
695
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
689
696
|
} }, 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) },
|
|
690
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () =>
|
|
691
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
692
|
-
} },
|
|
697
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.createElement("button", { className: "diff-widget-tooltip relative 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) },
|
|
693
698
|
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) },
|
|
694
699
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
695
700
|
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.onSplitHunkExpand("down", index) },
|
|
@@ -701,16 +706,16 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
701
706
|
color: `var(${hunkContentColorName})`,
|
|
702
707
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
703
708
|
};
|
|
704
|
-
const
|
|
709
|
+
const InternalDiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
705
710
|
const { useDiffContext } = useDiffViewContext();
|
|
706
711
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
707
712
|
if (diffViewMode === exports.DiffModeEnum.SplitGitHub ||
|
|
708
713
|
diffViewMode === exports.DiffModeEnum.Split ||
|
|
709
714
|
diffViewMode === exports.DiffModeEnum.Unified) {
|
|
710
|
-
return React__namespace.createElement(
|
|
715
|
+
return React__namespace.createElement(InternalDiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
711
716
|
}
|
|
712
717
|
else {
|
|
713
|
-
return React__namespace.createElement(
|
|
718
|
+
return React__namespace.createElement(InternalDiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
714
719
|
}
|
|
715
720
|
};
|
|
716
721
|
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -721,10 +726,10 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
721
726
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
722
727
|
if (!currentIsShow && !currentIsPureHunk)
|
|
723
728
|
return null;
|
|
724
|
-
return React__namespace.createElement(
|
|
729
|
+
return React__namespace.createElement(InternalDiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
725
730
|
};
|
|
726
731
|
|
|
727
|
-
const
|
|
732
|
+
const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
728
733
|
const { useWidget } = useDiffWidgetContext();
|
|
729
734
|
const { useDiffContext } = useDiffViewContext();
|
|
730
735
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
@@ -735,9 +740,11 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
735
740
|
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
736
741
|
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
737
742
|
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
738
|
-
const
|
|
743
|
+
const otherSide = side === exports.SplitSide.old ? exports.SplitSide.new : exports.SplitSide.old;
|
|
744
|
+
const currentHasWidget = side === exports.SplitSide.old ? oldLineWidget : newLineWidget;
|
|
745
|
+
const hasWidget = oldLineWidget || newLineWidget;
|
|
739
746
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
740
|
-
const currentWidgetRendered =
|
|
747
|
+
const currentWidgetRendered = currentHasWidget &&
|
|
741
748
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
742
749
|
diffFile,
|
|
743
750
|
side,
|
|
@@ -747,16 +754,16 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
747
754
|
useSyncHeight({
|
|
748
755
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
749
756
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
750
|
-
side: exports.SplitSide[side],
|
|
751
|
-
enable:
|
|
757
|
+
side: exports.SplitSide[currentHasWidget ? side : otherSide],
|
|
758
|
+
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
752
759
|
});
|
|
753
760
|
const width = useDomWidth({
|
|
754
761
|
selector: side === exports.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
755
|
-
enable: !!
|
|
762
|
+
enable: !!currentHasWidget && typeof renderWidgetLine === "function",
|
|
756
763
|
});
|
|
757
764
|
if (!renderWidgetLine)
|
|
758
765
|
return null;
|
|
759
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": exports.SplitSide[side], className: "diff-line diff-line-widget" },
|
|
766
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": exports.SplitSide[side], className: "diff-line diff-line-widget" }, currentHasWidget ? (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
760
767
|
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": exports.SplitSide[side], className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 && currentWidgetRendered))) : (React__namespace.createElement("td", { className: `diff-line-widget-${exports.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
761
768
|
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": exports.SplitSide[side] })))));
|
|
762
769
|
};
|
|
@@ -775,7 +782,7 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
775
782
|
}, [diffFile, index]), (p, c) => p === c);
|
|
776
783
|
if (!currentIsShow)
|
|
777
784
|
return null;
|
|
778
|
-
return React__namespace.createElement(
|
|
785
|
+
return React__namespace.createElement(InternalDiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
|
|
779
786
|
};
|
|
780
787
|
|
|
781
788
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -851,7 +858,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
851
858
|
});
|
|
852
859
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
853
860
|
|
|
854
|
-
const
|
|
861
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
855
862
|
var _a, _b;
|
|
856
863
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
857
864
|
const newLine = diffFile.getSplitRightLine(index);
|
|
@@ -907,10 +914,10 @@ const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
907
914
|
const newLine = diffFile.getSplitRightLine(index);
|
|
908
915
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
909
916
|
return null;
|
|
910
|
-
return React__namespace.createElement(
|
|
917
|
+
return React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
911
918
|
};
|
|
912
919
|
|
|
913
|
-
const
|
|
920
|
+
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
914
921
|
const { useDiffContext } = useDiffViewContext();
|
|
915
922
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
916
923
|
const newLine = diffFile.getSplitRightLine(index);
|
|
@@ -961,7 +968,7 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
961
968
|
const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
|
|
962
969
|
if (!currentIsShow)
|
|
963
970
|
return null;
|
|
964
|
-
return (React__namespace.createElement(
|
|
971
|
+
return (React__namespace.createElement(InternalDiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
965
972
|
};
|
|
966
973
|
|
|
967
974
|
const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1035,7 +1042,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1035
1042
|
color: `var(${hunkContentColorName})`,
|
|
1036
1043
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
1037
1044
|
};
|
|
1038
|
-
const
|
|
1045
|
+
const InternalDiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1039
1046
|
const { useDiffContext } = useDiffViewContext();
|
|
1040
1047
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
1041
1048
|
if (diffViewMode === exports.DiffModeEnum.SplitGitHub ||
|
|
@@ -1055,10 +1062,10 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1055
1062
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
1056
1063
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1057
1064
|
return null;
|
|
1058
|
-
return React__namespace.createElement(
|
|
1065
|
+
return React__namespace.createElement(InternalDiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1059
1066
|
};
|
|
1060
1067
|
|
|
1061
|
-
const
|
|
1068
|
+
const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1062
1069
|
const { useWidget } = useDiffWidgetContext();
|
|
1063
1070
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1064
1071
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1100,7 +1107,7 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1100
1107
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1101
1108
|
if (!currentIsShow)
|
|
1102
1109
|
return null;
|
|
1103
|
-
return React__namespace.createElement(
|
|
1110
|
+
return React__namespace.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1104
1111
|
};
|
|
1105
1112
|
|
|
1106
1113
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
@@ -1110,6 +1117,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1110
1117
|
const setId = (_id) => (id.value = _id);
|
|
1111
1118
|
const mode = reactivityStore.ref(props.diffViewMode);
|
|
1112
1119
|
const setMode = (_mode) => (mode.value = _mode);
|
|
1120
|
+
const mounted = reactivityStore.ref(props.isMounted);
|
|
1121
|
+
const setMounted = (_mounted) => (mounted.value = _mounted);
|
|
1113
1122
|
const enableWrap = reactivityStore.ref(props.diffViewWrap);
|
|
1114
1123
|
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1115
1124
|
const enableAddWidget = reactivityStore.ref(props.diffViewAddWidget);
|
|
@@ -1156,6 +1165,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1156
1165
|
setId,
|
|
1157
1166
|
mode,
|
|
1158
1167
|
setMode,
|
|
1168
|
+
mounted,
|
|
1169
|
+
setMounted,
|
|
1159
1170
|
enableWrap,
|
|
1160
1171
|
setEnableWrap,
|
|
1161
1172
|
enableAddWidget,
|
|
@@ -1382,7 +1393,7 @@ const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1382
1393
|
return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1383
1394
|
};
|
|
1384
1395
|
|
|
1385
|
-
const
|
|
1396
|
+
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
1386
1397
|
const { useDiffContext } = useDiffViewContext();
|
|
1387
1398
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
1388
1399
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1429,10 +1440,10 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1429
1440
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
1430
1441
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
|
|
1431
1442
|
return null;
|
|
1432
|
-
return (React__namespace.createElement(
|
|
1443
|
+
return (React__namespace.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1433
1444
|
};
|
|
1434
1445
|
|
|
1435
|
-
const
|
|
1446
|
+
const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1436
1447
|
var _a;
|
|
1437
1448
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
1438
1449
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -1474,10 +1485,10 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1474
1485
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
|
|
1475
1486
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1476
1487
|
return null;
|
|
1477
|
-
return React__namespace.createElement(
|
|
1488
|
+
return React__namespace.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1478
1489
|
};
|
|
1479
1490
|
|
|
1480
|
-
const
|
|
1491
|
+
const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1481
1492
|
const { useWidget } = useDiffWidgetContext();
|
|
1482
1493
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1483
1494
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1518,7 +1529,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1518
1529
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1519
1530
|
if (!currentIsShow)
|
|
1520
1531
|
return null;
|
|
1521
|
-
return React__namespace.createElement(
|
|
1532
|
+
return React__namespace.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1522
1533
|
};
|
|
1523
1534
|
|
|
1524
1535
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1594,27 +1605,49 @@ exports.DiffModeEnum = void 0;
|
|
|
1594
1605
|
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1595
1606
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1596
1607
|
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1597
|
-
const
|
|
1598
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1608
|
+
const InternalDiffView = (props) => {
|
|
1609
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
|
|
1599
1610
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1600
|
-
const isMounted = useIsMounted();
|
|
1601
1611
|
const wrapperRef = React.useRef();
|
|
1602
1612
|
// performance optimization
|
|
1603
1613
|
const useDiffContext = React.useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1604
1614
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1605
1615
|
[]);
|
|
1606
1616
|
React.useEffect(() => {
|
|
1607
|
-
const { id, setId, mode, setMode, enableAddWidget, setEnableAddWidget, enableHighlight, setEnableHighlight, enableWrap, setEnableWrap, setExtendData, fontSize, setFontSize, onAddWidgetClick: _onAddWidgetClick, setOnAddWidgetClick, renderExtendLine: _renderExtendLine, setRenderExtendLine, renderWidgetLine: _renderWidgetLine, setRenderWidgetLine, } = useDiffContext.getReadonlyState();
|
|
1608
|
-
diffFileId && diffFileId !== id
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1617
|
+
const { id, setId, mode, setMode, mounted, setMounted, enableAddWidget, setEnableAddWidget, enableHighlight, setEnableHighlight, enableWrap, setEnableWrap, setExtendData, fontSize, setFontSize, onAddWidgetClick: _onAddWidgetClick, setOnAddWidgetClick, renderExtendLine: _renderExtendLine, setRenderExtendLine, renderWidgetLine: _renderWidgetLine, setRenderWidgetLine, } = useDiffContext.getReadonlyState();
|
|
1618
|
+
if (diffFileId && diffFileId !== id) {
|
|
1619
|
+
setId(diffFileId);
|
|
1620
|
+
}
|
|
1621
|
+
if (diffViewMode && diffViewMode !== mode) {
|
|
1622
|
+
setMode(diffViewMode);
|
|
1623
|
+
}
|
|
1624
|
+
if (mounted !== isMounted) {
|
|
1625
|
+
setMounted(isMounted);
|
|
1626
|
+
}
|
|
1627
|
+
if (diffViewAddWidget !== enableAddWidget) {
|
|
1628
|
+
setEnableAddWidget(diffViewAddWidget);
|
|
1629
|
+
}
|
|
1630
|
+
if (diffViewHighlight !== enableHighlight) {
|
|
1631
|
+
setEnableHighlight(diffViewHighlight);
|
|
1632
|
+
}
|
|
1633
|
+
if (diffViewWrap !== enableWrap) {
|
|
1634
|
+
setEnableWrap(diffViewWrap);
|
|
1635
|
+
}
|
|
1636
|
+
if (extendData) {
|
|
1637
|
+
setExtendData(extendData);
|
|
1638
|
+
}
|
|
1639
|
+
if (diffViewFontSize && diffViewFontSize !== fontSize) {
|
|
1640
|
+
setFontSize(diffViewFontSize);
|
|
1641
|
+
}
|
|
1642
|
+
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1643
|
+
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1644
|
+
}
|
|
1645
|
+
if (renderExtendLine !== _renderExtendLine) {
|
|
1646
|
+
setRenderExtendLine(renderExtendLine);
|
|
1647
|
+
}
|
|
1648
|
+
if (renderWidgetLine !== _renderWidgetLine) {
|
|
1649
|
+
setRenderWidgetLine(renderWidgetLine);
|
|
1650
|
+
}
|
|
1618
1651
|
}, [
|
|
1619
1652
|
useDiffContext,
|
|
1620
1653
|
diffViewFontSize,
|
|
@@ -1623,6 +1656,7 @@ const _InternalDiffView = (props) => {
|
|
|
1623
1656
|
diffViewWrap,
|
|
1624
1657
|
diffViewAddWidget,
|
|
1625
1658
|
diffFileId,
|
|
1659
|
+
isMounted,
|
|
1626
1660
|
renderWidgetLine,
|
|
1627
1661
|
renderExtendLine,
|
|
1628
1662
|
extendData,
|
|
@@ -1638,14 +1672,14 @@ const _InternalDiffView = (props) => {
|
|
|
1638
1672
|
}, [diffFile]);
|
|
1639
1673
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1640
1674
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1641
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1675
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.26", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1642
1676
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1643
1677
|
// @ts-ignore
|
|
1644
1678
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
1645
1679
|
} },
|
|
1646
1680
|
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 })))))));
|
|
1647
1681
|
};
|
|
1648
|
-
const
|
|
1682
|
+
const MemoedInternalDiffView = React.memo(InternalDiffView);
|
|
1649
1683
|
const DiffViewWithRef = (props, ref) => {
|
|
1650
1684
|
var _a, _b;
|
|
1651
1685
|
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
|
|
@@ -1669,6 +1703,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1669
1703
|
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1670
1704
|
diffFileRef.current = diffFile;
|
|
1671
1705
|
}
|
|
1706
|
+
const isMounted = useIsMounted();
|
|
1672
1707
|
React.useEffect(() => {
|
|
1673
1708
|
if (_diffFile && diffFile) {
|
|
1674
1709
|
_diffFile._addClonedInstance(diffFile);
|
|
@@ -1698,12 +1733,12 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1698
1733
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1699
1734
|
if (!diffFile)
|
|
1700
1735
|
return null;
|
|
1701
|
-
return (React__namespace.createElement(
|
|
1736
|
+
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 })));
|
|
1702
1737
|
};
|
|
1703
1738
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1704
1739
|
InnerDiffView.displayName = "DiffView";
|
|
1705
1740
|
const DiffView = InnerDiffView;
|
|
1706
|
-
const version = "0.0.
|
|
1741
|
+
const version = "0.0.26";
|
|
1707
1742
|
|
|
1708
1743
|
exports.DiffView = DiffView;
|
|
1709
1744
|
exports.version = version;
|