@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.
@@ -255,7 +255,7 @@
255
255
  }
256
256
  .diff-tailwindcss-wrapper .\!text-red-500 {
257
257
  --tw-text-opacity: 1 !important;
258
- color: rgb(239 68 68 / var(--tw-text-opacity)) !important;
258
+ color: rgb(239 68 68 / var(--tw-text-opacity, 1)) !important;
259
259
  }
260
260
  .diff-tailwindcss-wrapper .opacity-\[0\.5\] {
261
261
  opacity: 0.5;
@@ -105,7 +105,7 @@
105
105
  --tw-contain-paint: ;
106
106
  --tw-contain-style: ;
107
107
  }/*
108
- ! tailwindcss v3.4.14 | MIT License | https://tailwindcss.com
108
+ ! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com
109
109
  *//*
110
110
  1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
111
111
  2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
@@ -761,7 +761,7 @@ video {
761
761
  }
762
762
  .diff-tailwindcss-wrapper .\!text-red-500 {
763
763
  --tw-text-opacity: 1 !important;
764
- color: rgb(239 68 68 / var(--tw-text-opacity)) !important;
764
+ color: rgb(239 68 68 / var(--tw-text-opacity, 1)) !important;
765
765
  }
766
766
  .diff-tailwindcss-wrapper .opacity-\[0\.5\] {
767
767
  opacity: 0.5;
@@ -2,7 +2,7 @@
2
2
  import { NewLineSymbol, DiffLineType, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
3
3
  export * from '@git-diff-view/core';
4
4
  import * as React from 'react';
5
- import { useState, useEffect, useRef, useLayoutEffect, createContext, useContext, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
5
+ import { useState, useEffect, useRef, useLayoutEffect, createContext, useContext, memo, Fragment, useMemo, useCallback, forwardRef, useImperativeHandle } from 'react';
6
6
  import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
7
7
  import { flushSync } from 'react-dom';
8
8
  import { createStore, ref } from 'reactivity-store';
@@ -65,7 +65,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
65
65
  }
66
66
 
67
67
  function __classPrivateFieldSet(receiver, state, value, kind, f) {
68
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
68
+ 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");
69
69
  return (state.set(receiver, value)), value;
70
70
  }
71
71
 
@@ -188,7 +188,7 @@ const syncScroll = (left, right) => {
188
188
  const diffFontSizeName = "--diff-font-size--";
189
189
  const diffAsideWidthName = "--diff-aside-width--";
190
190
 
191
- // eslint-disable-next-line @typescript-eslint/ban-types
191
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
192
192
  const memoFunc = (func) => {
193
193
  const cache = {};
194
194
  return ((key) => {
@@ -406,7 +406,7 @@ const DiffWidgetContext = createContext(null);
406
406
  DiffWidgetContext.displayName = "DiffWidgetContext";
407
407
  const useDiffWidgetContext = () => useContext(DiffWidgetContext);
408
408
 
409
- const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
409
+ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
410
410
  var _a, _b;
411
411
  const getCurrentSyntaxLine = side === SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
412
412
  const oldLine = diffFile.getSplitLeftLine(index);
@@ -447,13 +447,13 @@ const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
447
447
  const currentLine = getCurrentLine(index);
448
448
  if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
449
449
  return null;
450
- return React.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
450
+ return React.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
451
451
  };
452
452
 
453
453
  const useDomWidth = ({ selector, enable }) => {
454
454
  const [width, setWidth] = useState(0);
455
455
  const { useDiffContext } = useDiffViewContext();
456
- const id = useDiffContext(useCallback((s) => s.id, []));
456
+ const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
457
457
  useEffect(() => {
458
458
  if (enable) {
459
459
  const container = document.querySelector(`#diff-root${id}`);
@@ -489,86 +489,95 @@ const useDomWidth = ({ selector, enable }) => {
489
489
  typedWrapper.setAttribute("data-observe", "height");
490
490
  return () => cleanCb();
491
491
  }
492
- }, [selector, enable, id]);
492
+ }, [selector, enable, id, mounted]);
493
493
  return width;
494
494
  };
495
495
 
496
- // TODO
497
496
  const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
498
497
  const { useDiffContext } = useDiffViewContext();
499
- const id = useDiffContext(useCallback((s) => s.id, []));
498
+ const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
500
499
  useEffect(() => {
501
500
  if (enable) {
502
- let clean = () => { };
503
- // fix the dom delay update
504
- const timer = setTimeout(() => {
505
- const container = document.querySelector(`#diff-root${id}`);
506
- const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
507
- const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
508
- if (elements.length === 2 && wrappers.length === 2) {
509
- const ele1 = elements[0];
510
- const ele2 = elements[1];
511
- const wrapper1 = wrappers[0];
512
- const wrapper2 = wrappers[1];
513
- const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
514
- const cb = () => {
515
- ele1.style.height = "auto";
516
- ele2.style.height = "auto";
517
- const rect1 = ele1.getBoundingClientRect();
518
- const rect2 = ele2.getBoundingClientRect();
519
- const maxHeight = Math.max(rect1.height, rect2.height);
520
- wrapper1.style.height = maxHeight + "px";
521
- wrapper2.style.height = maxHeight + "px";
522
- wrapper1.setAttribute("data-sync-height", String(maxHeight));
523
- wrapper2.setAttribute("data-sync-height", String(maxHeight));
524
- };
525
- cb();
526
- const observer = new ResizeObserver(cb);
527
- observer.observe(target);
528
- target.setAttribute("data-observe", "height");
529
- clean = () => {
530
- observer.disconnect();
531
- target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
532
- };
501
+ const container = document.querySelector(`#diff-root${id}`);
502
+ const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
503
+ const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
504
+ if (elements.length === 2 && wrappers.length === 2) {
505
+ const ele1 = elements[0];
506
+ const ele2 = elements[1];
507
+ const wrapper1 = wrappers[0];
508
+ const wrapper2 = wrappers[1];
509
+ const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
510
+ const typedTarget = target;
511
+ const cb = () => {
512
+ ele1.style.height = "auto";
513
+ ele2.style.height = "auto";
514
+ const rect1 = ele1.getBoundingClientRect();
515
+ const rect2 = ele2.getBoundingClientRect();
516
+ const maxHeight = Math.max(rect1.height, rect2.height);
517
+ wrapper1.style.height = maxHeight + "px";
518
+ wrapper2.style.height = maxHeight + "px";
519
+ wrapper1.setAttribute("data-sync-height", String(maxHeight));
520
+ wrapper2.setAttribute("data-sync-height", String(maxHeight));
521
+ };
522
+ cb();
523
+ const cleanCb = () => {
524
+ var _a;
525
+ typedTarget.__observeCallback.delete(cb);
526
+ if (typedTarget.__observeCallback.size === 0) {
527
+ (_a = typedTarget.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
528
+ typedTarget.removeAttribute("data-observe");
529
+ delete typedTarget.__observeCallback;
530
+ delete typedTarget.__observeInstance;
531
+ }
532
+ };
533
+ if (typedTarget.__observeCallback) {
534
+ typedTarget.__observeCallback.add(cb);
535
+ return () => cleanCb();
533
536
  }
534
- });
535
- return () => {
536
- clean();
537
- clearTimeout(timer);
538
- };
537
+ typedTarget.__observeCallback = new Set();
538
+ typedTarget.__observeCallback.add(cb);
539
+ const observer = new ResizeObserver(() => typedTarget.__observeCallback.forEach((cb) => cb()));
540
+ typedTarget.__observeInstance = observer;
541
+ observer.observe(target);
542
+ target.setAttribute("data-observe", "height");
543
+ return () => cleanCb();
544
+ }
539
545
  }
540
- }, [selector, enable, side, id, wrapper]);
546
+ }, [selector, enable, side, id, wrapper, mounted]);
541
547
  };
542
548
 
543
- const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
549
+ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
544
550
  const { useDiffContext } = useDiffViewContext();
545
551
  const oldLine = diffFile.getSplitLeftLine(index);
546
552
  const newLine = diffFile.getSplitRightLine(index);
547
553
  const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
548
554
  const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
555
+ const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
549
556
  const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
550
- const hasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
557
+ const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
558
+ const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
559
+ ((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
551
560
  const currentExtendRendered = hasExtend &&
552
561
  (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
553
562
  diffFile,
554
563
  side,
555
564
  lineNumber: currentLineNumber,
556
- data: currentExtend.data,
565
+ data: currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data,
557
566
  onUpdate: diffFile.notifyAll,
558
567
  }));
559
568
  useSyncHeight({
560
569
  selector: `div[data-line="${lineNumber}-extend-content"]`,
561
570
  wrapper: `tr[data-line="${lineNumber}-extend"]`,
562
- side: SplitSide[side],
571
+ side: SplitSide[currentSideHasExtend ? side : otherSide],
563
572
  enable: hasExtend && typeof renderExtendLine === "function",
564
573
  });
565
574
  const width = useDomWidth({
566
575
  selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
567
- enable: hasExtend && typeof renderExtendLine === "function",
576
+ enable: currentSideHasExtend && typeof renderExtendLine === "function",
568
577
  });
569
578
  if (!renderExtendLine)
570
579
  return null;
571
- return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, hasExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
580
+ return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentSideHasExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
572
581
  React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side], className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 && currentExtendRendered))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
573
582
  React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] })))));
574
583
  };
@@ -590,7 +599,7 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
590
599
  const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
591
600
  if (!currentIsShow)
592
601
  return null;
593
- return (React.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
602
+ return (React.createElement(InternalDiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
594
603
  };
595
604
 
596
605
  const ExpandDown = ({ className }) => {
@@ -606,7 +615,7 @@ const ExpandAll = ({ className }) => {
606
615
  React.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" })));
607
616
  };
608
617
 
609
- const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
618
+ const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
610
619
  var _a;
611
620
  const currentHunk = diffFile.getSplitHunkLine(index);
612
621
  const expandEnabled = diffFile.getExpandEnabled();
@@ -630,9 +639,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
630
639
  minWidth: `var(${diffAsideWidthName})`,
631
640
  maxWidth: `var(${diffAsideWidthName})`,
632
641
  } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
633
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.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: () => {
634
- diffFile.onSplitHunkExpand("down", index);
635
- } },
642
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.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) },
636
643
  React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
637
644
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
638
645
  React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
@@ -645,7 +652,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
645
652
  } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
646
653
  React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
647
654
  };
648
- const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
655
+ const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
649
656
  var _a;
650
657
  const currentHunk = diffFile.getSplitHunkLine(index);
651
658
  const expandEnabled = diffFile.getExpandEnabled();
@@ -668,9 +675,7 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
668
675
  minWidth: `var(${diffAsideWidthName})`,
669
676
  maxWidth: `var(${diffAsideWidthName})`,
670
677
  } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
671
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.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: () => {
672
- diffFile.onSplitHunkExpand("down", index);
673
- } },
678
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.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) },
674
679
  React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
675
680
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
676
681
  React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
@@ -682,16 +687,16 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
682
687
  color: `var(${hunkContentColorName})`,
683
688
  } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
684
689
  };
685
- const _DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
690
+ const InternalDiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
686
691
  const { useDiffContext } = useDiffViewContext();
687
692
  const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
688
693
  if (diffViewMode === DiffModeEnum.SplitGitHub ||
689
694
  diffViewMode === DiffModeEnum.Split ||
690
695
  diffViewMode === DiffModeEnum.Unified) {
691
- return React.createElement(_DiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
696
+ return React.createElement(InternalDiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
692
697
  }
693
698
  else {
694
- return React.createElement(_DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
699
+ return React.createElement(InternalDiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
695
700
  }
696
701
  };
697
702
  const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
@@ -702,10 +707,10 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
702
707
  const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
703
708
  if (!currentIsShow && !currentIsPureHunk)
704
709
  return null;
705
- return React.createElement(_DiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
710
+ return React.createElement(InternalDiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
706
711
  };
707
712
 
708
- const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
713
+ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
709
714
  const { useWidget } = useDiffWidgetContext();
710
715
  const { useDiffContext } = useDiffViewContext();
711
716
  const oldLine = diffFile.getSplitLeftLine(index);
@@ -716,9 +721,11 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
716
721
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
717
722
  const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
718
723
  const currentLine = side === SplitSide.old ? oldLine : newLine;
719
- const currentWidget = side === SplitSide.old ? oldLineWidget : newLineWidget;
724
+ const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
725
+ const currentHasWidget = side === SplitSide.old ? oldLineWidget : newLineWidget;
726
+ const hasWidget = oldLineWidget || newLineWidget;
720
727
  const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
721
- const currentWidgetRendered = currentWidget &&
728
+ const currentWidgetRendered = currentHasWidget &&
722
729
  (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
723
730
  diffFile,
724
731
  side,
@@ -728,16 +735,16 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
728
735
  useSyncHeight({
729
736
  selector: `div[data-line="${lineNumber}-widget-content"]`,
730
737
  wrapper: `tr[data-line="${lineNumber}-widget"]`,
731
- side: SplitSide[side],
732
- enable: !!currentWidget && typeof renderWidgetLine === "function",
738
+ side: SplitSide[currentHasWidget ? side : otherSide],
739
+ enable: hasWidget && typeof renderWidgetLine === "function",
733
740
  });
734
741
  const width = useDomWidth({
735
742
  selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
736
- enable: !!currentWidget && typeof renderWidgetLine === "function",
743
+ enable: !!currentHasWidget && typeof renderWidgetLine === "function",
737
744
  });
738
745
  if (!renderWidgetLine)
739
746
  return null;
740
- return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" }, currentWidget ? (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-content p-0`, colSpan: 2 },
747
+ return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" }, currentHasWidget ? (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-content p-0`, colSpan: 2 },
741
748
  React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side], className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 && currentWidgetRendered))) : (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
742
749
  React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
743
750
  };
@@ -756,7 +763,7 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
756
763
  }, [diffFile, index]), (p, c) => p === c);
757
764
  if (!currentIsShow)
758
765
  return null;
759
- return React.createElement(_DiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
766
+ return React.createElement(InternalDiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
760
767
  };
761
768
 
762
769
  /* eslint-disable @typescript-eslint/ban-ts-comment */
