@git-diff-view/react 0.0.14 → 0.0.16
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 +241 -230
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +241 -230
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +2 -2
- package/dist/esm/index.mjs +242 -230
- 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
|
|
|
@@ -160,6 +161,7 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
160
161
|
return width;
|
|
161
162
|
};
|
|
162
163
|
|
|
164
|
+
// TODO
|
|
163
165
|
const useSyncHeight = ({ selector, side, enable }) => {
|
|
164
166
|
const { useDiffContext } = useDiffViewContext();
|
|
165
167
|
const id = useDiffContext(useCallback((s) => s.id, []));
|
|
@@ -170,6 +172,7 @@ const useSyncHeight = ({ selector, side, enable }) => {
|
|
|
170
172
|
if (elements.length === 2) {
|
|
171
173
|
const ele1 = elements[0];
|
|
172
174
|
const ele2 = elements[1];
|
|
175
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
173
176
|
const cb = () => {
|
|
174
177
|
ele1.style.height = "auto";
|
|
175
178
|
ele2.style.height = "auto";
|
|
@@ -189,7 +192,6 @@ const useSyncHeight = ({ selector, side, enable }) => {
|
|
|
189
192
|
};
|
|
190
193
|
cb();
|
|
191
194
|
const observer = new ResizeObserver(cb);
|
|
192
|
-
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
193
195
|
observer.observe(target);
|
|
194
196
|
target.setAttribute("data-observe", "height");
|
|
195
197
|
return () => {
|
|
@@ -243,15 +245,14 @@ const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend,
|
|
|
243
245
|
const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
|
|
244
246
|
const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
|
|
245
247
|
const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
246
|
-
const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
247
248
|
useSyncHeight({
|
|
248
249
|
selector: `tr[data-line="${lineNumber}-extend"]`,
|
|
249
|
-
side:
|
|
250
|
-
enable:
|
|
250
|
+
side: SplitSide[side],
|
|
251
|
+
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
251
252
|
});
|
|
252
253
|
const width = useDomWidth({
|
|
253
254
|
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
254
|
-
enable: !!currentExtend && typeof renderExtendLine === "function",
|
|
255
|
+
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
255
256
|
});
|
|
256
257
|
if (!renderExtendLine)
|
|
257
258
|
return null;
|
|
@@ -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: {
|
|
@@ -390,8 +490,8 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
390
490
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
391
491
|
useSyncHeight({
|
|
392
492
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
393
|
-
side: SplitSide[
|
|
394
|
-
enable:
|
|
493
|
+
side: SplitSide[side],
|
|
494
|
+
enable: true,
|
|
395
495
|
});
|
|
396
496
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
397
497
|
const isExpandAll = currentHunk &&
|
|
@@ -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 },
|
|
@@ -654,13 +753,12 @@ const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
654
753
|
};
|
|
655
754
|
|
|
656
755
|
const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWidget, currentWidget, }) => {
|
|
657
|
-
const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
658
756
|
const { useDiffContext } = useDiffViewContext();
|
|
659
757
|
const renderWidgetLine = useDiffContext(React.useCallback((s) => s.renderWidgetLine, []));
|
|
660
758
|
useSyncHeight({
|
|
661
759
|
selector: `tr[data-line="${lineNumber}-widget"]`,
|
|
662
|
-
side:
|
|
663
|
-
enable:
|
|
760
|
+
side: SplitSide[side],
|
|
761
|
+
enable: currentWidget && typeof renderWidgetLine === "function",
|
|
664
762
|
});
|
|
665
763
|
const width = useDomWidth({
|
|
666
764
|
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
@@ -705,7 +803,7 @@ const onMouseDown$1 = (e) => {
|
|
|
705
803
|
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
706
804
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
707
805
|
const lines = getSplitContentLines(diffFile);
|
|
708
|
-
return (React.createElement("table", { className: className + " border-collapse
|
|
806
|
+
return (React.createElement("table", { className: className + " w-full border-collapse", "data-mode": SplitSide[side] },
|
|
709
807
|
React.createElement("colgroup", null,
|
|
710
808
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-num-col` }),
|
|
711
809
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-content-col` })),
|
|
@@ -745,19 +843,19 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
745
843
|
font,
|
|
746
844
|
});
|
|
747
845
|
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
|
|
846
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap flex w-full basis-[50%]" },
|
|
847
|
+
React.createElement("div", { className: "old-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
750
848
|
// @ts-ignore
|
|
751
|
-
[
|
|
849
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
752
850
|
overscrollBehaviorX: "none",
|
|
753
851
|
fontFamily: "Menlo, Consolas, monospace",
|
|
754
852
|
fontSize: `var(${diffFontSizeName})`,
|
|
755
853
|
} },
|
|
756
854
|
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
757
855
|
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
|
|
856
|
+
React.createElement("div", { className: "new-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
759
857
|
// @ts-ignore
|
|
760
|
-
[
|
|
858
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
761
859
|
overscrollBehaviorX: "none",
|
|
762
860
|
fontFamily: "Menlo, Consolas, monospace",
|
|
763
861
|
fontSize: `var(${diffFontSizeName})`,
|
|
@@ -783,9 +881,9 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
783
881
|
lineNumber: oldLine.lineNumber,
|
|
784
882
|
data: oldLineExtend.data,
|
|
785
883
|
onUpdate: diffFile.notifyAll,
|
|
786
|
-
}))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder p-0
|
|
884
|
+
}))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
787
885
|
React.createElement("span", null, "\u2002"))),
|
|
788
|
-
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content
|
|
886
|
+
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
|
|
789
887
|
React.createElement("div", { className: "diff-line-extend-wrapper" }, (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
790
888
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
791
889
|
diffFile,
|
|
@@ -793,7 +891,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
793
891
|
lineNumber: newLine.lineNumber,
|
|
794
892
|
data: newLineExtend.data,
|
|
795
893
|
onUpdate: diffFile.notifyAll,
|
|
796
|
-
}))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder
|
|
894
|
+
}))))) : (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
895
|
React.createElement("span", null, "\u2002")))));
|
|
798
896
|
};
|
|
799
897
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -833,16 +931,16 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
|
833
931
|
if (!currentIsShow && !currentIsPureHunk)
|
|
834
932
|
return null;
|
|
835
933
|
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
|
|
934
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
837
935
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
838
936
|
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: "
|
|
937
|
+
} }, 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) },
|
|
938
|
+
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) },
|
|
939
|
+
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
940
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
843
|
-
React.createElement("button", { className: "
|
|
941
|
+
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
942
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
845
|
-
React.createElement("button", { className: "
|
|
943
|
+
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
944
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
847
945
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
|
|
848
946
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -866,31 +964,31 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
866
964
|
if (!currentIsShow && !currentIsPureHunk)
|
|
867
965
|
return null;
|
|
868
966
|
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
|
|
967
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
870
968
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
871
969
|
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: "
|
|
970
|
+
} }, 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) },
|
|
971
|
+
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) },
|
|
972
|
+
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
973
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
876
|
-
React.createElement("button", { className: "
|
|
974
|
+
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
975
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
878
|
-
React.createElement("button", { className: "
|
|
976
|
+
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
977
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
880
978
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
881
979
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
882
980
|
color: `var(${hunkContentColorName})`,
|
|
883
981
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
|
|
884
|
-
React.createElement("td", { className: "diff-line-hunk-action
|
|
982
|
+
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
983
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
886
984
|
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: "
|
|
985
|
+
} }, 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) },
|
|
986
|
+
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) },
|
|
987
|
+
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
988
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
891
|
-
React.createElement("button", { className: "
|
|
989
|
+
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
990
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
893
|
-
React.createElement("button", { className: "
|
|
991
|
+
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
992
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
895
993
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
896
994
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -936,19 +1034,19 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
936
1034
|
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
937
1035
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
938
1036
|
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%]
|
|
1037
|
+
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})` } },
|
|
1038
|
+
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
1039
|
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
942
1040
|
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%]
|
|
1041
|
+
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
1042
|
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
1043
|
React.createElement("span", null, "\u2002"))),
|
|
946
1044
|
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%]
|
|
1045
|
+
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})` } },
|
|
1046
|
+
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
1047
|
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
950
1048
|
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%]
|
|
1049
|
+
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
1050
|
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
1051
|
React.createElement("span", null, "\u2002")))));
|
|
954
1052
|
};
|
|
@@ -976,15 +1074,15 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
|
|
|
976
1074
|
side: SplitSide.old,
|
|
977
1075
|
lineNumber: oldLine.lineNumber,
|
|
978
1076
|
onClose: () => setWidget({}),
|
|
979
|
-
})))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder p-0
|
|
1077
|
+
})))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
980
1078
|
React.createElement("span", null, "\u2002"))),
|
|
981
|
-
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content
|
|
1079
|
+
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
|
|
982
1080
|
React.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
983
1081
|
diffFile,
|
|
984
1082
|
side: SplitSide.new,
|
|
985
1083
|
lineNumber: newLine.lineNumber,
|
|
986
1084
|
onClose: () => setWidget({}),
|
|
987
|
-
})))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder
|
|
1085
|
+
})))) : (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
1086
|
React.createElement("span", null, "\u2002")))));
|
|
989
1087
|
};
|
|
990
1088
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1000,6 +1098,7 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1000
1098
|
return (React.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineWidget: oldLineWidget, newLineWidget: newLineWidget }));
|
|
1001
1099
|
};
|
|
1002
1100
|
|
|
1101
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1003
1102
|
const Style = ({ useSelector, id, }) => {
|
|
1004
1103
|
const splitRef = useSelector((s) => s.splitRef);
|
|
1005
1104
|
return (React.createElement("style", { "data-select-style": true }, splitRef === SplitSide.old
|
|
@@ -1011,20 +1110,12 @@ const Style = ({ useSelector, id, }) => {
|
|
|
1011
1110
|
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1012
1111
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1013
1112
|
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;
|
|
1113
|
+
const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
|
|
1024
1114
|
const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
|
|
1025
1115
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
1026
1116
|
const onMouseDown = useCallback((e) => {
|
|
1027
1117
|
let ele = e.target;
|
|
1118
|
+
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1028
1119
|
// need remove all the selection
|
|
1029
1120
|
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1030
1121
|
removeAllSelection();
|
|
@@ -1040,7 +1131,8 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1040
1131
|
removeAllSelection();
|
|
1041
1132
|
}
|
|
1042
1133
|
}
|
|
1043
|
-
|
|
1134
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1135
|
+
}, []);
|
|
1044
1136
|
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1045
1137
|
const _width = useTextWidth({
|
|
1046
1138
|
text: splitLineLength.toString(),
|
|
@@ -1050,11 +1142,13 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1050
1142
|
const lines = getSplitContentLines(diffFile);
|
|
1051
1143
|
return (React.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
|
|
1052
1144
|
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1145
|
+
// @ts-ignore
|
|
1146
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1053
1147
|
fontFamily: "Menlo, Consolas, monospace",
|
|
1054
1148
|
fontSize: `var(${diffFontSizeName})`,
|
|
1055
1149
|
} },
|
|
1056
|
-
React.createElement(Style, { useSelector:
|
|
1057
|
-
React.createElement("table", { className: "diff-table
|
|
1150
|
+
React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1151
|
+
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse" },
|
|
1058
1152
|
React.createElement("colgroup", null,
|
|
1059
1153
|
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1060
1154
|
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
@@ -1078,20 +1172,11 @@ DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
|
1078
1172
|
|
|
1079
1173
|
const DiffSplitView = memo(({ diffFile }) => {
|
|
1080
1174
|
const { useDiffContext } = useDiffViewContext();
|
|
1081
|
-
const
|
|
1175
|
+
const useDiffContextRef = useRef(useDiffContext);
|
|
1176
|
+
useDiffContextRef.current = useDiffContext;
|
|
1177
|
+
const enableWrap = useDiffContext(useCallback((s) => s.enableWrap, []));
|
|
1082
1178
|
// 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]);
|
|
1179
|
+
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1095
1180
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1096
1181
|
useEffect(() => {
|
|
1097
1182
|
const { setWidget } = useWidget.getReadonlyState();
|
|
@@ -1112,7 +1197,7 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, ne
|
|
|
1112
1197
|
if (!renderExtendLine)
|
|
1113
1198
|
return null;
|
|
1114
1199
|
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
|
|
1200
|
+
React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1116
1201
|
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
1117
1202
|
width > 0 &&
|
|
1118
1203
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
@@ -1162,19 +1247,19 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1162
1247
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
1163
1248
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
1164
1249
|
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
|
|
1250
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[100px] select-none p-[1px]", style: {
|
|
1166
1251
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
1167
1252
|
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: "
|
|
1253
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1254
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1255
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1256
|
+
} }, 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) },
|
|
1257
|
+
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) },
|
|
1258
|
+
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
1259
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
1175
|
-
React.createElement("button", { className: "
|
|
1260
|
+
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
1261
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
1177
|
-
React.createElement("button", { className: "
|
|
1262
|
+
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
1263
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
1179
1264
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1180
1265
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -1196,12 +1281,12 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1196
1281
|
|
|
1197
1282
|
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1198
1283
|
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
|
|
1284
|
+
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
1285
|
color: `var(${plainLineNumberColorName})`,
|
|
1201
1286
|
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1202
|
-
width: `calc(calc(var(${
|
|
1203
|
-
maxWidth: `calc(calc(var(${
|
|
1204
|
-
minWidth: `calc(calc(var(${
|
|
1287
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1288
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1289
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1205
1290
|
} },
|
|
1206
1291
|
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1207
1292
|
React.createElement("div", { className: "flex" },
|
|
@@ -1213,17 +1298,17 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1213
1298
|
};
|
|
1214
1299
|
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1215
1300
|
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
|
|
1301
|
+
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
1302
|
color: `var(${plainLineNumberColorName})`,
|
|
1218
1303
|
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1219
|
-
width: `calc(calc(var(${
|
|
1220
|
-
maxWidth: `calc(calc(var(${
|
|
1221
|
-
minWidth: `calc(calc(var(${
|
|
1304
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1305
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1306
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1222
1307
|
} },
|
|
1223
1308
|
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1224
1309
|
React.createElement("div", { className: "flex" },
|
|
1225
1310
|
React.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1226
|
-
React.createElement("span", { className: "
|
|
1311
|
+
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1227
1312
|
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1228
1313
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1229
1314
|
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
@@ -1260,11 +1345,11 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1260
1345
|
}
|
|
1261
1346
|
else {
|
|
1262
1347
|
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
|
|
1348
|
+
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
1349
|
color: `var(${plainLineNumberColorName})`,
|
|
1265
|
-
width: `calc(calc(var(${
|
|
1266
|
-
maxWidth: `calc(calc(var(${
|
|
1267
|
-
minWidth: `calc(calc(var(${
|
|
1350
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1351
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1352
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1268
1353
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1269
1354
|
} },
|
|
1270
1355
|
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 +1416,10 @@ const onMouseDown = (e) => {
|
|
|
1331
1416
|
};
|
|
1332
1417
|
const DiffUnifiedView = memo(({ diffFile }) => {
|
|
1333
1418
|
const { useDiffContext } = useDiffViewContext();
|
|
1419
|
+
const useDiffContextRef = useRef(useDiffContext);
|
|
1420
|
+
useDiffContextRef.current = useDiffContext;
|
|
1334
1421
|
// 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]);
|
|
1422
|
+
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1347
1423
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1348
1424
|
const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
|
|
1349
1425
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
@@ -1354,19 +1430,19 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1354
1430
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1355
1431
|
const _width = useTextWidth({
|
|
1356
1432
|
text: unifiedLineLength.toString(),
|
|
1357
|
-
font: { fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" },
|
|
1433
|
+
font: useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]),
|
|
1358
1434
|
});
|
|
1359
|
-
const width = Math.max(40, _width +
|
|
1435
|
+
const width = Math.max(40, _width + 10);
|
|
1360
1436
|
const lines = getUnifiedContentLine(diffFile);
|
|
1361
1437
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1362
1438
|
React.createElement("div", { className: "unified-diff-view w-full" },
|
|
1363
|
-
React.createElement("div", { className: "unified-diff-table-wrapper overflow-x-auto overflow-y-hidden
|
|
1439
|
+
React.createElement("div", { className: "unified-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1364
1440
|
// @ts-ignore
|
|
1365
|
-
[
|
|
1441
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1366
1442
|
fontFamily: "Menlo, Consolas, monospace",
|
|
1367
1443
|
fontSize: `var(${diffFontSizeName})`,
|
|
1368
1444
|
} },
|
|
1369
|
-
React.createElement("table", { className: "unified-diff-table border-collapse
|
|
1445
|
+
React.createElement("table", { className: "unified-diff-table w-full border-collapse" },
|
|
1370
1446
|
React.createElement("colgroup", null,
|
|
1371
1447
|
React.createElement("col", { className: "unified-diff-table-num-col" }),
|
|
1372
1448
|
React.createElement("col", { className: "unified-diff-table-content-col" })),
|
|
@@ -1384,7 +1460,6 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1384
1460
|
});
|
|
1385
1461
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1386
1462
|
|
|
1387
|
-
const diffFontSizeName = "--diff-font-size--";
|
|
1388
1463
|
_cacheMap.name = "@git-diff-view/react";
|
|
1389
1464
|
var SplitSide;
|
|
1390
1465
|
(function (SplitSide) {
|
|
@@ -1395,76 +1470,7 @@ const _InternalDiffView = (props) => {
|
|
|
1395
1470
|
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1396
1471
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1397
1472
|
// 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
|
-
}),
|
|
1473
|
+
const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1468
1474
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1469
1475
|
[]);
|
|
1470
1476
|
useEffect(() => {
|
|
@@ -1494,7 +1500,7 @@ const _InternalDiffView = (props) => {
|
|
|
1494
1500
|
]);
|
|
1495
1501
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1496
1502
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1497
|
-
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.
|
|
1503
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.16"}`, "data-highlighter": diffFile._getHighlighterName() },
|
|
1498
1504
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1499
1505
|
// @ts-ignore
|
|
1500
1506
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1503,6 +1509,7 @@ const _InternalDiffView = (props) => {
|
|
|
1503
1509
|
};
|
|
1504
1510
|
const InternalDiffView = memo(_InternalDiffView);
|
|
1505
1511
|
const DiffViewWithRef = (props, ref) => {
|
|
1512
|
+
var _a, _b;
|
|
1506
1513
|
const { registerHighlighter, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffFile"]);
|
|
1507
1514
|
const diffFile = useMemo(() => {
|
|
1508
1515
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1516,6 +1523,11 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1516
1523
|
}
|
|
1517
1524
|
return null;
|
|
1518
1525
|
}, [data, _diffFile]);
|
|
1526
|
+
const diffFileRef = useRef(diffFile);
|
|
1527
|
+
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
1528
|
+
(_b = (_a = diffFileRef.current)._destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1529
|
+
diffFileRef.current = diffFile;
|
|
1530
|
+
}
|
|
1519
1531
|
useEffect(() => {
|
|
1520
1532
|
if (!diffFile)
|
|
1521
1533
|
return;
|
|
@@ -1547,7 +1559,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1547
1559
|
};
|
|
1548
1560
|
const DiffView = forwardRef(DiffViewWithRef);
|
|
1549
1561
|
DiffView.displayName = "DiffView";
|
|
1550
|
-
const version = "0.0.
|
|
1562
|
+
const version = "0.0.16";
|
|
1551
1563
|
|
|
1552
|
-
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide,
|
|
1564
|
+
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
|
|
1553
1565
|
//# sourceMappingURL=index.mjs.map
|