@git-diff-view/react 0.0.31 → 0.0.33

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.
@@ -50,9 +50,6 @@
50
50
  .diff-tailwindcss-wrapper .top-0 {
51
51
  top: 0px;
52
52
  }
53
- .diff-tailwindcss-wrapper .top-\[1px\] {
54
- top: 1px;
55
- }
56
53
  .diff-tailwindcss-wrapper .top-\[50\%\] {
57
54
  top: 50%;
58
55
  }
@@ -105,7 +105,7 @@
105
105
  --tw-contain-paint: ;
106
106
  --tw-contain-style: ;
107
107
  }/*
108
- ! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com
108
+ ! tailwindcss v3.4.18 | 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)
@@ -556,9 +556,6 @@ video {
556
556
  .diff-tailwindcss-wrapper .top-0 {
557
557
  top: 0px;
558
558
  }
559
- .diff-tailwindcss-wrapper .top-\[1px\] {
560
- top: 1px;
561
- }
562
559
  .diff-tailwindcss-wrapper .top-\[50\%\] {
563
560
  top: 50%;
564
561
  }
@@ -186,6 +186,35 @@ const syncScroll = (left, right) => {
186
186
  right.onscroll = null;
187
187
  };
188
188
  };
189
+ const getElementRoot = (element) => {
190
+ if (element) {
191
+ const root = element.getRootNode();
192
+ if (root instanceof ShadowRoot) {
193
+ return root;
194
+ }
195
+ return element.ownerDocument;
196
+ }
197
+ return document;
198
+ };
199
+ const getDiffIdFromElement = (element) => {
200
+ if (element) {
201
+ if (typeof element.closest === "function") {
202
+ const diffRoot = element.closest('[data-component="git-diff-view"]');
203
+ const ele = diffRoot.querySelector(".diff-view-wrapper");
204
+ return ele.getAttribute("id");
205
+ }
206
+ else {
207
+ let el = element;
208
+ while (el) {
209
+ if (el.getAttribute && el.getAttribute("data-component") === "git-diff-view") {
210
+ const ele = el.querySelector(".diff-view-wrapper");
211
+ return ele.getAttribute("id");
212
+ }
213
+ el = el.parentElement;
214
+ }
215
+ }
216
+ }
217
+ };
189
218
 
190
219
  const diffFontSizeName = "--diff-font-size--";
191
220
  const diffAsideWidthName = "--diff-aside-width--";
@@ -271,6 +300,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
271
300
  (className ? " " + className : ""), style: {
272
301
  width: `calc(var(${diffFontSizeName}) * 1.4)`,
273
302
  height: `calc(var(${diffFontSizeName}) * 1.4)`,
303
+ top: `calc(var(${diffFontSizeName}) * 0.1)`,
274
304
  } },
275
305
  React.createElement("button", { className: "diff-add-widget z-[1] flex h-full w-full origin-center cursor-pointer items-center justify-center rounded-md text-[1.2em]", style: {
276
306
  color: `var(${addWidgetColorName})`,
@@ -281,9 +311,10 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
281
311
  } }, "+")));
282
312
  };
283
313
  const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
284
- return (React.createElement("div", { className: "diff-add-widget-wrapper invisible absolute left-[100%] top-[1px] translate-x-[-50%] select-none transition-transform hover:scale-110 group-hover:visible", style: {
314
+ return (React.createElement("div", { className: "diff-add-widget-wrapper invisible absolute left-[100%] translate-x-[-50%] select-none transition-transform hover:scale-110 group-hover:visible", style: {
285
315
  width: `calc(var(${diffFontSizeName}) * 1.4)`,
286
316
  height: `calc(var(${diffFontSizeName}) * 1.4)`,
317
+ top: `calc(var(${diffFontSizeName}) * 0.1)`,
287
318
  } },
288
319
  React.createElement("button", { className: "diff-add-widget z-[1] flex h-full w-full origin-center cursor-pointer items-center justify-center rounded-md text-[1.2em]", style: {
289
320
  color: `var(${addWidgetColorName})`,
@@ -519,10 +550,15 @@ const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWi
519
550
  const useDomWidth = ({ selector, enable }) => {
520
551
  const [width, setWidth] = useState(0);
521
552
  const { useDiffContext } = useDiffViewContext();
522
- const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
553
+ const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
554
+ id: s.id,
555
+ mounted: s.mounted,
556
+ dom: s.dom,
557
+ }));
523
558
  useEffect(() => {
524
559
  if (enable) {
525
- const container = document.querySelector(`#diff-root${id}`);
560
+ const rootDocument = getElementRoot(dom);
561
+ const container = rootDocument.querySelector(`#diff-root${id}`);
526
562
  const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
527
563
  if (!wrapper)
528
564
  return;
@@ -555,16 +591,21 @@ const useDomWidth = ({ selector, enable }) => {
555
591
  typedWrapper.setAttribute("data-observe", "height");
556
592
  return () => cleanCb();
557
593
  }
558
- }, [selector, enable, id, mounted]);
594
+ }, [selector, enable, id, mounted, dom]);
559
595
  return width;
560
596
  };
561
597
 
562
598
  const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
563
599
  const { useDiffContext } = useDiffViewContext();
564
- const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
600
+ const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
601
+ id: s.id,
602
+ mounted: s.mounted,
603
+ dom: s.dom,
604
+ }));
565
605
  useEffect(() => {
566
606
  if (enable) {
567
- const container = document.querySelector(`#diff-root${id}`);
607
+ const rootDocument = getElementRoot(dom);
608
+ const container = rootDocument.querySelector(`#diff-root${id}`);
568
609
  const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
569
610
  const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
570
611
  if (elements.length === 2 && wrappers.length === 2) {
@@ -609,7 +650,7 @@ const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
609
650
  return () => cleanCb();
610
651
  }
611
652
  }
612
- }, [selector, enable, side, id, wrapper, mounted]);
653
+ }, [selector, enable, side, id, wrapper, mounted, dom]);
613
654
  };
614
655
 
615
656
  const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
@@ -900,6 +941,10 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
900
941
  removeAllSelection();
901
942
  return;
902
943
  }
944
+ const id = getDiffIdFromElement(ele);
945
+ if (id && id !== `diff-root${diffFile.getId()}`) {
946
+ return;
947
+ }
903
948
  while (ele && ele instanceof HTMLElement) {
904
949
  const state = ele.getAttribute("data-state");
905
950
  const side = ele.getAttribute("data-side");
@@ -1239,6 +1284,10 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1239
1284
  removeAllSelection();
1240
1285
  return;
1241
1286
  }
1287
+ const id = getDiffIdFromElement(ele);
1288
+ if (id && id !== `diff-root${diffFile.getId()}`) {
1289
+ return;
1290
+ }
1242
1291
  while (ele && ele instanceof HTMLElement) {
1243
1292
  const state = ele.getAttribute("data-state");
1244
1293
  const side = ele.getAttribute("data-side");
@@ -1298,6 +1347,8 @@ DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
1298
1347
  const createDiffConfigStore = (props, diffFileId) => {
1299
1348
  return createStore(() => {
1300
1349
  var _a, _b;
1350
+ const dom = ref();
1351
+ const setDom = (_dom) => (dom.value = _dom);
1301
1352
  const id = ref(diffFileId);
1302
1353
  const setId = (_id) => (id.value = _id);
1303
1354
  const mode = ref(props.diffViewMode);
@@ -1350,6 +1401,8 @@ const createDiffConfigStore = (props, diffFileId) => {
1350
1401
  return {
1351
1402
  id,
1352
1403
  setId,
1404
+ dom,
1405
+ setDom,
1353
1406
  mode,
1354
1407
  setMode,
1355
1408
  mounted,
@@ -1505,20 +1558,21 @@ const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enabl
1505
1558
  return (React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
1506
1559
  };
1507
1560
 
1508
- const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
1561
+ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, enableWrap, oldLineExtend, newLineExtend, }) => {
1509
1562
  const { useDiffContext } = useDiffViewContext();
1510
1563
  const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
1511
1564
  const unifiedItem = diffFile.getUnifiedLine(index);
1565
+ // TODO use css variable to get width
1512
1566
  const width = useDomWidth({
1513
1567
  selector: ".unified-diff-table-wrapper",
1514
- enable: typeof renderExtendLine === "function",
1568
+ enable: typeof renderExtendLine === "function" && !enableWrap,
1515
1569
  });
1516
1570
  if (!renderExtendLine)
1517
1571
  return null;
1518
1572
  return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
1519
1573
  React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
1520
1574
  React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
1521
- width > 0 &&
1575
+ (enableWrap ? true : width > 0) &&
1522
1576
  (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
1523
1577
  (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
1524
1578
  (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
@@ -1528,7 +1582,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
1528
1582
  data: oldLineExtend.data,
1529
1583
  onUpdate: diffFile.notifyAll,
1530
1584
  })),
1531
- width > 0 &&
1585
+ (enableWrap ? true : width > 0) &&
1532
1586
  (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined &&
1533
1587
  (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null &&
1534
1588
  (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
@@ -1539,7 +1593,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
1539
1593
  onUpdate: diffFile.notifyAll,
1540
1594
  }))))));
1541
1595
  };
1542
- const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
1596
+ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
1543
1597
  const { useDiffContext } = useDiffViewContext();
1544
1598
  const unifiedItem = diffFile.getUnifiedLine(index);
1545
1599
  const { oldLineExtend, newLineExtend } = useDiffContext(useCallback((s) => {
@@ -1552,7 +1606,7 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
1552
1606
  const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
1553
1607
  if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
1554
1608
  return null;
1555
- return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
1609
+ return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
1556
1610
  };
1557
1611
 
1558
1612
  const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
@@ -1600,7 +1654,7 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1600
1654
  return React.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1601
1655
  };
1602
1656
 
1603
- const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1657
+ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
1604
1658
  const { useWidget } = useDiffWidgetContext();
1605
1659
  const setWidget = useWidget.getReadonlyState().setWidget;
1606
1660
  const unifiedItem = diffFile.getUnifiedLine(index);
@@ -1614,21 +1668,21 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1614
1668
  const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
1615
1669
  const width = useDomWidth({
1616
1670
  selector: ".unified-diff-table-wrapper",
1617
- enable: typeof renderWidgetLine === "function",
1671
+ enable: typeof renderWidgetLine === "function" && !enableWrap,
1618
1672
  });
1619
1673
  if (!renderWidgetLine)
1620
1674
  return null;
1621
1675
  return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
1622
1676
  React.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
1623
1677
  React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
1624
- width > 0 &&
1678
+ (enableWrap ? true : width > 0) &&
1625
1679
  oldWidget &&
1626
1680
  (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
1627
- width > 0 &&
1681
+ (enableWrap ? true : width > 0) &&
1628
1682
  newWidget &&
1629
1683
  (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
1630
1684
  };
1631
- const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1685
+ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
1632
1686
  const { useWidget } = useDiffWidgetContext();
1633
1687
  const currentIsShow = useWidget.useShallowSelector(React.useCallback((s) => {
1634
1688
  const widgetLineNumber = s.widgetLineNumber;
@@ -1641,7 +1695,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1641
1695
  }, [diffFile, index]), (p, c) => p === c);
1642
1696
  if (!currentIsShow)
1643
1697
  return null;
1644
- return React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1698
+ return (React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap }));
1645
1699
  };
1646
1700
 
1647
1701
  /* eslint-disable @typescript-eslint/ban-ts-comment */