@@ -832,7 +839,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
832
839
  });
833
840
  DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
834
841
 
835
- const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
842
+ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
836
843
  var _a, _b;
837
844
  const oldLine = diffFile.getSplitLeftLine(index);
838
845
  const newLine = diffFile.getSplitRightLine(index);
@@ -888,10 +895,10 @@ const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
888
895
  const newLine = diffFile.getSplitRightLine(index);
889
896
  if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
890
897
  return null;
891
- return React.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
898
+ return React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
892
899
  };
893
900
 
894
- const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
901
+ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
895
902
  const { useDiffContext } = useDiffViewContext();
896
903
  const oldLine = diffFile.getSplitLeftLine(index);
897
904
  const newLine = diffFile.getSplitRightLine(index);
@@ -942,7 +949,7 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
942
949
  const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
943
950
  if (!currentIsShow)
944
951
  return null;
945
- return (React.createElement(_DiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
952
+ return (React.createElement(InternalDiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
946
953
  };
947
954
 
948
955
  const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
@@ -1016,7 +1023,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
1016
1023
  color: `var(${hunkContentColorName})`,
1017
1024
  } }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
1018
1025
  };
1019
- const _DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1026
+ const InternalDiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1020
1027
  const { useDiffContext } = useDiffViewContext();
1021
1028
  const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
