@git-diff-view/react 0.0.25 → 0.0.27
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 +543 -376
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +543 -376
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +5 -1
- package/dist/css/diff-view.css +6 -2
- package/dist/esm/index.mjs +485 -321
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +317 -23
- package/package.json +8 -7
- package/src/_base.css +3 -0
- package/src/_base_pure.css +2 -0
- package/src/_com.css +172 -0
- package/src/_theme.css +2 -0
- package/src/components/DiffAddWidget.tsx +86 -0
- package/src/components/DiffContent.tsx +367 -0
- package/src/components/DiffContent_v2.tsx +344 -0
- package/src/components/DiffExpand.tsx +25 -0
- package/src/components/DiffNoNewLine.tsx +10 -0
- package/src/components/DiffSplitContentLineNormal.tsx +164 -0
- package/src/components/DiffSplitContentLineWrap.tsx +234 -0
- package/src/components/DiffSplitExtendLineNormal.tsx +150 -0
- package/src/components/DiffSplitExtendLineWrap.tsx +133 -0
- package/src/components/DiffSplitHunkLineNormal.tsx +316 -0
- package/src/components/DiffSplitHunkLineWrap.tsx +340 -0
- package/src/components/DiffSplitView.tsx +46 -0
- package/src/components/DiffSplitViewNormal.tsx +205 -0
- package/src/components/DiffSplitViewWrap.tsx +141 -0
- package/src/components/DiffSplitWidgetLineNormal.tsx +149 -0
- package/src/components/DiffSplitWidgetLineWrap.tsx +127 -0
- package/src/components/DiffUnifiedContentLine.tsx +342 -0
- package/src/components/DiffUnifiedExtendLine.tsx +103 -0
- package/src/components/DiffUnifiedHunkLine.tsx +148 -0
- package/src/components/DiffUnifiedView.tsx +159 -0
- package/src/components/DiffUnifiedWidgetLine.tsx +104 -0
- package/src/components/DiffView.tsx +365 -0
- package/src/components/DiffViewContext.ts +11 -0
- package/src/components/DiffWidgetContext.ts +17 -0
- package/src/components/tools.ts +132 -0
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +152 -0
- package/src/components/v2/DiffSplitContentLineWrap_v2.tsx +259 -0
- package/src/components/v2/DiffSplitExtendLineNormal_v2.tsx +146 -0
- package/src/components/v2/DiffSplitExtendLineWrap_v2.tsx +123 -0
- package/src/components/v2/DiffSplitHunkLineNormal_v2.tsx +302 -0
- package/src/components/v2/DiffSplitHunkLineWrap_v2.tsx +326 -0
- package/src/components/v2/DiffSplitViewLineNormal_v2.tsx +33 -0
- package/src/components/v2/DiffSplitViewLineWrap_v2.tsx +24 -0
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +159 -0
- package/src/components/v2/DiffSplitViewWrap_v2.tsx +104 -0
- package/src/components/v2/DiffSplitView_v2.tsx +47 -0
- package/src/components/v2/DiffSplitWidgetLineNormal_v2.tsx +132 -0
- package/src/components/v2/DiffSplitWidgetLineWrap_v2.tsx +119 -0
- package/src/global.d.ts +12 -0
- package/src/hooks/useCallbackRef.ts +18 -0
- package/src/hooks/useDomWidth.ts +67 -0
- package/src/hooks/useIsMounted.ts +11 -0
- package/src/hooks/useSafeLayout.ts +5 -0
- package/src/hooks/useSyncHeight.ts +87 -0
- package/src/hooks/useTextWidth.ts +27 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/index.ts +3 -0
- package/src/tailwind.css +3 -0
- package/src/tailwind_pure.css +3 -0
- package/styles/diff-view-pure.css +5 -1
- package/styles/diff-view.css +6 -2
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
var core = require('@git-diff-view/core');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var index_js = require('use-sync-external-store/shim/index.js');
|
|
7
|
-
var reactDom = require('react-dom');
|
|
8
7
|
var reactivityStore = require('reactivity-store');
|
|
9
8
|
|
|
10
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -84,7 +83,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
87
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
86
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
88
87
|
return (state.set(receiver, value)), value;
|
|
89
88
|
}
|
|
90
89
|
|
|
@@ -145,7 +144,9 @@ const delLineNumberBGName = "--diff-del-lineNumber--";
|
|
|
145
144
|
const plainContentBGName = "--diff-plain-content--";
|
|
146
145
|
const expandContentBGName = "--diff-expand-content--";
|
|
147
146
|
const plainLineNumberColorName = "--diff-plain-lineNumber-color--";
|
|
147
|
+
const expandLineNumberColorName = "--diff-expand-lineNumber-color--";
|
|
148
148
|
const plainLineNumberBGName = "--diff-plain-lineNumber--";
|
|
149
|
+
const expandLineNumberBGName = "--diff-expand-lineNumber--";
|
|
149
150
|
const hunkContentBGName = "--diff-hunk-content--";
|
|
150
151
|
const hunkContentColorName = "--diff-hunk-content-color--";
|
|
151
152
|
const hunkLineNumberBGName = "--diff-hunk-lineNumber--";
|
|
@@ -170,7 +171,7 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
170
171
|
? `var(${delLineNumberBGName})`
|
|
171
172
|
: hasDiff
|
|
172
173
|
? `var(${plainLineNumberBGName})`
|
|
173
|
-
: `var(${
|
|
174
|
+
: `var(${expandLineNumberBGName})`;
|
|
174
175
|
};
|
|
175
176
|
|
|
176
177
|
const removeAllSelection = () => {
|
|
@@ -207,7 +208,7 @@ const syncScroll = (left, right) => {
|
|
|
207
208
|
const diffFontSizeName = "--diff-font-size--";
|
|
208
209
|
const diffAsideWidthName = "--diff-aside-width--";
|
|
209
210
|
|
|
210
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
211
212
|
const memoFunc = (func) => {
|
|
212
213
|
const cache = {};
|
|
213
214
|
return ((key) => {
|
|
@@ -299,6 +300,7 @@ const DiffNoNewLine = () => {
|
|
|
299
300
|
React__namespace.createElement("path", { d: "M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 1 0-13 0 6.5 6.5 0 0 0 13 0Z" })));
|
|
300
301
|
};
|
|
301
302
|
|
|
303
|
+
/* eslint-disable max-lines */
|
|
302
304
|
const temp = {};
|
|
303
305
|
const formatStringToCamelCase = (str) => {
|
|
304
306
|
if (str.startsWith("--"))
|
|
@@ -325,30 +327,52 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
325
327
|
});
|
|
326
328
|
return style;
|
|
327
329
|
});
|
|
328
|
-
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
330
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
329
331
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
330
332
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
331
|
-
const range = changes.range;
|
|
332
|
-
const str1 = rawLine.slice(0, range.location);
|
|
333
|
-
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
334
|
-
const str3 = rawLine.slice(range.location + range.length);
|
|
335
|
-
const isLast = str2.includes("\n");
|
|
336
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
337
333
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
334
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof core.getPlainDiffTemplate === "function") {
|
|
335
|
+
core.getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
336
|
+
}
|
|
337
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
338
|
+
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
339
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
340
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
341
|
+
width: `var(${diffFontSizeName})`,
|
|
342
|
+
height: `var(${diffFontSizeName})`,
|
|
343
|
+
} },
|
|
344
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
// TODO remove
|
|
348
|
+
const range = changes.range;
|
|
349
|
+
const str1 = rawLine.slice(0, range.location);
|
|
350
|
+
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
351
|
+
const str3 = rawLine.slice(range.location + range.length);
|
|
352
|
+
const isLast = str2.includes("\n");
|
|
353
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
354
|
+
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
355
|
+
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
356
|
+
str1,
|
|
357
|
+
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
358
|
+
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
359
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
360
|
+
_str2,
|
|
361
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
362
|
+
str3),
|
|
363
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
364
|
+
width: `var(${diffFontSizeName})`,
|
|
365
|
+
height: `var(${diffFontSizeName})`,
|
|
366
|
+
} },
|
|
367
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
371
|
+
plainLine.template = core.getPlainLineTemplate(plainLine.value);
|
|
372
|
+
}
|
|
373
|
+
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
338
374
|
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
339
|
-
React__namespace.createElement("span", { "data-
|
|
340
|
-
str1,
|
|
341
|
-
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
342
|
-
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
343
|
-
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
344
|
-
_str2,
|
|
345
|
-
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
346
|
-
str3),
|
|
347
|
-
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
348
|
-
width: `var(${diffFontSizeName})`,
|
|
349
|
-
height: `var(${diffFontSizeName})`,
|
|
350
|
-
} },
|
|
351
|
-
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
375
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
352
376
|
}
|
|
353
377
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
354
378
|
};
|
|
@@ -360,49 +384,73 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
360
384
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
361
385
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
362
386
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
363
|
-
|
|
387
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof core.getSyntaxDiffTemplate === "function") {
|
|
388
|
+
core.getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
389
|
+
}
|
|
390
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
391
|
+
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
392
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
393
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
394
|
+
width: `var(${diffFontSizeName})`,
|
|
395
|
+
height: `var(${diffFontSizeName})`,
|
|
396
|
+
} },
|
|
397
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// TODO remove
|
|
401
|
+
const range = changes.range;
|
|
402
|
+
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
403
|
+
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
|
|
404
|
+
var _a, _b, _c, _d, _e, _f;
|
|
405
|
+
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
406
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
const index1 = range.location - node.startIndex;
|
|
410
|
+
const index2 = index1 < 0 ? 0 : index1;
|
|
411
|
+
const str1 = node.value.slice(0, index2);
|
|
412
|
+
const str2 = node.value.slice(index2, index1 + range.length);
|
|
413
|
+
const str3 = node.value.slice(index1 + range.length);
|
|
414
|
+
const isStart = str1.length || range.location === node.startIndex;
|
|
415
|
+
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
416
|
+
const isLast = str2.includes("\n");
|
|
417
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
418
|
+
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_e = (_d = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _d === void 0 ? void 0 : _d.className) === null || _e === void 0 ? void 0 : _e.join(" "), style: getStyleObjectFromString(((_f = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _f === void 0 ? void 0 : _f.style) || "") },
|
|
419
|
+
str1,
|
|
420
|
+
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
421
|
+
backgroundColor: operator === "add"
|
|
422
|
+
? `var(${addContentHighlightBGName})`
|
|
423
|
+
: `var(${delContentHighlightBGName})`,
|
|
424
|
+
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
425
|
+
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
426
|
+
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
427
|
+
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
428
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
429
|
+
_str2,
|
|
430
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
431
|
+
str3));
|
|
432
|
+
}
|
|
433
|
+
})),
|
|
434
|
+
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
435
|
+
width: `var(${diffFontSizeName})`,
|
|
436
|
+
height: `var(${diffFontSizeName})`,
|
|
437
|
+
} },
|
|
438
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (!syntaxLine.template) {
|
|
442
|
+
syntaxLine.template = core.getSyntaxLineTemplate(syntaxLine);
|
|
443
|
+
}
|
|
444
|
+
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
364
445
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
365
|
-
React__namespace.createElement("span", { "data-
|
|
366
|
-
var _a, _b, _c, _d, _e, _f;
|
|
367
|
-
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
368
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
const index1 = range.location - node.startIndex;
|
|
372
|
-
const index2 = index1 < 0 ? 0 : index1;
|
|
373
|
-
const str1 = node.value.slice(0, index2);
|
|
374
|
-
const str2 = node.value.slice(index2, index1 + range.length);
|
|
375
|
-
const str3 = node.value.slice(index1 + range.length);
|
|
376
|
-
const isStart = str1.length || range.location === node.startIndex;
|
|
377
|
-
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
378
|
-
const isLast = str2.includes("\n");
|
|
379
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
380
|
-
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_e = (_d = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _d === void 0 ? void 0 : _d.className) === null || _e === void 0 ? void 0 : _e.join(" "), style: getStyleObjectFromString(((_f = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _f === void 0 ? void 0 : _f.style) || "") },
|
|
381
|
-
str1,
|
|
382
|
-
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
383
|
-
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
384
|
-
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
385
|
-
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
386
|
-
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
387
|
-
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
388
|
-
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
389
|
-
_str2,
|
|
390
|
-
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
391
|
-
str3));
|
|
392
|
-
}
|
|
393
|
-
})),
|
|
394
|
-
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
395
|
-
width: `var(${diffFontSizeName})`,
|
|
396
|
-
height: `var(${diffFontSizeName})`,
|
|
397
|
-
} },
|
|
398
|
-
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
446
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
399
447
|
}
|
|
400
448
|
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" }, (_b = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _b === void 0 ? void 0 : _b.map(({ node, wrapper }, index) => {
|
|
401
449
|
var _a, _b, _c;
|
|
402
450
|
return (React__namespace.createElement("span", { key: index, "data-start": node.startIndex, "data-end": node.endIndex, className: (_b = (_a = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _a === void 0 ? void 0 : _a.className) === null || _b === void 0 ? void 0 : _b.join(" "), style: getStyleObjectFromString(((_c = wrapper === null || wrapper === void 0 ? void 0 : wrapper.properties) === null || _c === void 0 ? void 0 : _c.style) || "") }, node.value));
|
|
403
451
|
})));
|
|
404
452
|
};
|
|
405
|
-
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
453
|
+
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
406
454
|
var _a;
|
|
407
455
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
|
|
408
456
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
|
|
@@ -414,7 +462,7 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
414
462
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
415
463
|
} },
|
|
416
464
|
React__namespace.createElement("span", { "data-operator": isAdded ? "+" : isDelete ? "-" : undefined, className: "diff-line-content-operator ml-[-1.5em] inline-block w-[1.5em] select-none indent-[0.2em]" }, isAdded ? "+" : isDelete ? "-" : " "),
|
|
417
|
-
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React__namespace.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React__namespace.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, enableWrap: enableWrap }))));
|
|
465
|
+
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React__namespace.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React__namespace.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, enableWrap: enableWrap }))));
|
|
418
466
|
};
|
|
419
467
|
|
|
420
468
|
const DiffViewContext = React.createContext(null);
|
|
@@ -425,54 +473,52 @@ const DiffWidgetContext = React.createContext(null);
|
|
|
425
473
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
426
474
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
427
475
|
|
|
428
|
-
const
|
|
476
|
+
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
429
477
|
var _a, _b;
|
|
430
|
-
const getCurrentSyntaxLine = side ===
|
|
478
|
+
const getCurrentSyntaxLine = side === core.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
479
|
+
const getCurrentPlainLine = side === core.SplitSide.old ? diffFile.getOldPlainLine : diffFile.getNewPlainLine;
|
|
431
480
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
432
481
|
const newLine = diffFile.getSplitRightLine(index);
|
|
433
|
-
const currentLine = side ===
|
|
482
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
434
483
|
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
435
484
|
const hasContent = !!currentLine.lineNumber;
|
|
436
485
|
const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
437
486
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
|
|
438
487
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
|
|
439
488
|
const { useDiffContext } = useDiffViewContext();
|
|
440
|
-
const
|
|
441
|
-
enableHighlight: s.enableHighlight,
|
|
442
|
-
enableAddWidget: s.enableAddWidget,
|
|
443
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
444
|
-
}));
|
|
489
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
445
490
|
const { useWidget } = useDiffWidgetContext();
|
|
446
491
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
447
492
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
448
493
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
449
494
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
450
|
-
|
|
451
|
-
|
|
495
|
+
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
496
|
+
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff || !hasContent ? "diff" : "plain", "data-side": core.SplitSide[side], className: "diff-line" + (hasContent ? " group" : "") }, hasContent ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
497
|
+
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-num sticky left-0 w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
|
|
452
498
|
backgroundColor: lineNumberBG,
|
|
453
|
-
color: `var(${plainLineNumberColorName})`,
|
|
499
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
454
500
|
width: `var(${diffAsideWidthName})`,
|
|
455
501
|
minWidth: `var(${diffAsideWidthName})`,
|
|
456
502
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
457
503
|
} },
|
|
458
504
|
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
459
505
|
React__namespace.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
460
|
-
React__namespace.createElement("td", { className: `diff-line-${
|
|
461
|
-
React__namespace.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: `diff-line-${
|
|
506
|
+
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
507
|
+
React__namespace.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, plainLine: plainLine, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
462
508
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
463
509
|
};
|
|
464
|
-
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
465
|
-
const getCurrentLine = side ===
|
|
510
|
+
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
511
|
+
const getCurrentLine = side === core.SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
466
512
|
const currentLine = getCurrentLine(index);
|
|
467
513
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
468
514
|
return null;
|
|
469
|
-
return React__namespace.createElement(
|
|
515
|
+
return (React__namespace.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
470
516
|
};
|
|
471
517
|
|
|
472
518
|
const useDomWidth = ({ selector, enable }) => {
|
|
473
519
|
const [width, setWidth] = React.useState(0);
|
|
474
520
|
const { useDiffContext } = useDiffViewContext();
|
|
475
|
-
const id = useDiffContext
|
|
521
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
476
522
|
React.useEffect(() => {
|
|
477
523
|
if (enable) {
|
|
478
524
|
const container = document.querySelector(`#diff-root${id}`);
|
|
@@ -508,88 +554,97 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
508
554
|
typedWrapper.setAttribute("data-observe", "height");
|
|
509
555
|
return () => cleanCb();
|
|
510
556
|
}
|
|
511
|
-
}, [selector, enable, id]);
|
|
557
|
+
}, [selector, enable, id, mounted]);
|
|
512
558
|
return width;
|
|
513
559
|
};
|
|
514
560
|
|
|
515
|
-
// TODO
|
|
516
561
|
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
517
562
|
const { useDiffContext } = useDiffViewContext();
|
|
518
|
-
const id = useDiffContext
|
|
563
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
519
564
|
React.useEffect(() => {
|
|
520
565
|
if (enable) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
const
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
566
|
+
const container = document.querySelector(`#diff-root${id}`);
|
|
567
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
568
|
+
const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
|
|
569
|
+
if (elements.length === 2 && wrappers.length === 2) {
|
|
570
|
+
const ele1 = elements[0];
|
|
571
|
+
const ele2 = elements[1];
|
|
572
|
+
const wrapper1 = wrappers[0];
|
|
573
|
+
const wrapper2 = wrappers[1];
|
|
574
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
575
|
+
const typedTarget = target;
|
|
576
|
+
const cb = () => {
|
|
577
|
+
ele1.style.height = "auto";
|
|
578
|
+
ele2.style.height = "auto";
|
|
579
|
+
const rect1 = ele1.getBoundingClientRect();
|
|
580
|
+
const rect2 = ele2.getBoundingClientRect();
|
|
581
|
+
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
582
|
+
wrapper1.style.height = maxHeight + "px";
|
|
583
|
+
wrapper2.style.height = maxHeight + "px";
|
|
584
|
+
wrapper1.setAttribute("data-sync-height", String(maxHeight));
|
|
585
|
+
wrapper2.setAttribute("data-sync-height", String(maxHeight));
|
|
586
|
+
};
|
|
587
|
+
cb();
|
|
588
|
+
const cleanCb = () => {
|
|
589
|
+
var _a;
|
|
590
|
+
typedTarget.__observeCallback.delete(cb);
|
|
591
|
+
if (typedTarget.__observeCallback.size === 0) {
|
|
592
|
+
(_a = typedTarget.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
593
|
+
typedTarget.removeAttribute("data-observe");
|
|
594
|
+
delete typedTarget.__observeCallback;
|
|
595
|
+
delete typedTarget.__observeInstance;
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
if (typedTarget.__observeCallback) {
|
|
599
|
+
typedTarget.__observeCallback.add(cb);
|
|
600
|
+
return () => cleanCb();
|
|
552
601
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
602
|
+
typedTarget.__observeCallback = new Set();
|
|
603
|
+
typedTarget.__observeCallback.add(cb);
|
|
604
|
+
const observer = new ResizeObserver(() => typedTarget.__observeCallback.forEach((cb) => cb()));
|
|
605
|
+
typedTarget.__observeInstance = observer;
|
|
606
|
+
observer.observe(target);
|
|
607
|
+
target.setAttribute("data-observe", "height");
|
|
608
|
+
return () => cleanCb();
|
|
609
|
+
}
|
|
558
610
|
}
|
|
559
|
-
}, [selector, enable, side, id, wrapper]);
|
|
611
|
+
}, [selector, enable, side, id, wrapper, mounted]);
|
|
560
612
|
};
|
|
561
613
|
|
|
562
|
-
const
|
|
614
|
+
const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
563
615
|
const { useDiffContext } = useDiffViewContext();
|
|
564
616
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
565
617
|
const newLine = diffFile.getSplitRightLine(index);
|
|
566
618
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
567
|
-
const currentExtend = side ===
|
|
568
|
-
const
|
|
569
|
-
const
|
|
619
|
+
const currentExtend = side === core.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
620
|
+
const otherSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
621
|
+
const currentLineNumber = side === core.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
622
|
+
const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
|
|
623
|
+
const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
|
|
624
|
+
((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
|
|
570
625
|
const currentExtendRendered = hasExtend &&
|
|
571
626
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
572
627
|
diffFile,
|
|
573
628
|
side,
|
|
574
629
|
lineNumber: currentLineNumber,
|
|
575
|
-
data: currentExtend.data,
|
|
630
|
+
data: currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data,
|
|
576
631
|
onUpdate: diffFile.notifyAll,
|
|
577
632
|
}));
|
|
578
633
|
useSyncHeight({
|
|
579
634
|
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
580
635
|
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
581
|
-
side:
|
|
636
|
+
side: core.SplitSide[currentSideHasExtend ? side : otherSide],
|
|
582
637
|
enable: hasExtend && typeof renderExtendLine === "function",
|
|
583
638
|
});
|
|
584
639
|
const width = useDomWidth({
|
|
585
|
-
selector: side ===
|
|
586
|
-
enable:
|
|
640
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
641
|
+
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
587
642
|
});
|
|
588
643
|
if (!renderExtendLine)
|
|
589
644
|
return null;
|
|
590
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side":
|
|
591
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side":
|
|
592
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side":
|
|
645
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": core.SplitSide[side], className: "diff-line diff-line-extend" }, currentSideHasExtend ? (React__namespace.createElement("td", { className: `diff-line-extend-${core.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
646
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": core.SplitSide[side], className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } }, width > 0 && currentExtendRendered))) : (React__namespace.createElement("td", { className: `diff-line-extend-${core.SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
647
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": core.SplitSide[side] })))));
|
|
593
648
|
};
|
|
594
649
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
595
650
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -605,11 +660,11 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
605
660
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
606
661
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
607
662
|
const enableExpand = diffFile.getExpandEnabled();
|
|
608
|
-
const currentLine = side ===
|
|
663
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
609
664
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
610
665
|
if (!currentIsShow)
|
|
611
666
|
return null;
|
|
612
|
-
return (React__namespace.createElement(
|
|
667
|
+
return (React__namespace.createElement(InternalDiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
613
668
|
};
|
|
614
669
|
|
|
615
670
|
const ExpandDown = ({ className }) => {
|
|
@@ -625,23 +680,23 @@ const ExpandAll = ({ className }) => {
|
|
|
625
680
|
React__namespace.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" })));
|
|
626
681
|
};
|
|
627
682
|
|
|
628
|
-
const
|
|
683
|
+
const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
629
684
|
var _a;
|
|
630
685
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
631
686
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
632
687
|
useSyncHeight({
|
|
633
688
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
634
|
-
side:
|
|
635
|
-
enable: side ===
|
|
689
|
+
side: core.SplitSide[core.SplitSide.old],
|
|
690
|
+
enable: side === core.SplitSide.new,
|
|
636
691
|
});
|
|
637
|
-
const enableHunkAction = side ===
|
|
692
|
+
const enableHunkAction = side === core.SplitSide.old;
|
|
638
693
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
639
694
|
const isExpandAll = currentHunk &&
|
|
640
695
|
currentHunk.splitInfo &&
|
|
641
696
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
642
697
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
643
698
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
644
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side":
|
|
699
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": core.SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
645
700
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
646
701
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
647
702
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -649,9 +704,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
649
704
|
minWidth: `var(${diffAsideWidthName})`,
|
|
650
705
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
651
706
|
} }, couldExpand ? (isFirstLine ? (React__namespace.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) },
|
|
652
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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: () =>
|
|
653
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
654
|
-
} },
|
|
707
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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: () => diffFile.onSplitHunkExpand("down", index) },
|
|
655
708
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.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) },
|
|
656
709
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
657
710
|
React__namespace.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) },
|
|
@@ -664,13 +717,13 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
664
717
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React__namespace.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
665
718
|
React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
666
719
|
};
|
|
667
|
-
const
|
|
720
|
+
const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
668
721
|
var _a;
|
|
669
722
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
670
723
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
671
724
|
useSyncHeight({
|
|
672
725
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
673
|
-
side:
|
|
726
|
+
side: core.SplitSide[side],
|
|
674
727
|
enable: true,
|
|
675
728
|
});
|
|
676
729
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
@@ -679,7 +732,7 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
679
732
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
680
733
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
681
734
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
682
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side":
|
|
735
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": core.SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
683
736
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
684
737
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
685
738
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -687,9 +740,7 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
687
740
|
minWidth: `var(${diffAsideWidthName})`,
|
|
688
741
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
689
742
|
} }, couldExpand ? (isFirstLine ? (React__namespace.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) },
|
|
690
|
-
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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: () =>
|
|
691
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
692
|
-
} },
|
|
743
|
+
React__namespace.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React__namespace.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: () => diffFile.onSplitHunkExpand("down", index) },
|
|
693
744
|
React__namespace.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React__namespace.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) },
|
|
694
745
|
React__namespace.createElement(ExpandAll, { className: "fill-current" }))) : (React__namespace.createElement(React__namespace.Fragment, null,
|
|
695
746
|
React__namespace.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) },
|
|
@@ -701,16 +752,16 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
701
752
|
color: `var(${hunkContentColorName})`,
|
|
702
753
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
703
754
|
};
|
|
704
|
-
const
|
|
755
|
+
const InternalDiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
705
756
|
const { useDiffContext } = useDiffViewContext();
|
|
706
757
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
707
758
|
if (diffViewMode === exports.DiffModeEnum.SplitGitHub ||
|
|
708
759
|
diffViewMode === exports.DiffModeEnum.Split ||
|
|
709
760
|
diffViewMode === exports.DiffModeEnum.Unified) {
|
|
710
|
-
return React__namespace.createElement(
|
|
761
|
+
return React__namespace.createElement(InternalDiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
711
762
|
}
|
|
712
763
|
else {
|
|
713
|
-
return React__namespace.createElement(
|
|
764
|
+
return React__namespace.createElement(InternalDiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
714
765
|
}
|
|
715
766
|
};
|
|
716
767
|
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -721,10 +772,10 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
721
772
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
722
773
|
if (!currentIsShow && !currentIsPureHunk)
|
|
723
774
|
return null;
|
|
724
|
-
return React__namespace.createElement(
|
|
775
|
+
return React__namespace.createElement(InternalDiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
725
776
|
};
|
|
726
777
|
|
|
727
|
-
const
|
|
778
|
+
const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
728
779
|
const { useWidget } = useDiffWidgetContext();
|
|
729
780
|
const { useDiffContext } = useDiffViewContext();
|
|
730
781
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
@@ -732,12 +783,14 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
732
783
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
733
784
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
734
785
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
735
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
736
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
737
|
-
const currentLine = side ===
|
|
738
|
-
const
|
|
786
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
787
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
788
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
789
|
+
const otherSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
790
|
+
const currentHasWidget = side === core.SplitSide.old ? oldLineWidget : newLineWidget;
|
|
791
|
+
const hasWidget = oldLineWidget || newLineWidget;
|
|
739
792
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
740
|
-
const currentWidgetRendered =
|
|
793
|
+
const currentWidgetRendered = currentHasWidget &&
|
|
741
794
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
742
795
|
diffFile,
|
|
743
796
|
side,
|
|
@@ -747,18 +800,18 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
747
800
|
useSyncHeight({
|
|
748
801
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
749
802
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
750
|
-
side:
|
|
751
|
-
enable:
|
|
803
|
+
side: core.SplitSide[currentHasWidget ? side : otherSide],
|
|
804
|
+
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
752
805
|
});
|
|
753
806
|
const width = useDomWidth({
|
|
754
|
-
selector: side ===
|
|
755
|
-
enable: !!
|
|
807
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
808
|
+
enable: !!currentHasWidget && typeof renderWidgetLine === "function",
|
|
756
809
|
});
|
|
757
810
|
if (!renderWidgetLine)
|
|
758
811
|
return null;
|
|
759
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side":
|
|
760
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side":
|
|
761
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side":
|
|
812
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": core.SplitSide[side], className: "diff-line diff-line-widget" }, currentHasWidget ? (React__namespace.createElement("td", { className: `diff-line-widget-${core.SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
813
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": core.SplitSide[side], className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } }, width > 0 && currentWidgetRendered))) : (React__namespace.createElement("td", { className: `diff-line-widget-${core.SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
814
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": core.SplitSide[side] })))));
|
|
762
815
|
};
|
|
763
816
|
// TODO! improve performance
|
|
764
817
|
const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
@@ -768,44 +821,36 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
768
821
|
const widgetSide = s.widgetSide;
|
|
769
822
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
770
823
|
const newLine = diffFile.getSplitRightLine(index);
|
|
771
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
772
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
824
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
825
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
773
826
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
774
827
|
return currentIsShow;
|
|
775
828
|
}, [diffFile, index]), (p, c) => p === c);
|
|
776
829
|
if (!currentIsShow)
|
|
777
830
|
return null;
|
|
778
|
-
return React__namespace.createElement(
|
|
831
|
+
return React__namespace.createElement(InternalDiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
|
|
779
832
|
};
|
|
780
833
|
|
|
781
834
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
782
|
-
const
|
|
783
|
-
const
|
|
784
|
-
// need remove all the selection
|
|
785
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
786
|
-
removeAllSelection();
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
791
|
-
const className = side === exports.SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
835
|
+
const DiffSplitViewTable = ({ side, diffFile, enableAddWidget, enableHighlight, onMouseDown, }) => {
|
|
836
|
+
const className = side === core.SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
792
837
|
const lines = core.getSplitContentLines(diffFile);
|
|
793
|
-
return (React__namespace.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode":
|
|
838
|
+
return (React__namespace.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": core.SplitSide[side] },
|
|
794
839
|
React__namespace.createElement("colgroup", null,
|
|
795
|
-
React__namespace.createElement("col", { className: `diff-table-${
|
|
796
|
-
React__namespace.createElement("col", { className: `diff-table-${
|
|
840
|
+
React__namespace.createElement("col", { className: `diff-table-${core.SplitSide[side]}-num-col` }),
|
|
841
|
+
React__namespace.createElement("col", { className: `diff-table-${core.SplitSide[side]}-content-col` })),
|
|
797
842
|
React__namespace.createElement("thead", { className: "hidden" },
|
|
798
843
|
React__namespace.createElement("tr", null,
|
|
799
844
|
React__namespace.createElement("th", { scope: "col" },
|
|
800
|
-
|
|
845
|
+
core.SplitSide[side],
|
|
801
846
|
" line number"),
|
|
802
847
|
React__namespace.createElement("th", { scope: "col" },
|
|
803
|
-
|
|
848
|
+
core.SplitSide[side],
|
|
804
849
|
" line content"))),
|
|
805
|
-
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown
|
|
850
|
+
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
806
851
|
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
807
852
|
React__namespace.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
808
|
-
React__namespace.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
853
|
+
React__namespace.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
809
854
|
React__namespace.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
810
855
|
React__namespace.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
811
856
|
React__namespace.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -813,9 +858,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
813
858
|
const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
814
859
|
const ref1 = React.useRef(null);
|
|
815
860
|
const ref2 = React.useRef(null);
|
|
861
|
+
const ref = React.useRef();
|
|
816
862
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
817
863
|
const { useDiffContext } = useDiffViewContext();
|
|
818
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) =>
|
|
864
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
865
|
+
fontSize: s.fontSize,
|
|
866
|
+
enableAddWidget: s.enableAddWidget,
|
|
867
|
+
enableHighlight: s.enableHighlight,
|
|
868
|
+
}));
|
|
819
869
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
820
870
|
React.useEffect(() => {
|
|
821
871
|
const left = ref1.current;
|
|
@@ -830,7 +880,46 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
830
880
|
font,
|
|
831
881
|
});
|
|
832
882
|
const width = Math.max(40, _width + 25);
|
|
883
|
+
const setStyle = (side) => {
|
|
884
|
+
if (!ref.current)
|
|
885
|
+
return;
|
|
886
|
+
if (!side) {
|
|
887
|
+
ref.current.textContent = "";
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
891
|
+
ref.current.textContent = `#${id} [data-state="extend"] {user-select: none} \n#${id} [data-state="hunk"] {user-select: none} \n#${id} [data-state="widget"] {user-select: none}`;
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
const onMouseDown = (e) => {
|
|
895
|
+
let ele = e.target;
|
|
896
|
+
// need remove all the selection
|
|
897
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
898
|
+
removeAllSelection();
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
while (ele && ele instanceof HTMLElement) {
|
|
902
|
+
const state = ele.getAttribute("data-state");
|
|
903
|
+
const side = ele.getAttribute("data-side");
|
|
904
|
+
if (side) {
|
|
905
|
+
setStyle(core.SplitSide[side]);
|
|
906
|
+
removeAllSelection();
|
|
907
|
+
}
|
|
908
|
+
if (state) {
|
|
909
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
910
|
+
setStyle(undefined);
|
|
911
|
+
removeAllSelection();
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
else {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
ele = ele.parentElement;
|
|
919
|
+
}
|
|
920
|
+
};
|
|
833
921
|
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
|
|
922
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
834
923
|
React__namespace.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
835
924
|
// @ts-ignore
|
|
836
925
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -838,7 +927,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
838
927
|
fontFamily: "Menlo, Consolas, monospace",
|
|
839
928
|
fontSize: `var(${diffFontSizeName})`,
|
|
840
929
|
} },
|
|
841
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
930
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
842
931
|
React__namespace.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
843
932
|
React__namespace.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
844
933
|
// @ts-ignore
|
|
@@ -847,26 +936,24 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
847
936
|
fontFamily: "Menlo, Consolas, monospace",
|
|
848
937
|
fontSize: `var(${diffFontSizeName})`,
|
|
849
938
|
} },
|
|
850
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
939
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
851
940
|
});
|
|
852
941
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
853
942
|
|
|
854
|
-
const
|
|
943
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
855
944
|
var _a, _b;
|
|
856
945
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
857
946
|
const newLine = diffFile.getSplitRightLine(index);
|
|
858
947
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
948
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
859
949
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
950
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
860
951
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
861
952
|
const hasChange = core.checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || core.checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
862
953
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Delete;
|
|
863
954
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Add;
|
|
864
955
|
const { useDiffContext } = useDiffViewContext();
|
|
865
|
-
const
|
|
866
|
-
enableHighlight: s.enableHighlight,
|
|
867
|
-
enableAddWidget: s.enableAddWidget,
|
|
868
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
869
|
-
}));
|
|
956
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
870
957
|
const { useWidget } = useDiffWidgetContext();
|
|
871
958
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
872
959
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -877,40 +964,40 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
877
964
|
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
878
965
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
879
966
|
hasOldLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
880
|
-
React__namespace.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":
|
|
881
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side:
|
|
967
|
+
React__namespace.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": core.SplitSide[core.SplitSide.old], style: { backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` } },
|
|
968
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: core.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 }) })),
|
|
882
969
|
React__namespace.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
883
|
-
React__namespace.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side":
|
|
884
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side:
|
|
885
|
-
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side":
|
|
970
|
+
React__namespace.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": core.SplitSide[core.SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
971
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: core.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 }) })),
|
|
972
|
+
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, plainLine: oldPlainLine, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side": core.SplitSide[core.SplitSide.old], style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
886
973
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
887
974
|
hasNewLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
888
|
-
React__namespace.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":
|
|
975
|
+
React__namespace.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": core.SplitSide[core.SplitSide.new], style: {
|
|
889
976
|
backgroundColor: newLineNumberBG,
|
|
890
|
-
color: `var(${plainLineNumberColorName})`,
|
|
977
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
891
978
|
borderLeftColor: `var(${borderColorName})`,
|
|
892
979
|
borderLeftStyle: "solid",
|
|
893
980
|
} },
|
|
894
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side:
|
|
981
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: core.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 }) })),
|
|
895
982
|
React__namespace.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
896
|
-
React__namespace.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side":
|
|
897
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side:
|
|
898
|
-
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
983
|
+
React__namespace.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": core.SplitSide[core.SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
984
|
+
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: core.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 }) })),
|
|
985
|
+
React__namespace.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, plainLine: newPlainLine, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React__namespace.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
899
986
|
backgroundColor: `var(${emptyBGName})`,
|
|
900
987
|
borderLeftColor: `var(${borderColorName})`,
|
|
901
988
|
borderLeftStyle: "solid",
|
|
902
|
-
}, "data-side":
|
|
989
|
+
}, "data-side": core.SplitSide[core.SplitSide.new], colSpan: 2 },
|
|
903
990
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
904
991
|
};
|
|
905
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
992
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
906
993
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
907
994
|
const newLine = diffFile.getSplitRightLine(index);
|
|
908
995
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
909
996
|
return null;
|
|
910
|
-
return React__namespace.createElement(
|
|
997
|
+
return (React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
911
998
|
};
|
|
912
999
|
|
|
913
|
-
const
|
|
1000
|
+
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
914
1001
|
const { useDiffContext } = useDiffViewContext();
|
|
915
1002
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
916
1003
|
const newLine = diffFile.getSplitRightLine(index);
|
|
@@ -921,7 +1008,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
921
1008
|
const oldExtendRendered = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
922
1009
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
923
1010
|
diffFile,
|
|
924
|
-
side:
|
|
1011
|
+
side: core.SplitSide.old,
|
|
925
1012
|
lineNumber: oldLine.lineNumber,
|
|
926
1013
|
data: oldLineExtend.data,
|
|
927
1014
|
onUpdate: diffFile.notifyAll,
|
|
@@ -929,20 +1016,20 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
929
1016
|
const newExtendRendered = (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
930
1017
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
931
1018
|
diffFile,
|
|
932
|
-
side:
|
|
1019
|
+
side: core.SplitSide.new,
|
|
933
1020
|
lineNumber: newLine.lineNumber,
|
|
934
1021
|
data: newLineExtend.data,
|
|
935
1022
|
onUpdate: diffFile.notifyAll,
|
|
936
1023
|
}));
|
|
937
1024
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
938
1025
|
oldExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
939
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }
|
|
1026
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 })),
|
|
940
1027
|
newExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
|
|
941
1028
|
React__namespace.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React__namespace.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
942
1029
|
backgroundColor: `var(${emptyBGName})`,
|
|
943
1030
|
borderLeftColor: `var(${borderColorName})`,
|
|
944
1031
|
borderLeftStyle: "solid",
|
|
945
|
-
}, colSpan: 2 }
|
|
1032
|
+
}, colSpan: 2 }))));
|
|
946
1033
|
};
|
|
947
1034
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
948
1035
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -961,7 +1048,7 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
961
1048
|
const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
|
|
962
1049
|
if (!currentIsShow)
|
|
963
1050
|
return null;
|
|
964
|
-
return (React__namespace.createElement(
|
|
1051
|
+
return (React__namespace.createElement(InternalDiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
965
1052
|
};
|
|
966
1053
|
|
|
967
1054
|
const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1035,7 +1122,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1035
1122
|
color: `var(${hunkContentColorName})`,
|
|
1036
1123
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
1037
1124
|
};
|
|
1038
|
-
const
|
|
1125
|
+
const InternalDiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1039
1126
|
const { useDiffContext } = useDiffViewContext();
|
|
1040
1127
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
1041
1128
|
if (diffViewMode === exports.DiffModeEnum.SplitGitHub ||
|
|
@@ -1055,10 +1142,10 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1055
1142
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
1056
1143
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1057
1144
|
return null;
|
|
1058
|
-
return React__namespace.createElement(
|
|
1145
|
+
return React__namespace.createElement(InternalDiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1059
1146
|
};
|
|
1060
1147
|
|
|
1061
|
-
const
|
|
1148
|
+
const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1062
1149
|
const { useWidget } = useDiffWidgetContext();
|
|
1063
1150
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1064
1151
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1067,23 +1154,23 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1067
1154
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1068
1155
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1069
1156
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1070
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1071
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
1157
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1158
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1072
1159
|
const oldWidgetRendered = oldLineWidget &&
|
|
1073
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1160
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.old, lineNumber: oldLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1074
1161
|
const newWidgetRendered = newLineWidget &&
|
|
1075
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1162
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.new, lineNumber: newLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1076
1163
|
if (!renderWidgetLine)
|
|
1077
1164
|
return null;
|
|
1078
1165
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1079
1166
|
oldWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
1080
|
-
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }
|
|
1167
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 })),
|
|
1081
1168
|
newWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
|
|
1082
1169
|
React__namespace.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React__namespace.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
1083
1170
|
backgroundColor: `var(${emptyBGName})`,
|
|
1084
1171
|
borderLeftColor: `var(${borderColorName})`,
|
|
1085
1172
|
borderLeftStyle: "solid",
|
|
1086
|
-
}, colSpan: 2 }
|
|
1173
|
+
}, colSpan: 2 }))));
|
|
1087
1174
|
};
|
|
1088
1175
|
// TODO! improve performance
|
|
1089
1176
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1093,16 +1180,103 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1093
1180
|
const widgetSide = s.widgetSide;
|
|
1094
1181
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1095
1182
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1096
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1097
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
1183
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1184
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1098
1185
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
1099
1186
|
return currentIsShow;
|
|
1100
1187
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1101
1188
|
if (!currentIsShow)
|
|
1102
1189
|
return null;
|
|
1103
|
-
return React__namespace.createElement(
|
|
1190
|
+
return React__namespace.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1104
1191
|
};
|
|
1105
1192
|
|
|
1193
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1194
|
+
const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
1195
|
+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1196
|
+
const { useDiffContext } = useDiffViewContext();
|
|
1197
|
+
const ref = React.useRef(null);
|
|
1198
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1199
|
+
fontSize: s.fontSize,
|
|
1200
|
+
enableAddWidget: s.enableAddWidget,
|
|
1201
|
+
enableHighlight: s.enableHighlight,
|
|
1202
|
+
}));
|
|
1203
|
+
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1204
|
+
const font = React.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1205
|
+
const _width = useTextWidth({
|
|
1206
|
+
text: splitLineLength.toString(),
|
|
1207
|
+
font,
|
|
1208
|
+
});
|
|
1209
|
+
const width = Math.max(40, _width + 25);
|
|
1210
|
+
const lines = core.getSplitContentLines(diffFile);
|
|
1211
|
+
const setStyle = (side) => {
|
|
1212
|
+
if (!ref.current)
|
|
1213
|
+
return;
|
|
1214
|
+
if (!side) {
|
|
1215
|
+
ref.current.textContent = "";
|
|
1216
|
+
}
|
|
1217
|
+
else {
|
|
1218
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1219
|
+
const targetSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
1220
|
+
ref.current.textContent = `#${id} [data-side="${core.SplitSide[targetSide]}"] {user-select: none} \n#${id} [data-state="extend"] {user-select: none} \n#${id} [data-state="hunk"] {user-select: none} \n#${id} [data-state="widget"] {user-select: none}`;
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
const onMouseDown = (e) => {
|
|
1224
|
+
let ele = e.target;
|
|
1225
|
+
// need remove all the selection
|
|
1226
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1227
|
+
removeAllSelection();
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1231
|
+
const state = ele.getAttribute("data-state");
|
|
1232
|
+
const side = ele.getAttribute("data-side");
|
|
1233
|
+
if (side) {
|
|
1234
|
+
setStyle(core.SplitSide[side]);
|
|
1235
|
+
removeAllSelection();
|
|
1236
|
+
}
|
|
1237
|
+
if (state) {
|
|
1238
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1239
|
+
setStyle(undefined);
|
|
1240
|
+
removeAllSelection();
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
else {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
ele = ele.parentElement;
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1251
|
+
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1252
|
+
// @ts-ignore
|
|
1253
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1254
|
+
fontFamily: "Menlo, Consolas, monospace",
|
|
1255
|
+
fontSize: `var(${diffFontSizeName})`,
|
|
1256
|
+
} },
|
|
1257
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1258
|
+
React__namespace.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1259
|
+
React__namespace.createElement("colgroup", null,
|
|
1260
|
+
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1261
|
+
React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1262
|
+
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1263
|
+
React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1264
|
+
React__namespace.createElement("thead", { className: "hidden" },
|
|
1265
|
+
React__namespace.createElement("tr", null,
|
|
1266
|
+
React__namespace.createElement("th", { scope: "col" }, "old line number"),
|
|
1267
|
+
React__namespace.createElement("th", { scope: "col" }, "old line content"),
|
|
1268
|
+
React__namespace.createElement("th", { scope: "col" }, "new line number"),
|
|
1269
|
+
React__namespace.createElement("th", { scope: "col" }, "new line content"))),
|
|
1270
|
+
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1271
|
+
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
1272
|
+
React__namespace.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1273
|
+
React__namespace.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
1274
|
+
React__namespace.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1275
|
+
React__namespace.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1276
|
+
React__namespace.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1277
|
+
});
|
|
1278
|
+
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1279
|
+
|
|
1106
1280
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1107
1281
|
return reactivityStore.createStore(() => {
|
|
1108
1282
|
var _a, _b;
|
|
@@ -1110,6 +1284,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1110
1284
|
const setId = (_id) => (id.value = _id);
|
|
1111
1285
|
const mode = reactivityStore.ref(props.diffViewMode);
|
|
1112
1286
|
const setMode = (_mode) => (mode.value = _mode);
|
|
1287
|
+
const mounted = reactivityStore.ref(props.isMounted);
|
|
1288
|
+
const setMounted = (_mounted) => (mounted.value = _mounted);
|
|
1113
1289
|
const enableWrap = reactivityStore.ref(props.diffViewWrap);
|
|
1114
1290
|
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1115
1291
|
const enableAddWidget = reactivityStore.ref(props.diffViewAddWidget);
|
|
@@ -1148,6 +1324,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1148
1324
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1149
1325
|
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
1150
1326
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1327
|
+
const onCreateUseWidgetHook = reactivityStore.ref(props.onCreateUseWidgetHook);
|
|
1328
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1151
1329
|
// 避免无意义的订阅
|
|
1152
1330
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1153
1331
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1156,6 +1334,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1156
1334
|
setId,
|
|
1157
1335
|
mode,
|
|
1158
1336
|
setMode,
|
|
1337
|
+
mounted,
|
|
1338
|
+
setMounted,
|
|
1159
1339
|
enableWrap,
|
|
1160
1340
|
setEnableWrap,
|
|
1161
1341
|
enableAddWidget,
|
|
@@ -1172,6 +1352,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1172
1352
|
setRenderExtendLine,
|
|
1173
1353
|
onAddWidgetClick,
|
|
1174
1354
|
setOnAddWidgetClick,
|
|
1355
|
+
onCreateUseWidgetHook,
|
|
1356
|
+
setOnCreateUseWidgetHook,
|
|
1175
1357
|
};
|
|
1176
1358
|
});
|
|
1177
1359
|
};
|
|
@@ -1190,95 +1372,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1190
1372
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1191
1373
|
});
|
|
1192
1374
|
};
|
|
1193
|
-
const createDiffSplitConfigStore = () => {
|
|
1194
|
-
return reactivityStore.createStore(() => {
|
|
1195
|
-
const splitRef = reactivityStore.ref(undefined);
|
|
1196
|
-
const setSplit = (side) => {
|
|
1197
|
-
reactDom.flushSync(() => {
|
|
1198
|
-
splitRef.value = side;
|
|
1199
|
-
});
|
|
1200
|
-
};
|
|
1201
|
-
return { splitRef, setSplit };
|
|
1202
|
-
});
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1206
|
-
const Style = ({ useSelector, id, }) => {
|
|
1207
|
-
const splitRef = useSelector((s) => s.splitRef);
|
|
1208
|
-
return (React__namespace.createElement("style", { "data-select-style": true }, splitRef === exports.SplitSide.old
|
|
1209
|
-
? `#${id} td[data-side="${exports.SplitSide[exports.SplitSide.new]}"] {user-select: none}`
|
|
1210
|
-
: splitRef === exports.SplitSide.new
|
|
1211
|
-
? `#${id} td[data-side="${exports.SplitSide[exports.SplitSide.old]}"] {user-select: none}`
|
|
1212
|
-
: ""));
|
|
1213
|
-
};
|
|
1214
|
-
const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
1215
|
-
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1216
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1217
|
-
const useSplitConfig = React.useMemo(() => createDiffSplitConfigStore(), []);
|
|
1218
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
1219
|
-
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1220
|
-
const onMouseDown = React.useCallback((e) => {
|
|
1221
|
-
let ele = e.target;
|
|
1222
|
-
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1223
|
-
// need remove all the selection
|
|
1224
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1225
|
-
removeAllSelection();
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
|
-
while (ele && ele instanceof HTMLElement && ele.nodeName !== "TD") {
|
|
1229
|
-
ele = ele.parentElement;
|
|
1230
|
-
}
|
|
1231
|
-
if (ele instanceof HTMLElement) {
|
|
1232
|
-
const side = ele.getAttribute("data-side");
|
|
1233
|
-
if (side) {
|
|
1234
|
-
setSelectSide(exports.SplitSide[side]);
|
|
1235
|
-
removeAllSelection();
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1239
|
-
}, []);
|
|
1240
|
-
const font = React.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1241
|
-
const _width = useTextWidth({
|
|
1242
|
-
text: splitLineLength.toString(),
|
|
1243
|
-
font,
|
|
1244
|
-
});
|
|
1245
|
-
const width = Math.max(40, _width + 25);
|
|
1246
|
-
const lines = core.getSplitContentLines(diffFile);
|
|
1247
|
-
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1248
|
-
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1249
|
-
// @ts-ignore
|
|
1250
|
-
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1251
|
-
fontFamily: "Menlo, Consolas, monospace",
|
|
1252
|
-
fontSize: `var(${diffFontSizeName})`,
|
|
1253
|
-
} },
|
|
1254
|
-
React__namespace.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1255
|
-
React__namespace.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1256
|
-
React__namespace.createElement("colgroup", null,
|
|
1257
|
-
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1258
|
-
React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1259
|
-
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1260
|
-
React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1261
|
-
React__namespace.createElement("thead", { className: "hidden" },
|
|
1262
|
-
React__namespace.createElement("tr", null,
|
|
1263
|
-
React__namespace.createElement("th", { scope: "col" }, "old line number"),
|
|
1264
|
-
React__namespace.createElement("th", { scope: "col" }, "old line content"),
|
|
1265
|
-
React__namespace.createElement("th", { scope: "col" }, "new line number"),
|
|
1266
|
-
React__namespace.createElement("th", { scope: "col" }, "new line content"))),
|
|
1267
|
-
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1268
|
-
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
1269
|
-
React__namespace.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1270
|
-
React__namespace.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1271
|
-
React__namespace.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1272
|
-
React__namespace.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1273
|
-
React__namespace.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1274
|
-
});
|
|
1275
|
-
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1276
1375
|
|
|
1277
1376
|
const DiffSplitView = React.memo(({ diffFile }) => {
|
|
1278
1377
|
const { useDiffContext } = useDiffViewContext();
|
|
1279
1378
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1280
1379
|
useDiffContextRef.current = useDiffContext;
|
|
1281
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1380
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1381
|
+
enableWrap: s.enableWrap,
|
|
1382
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1383
|
+
}));
|
|
1282
1384
|
// performance optimization
|
|
1283
1385
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1284
1386
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1286,11 +1388,14 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
1286
1388
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1287
1389
|
setWidget({});
|
|
1288
1390
|
}, [diffFile, useWidget]);
|
|
1391
|
+
React.useEffect(() => {
|
|
1392
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1393
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1289
1394
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React__namespace.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React__namespace.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1290
1395
|
});
|
|
1291
1396
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1292
1397
|
|
|
1293
|
-
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1398
|
+
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1294
1399
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1295
1400
|
React__namespace.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: {
|
|
1296
1401
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1299,15 +1404,15 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1299
1404
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1300
1405
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1301
1406
|
} },
|
|
1302
|
-
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side:
|
|
1407
|
+
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: core.SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1303
1408
|
React__namespace.createElement("div", { className: "flex" },
|
|
1304
1409
|
React__namespace.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
|
|
1305
1410
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1306
1411
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1307
1412
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1308
|
-
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1413
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1309
1414
|
};
|
|
1310
|
-
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1415
|
+
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1311
1416
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1312
1417
|
React__namespace.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: {
|
|
1313
1418
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1316,23 +1421,18 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1316
1421
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1317
1422
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1318
1423
|
} },
|
|
1319
|
-
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side:
|
|
1424
|
+
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: core.SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
|
|
1320
1425
|
React__namespace.createElement("div", { className: "flex" },
|
|
1321
1426
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1322
1427
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1323
1428
|
React__namespace.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1324
1429
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1325
|
-
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1430
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1326
1431
|
};
|
|
1327
|
-
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
1432
|
+
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1328
1433
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1329
1434
|
const { useDiffContext } = useDiffViewContext();
|
|
1330
|
-
const
|
|
1331
|
-
enableWrap: s.enableWrap,
|
|
1332
|
-
enableHighlight: s.enableHighlight,
|
|
1333
|
-
enableAddWidget: s.enableAddWidget,
|
|
1334
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1335
|
-
}));
|
|
1435
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1336
1436
|
const { useWidget } = useDiffWidgetContext();
|
|
1337
1437
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1338
1438
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1346,24 +1446,29 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1346
1446
|
: oldLinenumber
|
|
1347
1447
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1348
1448
|
: undefined;
|
|
1449
|
+
const plainLine = newLineNumber
|
|
1450
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1451
|
+
: oldLinenumber
|
|
1452
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1453
|
+
: undefined;
|
|
1349
1454
|
if (hasChange) {
|
|
1350
1455
|
if (unifiedLine.oldLineNumber) {
|
|
1351
|
-
return (React__namespace.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); } }));
|
|
1456
|
+
return (React__namespace.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, plainLine: plainLine, 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); } }));
|
|
1352
1457
|
}
|
|
1353
1458
|
else {
|
|
1354
|
-
return (React__namespace.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); } }));
|
|
1459
|
+
return (React__namespace.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, plainLine: plainLine, 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); } }));
|
|
1355
1460
|
}
|
|
1356
1461
|
}
|
|
1357
1462
|
else {
|
|
1358
1463
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1359
1464
|
React__namespace.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: {
|
|
1360
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1465
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1361
1466
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1362
1467
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1363
1468
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1364
1469
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1365
1470
|
} },
|
|
1366
|
-
enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side:
|
|
1471
|
+
enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: core.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 }) })),
|
|
1367
1472
|
React__namespace.createElement("div", { className: "flex opacity-[0.5]" },
|
|
1368
1473
|
React__namespace.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
1369
1474
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
@@ -1371,18 +1476,18 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1371
1476
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1372
1477
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1373
1478
|
} },
|
|
1374
|
-
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1479
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1375
1480
|
}
|
|
1376
1481
|
});
|
|
1377
1482
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1378
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1483
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1379
1484
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1380
1485
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1381
1486
|
return null;
|
|
1382
|
-
return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1487
|
+
return (React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
|
|
1383
1488
|
};
|
|
1384
1489
|
|
|
1385
|
-
const
|
|
1490
|
+
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
1386
1491
|
const { useDiffContext } = useDiffViewContext();
|
|
1387
1492
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
1388
1493
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1394,13 +1499,13 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, ne
|
|
|
1394
1499
|
return null;
|
|
1395
1500
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1396
1501
|
React__namespace.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1397
|
-
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
1502
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1398
1503
|
width > 0 &&
|
|
1399
1504
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1400
1505
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
1401
1506
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1402
1507
|
diffFile,
|
|
1403
|
-
side:
|
|
1508
|
+
side: core.SplitSide.old,
|
|
1404
1509
|
lineNumber: unifiedItem.oldLineNumber,
|
|
1405
1510
|
data: oldLineExtend.data,
|
|
1406
1511
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1410,7 +1515,7 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, ne
|
|
|
1410
1515
|
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null &&
|
|
1411
1516
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1412
1517
|
diffFile,
|
|
1413
|
-
side:
|
|
1518
|
+
side: core.SplitSide.new,
|
|
1414
1519
|
lineNumber: unifiedItem.newLineNumber,
|
|
1415
1520
|
data: newLineExtend.data,
|
|
1416
1521
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1429,10 +1534,10 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1429
1534
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
1430
1535
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
|
|
1431
1536
|
return null;
|
|
1432
|
-
return (React__namespace.createElement(
|
|
1537
|
+
return (React__namespace.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1433
1538
|
};
|
|
1434
1539
|
|
|
1435
|
-
const
|
|
1540
|
+
const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1436
1541
|
var _a;
|
|
1437
1542
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
1438
1543
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -1474,18 +1579,18 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1474
1579
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
|
|
1475
1580
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1476
1581
|
return null;
|
|
1477
|
-
return React__namespace.createElement(
|
|
1582
|
+
return React__namespace.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1478
1583
|
};
|
|
1479
1584
|
|
|
1480
|
-
const
|
|
1585
|
+
const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1481
1586
|
const { useWidget } = useDiffWidgetContext();
|
|
1482
1587
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1483
1588
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1484
1589
|
const onClose = () => setWidget({});
|
|
1485
1590
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1486
1591
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1487
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1488
|
-
const newWidget = unifiedItem.newLineNumber && widgetSide ===
|
|
1592
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1593
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1489
1594
|
const { useDiffContext } = useDiffViewContext();
|
|
1490
1595
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1491
1596
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
@@ -1497,13 +1602,13 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1497
1602
|
return null;
|
|
1498
1603
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1499
1604
|
React__namespace.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
|
|
1500
|
-
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } },
|
|
1605
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1501
1606
|
width > 0 &&
|
|
1502
1607
|
oldWidget &&
|
|
1503
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1608
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
1504
1609
|
width > 0 &&
|
|
1505
1610
|
newWidget &&
|
|
1506
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1611
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
|
|
1507
1612
|
};
|
|
1508
1613
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1509
1614
|
const { useWidget } = useDiffWidgetContext();
|
|
@@ -1511,41 +1616,40 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1511
1616
|
const widgetLineNumber = s.widgetLineNumber;
|
|
1512
1617
|
const widgetSide = s.widgetSide;
|
|
1513
1618
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1514
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1515
|
-
const newWidget = unifiedItem.newLineNumber && widgetSide ===
|
|
1619
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1620
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1516
1621
|
const currentIsShow = oldWidget || newWidget;
|
|
1517
1622
|
return currentIsShow;
|
|
1518
1623
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1519
1624
|
if (!currentIsShow)
|
|
1520
1625
|
return null;
|
|
1521
|
-
return React__namespace.createElement(
|
|
1626
|
+
return React__namespace.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1522
1627
|
};
|
|
1523
1628
|
|
|
1524
1629
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1525
|
-
const onMouseDown = (e) => {
|
|
1526
|
-
const ele = e.target;
|
|
1527
|
-
// need remove all the selection
|
|
1528
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1529
|
-
removeAllSelection();
|
|
1530
|
-
return;
|
|
1531
|
-
}
|
|
1532
|
-
};
|
|
1533
1630
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
1534
1631
|
const { useDiffContext } = useDiffViewContext();
|
|
1632
|
+
const ref = React.useRef(null);
|
|
1535
1633
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1536
1634
|
useDiffContextRef.current = useDiffContext;
|
|
1537
1635
|
// performance optimization
|
|
1538
1636
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1539
1637
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
1540
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1638
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1541
1639
|
fontSize: s.fontSize,
|
|
1542
1640
|
enableWrap: s.enableWrap,
|
|
1641
|
+
enableHighlight: s.enableHighlight,
|
|
1642
|
+
enableAddWidget: s.enableAddWidget,
|
|
1643
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1543
1644
|
}));
|
|
1544
1645
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1545
1646
|
React.useEffect(() => {
|
|
1546
1647
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1547
1648
|
setWidget({});
|
|
1548
1649
|
}, [diffFile, useWidget]);
|
|
1650
|
+
React.useEffect(() => {
|
|
1651
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1652
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1549
1653
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1550
1654
|
const _width = useTextWidth({
|
|
1551
1655
|
text: unifiedLineLength.toString(),
|
|
@@ -1553,8 +1657,44 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1553
1657
|
});
|
|
1554
1658
|
const width = Math.max(40, _width + 10);
|
|
1555
1659
|
const lines = core.getUnifiedContentLine(diffFile);
|
|
1660
|
+
const setStyle = (side) => {
|
|
1661
|
+
if (!ref.current)
|
|
1662
|
+
return;
|
|
1663
|
+
if (!side) {
|
|
1664
|
+
ref.current.textContent = "";
|
|
1665
|
+
}
|
|
1666
|
+
else {
|
|
1667
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1668
|
+
ref.current.textContent = `#${id} [data-state="extend"] {user-select: none} \n#${id} [data-state="hunk"] {user-select: none} \n#${id} [data-state="widget"] {user-select: none}`;
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
const onMouseDown = (e) => {
|
|
1672
|
+
let ele = e.target;
|
|
1673
|
+
// need remove all the selection
|
|
1674
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1675
|
+
removeAllSelection();
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1679
|
+
const state = ele.getAttribute("data-state");
|
|
1680
|
+
if (state) {
|
|
1681
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1682
|
+
setStyle(undefined);
|
|
1683
|
+
removeAllSelection();
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
else {
|
|
1687
|
+
setStyle(core.SplitSide.new);
|
|
1688
|
+
removeAllSelection();
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
ele = ele.parentElement;
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1556
1695
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1557
1696
|
React__namespace.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
|
|
1697
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1558
1698
|
React__namespace.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1559
1699
|
// @ts-ignore
|
|
1560
1700
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1572,7 +1712,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1572
1712
|
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1573
1713
|
lines.map((item) => (React__namespace.createElement(React.Fragment, { key: item.index },
|
|
1574
1714
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1575
|
-
React__namespace.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1715
|
+
React__namespace.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }),
|
|
1576
1716
|
React__namespace.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1577
1717
|
React__namespace.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1578
1718
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1580,11 +1720,6 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1580
1720
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1581
1721
|
|
|
1582
1722
|
core._cacheMap.name = "@git-diff-view/react";
|
|
1583
|
-
exports.SplitSide = void 0;
|
|
1584
|
-
(function (SplitSide) {
|
|
1585
|
-
SplitSide[SplitSide["old"] = 1] = "old";
|
|
1586
|
-
SplitSide[SplitSide["new"] = 2] = "new";
|
|
1587
|
-
})(exports.SplitSide || (exports.SplitSide = {}));
|
|
1588
1723
|
exports.DiffModeEnum = void 0;
|
|
1589
1724
|
(function (DiffModeEnum) {
|
|
1590
1725
|
// github like
|
|
@@ -1594,27 +1729,52 @@ exports.DiffModeEnum = void 0;
|
|
|
1594
1729
|
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1595
1730
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1596
1731
|
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1597
|
-
const
|
|
1598
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1732
|
+
const InternalDiffView = (props) => {
|
|
1733
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1599
1734
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1600
|
-
const isMounted = useIsMounted();
|
|
1601
1735
|
const wrapperRef = React.useRef();
|
|
1602
1736
|
// performance optimization
|
|
1603
1737
|
const useDiffContext = React.useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1604
1738
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1605
1739
|
[]);
|
|
1606
1740
|
React.useEffect(() => {
|
|
1607
|
-
const { id, setId, mode, setMode, enableAddWidget, setEnableAddWidget, enableHighlight, setEnableHighlight, enableWrap, setEnableWrap, setExtendData, fontSize, setFontSize, onAddWidgetClick: _onAddWidgetClick, setOnAddWidgetClick, renderExtendLine: _renderExtendLine, setRenderExtendLine, renderWidgetLine: _renderWidgetLine, setRenderWidgetLine, } = useDiffContext.getReadonlyState();
|
|
1608
|
-
diffFileId && diffFileId !== id
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1741
|
+
const { id, setId, mode, setMode, mounted, setMounted, enableAddWidget, setEnableAddWidget, enableHighlight, setEnableHighlight, enableWrap, setEnableWrap, setExtendData, fontSize, setFontSize, onAddWidgetClick: _onAddWidgetClick, setOnAddWidgetClick, renderExtendLine: _renderExtendLine, setRenderExtendLine, renderWidgetLine: _renderWidgetLine, setRenderWidgetLine, onCreateUseWidgetHook: _onCreateUseWidgetHook, setOnCreateUseWidgetHook, } = useDiffContext.getReadonlyState();
|
|
1742
|
+
if (diffFileId && diffFileId !== id) {
|
|
1743
|
+
setId(diffFileId);
|
|
1744
|
+
}
|
|
1745
|
+
if (diffViewMode && diffViewMode !== mode) {
|
|
1746
|
+
setMode(diffViewMode);
|
|
1747
|
+
}
|
|
1748
|
+
if (mounted !== isMounted) {
|
|
1749
|
+
setMounted(isMounted);
|
|
1750
|
+
}
|
|
1751
|
+
if (diffViewAddWidget !== enableAddWidget) {
|
|
1752
|
+
setEnableAddWidget(diffViewAddWidget);
|
|
1753
|
+
}
|
|
1754
|
+
if (diffViewHighlight !== enableHighlight) {
|
|
1755
|
+
setEnableHighlight(diffViewHighlight);
|
|
1756
|
+
}
|
|
1757
|
+
if (diffViewWrap !== enableWrap) {
|
|
1758
|
+
setEnableWrap(diffViewWrap);
|
|
1759
|
+
}
|
|
1760
|
+
if (extendData) {
|
|
1761
|
+
setExtendData(extendData);
|
|
1762
|
+
}
|
|
1763
|
+
if (diffViewFontSize && diffViewFontSize !== fontSize) {
|
|
1764
|
+
setFontSize(diffViewFontSize);
|
|
1765
|
+
}
|
|
1766
|
+
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1767
|
+
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1768
|
+
}
|
|
1769
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1770
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1771
|
+
}
|
|
1772
|
+
if (renderExtendLine !== _renderExtendLine) {
|
|
1773
|
+
setRenderExtendLine(renderExtendLine);
|
|
1774
|
+
}
|
|
1775
|
+
if (renderWidgetLine !== _renderWidgetLine) {
|
|
1776
|
+
setRenderWidgetLine(renderWidgetLine);
|
|
1777
|
+
}
|
|
1618
1778
|
}, [
|
|
1619
1779
|
useDiffContext,
|
|
1620
1780
|
diffViewFontSize,
|
|
@@ -1623,10 +1783,12 @@ const _InternalDiffView = (props) => {
|
|
|
1623
1783
|
diffViewWrap,
|
|
1624
1784
|
diffViewAddWidget,
|
|
1625
1785
|
diffFileId,
|
|
1786
|
+
isMounted,
|
|
1626
1787
|
renderWidgetLine,
|
|
1627
1788
|
renderExtendLine,
|
|
1628
1789
|
extendData,
|
|
1629
1790
|
onAddWidgetClick,
|
|
1791
|
+
onCreateUseWidgetHook,
|
|
1630
1792
|
]);
|
|
1631
1793
|
React.useEffect(() => {
|
|
1632
1794
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1638,14 +1800,14 @@ const _InternalDiffView = (props) => {
|
|
|
1638
1800
|
}, [diffFile]);
|
|
1639
1801
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1640
1802
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1641
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1803
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.27", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1642
1804
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1643
1805
|
// @ts-ignore
|
|
1644
1806
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
1645
1807
|
} },
|
|
1646
1808
|
React__namespace.createElement("div", { id: isMounted ? `diff-root${diffFileId}` : undefined, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & exports.DiffModeEnum.Split ? (React__namespace.createElement(DiffSplitView, { diffFile: diffFile })) : (React__namespace.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
|
|
1647
1809
|
};
|
|
1648
|
-
const
|
|
1810
|
+
const MemoedInternalDiffView = React.memo(InternalDiffView);
|
|
1649
1811
|
const DiffViewWithRef = (props, ref) => {
|
|
1650
1812
|
var _a, _b;
|
|
1651
1813
|
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
|
|
@@ -1669,6 +1831,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1669
1831
|
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1670
1832
|
diffFileRef.current = diffFile;
|
|
1671
1833
|
}
|
|
1834
|
+
const isMounted = useIsMounted();
|
|
1672
1835
|
React.useEffect(() => {
|
|
1673
1836
|
if (_diffFile && diffFile) {
|
|
1674
1837
|
_diffFile._addClonedInstance(diffFile);
|
|
@@ -1698,13 +1861,17 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1698
1861
|
React.useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1699
1862
|
if (!diffFile)
|
|
1700
1863
|
return null;
|
|
1701
|
-
return (React__namespace.createElement(
|
|
1864
|
+
return (React__namespace.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || exports.DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
1702
1865
|
};
|
|
1703
1866
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1704
1867
|
InnerDiffView.displayName = "DiffView";
|
|
1705
1868
|
const DiffView = InnerDiffView;
|
|
1706
|
-
const version = "0.0.
|
|
1869
|
+
const version = "0.0.27";
|
|
1707
1870
|
|
|
1871
|
+
Object.defineProperty(exports, "SplitSide", {
|
|
1872
|
+
enumerable: true,
|
|
1873
|
+
get: function () { return core.SplitSide; }
|
|
1874
|
+
});
|
|
1708
1875
|
exports.DiffView = DiffView;
|
|
1709
1876
|
exports.version = version;
|
|
1710
1877
|
Object.keys(core).forEach(function (k) {
|