@git-diff-view/react 0.0.16 → 0.0.17
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 +506 -474
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +506 -474
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view.css +13 -3
- package/dist/esm/index.mjs +494 -462
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +9 -4
- package/package.json +8 -5
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DiffLineType, NewLineSymbol, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
|
|
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';
|
|
@@ -118,93 +118,9 @@ const useTextWidth = ({ text, font, }) => {
|
|
|
118
118
|
return width;
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
const useDomWidth = ({ selector, enable }) => {
|
|
122
|
-
const [width, setWidth] = useState(0);
|
|
123
|
-
const { useDiffContext } = useDiffViewContext();
|
|
124
|
-
const id = useDiffContext(useCallback((s) => s.id, []));
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (enable) {
|
|
127
|
-
const container = document.querySelector(`#diff-root${id}`);
|
|
128
|
-
const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
|
|
129
|
-
if (!wrapper)
|
|
130
|
-
return;
|
|
131
|
-
const typedWrapper = wrapper;
|
|
132
|
-
const cb = () => {
|
|
133
|
-
var _a;
|
|
134
|
-
const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
|
|
135
|
-
setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
|
|
136
|
-
};
|
|
137
|
-
cb();
|
|
138
|
-
const cleanCb = () => {
|
|
139
|
-
var _a;
|
|
140
|
-
typedWrapper.__observeCallback.delete(cb);
|
|
141
|
-
if (typedWrapper.__observeCallback.size === 0) {
|
|
142
|
-
(_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
143
|
-
typedWrapper.removeAttribute("data-observe");
|
|
144
|
-
delete typedWrapper.__observeCallback;
|
|
145
|
-
delete typedWrapper.__observeInstance;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
if (typedWrapper.__observeCallback) {
|
|
149
|
-
typedWrapper.__observeCallback.add(cb);
|
|
150
|
-
return () => cleanCb();
|
|
151
|
-
}
|
|
152
|
-
typedWrapper.__observeCallback = new Set();
|
|
153
|
-
typedWrapper.__observeCallback.add(cb);
|
|
154
|
-
const observer = new ResizeObserver(() => typedWrapper.__observeCallback.forEach((cb) => cb()));
|
|
155
|
-
typedWrapper.__observeInstance = observer;
|
|
156
|
-
observer.observe(typedWrapper);
|
|
157
|
-
typedWrapper.setAttribute("data-observe", "height");
|
|
158
|
-
return () => cleanCb();
|
|
159
|
-
}
|
|
160
|
-
}, [selector, enable, id]);
|
|
161
|
-
return width;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// TODO
|
|
165
|
-
const useSyncHeight = ({ selector, side, enable }) => {
|
|
166
|
-
const { useDiffContext } = useDiffViewContext();
|
|
167
|
-
const id = useDiffContext(useCallback((s) => s.id, []));
|
|
168
|
-
useSafeLayout(() => {
|
|
169
|
-
if (enable) {
|
|
170
|
-
const container = document.querySelector(`#diff-root${id}`);
|
|
171
|
-
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
172
|
-
if (elements.length === 2) {
|
|
173
|
-
const ele1 = elements[0];
|
|
174
|
-
const ele2 = elements[1];
|
|
175
|
-
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
176
|
-
const cb = () => {
|
|
177
|
-
ele1.style.height = "auto";
|
|
178
|
-
ele2.style.height = "auto";
|
|
179
|
-
const rect1 = ele1.getBoundingClientRect();
|
|
180
|
-
const rect2 = ele2.getBoundingClientRect();
|
|
181
|
-
if (rect1.height !== rect2.height) {
|
|
182
|
-
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
183
|
-
ele1.style.height = maxHeight + "px";
|
|
184
|
-
ele2.style.height = maxHeight + "px";
|
|
185
|
-
ele1.setAttribute("data-sync-height", String(maxHeight));
|
|
186
|
-
ele2.setAttribute("data-sync-height", String(maxHeight));
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
ele1.removeAttribute("data-sync-height");
|
|
190
|
-
ele2.removeAttribute("data-sync-height");
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
cb();
|
|
194
|
-
const observer = new ResizeObserver(cb);
|
|
195
|
-
observer.observe(target);
|
|
196
|
-
target.setAttribute("data-observe", "height");
|
|
197
|
-
return () => {
|
|
198
|
-
observer.disconnect();
|
|
199
|
-
target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}, [selector, enable, side, id]);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
121
|
const addContentBGName = "--diff-add-content--";
|
|
207
122
|
const delContentBGName = "--diff-del-content--";
|
|
123
|
+
const borderColorName = "--diff-border--";
|
|
208
124
|
const addLineNumberBGName = "--diff-add-lineNumber--";
|
|
209
125
|
const delLineNumberBGName = "--diff-del-lineNumber--";
|
|
210
126
|
const plainContentBGName = "--diff-plain-content--";
|
|
@@ -238,70 +154,6 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
238
154
|
: `var(${expandContentBGName})`;
|
|
239
155
|
};
|
|
240
156
|
|
|
241
|
-
const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
242
|
-
const { useDiffContext } = useDiffViewContext();
|
|
243
|
-
const oldLine = diffFile.getSplitLeftLine(index);
|
|
244
|
-
const newLine = diffFile.getSplitRightLine(index);
|
|
245
|
-
const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
|
|
246
|
-
const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
|
|
247
|
-
const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
248
|
-
useSyncHeight({
|
|
249
|
-
selector: `tr[data-line="${lineNumber}-extend"]`,
|
|
250
|
-
side: SplitSide[side],
|
|
251
|
-
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
252
|
-
});
|
|
253
|
-
const width = useDomWidth({
|
|
254
|
-
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
255
|
-
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
256
|
-
});
|
|
257
|
-
if (!renderExtendLine)
|
|
258
|
-
return null;
|
|
259
|
-
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
260
|
-
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
261
|
-
(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) &&
|
|
262
|
-
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
263
|
-
diffFile,
|
|
264
|
-
side,
|
|
265
|
-
lineNumber: currentLineNumber,
|
|
266
|
-
data: currentExtend.data,
|
|
267
|
-
onUpdate: diffFile.notifyAll,
|
|
268
|
-
}))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
269
|
-
React.createElement("span", null, "\u2002")))));
|
|
270
|
-
};
|
|
271
|
-
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
272
|
-
const { useDiffContext } = useDiffViewContext();
|
|
273
|
-
const oldLine = diffFile.getSplitLeftLine(index);
|
|
274
|
-
const newLine = diffFile.getSplitRightLine(index);
|
|
275
|
-
const { oldLineExtend, newLineExtend } = useDiffContext(React.useCallback((s) => {
|
|
276
|
-
var _a, _b, _c, _d;
|
|
277
|
-
return ({
|
|
278
|
-
oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
|
|
279
|
-
newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
|
|
280
|
-
});
|
|
281
|
-
}, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
282
|
-
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
283
|
-
// if the expand action not enabled, the `isHidden` property will never change
|
|
284
|
-
const enableExpand = diffFile.getExpandEnabled();
|
|
285
|
-
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
286
|
-
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
287
|
-
if (!currentIsShow)
|
|
288
|
-
return null;
|
|
289
|
-
return (React.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const ExpandDown = ({ className }) => {
|
|
293
|
-
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
294
|
-
React.createElement("path", { d: "m8.177 14.323 2.896-2.896a.25.25 0 0 0-.177-.427H8.75V7.764a.75.75 0 1 0-1.5 0V11H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0ZM2.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75ZM8.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
295
|
-
};
|
|
296
|
-
const ExpandUp = ({ className }) => {
|
|
297
|
-
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
298
|
-
React.createElement("path", { d: "M7.823 1.677 4.927 4.573A.25.25 0 0 0 5.104 5H7.25v3.236a.75.75 0 1 0 1.5 0V5h2.146a.25.25 0 0 0 .177-.427L8.177 1.677a.25.25 0 0 0-.354 0ZM13.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Zm-3.75.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM7.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5ZM4 11.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM1.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Z" })));
|
|
299
|
-
};
|
|
300
|
-
const ExpandAll = ({ className }) => {
|
|
301
|
-
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
302
|
-
React.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
303
|
-
};
|
|
304
|
-
|
|
305
157
|
const removeAllSelection = () => {
|
|
306
158
|
const selection = window.getSelection();
|
|
307
159
|
for (let i = 0; i < selection.rangeCount; i++) {
|
|
@@ -445,105 +297,6 @@ const createDiffSplitConfigStore = () => {
|
|
|
445
297
|
const diffAsideWidthName = "--diff-aside-width--";
|
|
446
298
|
const diffFontSizeName = "--diff-font-size--";
|
|
447
299
|
|
|
448
|
-
const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
449
|
-
var _a;
|
|
450
|
-
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
451
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
452
|
-
useSyncHeight({
|
|
453
|
-
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
454
|
-
side: SplitSide[SplitSide.old],
|
|
455
|
-
enable: side === SplitSide.new,
|
|
456
|
-
});
|
|
457
|
-
const enableHunkAction = side === SplitSide.old;
|
|
458
|
-
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
459
|
-
const isExpandAll = currentHunk &&
|
|
460
|
-
currentHunk.splitInfo &&
|
|
461
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
462
|
-
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
463
|
-
const isLastLine = currentHunk && currentHunk.isLast;
|
|
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,
|
|
465
|
-
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
466
|
-
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
467
|
-
color: `var(${plainLineNumberColorName})`,
|
|
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: () => {
|
|
473
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
474
|
-
} },
|
|
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) },
|
|
476
|
-
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
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) },
|
|
478
|
-
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
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) },
|
|
480
|
-
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
481
|
-
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
482
|
-
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
483
|
-
color: `var(${hunkContentColorName})`,
|
|
484
|
-
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
485
|
-
React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
486
|
-
};
|
|
487
|
-
const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
488
|
-
var _a;
|
|
489
|
-
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
490
|
-
const expandEnabled = diffFile.getExpandEnabled();
|
|
491
|
-
useSyncHeight({
|
|
492
|
-
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
493
|
-
side: SplitSide[side],
|
|
494
|
-
enable: true,
|
|
495
|
-
});
|
|
496
|
-
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
497
|
-
const isExpandAll = currentHunk &&
|
|
498
|
-
currentHunk.splitInfo &&
|
|
499
|
-
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
500
|
-
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
501
|
-
const isLastLine = currentHunk && currentHunk.isLast;
|
|
502
|
-
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
503
|
-
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
504
|
-
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
505
|
-
color: `var(${plainLineNumberColorName})`,
|
|
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: () => {
|
|
511
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
512
|
-
} },
|
|
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) },
|
|
514
|
-
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
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) },
|
|
516
|
-
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
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) },
|
|
518
|
-
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
519
|
-
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
520
|
-
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
521
|
-
color: `var(${hunkContentColorName})`,
|
|
522
|
-
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
523
|
-
};
|
|
524
|
-
const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
|
|
525
|
-
const { useDiffContext } = useDiffViewContext();
|
|
526
|
-
const diffViewMode = useDiffContext(React.useCallback((s) => s.mode, []));
|
|
527
|
-
if (diffViewMode === DiffModeEnum.SplitGitHub ||
|
|
528
|
-
diffViewMode === DiffModeEnum.Split ||
|
|
529
|
-
diffViewMode === DiffModeEnum.Unified) {
|
|
530
|
-
return React.createElement(_DiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
return React.createElement(_DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
537
|
-
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
538
|
-
const currentIsShow = currentHunk &&
|
|
539
|
-
currentHunk.splitInfo &&
|
|
540
|
-
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
541
|
-
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
542
|
-
if (!currentIsShow && !currentIsPureHunk)
|
|
543
|
-
return null;
|
|
544
|
-
return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
545
|
-
};
|
|
546
|
-
|
|
547
300
|
const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
|
|
548
301
|
return (React.createElement("div", { className: "diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
|
|
549
302
|
(className ? " " + className : ""), style: {
|
|
@@ -720,11 +473,11 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
720
473
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
|
|
721
474
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
|
|
722
475
|
const { useDiffContext } = useDiffViewContext();
|
|
723
|
-
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext
|
|
476
|
+
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
|
|
724
477
|
enableHighlight: s.enableHighlight,
|
|
725
478
|
enableAddWidget: s.enableAddWidget,
|
|
726
479
|
onAddWidgetClick: s.onAddWidgetClick,
|
|
727
|
-
})
|
|
480
|
+
}));
|
|
728
481
|
const { useWidget } = useDiffWidgetContext();
|
|
729
482
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
730
483
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
@@ -744,7 +497,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
744
497
|
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 },
|
|
745
498
|
React.createElement("span", null, "\u2002")))));
|
|
746
499
|
};
|
|
747
|
-
const
|
|
500
|
+
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
748
501
|
const getCurrentLine = side === SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
749
502
|
const currentLine = getCurrentLine(index);
|
|
750
503
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
@@ -752,11 +505,264 @@ const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
752
505
|
return React.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
753
506
|
};
|
|
754
507
|
|
|
508
|
+
const useDomWidth = ({ selector, enable }) => {
|
|
509
|
+
const [width, setWidth] = useState(0);
|
|
510
|
+
const { useDiffContext } = useDiffViewContext();
|
|
511
|
+
const id = useDiffContext(useCallback((s) => s.id, []));
|
|
512
|
+
useEffect(() => {
|
|
513
|
+
if (enable) {
|
|
514
|
+
const container = document.querySelector(`#diff-root${id}`);
|
|
515
|
+
const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
|
|
516
|
+
if (!wrapper)
|
|
517
|
+
return;
|
|
518
|
+
const typedWrapper = wrapper;
|
|
519
|
+
const cb = () => {
|
|
520
|
+
var _a;
|
|
521
|
+
const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
|
|
522
|
+
setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
|
|
523
|
+
};
|
|
524
|
+
cb();
|
|
525
|
+
const cleanCb = () => {
|
|
526
|
+
var _a;
|
|
527
|
+
typedWrapper.__observeCallback.delete(cb);
|
|
528
|
+
if (typedWrapper.__observeCallback.size === 0) {
|
|
529
|
+
(_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
530
|
+
typedWrapper.removeAttribute("data-observe");
|
|
531
|
+
delete typedWrapper.__observeCallback;
|
|
532
|
+
delete typedWrapper.__observeInstance;
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
if (typedWrapper.__observeCallback) {
|
|
536
|
+
typedWrapper.__observeCallback.add(cb);
|
|
537
|
+
return () => cleanCb();
|
|
538
|
+
}
|
|
539
|
+
typedWrapper.__observeCallback = new Set();
|
|
540
|
+
typedWrapper.__observeCallback.add(cb);
|
|
541
|
+
const observer = new ResizeObserver(() => typedWrapper.__observeCallback.forEach((cb) => cb()));
|
|
542
|
+
typedWrapper.__observeInstance = observer;
|
|
543
|
+
observer.observe(typedWrapper);
|
|
544
|
+
typedWrapper.setAttribute("data-observe", "height");
|
|
545
|
+
return () => cleanCb();
|
|
546
|
+
}
|
|
547
|
+
}, [selector, enable, id]);
|
|
548
|
+
return width;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// TODO
|
|
552
|
+
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
553
|
+
const { useDiffContext } = useDiffViewContext();
|
|
554
|
+
const id = useDiffContext(useCallback((s) => s.id, []));
|
|
555
|
+
useSafeLayout(() => {
|
|
556
|
+
if (enable) {
|
|
557
|
+
const container = document.querySelector(`#diff-root${id}`);
|
|
558
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
559
|
+
const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
|
|
560
|
+
if (elements.length === 2 && wrappers.length === 2) {
|
|
561
|
+
const ele1 = elements[0];
|
|
562
|
+
const ele2 = elements[1];
|
|
563
|
+
const wrapper1 = wrappers[0];
|
|
564
|
+
const wrapper2 = wrappers[1];
|
|
565
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
566
|
+
const cb = () => {
|
|
567
|
+
ele1.style.height = "auto";
|
|
568
|
+
ele2.style.height = "auto";
|
|
569
|
+
const rect1 = ele1.getBoundingClientRect();
|
|
570
|
+
const rect2 = ele2.getBoundingClientRect();
|
|
571
|
+
if (rect1.height !== rect2.height) {
|
|
572
|
+
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
573
|
+
wrapper1.style.height = maxHeight + "px";
|
|
574
|
+
wrapper2.style.height = maxHeight + "px";
|
|
575
|
+
wrapper1.setAttribute("data-sync-height", String(maxHeight));
|
|
576
|
+
wrapper2.setAttribute("data-sync-height", String(maxHeight));
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
wrapper1.removeAttribute("data-sync-height");
|
|
580
|
+
wrapper2.removeAttribute("data-sync-height");
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
cb();
|
|
584
|
+
const observer = new ResizeObserver(cb);
|
|
585
|
+
observer.observe(target);
|
|
586
|
+
target.setAttribute("data-observe", "height");
|
|
587
|
+
return () => {
|
|
588
|
+
observer.disconnect();
|
|
589
|
+
target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}, [selector, enable, side, id, wrapper]);
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
597
|
+
const { useDiffContext } = useDiffViewContext();
|
|
598
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
599
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
600
|
+
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
601
|
+
const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
|
|
602
|
+
const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
603
|
+
useSyncHeight({
|
|
604
|
+
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
605
|
+
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
606
|
+
side: SplitSide[side],
|
|
607
|
+
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
608
|
+
});
|
|
609
|
+
const width = useDomWidth({
|
|
610
|
+
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
611
|
+
enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
|
|
612
|
+
});
|
|
613
|
+
if (!renderExtendLine)
|
|
614
|
+
return null;
|
|
615
|
+
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
616
|
+
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side], className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
617
|
+
(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) &&
|
|
618
|
+
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
619
|
+
diffFile,
|
|
620
|
+
side,
|
|
621
|
+
lineNumber: currentLineNumber,
|
|
622
|
+
data: currentExtend.data,
|
|
623
|
+
onUpdate: diffFile.notifyAll,
|
|
624
|
+
}))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
625
|
+
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] }, "\u2002")))));
|
|
626
|
+
};
|
|
627
|
+
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
628
|
+
const { useDiffContext } = useDiffViewContext();
|
|
629
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
630
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
631
|
+
const { oldLineExtend, newLineExtend } = useDiffContext(React.useCallback((s) => {
|
|
632
|
+
var _a, _b, _c, _d;
|
|
633
|
+
return ({
|
|
634
|
+
oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
|
|
635
|
+
newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
|
|
636
|
+
});
|
|
637
|
+
}, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
|
|
638
|
+
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
639
|
+
// if the expand action not enabled, the `isHidden` property will never change
|
|
640
|
+
const enableExpand = diffFile.getExpandEnabled();
|
|
641
|
+
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
642
|
+
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
643
|
+
if (!currentIsShow)
|
|
644
|
+
return null;
|
|
645
|
+
return (React.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
const ExpandDown = ({ className }) => {
|
|
649
|
+
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
650
|
+
React.createElement("path", { d: "m8.177 14.323 2.896-2.896a.25.25 0 0 0-.177-.427H8.75V7.764a.75.75 0 1 0-1.5 0V11H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0ZM2.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75ZM8.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
651
|
+
};
|
|
652
|
+
const ExpandUp = ({ className }) => {
|
|
653
|
+
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
654
|
+
React.createElement("path", { d: "M7.823 1.677 4.927 4.573A.25.25 0 0 0 5.104 5H7.25v3.236a.75.75 0 1 0 1.5 0V5h2.146a.25.25 0 0 0 .177-.427L8.177 1.677a.25.25 0 0 0-.354 0ZM13.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Zm-3.75.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM7.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5ZM4 11.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM1.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Z" })));
|
|
655
|
+
};
|
|
656
|
+
const ExpandAll = ({ className }) => {
|
|
657
|
+
return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
|
|
658
|
+
React.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
662
|
+
var _a;
|
|
663
|
+
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
664
|
+
const expandEnabled = diffFile.getExpandEnabled();
|
|
665
|
+
useSyncHeight({
|
|
666
|
+
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
667
|
+
side: SplitSide[SplitSide.old],
|
|
668
|
+
enable: side === SplitSide.new,
|
|
669
|
+
});
|
|
670
|
+
const enableHunkAction = side === SplitSide.old;
|
|
671
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
672
|
+
const isExpandAll = currentHunk &&
|
|
673
|
+
currentHunk.splitInfo &&
|
|
674
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
675
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
676
|
+
const isLastLine = currentHunk && currentHunk.isLast;
|
|
677
|
+
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,
|
|
678
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
679
|
+
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
680
|
+
color: `var(${plainLineNumberColorName})`,
|
|
681
|
+
width: `var(${diffAsideWidthName})`,
|
|
682
|
+
minWidth: `var(${diffAsideWidthName})`,
|
|
683
|
+
maxWidth: `var(${diffAsideWidthName})`,
|
|
684
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
685
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
686
|
+
diffFile.onSplitHunkExpand("down", index);
|
|
687
|
+
} },
|
|
688
|
+
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
689
|
+
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
690
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
691
|
+
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
692
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
693
|
+
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
694
|
+
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
695
|
+
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
696
|
+
color: `var(${hunkContentColorName})`,
|
|
697
|
+
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
698
|
+
React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
699
|
+
};
|
|
700
|
+
const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
701
|
+
var _a;
|
|
702
|
+
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
703
|
+
const expandEnabled = diffFile.getExpandEnabled();
|
|
704
|
+
useSyncHeight({
|
|
705
|
+
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
706
|
+
side: SplitSide[side],
|
|
707
|
+
enable: true,
|
|
708
|
+
});
|
|
709
|
+
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
710
|
+
const isExpandAll = currentHunk &&
|
|
711
|
+
currentHunk.splitInfo &&
|
|
712
|
+
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
713
|
+
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
714
|
+
const isLastLine = currentHunk && currentHunk.isLast;
|
|
715
|
+
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
716
|
+
React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
717
|
+
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
718
|
+
color: `var(${plainLineNumberColorName})`,
|
|
719
|
+
width: `var(${diffAsideWidthName})`,
|
|
720
|
+
minWidth: `var(${diffAsideWidthName})`,
|
|
721
|
+
maxWidth: `var(${diffAsideWidthName})`,
|
|
722
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
723
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
|
|
724
|
+
diffFile.onSplitHunkExpand("down", index);
|
|
725
|
+
} },
|
|
726
|
+
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
727
|
+
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
728
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
729
|
+
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
730
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
731
|
+
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
732
|
+
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
733
|
+
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
734
|
+
color: `var(${hunkContentColorName})`,
|
|
735
|
+
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
736
|
+
};
|
|
737
|
+
const _DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
738
|
+
const { useDiffContext } = useDiffViewContext();
|
|
739
|
+
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
740
|
+
if (diffViewMode === DiffModeEnum.SplitGitHub ||
|
|
741
|
+
diffViewMode === DiffModeEnum.Split ||
|
|
742
|
+
diffViewMode === DiffModeEnum.Unified) {
|
|
743
|
+
return React.createElement(_DiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
return React.createElement(_DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
750
|
+
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
751
|
+
const currentIsShow = currentHunk &&
|
|
752
|
+
currentHunk.splitInfo &&
|
|
753
|
+
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
754
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
755
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
756
|
+
return null;
|
|
757
|
+
return React.createElement(_DiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
758
|
+
};
|
|
759
|
+
|
|
755
760
|
const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWidget, currentWidget, }) => {
|
|
756
761
|
const { useDiffContext } = useDiffViewContext();
|
|
757
|
-
const renderWidgetLine = useDiffContext
|
|
762
|
+
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
758
763
|
useSyncHeight({
|
|
759
|
-
selector: `
|
|
764
|
+
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
765
|
+
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
760
766
|
side: SplitSide[side],
|
|
761
767
|
enable: currentWidget && typeof renderWidgetLine === "function",
|
|
762
768
|
});
|
|
@@ -767,18 +773,22 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
|
|
|
767
773
|
if (!renderWidgetLine)
|
|
768
774
|
return null;
|
|
769
775
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" }, currentWidget ? (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
770
|
-
React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
776
|
+
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side], className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
|
|
771
777
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
772
778
|
diffFile,
|
|
773
779
|
side,
|
|
774
780
|
lineNumber: currentLine.lineNumber,
|
|
775
781
|
onClose: () => setWidget({}),
|
|
776
782
|
}))))) : (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
777
|
-
React.createElement("
|
|
783
|
+
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] }, "\u2002")))));
|
|
778
784
|
};
|
|
779
785
|
const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
780
786
|
const { useWidget } = useDiffWidgetContext();
|
|
781
|
-
const { widgetLineNumber, widgetSide, setWidget } = useWidget
|
|
787
|
+
const { widgetLineNumber, widgetSide, setWidget } = useWidget.useShallowStableSelector((s) => ({
|
|
788
|
+
widgetLineNumber: s.widgetLineNumber,
|
|
789
|
+
widgetSide: s.widgetSide,
|
|
790
|
+
setWidget: s.setWidget,
|
|
791
|
+
}));
|
|
782
792
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
783
793
|
const newLine = diffFile.getSplitRightLine(index);
|
|
784
794
|
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
@@ -803,7 +813,7 @@ const onMouseDown$1 = (e) => {
|
|
|
803
813
|
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
804
814
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
805
815
|
const lines = getSplitContentLines(diffFile);
|
|
806
|
-
return (React.createElement("table", { className: className + " w-full border-collapse", "data-mode": SplitSide[side] },
|
|
816
|
+
return (React.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": SplitSide[side] },
|
|
807
817
|
React.createElement("colgroup", null,
|
|
808
818
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-num-col` }),
|
|
809
819
|
React.createElement("col", { className: `diff-table-${SplitSide[side]}-content-col` })),
|
|
@@ -818,7 +828,7 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
818
828
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown$1 },
|
|
819
829
|
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
820
830
|
React.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
821
|
-
React.createElement(
|
|
831
|
+
React.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
822
832
|
React.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
823
833
|
React.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
824
834
|
React.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -828,7 +838,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
828
838
|
const ref2 = useRef(null);
|
|
829
839
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
830
840
|
const { useDiffContext } = useDiffViewContext();
|
|
831
|
-
const fontSize = useDiffContext(
|
|
841
|
+
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
832
842
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
833
843
|
useEffect(() => {
|
|
834
844
|
const left = ref1.current;
|
|
@@ -843,8 +853,8 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
843
853
|
font,
|
|
844
854
|
});
|
|
845
855
|
const width = Math.max(40, _width + 25);
|
|
846
|
-
return (React.createElement("div", { className: "split-diff-view split-diff-view-
|
|
847
|
-
React.createElement("div", { className: "old-diff-table-wrapper
|
|
856
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
|
|
857
|
+
React.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
848
858
|
// @ts-ignore
|
|
849
859
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
850
860
|
overscrollBehaviorX: "none",
|
|
@@ -852,8 +862,8 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
852
862
|
fontSize: `var(${diffFontSizeName})`,
|
|
853
863
|
} },
|
|
854
864
|
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
855
|
-
React.createElement("div", { className: "diff-split-line w-[1.5px]
|
|
856
|
-
React.createElement("div", { className: "new-diff-table-wrapper
|
|
865
|
+
React.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
866
|
+
React.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
857
867
|
// @ts-ignore
|
|
858
868
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
859
869
|
overscrollBehaviorX: "none",
|
|
@@ -864,12 +874,66 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
864
874
|
});
|
|
865
875
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
866
876
|
|
|
877
|
+
const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
878
|
+
var _a, _b;
|
|
879
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
880
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
881
|
+
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
882
|
+
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
883
|
+
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
884
|
+
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
885
|
+
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
|
|
886
|
+
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
|
|
887
|
+
const { useDiffContext } = useDiffViewContext();
|
|
888
|
+
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
|
|
889
|
+
enableHighlight: s.enableHighlight,
|
|
890
|
+
enableAddWidget: s.enableAddWidget,
|
|
891
|
+
onAddWidgetClick: s.onAddWidgetClick,
|
|
892
|
+
}));
|
|
893
|
+
const { useWidget } = useDiffWidgetContext();
|
|
894
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
895
|
+
const hasOldLine = !!oldLine.lineNumber;
|
|
896
|
+
const hasNewLine = !!newLine.lineNumber;
|
|
897
|
+
const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
|
|
898
|
+
const oldLineNumberBG = getLineNumberBG(false, oldLineIsDelete, hasDiff);
|
|
899
|
+
const newLineContentBG = getContentBG(newLineIsAdded, false, hasDiff);
|
|
900
|
+
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
901
|
+
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
902
|
+
hasOldLine ? (React.createElement(React.Fragment, null,
|
|
903
|
+
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})` } },
|
|
904
|
+
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 }) })),
|
|
905
|
+
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
906
|
+
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
907
|
+
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 }) })),
|
|
908
|
+
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 },
|
|
909
|
+
React.createElement("span", null, "\u2002"))),
|
|
910
|
+
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
911
|
+
React.createElement("td", { className: "diff-line-new-num group relative w-[1%] min-w-[40px] select-none border-l-[1px] pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.new], style: {
|
|
912
|
+
backgroundColor: newLineNumberBG,
|
|
913
|
+
color: `var(${plainLineNumberColorName})`,
|
|
914
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
915
|
+
} },
|
|
916
|
+
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 }) })),
|
|
917
|
+
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
918
|
+
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
919
|
+
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 }) })),
|
|
920
|
+
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]", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
|
|
921
|
+
React.createElement("span", null, "\u2002")))));
|
|
922
|
+
};
|
|
923
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
924
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
925
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
926
|
+
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
927
|
+
return null;
|
|
928
|
+
return React.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
929
|
+
};
|
|
930
|
+
|
|
867
931
|
const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
868
932
|
const { useDiffContext } = useDiffViewContext();
|
|
869
933
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
870
934
|
const newLine = diffFile.getSplitRightLine(index);
|
|
871
935
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
872
|
-
const renderExtendLine = useDiffContext
|
|
936
|
+
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
873
937
|
if (!renderExtendLine)
|
|
874
938
|
return null;
|
|
875
939
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
@@ -883,7 +947,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
883
947
|
onUpdate: diffFile.notifyAll,
|
|
884
948
|
}))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
885
949
|
React.createElement("span", null, "\u2002"))),
|
|
886
|
-
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px]
|
|
950
|
+
newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
|
|
887
951
|
React.createElement("div", { className: "diff-line-extend-wrapper" }, (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
888
952
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
889
953
|
diffFile,
|
|
@@ -891,7 +955,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
891
955
|
lineNumber: newLine.lineNumber,
|
|
892
956
|
data: newLineExtend.data,
|
|
893
957
|
onUpdate: diffFile.notifyAll,
|
|
894
|
-
}))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px]
|
|
958
|
+
}))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
|
|
895
959
|
React.createElement("span", null, "\u2002")))));
|
|
896
960
|
};
|
|
897
961
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -922,25 +986,19 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
|
922
986
|
const isExpandAll = currentHunk &&
|
|
923
987
|
currentHunk.splitInfo &&
|
|
924
988
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
925
|
-
const currentIsShow = currentHunk &&
|
|
926
|
-
currentHunk.splitInfo &&
|
|
927
|
-
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
928
|
-
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
929
989
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
930
990
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
931
|
-
if (!currentIsShow && !currentIsPureHunk)
|
|
932
|
-
return null;
|
|
933
991
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
934
992
|
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
935
993
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
936
994
|
color: `var(${plainLineNumberColorName})`,
|
|
937
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]
|
|
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]
|
|
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]
|
|
995
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
996
|
+
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]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
997
|
+
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
940
998
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
941
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
999
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
942
1000
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
943
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1001
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
944
1002
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
945
1003
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
|
|
946
1004
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
@@ -955,49 +1013,44 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
955
1013
|
const isExpandAll = currentHunk &&
|
|
956
1014
|
currentHunk.splitInfo &&
|
|
957
1015
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
|
|
958
|
-
const currentIsShow = currentHunk &&
|
|
959
|
-
currentHunk.splitInfo &&
|
|
960
|
-
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
961
|
-
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
962
1016
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
963
1017
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
964
|
-
if (!currentIsShow && !currentIsPureHunk)
|
|
965
|
-
return null;
|
|
966
1018
|
return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
|
|
967
1019
|
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
968
1020
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
969
1021
|
color: `var(${plainLineNumberColorName})`,
|
|
970
|
-
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]
|
|
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]
|
|
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]
|
|
1022
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
1023
|
+
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]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
1024
|
+
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
973
1025
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
974
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1026
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
975
1027
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
976
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1028
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
977
1029
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
978
1030
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
979
1031
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
980
1032
|
color: `var(${hunkContentColorName})`,
|
|
981
1033
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
|
|
982
|
-
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px]
|
|
1034
|
+
React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
|
|
983
1035
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
984
1036
|
color: `var(${plainLineNumberColorName})`,
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
React.createElement(
|
|
1037
|
+
borderLeftColor: `var(${borderColorName})`,
|
|
1038
|
+
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
1039
|
+
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]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
1040
|
+
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
988
1041
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
989
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1042
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
990
1043
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
991
|
-
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]
|
|
1044
|
+
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
992
1045
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
993
1046
|
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
994
1047
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
995
1048
|
color: `var(${hunkContentColorName})`,
|
|
996
1049
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
997
1050
|
};
|
|
998
|
-
const
|
|
1051
|
+
const _DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
999
1052
|
const { useDiffContext } = useDiffViewContext();
|
|
1000
|
-
const diffViewMode = useDiffContext
|
|
1053
|
+
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
1001
1054
|
if (diffViewMode === DiffModeEnum.SplitGitHub ||
|
|
1002
1055
|
diffViewMode === DiffModeEnum.Split ||
|
|
1003
1056
|
diffViewMode === DiffModeEnum.Unified) {
|
|
@@ -1007,62 +1060,22 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1007
1060
|
return React.createElement(DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1008
1061
|
}
|
|
1009
1062
|
};
|
|
1010
|
-
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
1018
|
-
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
1019
|
-
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
|
|
1020
|
-
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
|
|
1021
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1022
|
-
const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React.useCallback((s) => ({
|
|
1023
|
-
enableHighlight: s.enableHighlight,
|
|
1024
|
-
enableAddWidget: s.enableAddWidget,
|
|
1025
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1026
|
-
}), []));
|
|
1027
|
-
const { useWidget } = useDiffWidgetContext();
|
|
1028
|
-
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1029
|
-
const hasOldLine = !!oldLine.lineNumber;
|
|
1030
|
-
const hasNewLine = !!newLine.lineNumber;
|
|
1031
|
-
const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
|
|
1032
|
-
const oldLineNumberBG = getLineNumberBG(false, oldLineIsDelete, hasDiff);
|
|
1033
|
-
const newLineContentBG = getContentBG(newLineIsAdded, false, hasDiff);
|
|
1034
|
-
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
1035
|
-
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
1036
|
-
hasOldLine ? (React.createElement(React.Fragment, null,
|
|
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 }) })),
|
|
1039
|
-
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
1040
|
-
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
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 }) })),
|
|
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 },
|
|
1043
|
-
React.createElement("span", null, "\u2002"))),
|
|
1044
|
-
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
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 }) })),
|
|
1047
|
-
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
1048
|
-
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
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 }) })),
|
|
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 },
|
|
1051
|
-
React.createElement("span", null, "\u2002")))));
|
|
1052
|
-
};
|
|
1053
|
-
const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
1054
|
-
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1055
|
-
const newLine = diffFile.getSplitRightLine(index);
|
|
1056
|
-
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
1063
|
+
const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1064
|
+
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
1065
|
+
const currentIsShow = currentHunk &&
|
|
1066
|
+
currentHunk.splitInfo &&
|
|
1067
|
+
currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
|
|
1068
|
+
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
1069
|
+
if (!currentIsShow && !currentIsPureHunk)
|
|
1057
1070
|
return null;
|
|
1058
|
-
return React.createElement(
|
|
1071
|
+
return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1059
1072
|
};
|
|
1060
1073
|
|
|
1061
1074
|
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newLineWidget, }) => {
|
|
1062
1075
|
const { useWidget } = useDiffWidgetContext();
|
|
1063
1076
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1064
1077
|
const { useDiffContext } = useDiffViewContext();
|
|
1065
|
-
const renderWidgetLine = useDiffContext
|
|
1078
|
+
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1066
1079
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1067
1080
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1068
1081
|
if (!renderWidgetLine)
|
|
@@ -1076,18 +1089,21 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
|
|
|
1076
1089
|
onClose: () => setWidget({}),
|
|
1077
1090
|
})))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
1078
1091
|
React.createElement("span", null, "\u2002"))),
|
|
1079
|
-
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px]
|
|
1092
|
+
newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})` } },
|
|
1080
1093
|
React.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
1081
1094
|
diffFile,
|
|
1082
1095
|
side: SplitSide.new,
|
|
1083
1096
|
lineNumber: newLine.lineNumber,
|
|
1084
1097
|
onClose: () => setWidget({}),
|
|
1085
|
-
})))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px]
|
|
1098
|
+
})))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
|
|
1086
1099
|
React.createElement("span", null, "\u2002")))));
|
|
1087
1100
|
};
|
|
1088
1101
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1089
1102
|
const { useWidget } = useDiffWidgetContext();
|
|
1090
|
-
const { widgetLineNumber, widgetSide } = useWidget(
|
|
1103
|
+
const { widgetLineNumber, widgetSide } = useWidget((s) => ({
|
|
1104
|
+
widgetLineNumber: s.widgetLineNumber,
|
|
1105
|
+
widgetSide: s.widgetSide,
|
|
1106
|
+
}));
|
|
1091
1107
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1092
1108
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1093
1109
|
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
@@ -1111,7 +1127,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1111
1127
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1112
1128
|
const { useDiffContext } = useDiffViewContext();
|
|
1113
1129
|
const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
|
|
1114
|
-
const fontSize = useDiffContext(
|
|
1130
|
+
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
1115
1131
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
1116
1132
|
const onMouseDown = useCallback((e) => {
|
|
1117
1133
|
let ele = e.target;
|
|
@@ -1140,7 +1156,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1140
1156
|
});
|
|
1141
1157
|
const width = Math.max(40, _width + 25);
|
|
1142
1158
|
const lines = getSplitContentLines(diffFile);
|
|
1143
|
-
return (React.createElement("div", { className: "split-diff-view split-diff-view-
|
|
1159
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1144
1160
|
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1145
1161
|
// @ts-ignore
|
|
1146
1162
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1148,7 +1164,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1148
1164
|
fontSize: `var(${diffFontSizeName})`,
|
|
1149
1165
|
} },
|
|
1150
1166
|
React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1151
|
-
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse" },
|
|
1167
|
+
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1152
1168
|
React.createElement("colgroup", null,
|
|
1153
1169
|
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1154
1170
|
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
@@ -1163,7 +1179,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
|
1163
1179
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1164
1180
|
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
1165
1181
|
React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1166
|
-
React.createElement(
|
|
1182
|
+
React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1167
1183
|
React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1168
1184
|
React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1169
1185
|
React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
@@ -1174,7 +1190,7 @@ const DiffSplitView = memo(({ diffFile }) => {
|
|
|
1174
1190
|
const { useDiffContext } = useDiffViewContext();
|
|
1175
1191
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1176
1192
|
useDiffContextRef.current = useDiffContext;
|
|
1177
|
-
const enableWrap = useDiffContext(
|
|
1193
|
+
const enableWrap = useDiffContext.useShallowStableSelector((s) => s.enableWrap);
|
|
1178
1194
|
// performance optimization
|
|
1179
1195
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1180
1196
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1186,9 +1202,101 @@ const DiffSplitView = memo(({ diffFile }) => {
|
|
|
1186
1202
|
});
|
|
1187
1203
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1188
1204
|
|
|
1205
|
+
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1206
|
+
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1207
|
+
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: {
|
|
1208
|
+
color: `var(${plainLineNumberColorName})`,
|
|
1209
|
+
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1210
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1211
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1212
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1213
|
+
} },
|
|
1214
|
+
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1215
|
+
React.createElement("div", { className: "flex" },
|
|
1216
|
+
React.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
|
|
1217
|
+
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1218
|
+
React.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1219
|
+
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1220
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1221
|
+
};
|
|
1222
|
+
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1223
|
+
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1224
|
+
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: {
|
|
1225
|
+
color: `var(${plainLineNumberColorName})`,
|
|
1226
|
+
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1227
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1228
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1229
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1230
|
+
} },
|
|
1231
|
+
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1232
|
+
React.createElement("div", { className: "flex" },
|
|
1233
|
+
React.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1234
|
+
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1235
|
+
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1236
|
+
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1237
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1238
|
+
};
|
|
1239
|
+
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
1240
|
+
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1241
|
+
const { useDiffContext } = useDiffViewContext();
|
|
1242
|
+
const { enableWrap, enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1243
|
+
enableWrap: s.enableWrap,
|
|
1244
|
+
enableHighlight: s.enableHighlight,
|
|
1245
|
+
enableAddWidget: s.enableAddWidget,
|
|
1246
|
+
onAddWidgetClick: s.onAddWidgetClick,
|
|
1247
|
+
}));
|
|
1248
|
+
const { useWidget } = useDiffWidgetContext();
|
|
1249
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1250
|
+
const hasDiff = unifiedLine.diff;
|
|
1251
|
+
const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
|
|
1252
|
+
const rawLine = unifiedLine.value || "";
|
|
1253
|
+
const diffLine = unifiedLine.diff;
|
|
1254
|
+
const newLineNumber = unifiedLine.newLineNumber;
|
|
1255
|
+
const oldLinenumber = unifiedLine.oldLineNumber;
|
|
1256
|
+
const syntaxLine = newLineNumber
|
|
1257
|
+
? diffFile.getNewSyntaxLine(newLineNumber)
|
|
1258
|
+
: oldLinenumber
|
|
1259
|
+
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1260
|
+
: undefined;
|
|
1261
|
+
if (hasChange) {
|
|
1262
|
+
if (unifiedLine.oldLineNumber) {
|
|
1263
|
+
return (React.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.oldLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
return (React.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.newLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
else {
|
|
1270
|
+
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1271
|
+
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: {
|
|
1272
|
+
color: `var(${plainLineNumberColorName})`,
|
|
1273
|
+
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1274
|
+
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1275
|
+
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1276
|
+
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1277
|
+
} },
|
|
1278
|
+
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 }) })),
|
|
1279
|
+
React.createElement("div", { className: "flex opacity-[0.5]" },
|
|
1280
|
+
React.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
1281
|
+
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1282
|
+
React.createElement("span", { "data-line-new-num": unifiedLine.newLineNumber, className: "inline-block w-[50%]" }, unifiedLine.newLineNumber))),
|
|
1283
|
+
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1284
|
+
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1285
|
+
} },
|
|
1286
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1290
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1291
|
+
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1292
|
+
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1293
|
+
return null;
|
|
1294
|
+
return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1189
1297
|
const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
1190
1298
|
const { useDiffContext } = useDiffViewContext();
|
|
1191
|
-
const renderExtendLine = useDiffContext(
|
|
1299
|
+
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
1192
1300
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1193
1301
|
const width = useDomWidth({
|
|
1194
1302
|
selector: ".unified-diff-table-wrapper",
|
|
@@ -1239,7 +1347,7 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1239
1347
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
1240
1348
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
1241
1349
|
const { useDiffContext } = useDiffViewContext();
|
|
1242
|
-
const enableWrap = useDiffContext(
|
|
1350
|
+
const enableWrap = useDiffContext.useShallowStableSelector((s) => s.enableWrap);
|
|
1243
1351
|
const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
|
|
1244
1352
|
const isExpandAll = currentHunk &&
|
|
1245
1353
|
currentHunk.unifiedInfo &&
|
|
@@ -1279,104 +1387,12 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1279
1387
|
return React.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1280
1388
|
};
|
|
1281
1389
|
|
|
1282
|
-
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1283
|
-
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
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: {
|
|
1285
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1286
|
-
backgroundColor: `var(${delLineNumberBGName})`,
|
|
1287
|
-
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1288
|
-
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1289
|
-
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1290
|
-
} },
|
|
1291
|
-
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1292
|
-
React.createElement("div", { className: "flex" },
|
|
1293
|
-
React.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
|
|
1294
|
-
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1295
|
-
React.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1296
|
-
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1297
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1298
|
-
};
|
|
1299
|
-
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1300
|
-
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
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: {
|
|
1302
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1303
|
-
backgroundColor: `var(${addLineNumberBGName})`,
|
|
1304
|
-
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1305
|
-
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1306
|
-
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1307
|
-
} },
|
|
1308
|
-
enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1309
|
-
React.createElement("div", { className: "flex" },
|
|
1310
|
-
React.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1311
|
-
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1312
|
-
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1313
|
-
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1314
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1315
|
-
};
|
|
1316
|
-
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
1317
|
-
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1318
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1319
|
-
const { enableWrap, enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React.useCallback((s) => ({
|
|
1320
|
-
enableWrap: s.enableWrap,
|
|
1321
|
-
enableHighlight: s.enableHighlight,
|
|
1322
|
-
enableAddWidget: s.enableAddWidget,
|
|
1323
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1324
|
-
}), []));
|
|
1325
|
-
const { useWidget } = useDiffWidgetContext();
|
|
1326
|
-
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1327
|
-
const hasDiff = unifiedLine.diff;
|
|
1328
|
-
const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
|
|
1329
|
-
const rawLine = unifiedLine.value || "";
|
|
1330
|
-
const diffLine = unifiedLine.diff;
|
|
1331
|
-
const newLineNumber = unifiedLine.newLineNumber;
|
|
1332
|
-
const oldLinenumber = unifiedLine.oldLineNumber;
|
|
1333
|
-
const syntaxLine = newLineNumber
|
|
1334
|
-
? diffFile.getNewSyntaxLine(newLineNumber)
|
|
1335
|
-
: oldLinenumber
|
|
1336
|
-
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1337
|
-
: undefined;
|
|
1338
|
-
if (hasChange) {
|
|
1339
|
-
if (unifiedLine.oldLineNumber) {
|
|
1340
|
-
return (React.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.oldLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1341
|
-
}
|
|
1342
|
-
else {
|
|
1343
|
-
return (React.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.newLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
else {
|
|
1347
|
-
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
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: {
|
|
1349
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1350
|
-
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1351
|
-
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1352
|
-
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1353
|
-
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1354
|
-
} },
|
|
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 }) })),
|
|
1356
|
-
React.createElement("div", { className: "flex opacity-[0.5]" },
|
|
1357
|
-
React.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
1358
|
-
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1359
|
-
React.createElement("span", { "data-line-new-num": unifiedLine.newLineNumber, className: "inline-block w-[50%]" }, unifiedLine.newLineNumber))),
|
|
1360
|
-
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1361
|
-
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1362
|
-
} },
|
|
1363
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1364
|
-
}
|
|
1365
|
-
});
|
|
1366
|
-
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1367
|
-
const DiffUnifiedLine = ({ index, diffFile, lineNumber, }) => {
|
|
1368
|
-
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1369
|
-
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1370
|
-
return null;
|
|
1371
|
-
return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1372
|
-
};
|
|
1373
|
-
|
|
1374
1390
|
const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNumber, setWidget, }) => {
|
|
1375
1391
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1376
1392
|
const onClose = () => setWidget({});
|
|
1377
1393
|
const { useDiffContext } = useDiffViewContext();
|
|
1378
1394
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1379
|
-
const renderWidgetLine = useDiffContext(
|
|
1395
|
+
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1380
1396
|
const width = useDomWidth({
|
|
1381
1397
|
selector: ".unified-diff-table-wrapper",
|
|
1382
1398
|
enable: typeof renderWidgetLine === "function",
|
|
@@ -1395,7 +1411,11 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
|
|
|
1395
1411
|
};
|
|
1396
1412
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1397
1413
|
const { useWidget } = useDiffWidgetContext();
|
|
1398
|
-
const { widgetSide, widgetLineNumber, setWidget } = useWidget
|
|
1414
|
+
const { widgetSide, widgetLineNumber, setWidget } = useWidget.useShallowStableSelector((s) => ({
|
|
1415
|
+
widgetLineNumber: s.widgetLineNumber,
|
|
1416
|
+
widgetSide: s.widgetSide,
|
|
1417
|
+
setWidget: s.setWidget,
|
|
1418
|
+
}));
|
|
1399
1419
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1400
1420
|
const oldWidget = unifiedItem.oldLineNumber && widgetSide === SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1401
1421
|
const newWidget = unifiedItem.newLineNumber && widgetSide === SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
@@ -1421,7 +1441,10 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1421
1441
|
// performance optimization
|
|
1422
1442
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1423
1443
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1424
|
-
const fontSize = useDiffContext(
|
|
1444
|
+
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1445
|
+
fontSize: s.fontSize,
|
|
1446
|
+
enableWrap: s.enableWrap,
|
|
1447
|
+
}));
|
|
1425
1448
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
|
|
1426
1449
|
useEffect(() => {
|
|
1427
1450
|
const { setWidget } = useWidget.getReadonlyState();
|
|
@@ -1435,14 +1458,14 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1435
1458
|
const width = Math.max(40, _width + 10);
|
|
1436
1459
|
const lines = getUnifiedContentLine(diffFile);
|
|
1437
1460
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1438
|
-
React.createElement("div", { className: "unified-diff-view w-full
|
|
1439
|
-
React.createElement("div", { className: "unified-diff-table-wrapper
|
|
1461
|
+
React.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
|
|
1462
|
+
React.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1440
1463
|
// @ts-ignore
|
|
1441
1464
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1442
1465
|
fontFamily: "Menlo, Consolas, monospace",
|
|
1443
1466
|
fontSize: `var(${diffFontSizeName})`,
|
|
1444
1467
|
} },
|
|
1445
|
-
React.createElement("table", { className:
|
|
1468
|
+
React.createElement("table", { className: `unified-diff-table w-full border-collapse border-spacing-0 ${enableWrap ? "table-fixed" : ""}` },
|
|
1446
1469
|
React.createElement("colgroup", null,
|
|
1447
1470
|
React.createElement("col", { className: "unified-diff-table-num-col" }),
|
|
1448
1471
|
React.createElement("col", { className: "unified-diff-table-content-col" })),
|
|
@@ -1453,7 +1476,7 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1453
1476
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1454
1477
|
lines.map((item) => (React.createElement(Fragment, { key: item.index },
|
|
1455
1478
|
React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1456
|
-
React.createElement(
|
|
1479
|
+
React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1457
1480
|
React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1458
1481
|
React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1459
1482
|
React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1469,6 +1492,7 @@ var SplitSide;
|
|
|
1469
1492
|
const _InternalDiffView = (props) => {
|
|
1470
1493
|
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1471
1494
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1495
|
+
const wrapperRef = useRef();
|
|
1472
1496
|
// performance optimization
|
|
1473
1497
|
const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1474
1498
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1498,9 +1522,16 @@ const _InternalDiffView = (props) => {
|
|
|
1498
1522
|
extendData,
|
|
1499
1523
|
onAddWidgetClick,
|
|
1500
1524
|
]);
|
|
1525
|
+
useEffect(() => {
|
|
1526
|
+
const cb = diffFile.subscribe(() => {
|
|
1527
|
+
var _a;
|
|
1528
|
+
(_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
|
|
1529
|
+
});
|
|
1530
|
+
return cb;
|
|
1531
|
+
}, [diffFile]);
|
|
1501
1532
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1502
1533
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1503
|
-
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version":
|
|
1534
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.17", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1504
1535
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1505
1536
|
// @ts-ignore
|
|
1506
1537
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1510,7 +1541,7 @@ const _InternalDiffView = (props) => {
|
|
|
1510
1541
|
const InternalDiffView = memo(_InternalDiffView);
|
|
1511
1542
|
const DiffViewWithRef = (props, ref) => {
|
|
1512
1543
|
var _a, _b;
|
|
1513
|
-
const { registerHighlighter, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffFile"]);
|
|
1544
|
+
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
|
|
1514
1545
|
const diffFile = useMemo(() => {
|
|
1515
1546
|
var _a, _b, _c, _d, _e, _f;
|
|
1516
1547
|
if (_diffFile) {
|
|
@@ -1525,16 +1556,17 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1525
1556
|
}, [data, _diffFile]);
|
|
1526
1557
|
const diffFileRef = useRef(diffFile);
|
|
1527
1558
|
if (diffFileRef.current && diffFileRef.current !== diffFile) {
|
|
1528
|
-
(_b = (_a = diffFileRef.current).
|
|
1559
|
+
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1529
1560
|
diffFileRef.current = diffFile;
|
|
1530
1561
|
}
|
|
1531
1562
|
useEffect(() => {
|
|
1532
1563
|
if (!diffFile)
|
|
1533
1564
|
return;
|
|
1565
|
+
diffFile.initTheme(diffViewTheme);
|
|
1534
1566
|
diffFile.initRaw();
|
|
1535
1567
|
diffFile.buildSplitDiffLines();
|
|
1536
1568
|
diffFile.buildUnifiedDiffLines();
|
|
1537
|
-
}, [diffFile]);
|
|
1569
|
+
}, [diffFile, diffViewTheme]);
|
|
1538
1570
|
useEffect(() => {
|
|
1539
1571
|
if (!diffFile)
|
|
1540
1572
|
return;
|
|
@@ -1542,7 +1574,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1542
1574
|
diffFile.initSyntax({ registerHighlighter });
|
|
1543
1575
|
diffFile.notifyAll();
|
|
1544
1576
|
}
|
|
1545
|
-
}, [diffFile, props.diffViewHighlight, registerHighlighter]);
|
|
1577
|
+
}, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
|
|
1546
1578
|
useEffect(() => {
|
|
1547
1579
|
if (_diffFile && diffFile) {
|
|
1548
1580
|
_diffFile._addClonedInstance(diffFile);
|
|
@@ -1551,7 +1583,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1551
1583
|
};
|
|
1552
1584
|
}
|
|
1553
1585
|
}, [diffFile, _diffFile]);
|
|
1554
|
-
useUnmount(() => { var _a; return (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile.
|
|
1586
|
+
useUnmount(() => { var _a; return (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile.clear) === null || _a === void 0 ? void 0 : _a.call(diffFile); }, [diffFile]);
|
|
1555
1587
|
useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1556
1588
|
if (!diffFile)
|
|
1557
1589
|
return null;
|
|
@@ -1559,7 +1591,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1559
1591
|
};
|
|
1560
1592
|
const DiffView = forwardRef(DiffViewWithRef);
|
|
1561
1593
|
DiffView.displayName = "DiffView";
|
|
1562
|
-
const version = "0.0.
|
|
1594
|
+
const version = "0.0.17";
|
|
1563
1595
|
|
|
1564
1596
|
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
|
|
1565
1597
|
//# sourceMappingURL=index.mjs.map
|