1022
1029
  if (diffViewMode === DiffModeEnum.SplitGitHub ||
@@ -1036,10 +1043,10 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1036
1043
  const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
1037
1044
  if (!currentIsShow && !currentIsPureHunk)
1038
1045
  return null;
1039
- return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1046
+ return React.createElement(InternalDiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1040
1047
  };
1041
1048
 
1042
- const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1049
+ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1043
1050
  const { useWidget } = useDiffWidgetContext();
1044
1051
  const setWidget = useWidget.getReadonlyState().setWidget;
1045
1052
  const { useDiffContext } = useDiffViewContext();
@@ -1081,7 +1088,7 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1081
1088
  }, [diffFile, index]), (p, c) => p === c);
1082
1089
  if (!currentIsShow)
1083
1090
  return null;
1084
- return React.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1091
+ return React.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1085
1092
  };
1086
1093
 
1087
1094
  const createDiffConfigStore = (props, diffFileId) => {
@@ -1091,6 +1098,8 @@ const createDiffConfigStore = (props, diffFileId) => {
1091
1098
  const setId = (_id) => (id.value = _id);
1092
1099
  const mode = ref(props.diffViewMode);
1093
1100
  const setMode = (_mode) => (mode.value = _mode);
1101
+ const mounted = ref(props.isMounted);
1102
+ const setMounted = (_mounted) => (mounted.value = _mounted);
1094
1103
  const enableWrap = ref(props.diffViewWrap);
1095
1104
  const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
1096
1105
  const enableAddWidget = ref(props.diffViewAddWidget);
@@ -1137,6 +1146,8 @@ const createDiffConfigStore = (props, diffFileId) => {
1137
1146
  setId,
1138
1147
  mode,
1139
1148
  setMode,
1149
+ mounted,
1150
+ setMounted,
1140
1151
  enableWrap,
1141
1152
  setEnableWrap,
1142
1153
  enableAddWidget,
@@ -1363,7 +1374,7 @@ const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
1363
1374
  return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1364
1375
  };
1365
1376
 
1366
- const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
1377
+ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
1367
1378
  const { useDiffContext } = useDiffViewContext();
1368
1379
  const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
1369
1380
  const unifiedItem = diffFile.getUnifiedLine(index);
@@ -1410,10 +1421,10 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
1410
1421
  const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
1411
1422
  if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
1412
1423
  return null;
1413
- return (React.createElement(_DiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
1424
+ return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
1414
1425
  };
1415
1426
 
1416
- const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1427
+ const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1417
1428
  var _a;
1418
1429
  const currentHunk = diffFile.getUnifiedHunkLine(index);
1419
1430
  const expandEnabled = diffFile.getExpandEnabled();
@@ -1455,10 +1466,10 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1455
1466
  const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
1456
1467
  if (!currentIsShow && !currentIsPureHunk)
1457
1468
  return null;
1458
- return React.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1469
+ return React.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1459
1470
  };
1460
1471
 
1461
- const _DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1472
+ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1462
1473
  const { useWidget } = useDiffWidgetContext();
1463
1474
  const setWidget = useWidget.getReadonlyState().setWidget;
1464
1475
  const unifiedItem = diffFile.getUnifiedLine(index);
@@ -1499,7 +1510,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1499
1510
  }, [diffFile, index]), (p, c) => p === c);
