@git-diff-view/react 0.0.14 → 0.0.15
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 +235 -223
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +235 -223
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +2 -2
- package/dist/esm/index.mjs +236 -223
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +469 -449
- package/package.json +7 -7
- package/readme.md +1 -1
package/dist/esm/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { composeLen, DiffLineType, NewLineSymbol, checkDiffLineIncludeChange, ge
|
|
|
2
2
|
export * from '@git-diff-view/core';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useRef, useEffect, createContext, useContext, useLayoutEffect, useState, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
5
|
-
import { createStore, ref } from 'reactivity-store';
|
|
6
5
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
7
6
|
import { flushSync } from 'react-dom';
|
|
7
|
+
import { createStore, ref } from 'reactivity-store';
|
|
8
8
|
|
|
9
9
|
/******************************************************************************
|
|
10
10
|
Copyright (c) Microsoft Corporation.
|
|
@@ -20,7 +20,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
20
20
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
21
|
PERFORMANCE OF THIS SOFTWARE.
|
|
22
22
|
***************************************************************************** */
|
|
23
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
23
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
function __rest(s, e) {
|
|
@@ -56,6 +56,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
56
56
|
const useUnmount = (cb, deps) => {
|
|
57
57
|
const ref = useRef(cb);
|
|
58
58
|
ref.current = cb;
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
60
|
useEffect(() => ref.current, deps);
|
|
60
61
|
};
|
|
61
62
|
|
|
@@ -170,6 +171,8 @@ const useSyncHeight = ({ selector, side, enable }) => {
|
|
|
170
171
|
if (elements.length === 2) {
|
|
171
172
|
const ele1 = elements[0];
|
|
172
173
|
const ele2 = elements[1];
|
|
174
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
175
|
+
const synced = ele1.getAttribute("data-side") !== side ? ele1 : ele2;
|
|
173
176
|
const cb = () => {
|
|
174
177
|
ele1.style.height = "auto";
|
|
175
178
|
ele2.style.height = "auto";
|
|
@@ -177,8 +180,7 @@ const useSyncHeight = ({ selector, side, enable }) => {
|
|
|
177
180
|
const rect2 = ele2.getBoundingClientRect();
|
|
178
181
|
if (rect1.height !== rect2.height) {
|
|
179
182
|
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
180
|
-
|
|
181
|
-
ele2.style.height = maxHeight + "px";
|
|
183
|
+
synced.style.height = maxHeight + "px";
|
|
182
184
|
ele1.setAttribute("data-sync-height", String(maxHeight));
|
|
183
185
|
ele2.setAttribute("data-sync-height", String(maxHeight));
|
|
184
186
|
}
|
|
@@ -189,7 +191,6 @@ const useSyncHeight = ({ selector, side, enable }) => {
|
|
|
189
191
|
};
|
|
190
192
|
cb();
|
|
191
193
|
const observer = new ResizeObserver(cb);
|
|
192
|
-
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
193
194
|
observer.observe(target);
|
|
194
195
|
target.setAttribute("data-observe", "height");
|
|
195
196
|
return () => {
|
|
@@ -264,7 +265,7 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend,
|
|
|
264
265
|
lineNumber: currentLineNumber,
|
|
265
266
|
data: currentExtend.data,
|
|
266
267
|
onUpdate: diffFile.notifyAll,
|
|
267
|
-
}))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder p-0
|
|
268
|
+
}))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
268
269
|
React.createElement("span", null, "\u2002")))));
|
|
269
270
|
};
|
|
270
271
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -343,7 +344,106 @@ const memoFunc = (func) => {
|
|
|
343
344
|
return result;
|
|
344
345
|
});
|
|
345
346
|
};
|
|
346
|
-
const
|
|
347
|
+
const createDiffConfigStore = (props, diffFileId) => {
|
|
348
|
+
return createStore(() => {
|
|
349
|
+
var _a, _b;
|
|
350
|
+
const id = ref(diffFileId);
|
|
351
|
+
const setId = (_id) => (id.value = _id);
|
|
352
|
+
const mode = ref(props.diffViewMode);
|
|
353
|
+
const setMode = (_mode) => (mode.value = _mode);
|
|
354
|
+
const enableWrap = ref(props.diffViewWrap);
|
|
355
|
+
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
356
|
+
const enableAddWidget = ref(props.diffViewAddWidget);
|
|
357
|
+
const setEnableAddWidget = (_enableAddWidget) => (enableAddWidget.value = _enableAddWidget);
|
|
358
|
+
const enableHighlight = ref(props.diffViewHighlight);
|
|
359
|
+
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
360
|
+
const fontSize = ref(props.diffViewFontSize);
|
|
361
|
+
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
362
|
+
const extendData = ref({
|
|
363
|
+
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
364
|
+
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
365
|
+
});
|
|
366
|
+
const setExtendData = (_extendData) => {
|
|
367
|
+
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
368
|
+
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
369
|
+
for (const key of existOldKeys) {
|
|
370
|
+
if (!inComingOldKeys.includes(key)) {
|
|
371
|
+
delete extendData.value.oldFile[key];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const key of inComingOldKeys) {
|
|
375
|
+
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
376
|
+
}
|
|
377
|
+
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
378
|
+
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
379
|
+
for (const key of existNewKeys) {
|
|
380
|
+
if (!inComingNewKeys.includes(key)) {
|
|
381
|
+
delete extendData.value.newFile[key];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
for (const key of inComingNewKeys) {
|
|
385
|
+
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const renderWidgetLine = ref(props.renderWidgetLine);
|
|
389
|
+
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
390
|
+
const renderExtendLine = ref(props.renderExtendLine);
|
|
391
|
+
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
392
|
+
// 避免无意义的订阅
|
|
393
|
+
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
394
|
+
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
395
|
+
return {
|
|
396
|
+
id,
|
|
397
|
+
setId,
|
|
398
|
+
mode,
|
|
399
|
+
setMode,
|
|
400
|
+
enableWrap,
|
|
401
|
+
setEnableWrap,
|
|
402
|
+
enableAddWidget,
|
|
403
|
+
setEnableAddWidget,
|
|
404
|
+
enableHighlight,
|
|
405
|
+
setEnableHighlight,
|
|
406
|
+
fontSize,
|
|
407
|
+
setFontSize,
|
|
408
|
+
extendData,
|
|
409
|
+
setExtendData,
|
|
410
|
+
renderWidgetLine,
|
|
411
|
+
setRenderWidgetLine,
|
|
412
|
+
renderExtendLine,
|
|
413
|
+
setRenderExtendLine,
|
|
414
|
+
onAddWidgetClick,
|
|
415
|
+
setOnAddWidgetClick,
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
const createDiffWidgetStore = (useDiffContextRef) => {
|
|
420
|
+
return createStore(() => {
|
|
421
|
+
const widgetSide = ref(undefined);
|
|
422
|
+
const widgetLineNumber = ref(undefined);
|
|
423
|
+
const setWidget = ({ side, lineNumber }) => {
|
|
424
|
+
var _a, _b;
|
|
425
|
+
const { renderWidgetLine } = ((_b = (_a = useDiffContextRef.current) === null || _a === void 0 ? void 0 : _a.getReadonlyState) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
|
|
426
|
+
if (typeof renderWidgetLine !== "function")
|
|
427
|
+
return;
|
|
428
|
+
widgetSide.value = side;
|
|
429
|
+
widgetLineNumber.value = lineNumber;
|
|
430
|
+
};
|
|
431
|
+
return { widgetSide, widgetLineNumber, setWidget };
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
const createDiffSplitConfigStore = () => {
|
|
435
|
+
return createStore(() => {
|
|
436
|
+
const splitRef = ref(undefined);
|
|
437
|
+
const setSplit = (side) => {
|
|
438
|
+
flushSync(() => {
|
|
439
|
+
splitRef.value = side;
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
return { splitRef, setSplit };
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
const diffAsideWidthName = "--diff-aside-width--";
|
|
446
|
+
const diffFontSizeName = "--diff-font-size--";
|
|
347
447
|
|
|
348
448
|
const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
349
449
|
var _a;
|
|
@@ -362,21 +462,21 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
362
462
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
363
463
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
364
464
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React.createElement(React.Fragment, null,
|
|
365
|
-
React.createElement("td", { className: "diff-line-hunk-action sticky left-0
|
|
465
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
366
466
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
367
467
|
color: `var(${plainLineNumberColorName})`,
|
|
368
|
-
width: `var(${
|
|
369
|
-
minWidth: `var(${
|
|
370
|
-
maxWidth: `var(${
|
|
371
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
372
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
468
|
+
width: `var(${diffAsideWidthName})`,
|
|
469
|
+
minWidth: `var(${diffAsideWidthName})`,
|
|
470
|
+
maxWidth: `var(${diffAsideWidthName})`,
|
|
471
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
472
|
+
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] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
373
473
|
diffFile.onSplitHunkExpand("down", index);
|
|
374
474
|
} },
|
|
375
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
475
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
376
476
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
377
|
-
React.createElement("button", { className: "
|
|
477
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
378
478
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
379
|
-
React.createElement("button", { className: "
|
|
479
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
380
480
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
381
481
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
382
482
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -400,21 +500,21 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
400
500
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
401
501
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
402
502
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
403
|
-
React.createElement("td", { className: "diff-line-hunk-action sticky left-0
|
|
503
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
404
504
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
405
505
|
color: `var(${plainLineNumberColorName})`,
|
|
406
|
-
width: `var(${
|
|
407
|
-
minWidth: `var(${
|
|
408
|
-
maxWidth: `var(${
|
|
409
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
410
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
506
|
+
width: `var(${diffAsideWidthName})`,
|
|
507
|
+
minWidth: `var(${diffAsideWidthName})`,
|
|
508
|
+
maxWidth: `var(${diffAsideWidthName})`,
|
|
509
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
510
|
+
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] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
411
511
|
diffFile.onSplitHunkExpand("down", index);
|
|
412
512
|
} },
|
|
413
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
513
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
414
514
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
415
|
-
React.createElement("button", { className: "
|
|
515
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
416
516
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
417
|
-
React.createElement("button", { className: "
|
|
517
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
418
518
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
419
519
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
420
520
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -445,14 +545,13 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
445
545
|
};
|
|
446
546
|
|
|
447
547
|
const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
|
|
448
|
-
return (React.createElement("div", { className: "diff-add-widget-wrapper
|
|
548
|
+
return (React.createElement("div", { className: "diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
|
|
549
|
+
(className ? " " + className : ""), style: {
|
|
449
550
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
450
551
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
451
552
|
} },
|
|
452
|
-
React.createElement("button", { className: "diff-add-widget
|
|
553
|
+
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: {
|
|
453
554
|
color: `var(${addWidgetColorName})`,
|
|
454
|
-
zIndex: 1,
|
|
455
|
-
fontSize: `1.2em`,
|
|
456
555
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
457
556
|
}, onClick: () => {
|
|
458
557
|
onOpenAddWidget(lineNumber, side);
|
|
@@ -460,14 +559,12 @@ const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpen
|
|
|
460
559
|
} }, "+")));
|
|
461
560
|
};
|
|
462
561
|
const DiffUnifiedAddWidget = ({ lineNumber, side, onWidgetClick, onOpenAddWidget, }) => {
|
|
463
|
-
return (React.createElement("div", { className: "diff-add-widget-wrapper absolute left-[100%] top-[1px] translate-x-[-50%]", style: {
|
|
562
|
+
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: {
|
|
464
563
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
465
564
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
466
565
|
} },
|
|
467
|
-
React.createElement("button", { className: "diff-add-widget
|
|
566
|
+
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: {
|
|
468
567
|
color: `var(${addWidgetColorName})`,
|
|
469
|
-
zIndex: 1,
|
|
470
|
-
fontSize: `1.2em`,
|
|
471
568
|
backgroundColor: `var(${addWidgetBGName})`,
|
|
472
569
|
}, onClick: () => {
|
|
473
570
|
onOpenAddWidget(lineNumber, side);
|
|
@@ -506,14 +603,15 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
506
603
|
return style;
|
|
507
604
|
});
|
|
508
605
|
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
509
|
-
const
|
|
510
|
-
if (
|
|
606
|
+
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
607
|
+
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
608
|
+
const range = changes.range;
|
|
511
609
|
const str1 = rawLine.slice(0, range.location);
|
|
512
610
|
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
513
611
|
const str3 = rawLine.slice(range.location + range.length);
|
|
514
612
|
const isLast = str2.includes("\n");
|
|
515
613
|
const _str2 = isLast ? str2.replace("\n", "") : str2;
|
|
516
|
-
const isNewLineSymbolChanged =
|
|
614
|
+
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
517
615
|
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
518
616
|
React.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
519
617
|
str1,
|
|
@@ -529,7 +627,7 @@ const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
|
529
627
|
: ""}`
|
|
530
628
|
: str2),
|
|
531
629
|
str3),
|
|
532
|
-
isNewLineSymbolChanged === NewLineSymbol.NEWLINE &&
|
|
630
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
|
|
533
631
|
width: `var(${diffFontSizeName})`,
|
|
534
632
|
height: `var(${diffFontSizeName})`,
|
|
535
633
|
} },
|
|
@@ -542,9 +640,10 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
542
640
|
if (!syntaxLine) {
|
|
543
641
|
return React.createElement(DiffString, { rawLine: rawLine, diffLine: diffLine, operator: operator });
|
|
544
642
|
}
|
|
545
|
-
const
|
|
546
|
-
if (
|
|
547
|
-
const isNewLineSymbolChanged =
|
|
643
|
+
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
644
|
+
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
645
|
+
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
646
|
+
const range = changes.range;
|
|
548
647
|
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
549
648
|
React.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
|
|
550
649
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -581,7 +680,7 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
581
680
|
str3));
|
|
582
681
|
}
|
|
583
682
|
})),
|
|
584
|
-
isNewLineSymbolChanged === NewLineSymbol.NEWLINE &&
|
|
683
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block text-red-500" : "inline-block align-middle text-red-500", style: {
|
|
585
684
|
width: `var(${diffFontSizeName})`,
|
|
586
685
|
height: `var(${diffFontSizeName})`,
|
|
587
686
|
} },
|
|
@@ -601,7 +700,7 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
601
700
|
whiteSpace: enableWrap ? "pre-wrap" : "pre",
|
|
602
701
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
603
702
|
} },
|
|
604
|
-
React.createElement("span", { "data-operator": isAdded ? "+" : isDelete ? "-" : undefined, className: "diff-line-content-operator
|
|
703
|
+
React.createElement("span", { "data-operator": isAdded ? "+" : isDelete ? "-" : undefined, className: "diff-line-content-operator ml-[-1.5em] inline-block w-[1.5em] select-none indent-[0.2em]" }, isAdded ? "+" : isDelete ? "-" : " "),
|
|
605
704
|
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, enableWrap: enableWrap }))));
|
|
606
705
|
};
|
|
607
706
|
|
|
@@ -632,14 +731,14 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
632
731
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
633
732
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
634
733
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff || !hasContent ? "diff" : "plain", "data-side": SplitSide[side], className: "diff-line" + (hasContent ? " group" : "") }, hasContent ? (React.createElement(React.Fragment, null,
|
|
635
|
-
React.createElement("td", { className: `diff-line-${SplitSide[side]}-num sticky left-0 pl-[10px] pr-[10px] text-right align-top
|
|
734
|
+
React.createElement("td", { className: `diff-line-${SplitSide[side]}-num sticky left-0 w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
|
|
636
735
|
backgroundColor: lineNumberBG,
|
|
637
736
|
color: `var(${plainLineNumberColorName})`,
|
|
638
|
-
width: `var(${
|
|
639
|
-
minWidth: `var(${
|
|
640
|
-
maxWidth: `var(${
|
|
737
|
+
width: `var(${diffAsideWidthName})`,
|
|
738
|
+
minWidth: `var(${diffAsideWidthName})`,
|
|
739
|
+
maxWidth: `var(${diffAsideWidthName})`,
|
|
641
740
|
} },
|
|
642
|
-
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%]
|
|
741
|
+
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
643
742
|
React.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
644
743
|
React.createElement("td", { className: `diff-line-${SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
645
744
|
React.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: `diff-line-${SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
@@ -705,7 +804,7 @@ const onMouseDown$1 = (e) => {
|
|
|
705
804
|
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
706
805
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
707
806
|
const lines = getSplitContentLines(diffFile);
|
|
708
|
-
return (React.createElement("table", { className: className + " border-collapse
|
|
807
|
+
return (React.createElement("table", { className: className + " w-full border-collapse", "data-mode": SplitSide[side] },
|
|
709
808
|
React.createElement("colgroup", null,
|
|
710
809
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-num-col` }),
|
|
711
810
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-content-col` })),
|
|
@@ -745,19 +844,19 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
745
844
|
font,
|
|
746
845
|
});
|
|
747
846
|
const width = Math.max(40, _width + 25);
|
|
748
|
-
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full
|
|
749
|
-
React.createElement("div", { className: "old-diff-table-wrapper overflow-x-auto overflow-y-hidden
|
|
847
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap flex w-full basis-[50%]" },
|
|
848
|
+
React.createElement("div", { className: "old-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
750
849
|
// @ts-ignore
|
|
751
|
-
[
|
|
850
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
752
851
|
overscrollBehaviorX: "none",
|
|
753
852
|
fontFamily: "Menlo, Consolas, monospace",
|
|
754
853
|
fontSize: `var(${diffFontSizeName})`,
|
|
755
854
|
} },
|
|
756
855
|
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
757
856
|
React.createElement("div", { className: "diff-split-line w-[1.5px] bg-[rgb(222,222,222)]" }),
|
|
758
|
-
React.createElement("div", { className: "new-diff-table-wrapper overflow-x-auto overflow-y-hidden
|
|
857
|
+
React.createElement("div", { className: "new-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
759
858
|
// @ts-ignore
|
|
760
|
-
[
|
|
859
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
761
860
|
overscrollBehaviorX: "none",
|
|
762
861
|
fontFamily: "Menlo, Consolas, monospace",
|
|
763
862
|
fontSize: `var(${diffFontSizeName})`,
|
|
@@ -783,9 +882,9 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
783
882
|
lineNumber: oldLine.lineNumber,
|
|
784
883
|
data: oldLineExtend.data,
|
|
785
884
|
onUpdate: diffFile.notifyAll,
|
|
786
|
-
}))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder p-0
|
|
885
|
+
}))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
787
886
|
React.createElement("span", null, "\u2002"))),
|
|
788
|
-
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content
|
|
887
|
+
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
|
|
789
888
|
React.createElement("div", { className: "diff-line-extend-wrapper" }, (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
790
889
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
791
890
|
diffFile,
|
|
@@ -793,7 +892,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
793
892
|
lineNumber: newLine.lineNumber,
|
|
794
893
|
data: newLineExtend.data,
|
|
795
894
|
onUpdate: diffFile.notifyAll,
|
|
796
|
-
}))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder
|
|
895
|
+
}))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] border-l-[rgb(222,222,222)] p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
797
896
|
React.createElement("span", null, "\u2002")))));
|
|
798
897
|
};
|
|
799
898
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -833,16 +932,16 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
|
833
932
|
if (!currentIsShow && !currentIsPureHunk)
|
|
834
933
|
return null;
|
|
835
934
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
836
|
-
React.createElement("td", { className: "diff-line-hunk-action
|
|
935
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
837
936
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
838
937
|
color: `var(${plainLineNumberColorName})`,
|
|
839
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
840
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
841
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
938
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
939
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
940
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
842
941
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
843
|
-
React.createElement("button", { className: "
|
|
942
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
844
943
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
845
|
-
React.createElement("button", { className: "
|
|
944
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
846
945
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
847
946
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
|
|
848
947
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -866,31 +965,31 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
866
965
|
if (!currentIsShow && !currentIsPureHunk)
|
|
867
966
|
return null;
|
|
868
967
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
869
|
-
React.createElement("td", { className: "diff-line-hunk-action
|
|
968
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
870
969
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
871
970
|
color: `var(${plainLineNumberColorName})`,
|
|
872
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
873
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
874
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
971
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
972
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
973
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
875
974
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
876
|
-
React.createElement("button", { className: "
|
|
975
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
877
976
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
878
|
-
React.createElement("button", { className: "
|
|
977
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
879
978
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
880
979
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
881
980
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
882
981
|
color: `var(${hunkContentColorName})`,
|
|
883
982
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
|
|
884
|
-
React.createElement("td", { className: "diff-line-hunk-action
|
|
983
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] border-l-[rgb(222,222,222)] p-[1px]", style: {
|
|
885
984
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
886
985
|
color: `var(${plainLineNumberColorName})`,
|
|
887
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
888
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
889
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
986
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
987
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
988
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
890
989
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
891
|
-
React.createElement("button", { className: "
|
|
990
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
892
991
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
893
|
-
React.createElement("button", { className: "
|
|
992
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
894
993
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
895
994
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
896
995
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -936,19 +1035,19 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
936
1035
|
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
937
1036
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
938
1037
|
hasOldLine ? (React.createElement(React.Fragment, null,
|
|
939
|
-
React.createElement("td", { className: "diff-line-old-num group relative pl-[10px] pr-[10px] text-right align-top
|
|
940
|
-
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%]
|
|
1038
|
+
React.createElement("td", { className: "diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` } },
|
|
1039
|
+
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
941
1040
|
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
942
1041
|
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
943
|
-
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] translate-x-[50%]
|
|
1042
|
+
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] z-[1] translate-x-[50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
944
1043
|
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
945
1044
|
React.createElement("span", null, "\u2002"))),
|
|
946
1045
|
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
947
|
-
React.createElement("td", { className: "diff-line-new-num group relative
|
|
948
|
-
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] translate-x-[-50%]
|
|
1046
|
+
React.createElement("td", { className: "diff-line-new-num group relative w-[1%] min-w-[40px] select-none border-l-[1px] border-l-[rgb(222,222,222)] pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineNumberBG, color: `var(${plainLineNumberColorName})` } },
|
|
1047
|
+
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
949
1048
|
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
950
1049
|
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
951
|
-
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] translate-x-[50%]
|
|
1050
|
+
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] z-[1] translate-x-[50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
952
1051
|
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px] border-l-[rgb(222,222,222)]", style: { backgroundColor: `var(${emptyBGName})` }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
|
|
953
1052
|
React.createElement("span", null, "\u2002")))));
|
|
954
1053
|
};
|
|
@@ -976,15 +1075,15 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
|
|
|
976
1075
|
side: SplitSide.old,
|
|
977
1076
|
lineNumber: oldLine.lineNumber,
|
|
978
1077
|
onClose: () => setWidget({}),
|
|
979
|
-
})))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder p-0
|
|
1078
|
+
})))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
980
1079
|
React.createElement("span", null, "\u2002"))),
|
|
981
|
-
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content
|
|
1080
|
+
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
|
|
982
1081
|
React.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
983
1082
|
diffFile,
|
|
984
1083
|
side: SplitSide.new,
|
|
985
1084
|
lineNumber: newLine.lineNumber,
|
|
986
1085
|
onClose: () => setWidget({}),
|
|
987
|
-
})))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder
|
|
1086
|
+
})))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] border-l-[rgb(222,222,222)] p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
988
1087
|
React.createElement("span", null, "\u2002")))));
|
|
989
1088
|
};
|
|
990
1089
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1000,6 +1099,7 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1000
1099
|
return (React.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineWidget: oldLineWidget, newLineWidget: newLineWidget }));
|
|
1001
1100
|
};
|
|
1002
1101
|
|
|
1102
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1003
1103
|
const Style = ({ useSelector, id, }) => {
|
|
1004
1104
|
const splitRef = useSelector((s) => s.splitRef);
|
|
1005
1105
|
return (React.createElement("style", { "data-select-style": true }, splitRef === SplitSide.old
|
|
@@ -1011,20 +1111,12 @@ const Style = ({ useSelector, id, }) => {
|
|
|
1011
1111
|
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1012
1112
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1013
1113
|
const { useDiffContext } = useDiffViewContext();
|
|
1014
|
-
const
|
|
1015
|
-
const splitRef = ref(undefined);
|
|
1016
|
-
const setSplit = (side) => {
|
|
1017
|
-
flushSync(() => {
|
|
1018
|
-
splitRef.value = side;
|
|
1019
|
-
});
|
|
1020
|
-
};
|
|
1021
|
-
return { splitRef, setSplit };
|
|
1022
|
-
}), []);
|
|
1023
|
-
const setSelectSide = splitSideInfo.getReadonlyState().setSplit;
|
|
1114
|
+
const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
|
|
1024
1115
|
const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
|
|
1025
1116
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
1026
1117
|
const onMouseDown = useCallback((e) => {
|
|
1027
1118
|
let ele = e.target;
|
|
1119
|
+
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1028
1120
|
// need remove all the selection
|
|
1029
1121
|
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1030
1122
|
removeAllSelection();
|
|
@@ -1040,7 +1132,8 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1040
1132
|
removeAllSelection();
|
|
1041
1133
|
}
|
|
1042
1134
|
}
|
|
1043
|
-
|
|
1135
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1136
|
+
}, []);
|
|
1044
1137
|
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1045
1138
|
const _width = useTextWidth({
|
|
1046
1139
|
text: splitLineLength.toString(),
|
|
@@ -1050,11 +1143,13 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1050
1143
|
const lines = getSplitContentLines(diffFile);
|
|
1051
1144
|
return (React.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
|
|
1052
1145
|
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1146
|
+
// @ts-ignore
|
|
1147
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1053
1148
|
fontFamily: "Menlo, Consolas, monospace",
|
|
1054
1149
|
fontSize: `var(${diffFontSizeName})`,
|
|
1055
1150
|
} },
|
|
1056
|
-
React.createElement(Style, { useSelector:
|
|
1057
|
-
React.createElement("table", { className: "diff-table
|
|
1151
|
+
React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1152
|
+
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse" },
|
|
1058
1153
|
React.createElement("colgroup", null,
|
|
1059
1154
|
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1060
1155
|
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
@@ -1078,20 +1173,11 @@ DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
|
1078
1173
|
|
|
1079
1174
|
const DiffSplitView = memo(({ diffFile }) => {
|
|
1080
1175
|
const { useDiffContext } = useDiffViewContext();
|
|
1081
|
-
const
|
|
1176
|
+
const useDiffContextRef = useRef(useDiffContext);
|
|
1177
|
+
useDiffContextRef.current = useDiffContext;
|
|
1178
|
+
const enableWrap = useDiffContext(useCallback((s) => s.enableWrap, []));
|
|
1082
1179
|
// performance optimization
|
|
1083
|
-
const useWidget = useMemo(() =>
|
|
1084
|
-
const widgetSide = ref(undefined);
|
|
1085
|
-
const widgetLineNumber = ref(undefined);
|
|
1086
|
-
const setWidget = ({ side, lineNumber }) => {
|
|
1087
|
-
const { renderWidgetLine } = useDiffContext.getReadonlyState();
|
|
1088
|
-
if (typeof renderWidgetLine !== "function")
|
|
1089
|
-
return;
|
|
1090
|
-
widgetSide.value = side;
|
|
1091
|
-
widgetLineNumber.value = lineNumber;
|
|
1092
|
-
};
|
|
1093
|
-
return { widgetSide, widgetLineNumber, setWidget };
|
|
1094
|
-
}), [useDiffContext]);
|
|
1180
|
+
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1095
1181
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1096
1182
|
useEffect(() => {
|
|
1097
1183
|
const { setWidget } = useWidget.getReadonlyState();
|
|
@@ -1112,7 +1198,7 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, ne
|
|
|
1112
1198
|
if (!renderExtendLine)
|
|
1113
1199
|
return null;
|
|
1114
1200
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1115
|
-
React.createElement("td", { className: "diff-line-extend-content align-top
|
|
1201
|
+
React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1116
1202
|
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
1117
1203
|
width > 0 &&
|
|
1118
1204
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
@@ -1162,19 +1248,19 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1162
1248
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
1163
1249
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
1164
1250
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
1165
|
-
React.createElement("td", { className: "diff-line-hunk-action sticky left-0
|
|
1251
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[100px] select-none p-[1px]", style: {
|
|
1166
1252
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
1167
1253
|
color: `var(${plainLineNumberColorName})`,
|
|
1168
|
-
width: `calc(calc(var(${
|
|
1169
|
-
maxWidth: `calc(calc(var(${
|
|
1170
|
-
minWidth: `calc(calc(var(${
|
|
1171
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "
|
|
1172
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "
|
|
1173
|
-
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "
|
|
1254
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1255
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1256
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1257
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
|
|
1258
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
|
|
1259
|
+
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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onUnifiedHunkExpand("all", index) },
|
|
1174
1260
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
1175
|
-
React.createElement("button", { className: "
|
|
1261
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onUnifiedHunkExpand("down", index) },
|
|
1176
1262
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
1177
|
-
React.createElement("button", { className: "
|
|
1263
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onUnifiedHunkExpand("up", index) },
|
|
1178
1264
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
1179
1265
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1180
1266
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -1196,12 +1282,12 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1196
1282
|
|
|
1197
1283
|
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1198
1284
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1199
|
-
React.createElement("td", { className: "diff-line-num sticky left-0
|
|
1285
|
+
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1200
1286
|
color: `var(${plainLineNumberColorName})`,
|
|
1201
1287
|
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1202
|
-
width: `calc(calc(var(${
|
|
1203
|
-
maxWidth: `calc(calc(var(${
|
|
1204
|
-
minWidth: `calc(calc(var(${
|
|
1288
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1289
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1290
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1205
1291
|
} },
|
|
1206
1292
|
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1207
1293
|
React.createElement("div", { className: "flex" },
|
|
@@ -1213,17 +1299,17 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1213
1299
|
};
|
|
1214
1300
|
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1215
1301
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1216
|
-
React.createElement("td", { className: "diff-line-num sticky left-0
|
|
1302
|
+
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1217
1303
|
color: `var(${plainLineNumberColorName})`,
|
|
1218
1304
|
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1219
|
-
width: `calc(calc(var(${
|
|
1220
|
-
maxWidth: `calc(calc(var(${
|
|
1221
|
-
minWidth: `calc(calc(var(${
|
|
1305
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1306
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1307
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1222
1308
|
} },
|
|
1223
1309
|
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1224
1310
|
React.createElement("div", { className: "flex" },
|
|
1225
1311
|
React.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1226
|
-
React.createElement("span", { className: "
|
|
1312
|
+
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1227
1313
|
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1228
1314
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1229
1315
|
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
@@ -1260,11 +1346,11 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1260
1346
|
}
|
|
1261
1347
|
else {
|
|
1262
1348
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1263
|
-
React.createElement("td", { className: "diff-line-num sticky left-0
|
|
1349
|
+
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1264
1350
|
color: `var(${plainLineNumberColorName})`,
|
|
1265
|
-
width: `calc(calc(var(${
|
|
1266
|
-
maxWidth: `calc(calc(var(${
|
|
1267
|
-
minWidth: `calc(calc(var(${
|
|
1351
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1352
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1353
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1268
1354
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1269
1355
|
} },
|
|
1270
1356
|
enableAddWidget && hasDiff && (React.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: SplitSide.new, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
@@ -1331,19 +1417,10 @@ const onMouseDown = (e) => {
|
|
|
1331
1417
|
};
|
|
1332
1418
|
const DiffUnifiedView = memo(({ diffFile }) => {
|
|
1333
1419
|
const { useDiffContext } = useDiffViewContext();
|
|
1420
|
+
const useDiffContextRef = useRef(useDiffContext);
|
|
1421
|
+
useDiffContextRef.current = useDiffContext;
|
|
1334
1422
|
// performance optimization
|
|
1335
|
-
const useWidget = useMemo(() =>
|
|
1336
|
-
const widgetSide = ref(undefined);
|
|
1337
|
-
const widgetLineNumber = ref(undefined);
|
|
1338
|
-
const setWidget = ({ side, lineNumber }) => {
|
|
1339
|
-
const { renderWidgetLine } = useDiffContext.getReadonlyState();
|
|
1340
|
-
if (typeof renderWidgetLine !== "function")
|
|
1341
|
-
return;
|
|
1342
|
-
widgetSide.value = side;
|
|
1343
|
-
widgetLineNumber.value = lineNumber;
|
|
1344
|
-
};
|
|
1345
|
-
return { widgetSide, widgetLineNumber, setWidget };
|
|
1346
|
-
}), [useDiffContext]);
|
|
1423
|
+
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1347
1424
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1348
1425
|
const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
|
|
1349
1426
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
@@ -1354,19 +1431,19 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1354
1431
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1355
1432
|
const _width = useTextWidth({
|
|
1356
1433
|
text: unifiedLineLength.toString(),
|
|
1357
|
-
font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
|
|
1434
|
+
font: useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]),
|
|
1358
1435
|
});
|
|
1359
|
-
const width = Math.max(40, _width +
|
|
1436
|
+
const width = Math.max(40, _width + 10);
|
|
1360
1437
|
const lines = getUnifiedContentLine(diffFile);
|
|
1361
1438
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1362
1439
|
React.createElement("div", { className: "unified-diff-view w-full" },
|
|
1363
|
-
React.createElement("div", { className: "unified-diff-table-wrapper overflow-x-auto overflow-y-hidden
|
|
1440
|
+
React.createElement("div", { className: "unified-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1364
1441
|
// @ts-ignore
|
|
1365
|
-
[
|
|
1442
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1366
1443
|
fontFamily: "Menlo, Consolas, monospace",
|
|
1367
1444
|
fontSize: `var(${diffFontSizeName})`,
|
|
1368
1445
|
} },
|
|
1369
|
-
React.createElement("table", { className: "unified-diff-table border-collapse
|
|
1446
|
+
React.createElement("table", { className: "unified-diff-table w-full border-collapse" },
|
|
1370
1447
|
React.createElement("colgroup", null,
|
|
1371
1448
|
React.createElement("col", { className: "unified-diff-table-num-col" }),
|
|
1372
1449
|
React.createElement("col", { className: "unified-diff-table-content-col" })),
|
|
@@ -1384,7 +1461,6 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1384
1461
|
});
|
|
1385
1462
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1386
1463
|
|
|
1387
|
-
const diffFontSizeName = "--diff-font-size--";
|
|
1388
1464
|
_cacheMap.name = "@git-diff-view/react";
|
|
1389
1465
|
var SplitSide;
|
|
1390
1466
|
(function (SplitSide) {
|
|
@@ -1395,76 +1471,7 @@ const _InternalDiffView = (props) => {
|
|
|
1395
1471
|
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1396
1472
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1397
1473
|
// performance optimization
|
|
1398
|
-
const useDiffContext = useMemo(() =>
|
|
1399
|
-
var _a, _b;
|
|
1400
|
-
const id = ref(diffFileId);
|
|
1401
|
-
const setId = (_id) => (id.value = _id);
|
|
1402
|
-
const mode = ref(props.diffViewMode);
|
|
1403
|
-
const setMode = (_mode) => (mode.value = _mode);
|
|
1404
|
-
const enableWrap = ref(props.diffViewWrap);
|
|
1405
|
-
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1406
|
-
const enableAddWidget = ref(props.diffViewAddWidget);
|
|
1407
|
-
const setEnableAddWidget = (_enableAddWidget) => (enableAddWidget.value = _enableAddWidget);
|
|
1408
|
-
const enableHighlight = ref(props.diffViewHighlight);
|
|
1409
|
-
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
1410
|
-
const fontSize = ref(props.diffViewFontSize);
|
|
1411
|
-
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
1412
|
-
const extendData = ref({
|
|
1413
|
-
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
1414
|
-
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
1415
|
-
});
|
|
1416
|
-
const setExtendData = (_extendData) => {
|
|
1417
|
-
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
1418
|
-
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
1419
|
-
for (const key of existOldKeys) {
|
|
1420
|
-
if (!inComingOldKeys.includes(key)) {
|
|
1421
|
-
delete extendData.value.oldFile[key];
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
for (const key of inComingOldKeys) {
|
|
1425
|
-
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
1426
|
-
}
|
|
1427
|
-
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
1428
|
-
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
1429
|
-
for (const key of existNewKeys) {
|
|
1430
|
-
if (!inComingNewKeys.includes(key)) {
|
|
1431
|
-
delete extendData.value.newFile[key];
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
for (const key of inComingNewKeys) {
|
|
1435
|
-
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
const renderWidgetLine = ref(props.renderWidgetLine);
|
|
1439
|
-
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1440
|
-
const renderExtendLine = ref(props.renderExtendLine);
|
|
1441
|
-
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1442
|
-
// 避免无意义的订阅
|
|
1443
|
-
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1444
|
-
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
1445
|
-
return {
|
|
1446
|
-
id,
|
|
1447
|
-
setId,
|
|
1448
|
-
mode,
|
|
1449
|
-
setMode,
|
|
1450
|
-
enableWrap,
|
|
1451
|
-
setEnableWrap,
|
|
1452
|
-
enableAddWidget,
|
|
1453
|
-
setEnableAddWidget,
|
|
1454
|
-
enableHighlight,
|
|
1455
|
-
setEnableHighlight,
|
|
1456
|
-
fontSize,
|
|
1457
|
-
setFontSize,
|
|
1458
|
-
extendData,
|
|
1459
|
-
setExtendData,
|
|
1460
|
-
renderWidgetLine,
|
|
1461
|
-
setRenderWidgetLine,
|
|
1462
|
-
renderExtendLine,
|
|
1463
|
-
setRenderExtendLine,
|
|
1464
|
-
onAddWidgetClick,
|
|
1465
|
-
setOnAddWidgetClick,
|
|
1466
|
-
};
|
|
1467
|
-
}),
|
|
1474
|
+
const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1468
1475
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1469
1476
|
[]);
|
|
1470
1477
|
useEffect(() => {
|
|
@@ -1494,7 +1501,7 @@ const _InternalDiffView = (props) => {
|
|
|
1494
1501
|
]);
|
|
1495
1502
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1496
1503
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1497
|
-
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.
|
|
1504
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.15"}`, "data-highlighter": diffFile._getHighlighterName() },
|
|
1498
1505
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1499
1506
|
// @ts-ignore
|
|
1500
1507
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1503,6 +1510,7 @@ const _InternalDiffView = (props) => {
|
|
|
1503
1510
|
};
|
|
1504
1511
|
const InternalDiffView = memo(_InternalDiffView);
|
|
1505
1512
|
const DiffViewWithRef = (props, ref) => {
|
|
1513
|
+
var _a, _b;
|
|
1506
1514
|
const { registerHighlighter, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffFile"]);
|
|
1507
1515
|
const diffFile = useMemo(() => {
|
|
1508
1516
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1516,6 +1524,11 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1516
1524
|
}
|
|
1517
1525
|
return null;
|
|
1518
1526
|
}, [data, _diffFile]);
|
|
1527
|
+
const diffFileRef = useRef(diffFile);
|
|
1528
|
+
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
1529
|
+
(_b = (_a = diffFileRef.current)._destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1530
|
+
diffFileRef.current = diffFile;
|
|
1531
|
+
}
|
|
1519
1532
|
useEffect(() => {
|
|
1520
1533
|
if (!diffFile)
|
|
1521
1534
|
return;
|
|
@@ -1547,7 +1560,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1547
1560
|
};
|
|
1548
1561
|
const DiffView = forwardRef(DiffViewWithRef);
|
|
1549
1562
|
DiffView.displayName = "DiffView";
|
|
1550
|
-
const version = "0.0.
|
|
1563
|
+
const version = "0.0.15";
|
|
1551
1564
|
|
|
1552
|
-
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide,
|
|
1565
|
+
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
|
|
1553
1566
|
//# sourceMappingURL=index.mjs.map
|