@@ -1694,6 +1748,10 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1694
1748
  removeAllSelection();
1695
1749
  return;
1696
1750
  }
1751
+ const id = getDiffIdFromElement(ele);
1752
+ if (id && id !== `diff-root${diffFile.getId()}`) {
1753
+ return;
1754
+ }
1697
1755
  while (ele && ele instanceof HTMLElement) {
1698
1756
  const state = ele.getAttribute("data-state");
1699
1757
  if (state) {
@@ -1738,8 +1796,8 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1738
1796
  lines.map((item) => (React.createElement(Fragment, { key: item.index },
1739
1797
  React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1740
1798
  React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }),
1741
- React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1742
- React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
1799
+ React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap }),
1800
+ React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap })))),
1743
1801
  React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
1744
1802
  });
1745
1803
  DiffUnifiedView.displayName = "DiffUnifiedView";
@@ -1805,9 +1863,12 @@ const InternalDiffView = (props) => {
1805
1863
  onAddWidgetClick,
1806
1864
  onCreateUseWidgetHook,
1807
1865
  ]);
1866
+ useEffect(() => {
1867
+ useDiffContext.getReadonlyState().setDom(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current);
1868
+ }, [useDiffContext, wrapperRef]);
1808
1869
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1809
1870
  return (React.createElement(DiffViewContext.Provider, { value: value },
1810
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.31", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1871
+ React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.33", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1811
1872
  React.createElement("div", { className: "diff-style-root", style: {
1812
1873
  // @ts-ignore
1813
1874
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -1886,7 +1947,7 @@ const DiffViewWithRef = (props, ref) => {
1886
1947
  const InnerDiffView = forwardRef(DiffViewWithRef);
1887
1948
  InnerDiffView.displayName = "DiffView";
1888
1949
  const DiffView = InnerDiffView;
1889
- const version = "0.0.31";
1950
+ const version = "0.0.33";
1890
1951
 
1891
1952
  export { DiffModeEnum, DiffView, version };
1892
1953
  //# sourceMappingURL=index.mjs.map