1500
1511
  if (!currentIsShow)
1501
1512
  return null;
1502
- return React.createElement(_DiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1513
+ return React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1503
1514
  };
1504
1515
 
1505
1516
  /* eslint-disable @typescript-eslint/ban-ts-comment */
@@ -1575,27 +1586,49 @@ var DiffModeEnum;
1575
1586
  DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
1576
1587
  DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
1577
1588
  })(DiffModeEnum || (DiffModeEnum = {}));
1578
- const _InternalDiffView = (props) => {
1579
- const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
1589
+ const InternalDiffView = (props) => {
1590
+ const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
1580
1591
  const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
1581
- const isMounted = useIsMounted();
1582
1592
  const wrapperRef = useRef();
1583
1593
  // performance optimization
1584
1594
  const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
1585
1595
  // eslint-disable-next-line react-hooks/exhaustive-deps
1586
1596
  []);
1587
1597
  useEffect(() => {
1588
- 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();
1589
- diffFileId && diffFileId !== id && setId(diffFileId);
1590
- diffViewMode && diffViewMode !== mode && setMode(diffViewMode);
1591
- diffViewAddWidget !== enableAddWidget && setEnableAddWidget(diffViewAddWidget);
1592
- diffViewHighlight !== enableHighlight && setEnableHighlight(diffViewHighlight);
1593
- diffViewWrap !== enableWrap && setEnableWrap(diffViewWrap);
1594
- extendData && setExtendData(extendData);
1595
- diffViewFontSize && diffViewFontSize !== fontSize && setFontSize(diffViewFontSize);
1596
- onAddWidgetClick !== _onAddWidgetClick.current && setOnAddWidgetClick({ current: onAddWidgetClick });
1597
- renderExtendLine !== _renderExtendLine && setRenderExtendLine(renderExtendLine);
1598
- renderWidgetLine !== _renderWidgetLine && setRenderWidgetLine(renderWidgetLine);
1598
+ 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();
1599
+ if (diffFileId && diffFileId !== id) {
1600
+ setId(diffFileId);
1601
+ }
1602
+ if (diffViewMode && diffViewMode !== mode) {
1603
+ setMode(diffViewMode);
1604
+ }
1605
+ if (mounted !== isMounted) {
1606
+ setMounted(isMounted);
1607
+ }
1608
+ if (diffViewAddWidget !== enableAddWidget) {
1609
+ setEnableAddWidget(diffViewAddWidget);
1610
+ }
1611
+ if (diffViewHighlight !== enableHighlight) {
1612
+ setEnableHighlight(diffViewHighlight);
1613
+ }
1614
+ if (diffViewWrap !== enableWrap) {
1615
+ setEnableWrap(diffViewWrap);
1616
+ }
1617
+ if (extendData) {
1618
+ setExtendData(extendData);
1619
+ }
1620
+ if (diffViewFontSize && diffViewFontSize !== fontSize) {
1621
+ setFontSize(diffViewFontSize);
1622
+ }
1623
+ if (onAddWidgetClick !== _onAddWidgetClick.current) {
1624
+ setOnAddWidgetClick({ current: onAddWidgetClick });
1625
+ }
1626
+ if (renderExtendLine !== _renderExtendLine) {
1627
+ setRenderExtendLine(renderExtendLine);
1628
+ }
1629
+ if (renderWidgetLine !== _renderWidgetLine) {
1630
+ setRenderWidgetLine(renderWidgetLine);
1631
+ }
1599
1632
  }, [
1600
1633
  useDiffContext,
1601
1634
  diffViewFontSize,
@@ -1604,6 +1637,7 @@ const _InternalDiffView = (props) => {
1604
1637
  diffViewWrap,
1605
1638
  diffViewAddWidget,
1606
1639
  diffFileId,
1640
+ isMounted,
1607
1641
  renderWidgetLine,
1608
1642
  renderExtendLine,
1609
1643
  extendData,
@@ -1619,14 +1653,14 @@ const _InternalDiffView = (props) => {
1619
1653
  }, [diffFile]);
1620
1654
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1621
1655
  return (React.createElement(DiffViewContext.Provider, { value: value },
1622
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.25", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1656
+ React.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 },
1623
1657
  React.createElement("div", { className: "diff-style-root", style: {
1624
1658
  // @ts-ignore
1625
1659
  [diffFontSizeName]: diffViewFontSize + "px",
1626
1660
  } },
1627
1661
  React.createElement("div", { id: isMounted ? `diff-root${diffFileId}` : undefined, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & DiffModeEnum.Split ? (React.createElement(DiffSplitView, { diffFile: diffFile })) : (React.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
1628
1662
  };
1629
- const InternalDiffView = memo(_InternalDiffView);
1663
+ const MemoedInternalDiffView = memo(InternalDiffView);
1630
1664
  const DiffViewWithRef = (props, ref) => {
1631
1665
  var _a, _b;
1632
1666
  const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
@@ -1650,6 +1684,7 @@ const DiffViewWithRef = (props, ref) => {
1650
1684
  (_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
1651
1685
  diffFileRef.current = diffFile;
1652
1686
  }
1687
+ const isMounted = useIsMounted();
1653
1688
  useEffect(() => {
1654
1689
  if (_diffFile && diffFile) {
1655
1690
  _diffFile._addClonedInstance(diffFile);
@@ -1679,12 +1714,12 @@ const DiffViewWithRef = (props, ref) => {
1679
1714
  useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
1680
1715
  if (!diffFile)
1681
1716
  return null;
1682
- return (React.createElement(InternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
1717
+ return (React.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
1683
1718
  };
1684
1719
  const InnerDiffView = forwardRef(DiffViewWithRef);
1685
1720
  InnerDiffView.displayName = "DiffView";
1686
1721
  const DiffView = InnerDiffView;
1687
- const version = "0.0.25";
1722
+ const version = "0.0.26";
1688
1723
 
1689
1724
  export { DiffModeEnum, DiffView, SplitSide, version };
1690
1725
  //# sourceMappingURL=index.mjs.map