@git-diff-view/react 0.0.31 → 0.0.32
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 +53 -23
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +53 -23
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +0 -3
- package/dist/css/diff-view.css +0 -3
- package/dist/esm/index.mjs +53 -23
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/components/DiffAddWidget.tsx +3 -1
- package/src/components/DiffUnifiedExtendLine.tsx +9 -3
- package/src/components/DiffUnifiedView.tsx +12 -2
- package/src/components/DiffUnifiedWidgetLine.tsx +10 -4
- package/src/components/DiffView.tsx +4 -0
- package/src/components/tools.ts +6 -0
- package/src/hooks/useDomWidth.ts +10 -3
- package/src/hooks/useSyncHeight.ts +10 -3
- package/styles/diff-view-pure.css +0 -3
- package/styles/diff-view.css +0 -3
package/dist/css/diff-view.css
CHANGED
package/dist/esm/index.mjs
CHANGED
|
@@ -186,6 +186,16 @@ 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
|
+
};
|
|
189
199
|
|
|
190
200
|
const diffFontSizeName = "--diff-font-size--";
|
|
191
201
|
const diffAsideWidthName = "--diff-aside-width--";
|
|
@@ -271,6 +281,7 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
271
281
|
(className ? " " + className : ""), style: {
|
|
272
282
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
273
283
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
284
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
274
285
|
} },
|
|
275
286
|
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
287
|
color: `var(${addWidgetColorName})`,
|
|
@@ -281,9 +292,10 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
281
292
|
} }, "+")));
|
|
282
293
|
};
|
|
283
294
|
const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
|
|
284
|
-
return (React.createElement("div", { className: "diff-add-widget-wrapper invisible absolute left-[100%]
|
|
295
|
+
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
296
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
286
297
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
298
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
287
299
|
} },
|
|
288
300
|
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
301
|
color: `var(${addWidgetColorName})`,
|
|
@@ -519,10 +531,15 @@ const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWi
|
|
|
519
531
|
const useDomWidth = ({ selector, enable }) => {
|
|
520
532
|
const [width, setWidth] = useState(0);
|
|
521
533
|
const { useDiffContext } = useDiffViewContext();
|
|
522
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
534
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
535
|
+
id: s.id,
|
|
536
|
+
mounted: s.mounted,
|
|
537
|
+
dom: s.dom,
|
|
538
|
+
}));
|
|
523
539
|
useEffect(() => {
|
|
524
540
|
if (enable) {
|
|
525
|
-
const
|
|
541
|
+
const rootDocument = getElementRoot(dom);
|
|
542
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
526
543
|
const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
|
|
527
544
|
if (!wrapper)
|
|
528
545
|
return;
|
|
@@ -555,16 +572,21 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
555
572
|
typedWrapper.setAttribute("data-observe", "height");
|
|
556
573
|
return () => cleanCb();
|
|
557
574
|
}
|
|
558
|
-
}, [selector, enable, id, mounted]);
|
|
575
|
+
}, [selector, enable, id, mounted, dom]);
|
|
559
576
|
return width;
|
|
560
577
|
};
|
|
561
578
|
|
|
562
579
|
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
563
580
|
const { useDiffContext } = useDiffViewContext();
|
|
564
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
581
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
582
|
+
id: s.id,
|
|
583
|
+
mounted: s.mounted,
|
|
584
|
+
dom: s.dom,
|
|
585
|
+
}));
|
|
565
586
|
useEffect(() => {
|
|
566
587
|
if (enable) {
|
|
567
|
-
const
|
|
588
|
+
const rootDocument = getElementRoot(dom);
|
|
589
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
568
590
|
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
569
591
|
const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
|
|
570
592
|
if (elements.length === 2 && wrappers.length === 2) {
|
|
@@ -609,7 +631,7 @@ const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
|
609
631
|
return () => cleanCb();
|
|
610
632
|
}
|
|
611
633
|
}
|
|
612
|
-
}, [selector, enable, side, id, wrapper, mounted]);
|
|
634
|
+
}, [selector, enable, side, id, wrapper, mounted, dom]);
|
|
613
635
|
};
|
|
614
636
|
|
|
615
637
|
const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
@@ -1298,6 +1320,8 @@ DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
|
1298
1320
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1299
1321
|
return createStore(() => {
|
|
1300
1322
|
var _a, _b;
|
|
1323
|
+
const dom = ref();
|
|
1324
|
+
const setDom = (_dom) => (dom.value = _dom);
|
|
1301
1325
|
const id = ref(diffFileId);
|
|
1302
1326
|
const setId = (_id) => (id.value = _id);
|
|
1303
1327
|
const mode = ref(props.diffViewMode);
|
|
@@ -1350,6 +1374,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1350
1374
|
return {
|
|
1351
1375
|
id,
|
|
1352
1376
|
setId,
|
|
1377
|
+
dom,
|
|
1378
|
+
setDom,
|
|
1353
1379
|
mode,
|
|
1354
1380
|
setMode,
|
|
1355
1381
|
mounted,
|
|
@@ -1505,20 +1531,21 @@ const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enabl
|
|
|
1505
1531
|
return (React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
|
|
1506
1532
|
};
|
|
1507
1533
|
|
|
1508
|
-
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
1534
|
+
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, enableWrap, oldLineExtend, newLineExtend, }) => {
|
|
1509
1535
|
const { useDiffContext } = useDiffViewContext();
|
|
1510
1536
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
1511
1537
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1538
|
+
// TODO use css variable to get width
|
|
1512
1539
|
const width = useDomWidth({
|
|
1513
1540
|
selector: ".unified-diff-table-wrapper",
|
|
1514
|
-
enable: typeof renderExtendLine === "function",
|
|
1541
|
+
enable: typeof renderExtendLine === "function" && !enableWrap,
|
|
1515
1542
|
});
|
|
1516
1543
|
if (!renderExtendLine)
|
|
1517
1544
|
return null;
|
|
1518
1545
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1519
1546
|
React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1520
1547
|
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1521
|
-
width > 0 &&
|
|
1548
|
+
(enableWrap ? true : width > 0) &&
|
|
1522
1549
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1523
1550
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
1524
1551
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
@@ -1528,7 +1555,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1528
1555
|
data: oldLineExtend.data,
|
|
1529
1556
|
onUpdate: diffFile.notifyAll,
|
|
1530
1557
|
})),
|
|
1531
|
-
width > 0 &&
|
|
1558
|
+
(enableWrap ? true : width > 0) &&
|
|
1532
1559
|
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined &&
|
|
1533
1560
|
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null &&
|
|
1534
1561
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
@@ -1539,7 +1566,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1539
1566
|
onUpdate: diffFile.notifyAll,
|
|
1540
1567
|
}))))));
|
|
1541
1568
|
};
|
|
1542
|
-
const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
1569
|
+
const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
|
|
1543
1570
|
const { useDiffContext } = useDiffViewContext();
|
|
1544
1571
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1545
1572
|
const { oldLineExtend, newLineExtend } = useDiffContext(useCallback((s) => {
|
|
@@ -1552,7 +1579,7 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1552
1579
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
1553
1580
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
|
|
1554
1581
|
return null;
|
|
1555
|
-
return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1582
|
+
return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1556
1583
|
};
|
|
1557
1584
|
|
|
1558
1585
|
const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1600,7 +1627,7 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1600
1627
|
return React.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1601
1628
|
};
|
|
1602
1629
|
|
|
1603
|
-
const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1630
|
+
const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
|
|
1604
1631
|
const { useWidget } = useDiffWidgetContext();
|
|
1605
1632
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1606
1633
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1614,21 +1641,21 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1614
1641
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1615
1642
|
const width = useDomWidth({
|
|
1616
1643
|
selector: ".unified-diff-table-wrapper",
|
|
1617
|
-
enable: typeof renderWidgetLine === "function",
|
|
1644
|
+
enable: typeof renderWidgetLine === "function" && !enableWrap,
|
|
1618
1645
|
});
|
|
1619
1646
|
if (!renderWidgetLine)
|
|
1620
1647
|
return null;
|
|
1621
1648
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1622
1649
|
React.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
|
|
1623
1650
|
React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1624
|
-
width > 0 &&
|
|
1651
|
+
(enableWrap ? true : width > 0) &&
|
|
1625
1652
|
oldWidget &&
|
|
1626
1653
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
1627
|
-
width > 0 &&
|
|
1654
|
+
(enableWrap ? true : width > 0) &&
|
|
1628
1655
|
newWidget &&
|
|
1629
1656
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
|
|
1630
1657
|
};
|
|
1631
|
-
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1658
|
+
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, enableWrap, }) => {
|
|
1632
1659
|
const { useWidget } = useDiffWidgetContext();
|
|
1633
1660
|
const currentIsShow = useWidget.useShallowSelector(React.useCallback((s) => {
|
|
1634
1661
|
const widgetLineNumber = s.widgetLineNumber;
|
|
@@ -1641,7 +1668,7 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1641
1668
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1642
1669
|
if (!currentIsShow)
|
|
1643
1670
|
return null;
|
|
1644
|
-
return React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1671
|
+
return (React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap }));
|
|
1645
1672
|
};
|
|
1646
1673
|
|
|
1647
1674
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1738,8 +1765,8 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1738
1765
|
lines.map((item) => (React.createElement(Fragment, { key: item.index },
|
|
1739
1766
|
React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1740
1767
|
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 })))),
|
|
1768
|
+
React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap }),
|
|
1769
|
+
React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap })))),
|
|
1743
1770
|
React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
1744
1771
|
});
|
|
1745
1772
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
@@ -1805,9 +1832,12 @@ const InternalDiffView = (props) => {
|
|
|
1805
1832
|
onAddWidgetClick,
|
|
1806
1833
|
onCreateUseWidgetHook,
|
|
1807
1834
|
]);
|
|
1835
|
+
useEffect(() => {
|
|
1836
|
+
useDiffContext.getReadonlyState().setDom(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current);
|
|
1837
|
+
}, [useDiffContext, wrapperRef]);
|
|
1808
1838
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1809
1839
|
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.
|
|
1840
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.32", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1811
1841
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1812
1842
|
// @ts-ignore
|
|
1813
1843
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1886,7 +1916,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1886
1916
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
1887
1917
|
InnerDiffView.displayName = "DiffView";
|
|
1888
1918
|
const DiffView = InnerDiffView;
|
|
1889
|
-
const version = "0.0.
|
|
1919
|
+
const version = "0.0.32";
|
|
1890
1920
|
|
|
1891
1921
|
export { DiffModeEnum, DiffView, version };
|
|
1892
1922
|
//# sourceMappingURL=index.mjs.map
|