@git-diff-view/react 0.0.26 → 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 +419 -287
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +419 -287
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +4 -0
- package/dist/css/diff-view.css +4 -0
- package/dist/esm/index.mjs +353 -224
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +296 -16
- package/package.json +4 -3
- 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 +4 -0
- package/styles/diff-view.css +4 -0
|
@@ -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) {
|
|
@@ -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 = () => {
|
|
@@ -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,48 +473,46 @@ const DiffWidgetContext = React.createContext(null);
|
|
|
425
473
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
426
474
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
427
475
|
|
|
428
|
-
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
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(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
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 }) => {
|
|
@@ -570,9 +616,9 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
570
616
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
571
617
|
const newLine = diffFile.getSplitRightLine(index);
|
|
572
618
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
573
|
-
const currentExtend = side ===
|
|
574
|
-
const otherSide = side ===
|
|
575
|
-
const currentLineNumber = side ===
|
|
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;
|
|
576
622
|
const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
|
|
577
623
|
const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
|
|
578
624
|
((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
|
|
@@ -587,18 +633,18 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
587
633
|
useSyncHeight({
|
|
588
634
|
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
589
635
|
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
590
|
-
side:
|
|
636
|
+
side: core.SplitSide[currentSideHasExtend ? side : otherSide],
|
|
591
637
|
enable: hasExtend && typeof renderExtendLine === "function",
|
|
592
638
|
});
|
|
593
639
|
const width = useDomWidth({
|
|
594
|
-
selector: side ===
|
|
640
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
595
641
|
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
596
642
|
});
|
|
597
643
|
if (!renderExtendLine)
|
|
598
644
|
return null;
|
|
599
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side":
|
|
600
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side":
|
|
601
|
-
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] })))));
|
|
602
648
|
};
|
|
603
649
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
604
650
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -614,7 +660,7 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
614
660
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
615
661
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
616
662
|
const enableExpand = diffFile.getExpandEnabled();
|
|
617
|
-
const currentLine = side ===
|
|
663
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
618
664
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
619
665
|
if (!currentIsShow)
|
|
620
666
|
return null;
|
|
@@ -640,17 +686,17 @@ const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, })
|
|
|
640
686
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
641
687
|
useSyncHeight({
|
|
642
688
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
643
|
-
side:
|
|
644
|
-
enable: side ===
|
|
689
|
+
side: core.SplitSide[core.SplitSide.old],
|
|
690
|
+
enable: side === core.SplitSide.new,
|
|
645
691
|
});
|
|
646
|
-
const enableHunkAction = side ===
|
|
692
|
+
const enableHunkAction = side === core.SplitSide.old;
|
|
647
693
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
648
694
|
const isExpandAll = currentHunk &&
|
|
649
695
|
currentHunk.splitInfo &&
|
|
650
696
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
651
697
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
652
698
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
653
|
-
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,
|
|
654
700
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
655
701
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
656
702
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -677,7 +723,7 @@ const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, })
|
|
|
677
723
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
678
724
|
useSyncHeight({
|
|
679
725
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
680
|
-
side:
|
|
726
|
+
side: core.SplitSide[side],
|
|
681
727
|
enable: true,
|
|
682
728
|
});
|
|
683
729
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
@@ -686,7 +732,7 @@ const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, })
|
|
|
686
732
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
687
733
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
688
734
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
689
|
-
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" },
|
|
690
736
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
691
737
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
692
738
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -737,11 +783,11 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
737
783
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
738
784
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
739
785
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
740
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
741
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
742
|
-
const currentLine = side ===
|
|
743
|
-
const otherSide = side ===
|
|
744
|
-
const currentHasWidget = side ===
|
|
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;
|
|
745
791
|
const hasWidget = oldLineWidget || newLineWidget;
|
|
746
792
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
747
793
|
const currentWidgetRendered = currentHasWidget &&
|
|
@@ -754,18 +800,18 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
754
800
|
useSyncHeight({
|
|
755
801
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
756
802
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
757
|
-
side:
|
|
803
|
+
side: core.SplitSide[currentHasWidget ? side : otherSide],
|
|
758
804
|
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
759
805
|
});
|
|
760
806
|
const width = useDomWidth({
|
|
761
|
-
selector: side ===
|
|
807
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
762
808
|
enable: !!currentHasWidget && typeof renderWidgetLine === "function",
|
|
763
809
|
});
|
|
764
810
|
if (!renderWidgetLine)
|
|
765
811
|
return null;
|
|
766
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side":
|
|
767
|
-
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side":
|
|
768
|
-
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] })))));
|
|
769
815
|
};
|
|
770
816
|
// TODO! improve performance
|
|
771
817
|
const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
@@ -775,8 +821,8 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
775
821
|
const widgetSide = s.widgetSide;
|
|
776
822
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
777
823
|
const newLine = diffFile.getSplitRightLine(index);
|
|
778
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
779
|
-
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;
|
|
780
826
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
781
827
|
return currentIsShow;
|
|
782
828
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -786,33 +832,25 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
786
832
|
};
|
|
787
833
|
|
|
788
834
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
789
|
-
const
|
|
790
|
-
const
|
|
791
|
-
// need remove all the selection
|
|
792
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
793
|
-
removeAllSelection();
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
798
|
-
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";
|
|
799
837
|
const lines = core.getSplitContentLines(diffFile);
|
|
800
|
-
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] },
|
|
801
839
|
React__namespace.createElement("colgroup", null,
|
|
802
|
-
React__namespace.createElement("col", { className: `diff-table-${
|
|
803
|
-
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` })),
|
|
804
842
|
React__namespace.createElement("thead", { className: "hidden" },
|
|
805
843
|
React__namespace.createElement("tr", null,
|
|
806
844
|
React__namespace.createElement("th", { scope: "col" },
|
|
807
|
-
|
|
845
|
+
core.SplitSide[side],
|
|
808
846
|
" line number"),
|
|
809
847
|
React__namespace.createElement("th", { scope: "col" },
|
|
810
|
-
|
|
848
|
+
core.SplitSide[side],
|
|
811
849
|
" line content"))),
|
|
812
|
-
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 },
|
|
813
851
|
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
814
852
|
React__namespace.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
815
|
-
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 }),
|
|
816
854
|
React__namespace.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
817
855
|
React__namespace.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
818
856
|
React__namespace.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -820,9 +858,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
820
858
|
const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
821
859
|
const ref1 = React.useRef(null);
|
|
822
860
|
const ref2 = React.useRef(null);
|
|
861
|
+
const ref = React.useRef();
|
|
823
862
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
824
863
|
const { useDiffContext } = useDiffViewContext();
|
|
825
|
-
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
|
+
}));
|
|
826
869
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
827
870
|
React.useEffect(() => {
|
|
828
871
|
const left = ref1.current;
|
|
@@ -837,7 +880,46 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
837
880
|
font,
|
|
838
881
|
});
|
|
839
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
|
+
};
|
|
840
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 }),
|
|
841
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: {
|
|
842
924
|
// @ts-ignore
|
|
843
925
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -845,7 +927,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
845
927
|
fontFamily: "Menlo, Consolas, monospace",
|
|
846
928
|
fontSize: `var(${diffFontSizeName})`,
|
|
847
929
|
} },
|
|
848
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
930
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
849
931
|
React__namespace.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
850
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: {
|
|
851
933
|
// @ts-ignore
|
|
@@ -854,26 +936,24 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
854
936
|
fontFamily: "Menlo, Consolas, monospace",
|
|
855
937
|
fontSize: `var(${diffFontSizeName})`,
|
|
856
938
|
} },
|
|
857
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
939
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
858
940
|
});
|
|
859
941
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
860
942
|
|
|
861
|
-
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
943
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
862
944
|
var _a, _b;
|
|
863
945
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
864
946
|
const newLine = diffFile.getSplitRightLine(index);
|
|
865
947
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
948
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
866
949
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
950
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
867
951
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
868
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);
|
|
869
953
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Delete;
|
|
870
954
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Add;
|
|
871
955
|
const { useDiffContext } = useDiffViewContext();
|
|
872
|
-
const
|
|
873
|
-
enableHighlight: s.enableHighlight,
|
|
874
|
-
enableAddWidget: s.enableAddWidget,
|
|
875
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
876
|
-
}));
|
|
956
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
877
957
|
const { useWidget } = useDiffWidgetContext();
|
|
878
958
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
879
959
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -884,37 +964,37 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
884
964
|
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
885
965
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
886
966
|
hasOldLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
887
|
-
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":
|
|
888
|
-
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 }) })),
|
|
889
969
|
React__namespace.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
890
|
-
React__namespace.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side":
|
|
891
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side:
|
|
892
|
-
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 },
|
|
893
973
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
894
974
|
hasNewLine ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
895
|
-
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: {
|
|
896
976
|
backgroundColor: newLineNumberBG,
|
|
897
|
-
color: `var(${plainLineNumberColorName})`,
|
|
977
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
898
978
|
borderLeftColor: `var(${borderColorName})`,
|
|
899
979
|
borderLeftStyle: "solid",
|
|
900
980
|
} },
|
|
901
|
-
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 }) })),
|
|
902
982
|
React__namespace.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
903
|
-
React__namespace.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side":
|
|
904
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side:
|
|
905
|
-
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: {
|
|
906
986
|
backgroundColor: `var(${emptyBGName})`,
|
|
907
987
|
borderLeftColor: `var(${borderColorName})`,
|
|
908
988
|
borderLeftStyle: "solid",
|
|
909
|
-
}, "data-side":
|
|
989
|
+
}, "data-side": core.SplitSide[core.SplitSide.new], colSpan: 2 },
|
|
910
990
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
911
991
|
};
|
|
912
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
992
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
913
993
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
914
994
|
const newLine = diffFile.getSplitRightLine(index);
|
|
915
995
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
916
996
|
return null;
|
|
917
|
-
return React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
997
|
+
return (React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
918
998
|
};
|
|
919
999
|
|
|
920
1000
|
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -928,7 +1008,7 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
928
1008
|
const oldExtendRendered = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
929
1009
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
930
1010
|
diffFile,
|
|
931
|
-
side:
|
|
1011
|
+
side: core.SplitSide.old,
|
|
932
1012
|
lineNumber: oldLine.lineNumber,
|
|
933
1013
|
data: oldLineExtend.data,
|
|
934
1014
|
onUpdate: diffFile.notifyAll,
|
|
@@ -936,20 +1016,20 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
936
1016
|
const newExtendRendered = (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
937
1017
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
938
1018
|
diffFile,
|
|
939
|
-
side:
|
|
1019
|
+
side: core.SplitSide.new,
|
|
940
1020
|
lineNumber: newLine.lineNumber,
|
|
941
1021
|
data: newLineExtend.data,
|
|
942
1022
|
onUpdate: diffFile.notifyAll,
|
|
943
1023
|
}));
|
|
944
1024
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
945
1025
|
oldExtendRendered ? (React__namespace.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
946
|
-
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 })),
|
|
947
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 },
|
|
948
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: {
|
|
949
1029
|
backgroundColor: `var(${emptyBGName})`,
|
|
950
1030
|
borderLeftColor: `var(${borderColorName})`,
|
|
951
1031
|
borderLeftStyle: "solid",
|
|
952
|
-
}, colSpan: 2 }
|
|
1032
|
+
}, colSpan: 2 }))));
|
|
953
1033
|
};
|
|
954
1034
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
955
1035
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1074,23 +1154,23 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1074
1154
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1075
1155
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1076
1156
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1077
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1078
|
-
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;
|
|
1079
1159
|
const oldWidgetRendered = oldLineWidget &&
|
|
1080
|
-
(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({}) }));
|
|
1081
1161
|
const newWidgetRendered = newLineWidget &&
|
|
1082
|
-
(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({}) }));
|
|
1083
1163
|
if (!renderWidgetLine)
|
|
1084
1164
|
return null;
|
|
1085
1165
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1086
1166
|
oldWidgetRendered ? (React__namespace.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
1087
|
-
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 })),
|
|
1088
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" } },
|
|
1089
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: {
|
|
1090
1170
|
backgroundColor: `var(${emptyBGName})`,
|
|
1091
1171
|
borderLeftColor: `var(${borderColorName})`,
|
|
1092
1172
|
borderLeftStyle: "solid",
|
|
1093
|
-
}, colSpan: 2 }
|
|
1173
|
+
}, colSpan: 2 }))));
|
|
1094
1174
|
};
|
|
1095
1175
|
// TODO! improve performance
|
|
1096
1176
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1100,8 +1180,8 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1100
1180
|
const widgetSide = s.widgetSide;
|
|
1101
1181
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1102
1182
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1103
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1104
|
-
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;
|
|
1105
1185
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
1106
1186
|
return currentIsShow;
|
|
1107
1187
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -1110,6 +1190,93 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1110
1190
|
return React__namespace.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1111
1191
|
};
|
|
1112
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
|
+
|
|
1113
1280
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1114
1281
|
return reactivityStore.createStore(() => {
|
|
1115
1282
|
var _a, _b;
|
|
@@ -1157,6 +1324,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1157
1324
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1158
1325
|
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
1159
1326
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1327
|
+
const onCreateUseWidgetHook = reactivityStore.ref(props.onCreateUseWidgetHook);
|
|
1328
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1160
1329
|
// 避免无意义的订阅
|
|
1161
1330
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1162
1331
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1183,6 +1352,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1183
1352
|
setRenderExtendLine,
|
|
1184
1353
|
onAddWidgetClick,
|
|
1185
1354
|
setOnAddWidgetClick,
|
|
1355
|
+
onCreateUseWidgetHook,
|
|
1356
|
+
setOnCreateUseWidgetHook,
|
|
1186
1357
|
};
|
|
1187
1358
|
});
|
|
1188
1359
|
};
|
|
@@ -1201,95 +1372,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1201
1372
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1202
1373
|
});
|
|
1203
1374
|
};
|
|
1204
|
-
const createDiffSplitConfigStore = () => {
|
|
1205
|
-
return reactivityStore.createStore(() => {
|
|
1206
|
-
const splitRef = reactivityStore.ref(undefined);
|
|
1207
|
-
const setSplit = (side) => {
|
|
1208
|
-
reactDom.flushSync(() => {
|
|
1209
|
-
splitRef.value = side;
|
|
1210
|
-
});
|
|
1211
|
-
};
|
|
1212
|
-
return { splitRef, setSplit };
|
|
1213
|
-
});
|
|
1214
|
-
};
|
|
1215
|
-
|
|
1216
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1217
|
-
const Style = ({ useSelector, id, }) => {
|
|
1218
|
-
const splitRef = useSelector((s) => s.splitRef);
|
|
1219
|
-
return (React__namespace.createElement("style", { "data-select-style": true }, splitRef === exports.SplitSide.old
|
|
1220
|
-
? `#${id} td[data-side="${exports.SplitSide[exports.SplitSide.new]}"] {user-select: none}`
|
|
1221
|
-
: splitRef === exports.SplitSide.new
|
|
1222
|
-
? `#${id} td[data-side="${exports.SplitSide[exports.SplitSide.old]}"] {user-select: none}`
|
|
1223
|
-
: ""));
|
|
1224
|
-
};
|
|
1225
|
-
const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
1226
|
-
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1227
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1228
|
-
const useSplitConfig = React.useMemo(() => createDiffSplitConfigStore(), []);
|
|
1229
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
1230
|
-
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1231
|
-
const onMouseDown = React.useCallback((e) => {
|
|
1232
|
-
let ele = e.target;
|
|
1233
|
-
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1234
|
-
// need remove all the selection
|
|
1235
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1236
|
-
removeAllSelection();
|
|
1237
|
-
return;
|
|
1238
|
-
}
|
|
1239
|
-
while (ele && ele instanceof HTMLElement && ele.nodeName !== "TD") {
|
|
1240
|
-
ele = ele.parentElement;
|
|
1241
|
-
}
|
|
1242
|
-
if (ele instanceof HTMLElement) {
|
|
1243
|
-
const side = ele.getAttribute("data-side");
|
|
1244
|
-
if (side) {
|
|
1245
|
-
setSelectSide(exports.SplitSide[side]);
|
|
1246
|
-
removeAllSelection();
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1250
|
-
}, []);
|
|
1251
|
-
const font = React.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1252
|
-
const _width = useTextWidth({
|
|
1253
|
-
text: splitLineLength.toString(),
|
|
1254
|
-
font,
|
|
1255
|
-
});
|
|
1256
|
-
const width = Math.max(40, _width + 25);
|
|
1257
|
-
const lines = core.getSplitContentLines(diffFile);
|
|
1258
|
-
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1259
|
-
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1260
|
-
// @ts-ignore
|
|
1261
|
-
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1262
|
-
fontFamily: "Menlo, Consolas, monospace",
|
|
1263
|
-
fontSize: `var(${diffFontSizeName})`,
|
|
1264
|
-
} },
|
|
1265
|
-
React__namespace.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1266
|
-
React__namespace.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1267
|
-
React__namespace.createElement("colgroup", null,
|
|
1268
|
-
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1269
|
-
React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1270
|
-
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1271
|
-
React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1272
|
-
React__namespace.createElement("thead", { className: "hidden" },
|
|
1273
|
-
React__namespace.createElement("tr", null,
|
|
1274
|
-
React__namespace.createElement("th", { scope: "col" }, "old line number"),
|
|
1275
|
-
React__namespace.createElement("th", { scope: "col" }, "old line content"),
|
|
1276
|
-
React__namespace.createElement("th", { scope: "col" }, "new line number"),
|
|
1277
|
-
React__namespace.createElement("th", { scope: "col" }, "new line content"))),
|
|
1278
|
-
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1279
|
-
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
1280
|
-
React__namespace.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1281
|
-
React__namespace.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1282
|
-
React__namespace.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1283
|
-
React__namespace.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1284
|
-
React__namespace.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1285
|
-
});
|
|
1286
|
-
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1287
1375
|
|
|
1288
1376
|
const DiffSplitView = React.memo(({ diffFile }) => {
|
|
1289
1377
|
const { useDiffContext } = useDiffViewContext();
|
|
1290
1378
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1291
1379
|
useDiffContextRef.current = useDiffContext;
|
|
1292
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1380
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1381
|
+
enableWrap: s.enableWrap,
|
|
1382
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1383
|
+
}));
|
|
1293
1384
|
// performance optimization
|
|
1294
1385
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1295
1386
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1297,11 +1388,14 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
1297
1388
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1298
1389
|
setWidget({});
|
|
1299
1390
|
}, [diffFile, useWidget]);
|
|
1391
|
+
React.useEffect(() => {
|
|
1392
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1393
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1300
1394
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React__namespace.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React__namespace.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1301
1395
|
});
|
|
1302
1396
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1303
1397
|
|
|
1304
|
-
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, }) => {
|
|
1305
1399
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1306
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: {
|
|
1307
1401
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1310,15 +1404,15 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1310
1404
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1311
1405
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1312
1406
|
} },
|
|
1313
|
-
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 }) })),
|
|
1314
1408
|
React__namespace.createElement("div", { className: "flex" },
|
|
1315
1409
|
React__namespace.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
|
|
1316
1410
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1317
1411
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1318
1412
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1319
|
-
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 }))));
|
|
1320
1414
|
};
|
|
1321
|
-
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, }) => {
|
|
1322
1416
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1323
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: {
|
|
1324
1418
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1327,23 +1421,18 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1327
1421
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1328
1422
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1329
1423
|
} },
|
|
1330
|
-
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 }) })),
|
|
1331
1425
|
React__namespace.createElement("div", { className: "flex" },
|
|
1332
1426
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1333
1427
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1334
1428
|
React__namespace.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1335
1429
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1336
|
-
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 }))));
|
|
1337
1431
|
};
|
|
1338
|
-
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
1432
|
+
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1339
1433
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1340
1434
|
const { useDiffContext } = useDiffViewContext();
|
|
1341
|
-
const
|
|
1342
|
-
enableWrap: s.enableWrap,
|
|
1343
|
-
enableHighlight: s.enableHighlight,
|
|
1344
|
-
enableAddWidget: s.enableAddWidget,
|
|
1345
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1346
|
-
}));
|
|
1435
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1347
1436
|
const { useWidget } = useDiffWidgetContext();
|
|
1348
1437
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1349
1438
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1357,24 +1446,29 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1357
1446
|
: oldLinenumber
|
|
1358
1447
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1359
1448
|
: undefined;
|
|
1449
|
+
const plainLine = newLineNumber
|
|
1450
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1451
|
+
: oldLinenumber
|
|
1452
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1453
|
+
: undefined;
|
|
1360
1454
|
if (hasChange) {
|
|
1361
1455
|
if (unifiedLine.oldLineNumber) {
|
|
1362
|
-
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); } }));
|
|
1363
1457
|
}
|
|
1364
1458
|
else {
|
|
1365
|
-
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); } }));
|
|
1366
1460
|
}
|
|
1367
1461
|
}
|
|
1368
1462
|
else {
|
|
1369
1463
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1370
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: {
|
|
1371
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1465
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1372
1466
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1373
1467
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1374
1468
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1375
1469
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1376
1470
|
} },
|
|
1377
|
-
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 }) })),
|
|
1378
1472
|
React__namespace.createElement("div", { className: "flex opacity-[0.5]" },
|
|
1379
1473
|
React__namespace.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
1380
1474
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
@@ -1382,15 +1476,15 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1382
1476
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1383
1477
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1384
1478
|
} },
|
|
1385
|
-
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 }))));
|
|
1386
1480
|
}
|
|
1387
1481
|
});
|
|
1388
1482
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1389
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1483
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1390
1484
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1391
1485
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1392
1486
|
return null;
|
|
1393
|
-
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 }));
|
|
1394
1488
|
};
|
|
1395
1489
|
|
|
1396
1490
|
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -1405,13 +1499,13 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1405
1499
|
return null;
|
|
1406
1500
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1407
1501
|
React__namespace.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1408
|
-
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 } },
|
|
1409
1503
|
width > 0 &&
|
|
1410
1504
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1411
1505
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
1412
1506
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1413
1507
|
diffFile,
|
|
1414
|
-
side:
|
|
1508
|
+
side: core.SplitSide.old,
|
|
1415
1509
|
lineNumber: unifiedItem.oldLineNumber,
|
|
1416
1510
|
data: oldLineExtend.data,
|
|
1417
1511
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1421,7 +1515,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1421
1515
|
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null &&
|
|
1422
1516
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1423
1517
|
diffFile,
|
|
1424
|
-
side:
|
|
1518
|
+
side: core.SplitSide.new,
|
|
1425
1519
|
lineNumber: unifiedItem.newLineNumber,
|
|
1426
1520
|
data: newLineExtend.data,
|
|
1427
1521
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1495,8 +1589,8 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1495
1589
|
const onClose = () => setWidget({});
|
|
1496
1590
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1497
1591
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1498
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1499
|
-
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;
|
|
1500
1594
|
const { useDiffContext } = useDiffViewContext();
|
|
1501
1595
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1502
1596
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
@@ -1508,13 +1602,13 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1508
1602
|
return null;
|
|
1509
1603
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1510
1604
|
React__namespace.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
|
|
1511
|
-
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 } },
|
|
1512
1606
|
width > 0 &&
|
|
1513
1607
|
oldWidget &&
|
|
1514
|
-
(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 })),
|
|
1515
1609
|
width > 0 &&
|
|
1516
1610
|
newWidget &&
|
|
1517
|
-
(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 }))))));
|
|
1518
1612
|
};
|
|
1519
1613
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1520
1614
|
const { useWidget } = useDiffWidgetContext();
|
|
@@ -1522,8 +1616,8 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1522
1616
|
const widgetLineNumber = s.widgetLineNumber;
|
|
1523
1617
|
const widgetSide = s.widgetSide;
|
|
1524
1618
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1525
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1526
|
-
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;
|
|
1527
1621
|
const currentIsShow = oldWidget || newWidget;
|
|
1528
1622
|
return currentIsShow;
|
|
1529
1623
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -1533,30 +1627,29 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1533
1627
|
};
|
|
1534
1628
|
|
|
1535
1629
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1536
|
-
const onMouseDown = (e) => {
|
|
1537
|
-
const ele = e.target;
|
|
1538
|
-
// need remove all the selection
|
|
1539
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1540
|
-
removeAllSelection();
|
|
1541
|
-
return;
|
|
1542
|
-
}
|
|
1543
|
-
};
|
|
1544
1630
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
1545
1631
|
const { useDiffContext } = useDiffViewContext();
|
|
1632
|
+
const ref = React.useRef(null);
|
|
1546
1633
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1547
1634
|
useDiffContextRef.current = useDiffContext;
|
|
1548
1635
|
// performance optimization
|
|
1549
1636
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1550
1637
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
1551
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1638
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1552
1639
|
fontSize: s.fontSize,
|
|
1553
1640
|
enableWrap: s.enableWrap,
|
|
1641
|
+
enableHighlight: s.enableHighlight,
|
|
1642
|
+
enableAddWidget: s.enableAddWidget,
|
|
1643
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1554
1644
|
}));
|
|
1555
1645
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1556
1646
|
React.useEffect(() => {
|
|
1557
1647
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1558
1648
|
setWidget({});
|
|
1559
1649
|
}, [diffFile, useWidget]);
|
|
1650
|
+
React.useEffect(() => {
|
|
1651
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1652
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1560
1653
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1561
1654
|
const _width = useTextWidth({
|
|
1562
1655
|
text: unifiedLineLength.toString(),
|
|
@@ -1564,8 +1657,44 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1564
1657
|
});
|
|
1565
1658
|
const width = Math.max(40, _width + 10);
|
|
1566
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
|
+
};
|
|
1567
1695
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1568
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 }),
|
|
1569
1698
|
React__namespace.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1570
1699
|
// @ts-ignore
|
|
1571
1700
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1583,7 +1712,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1583
1712
|
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1584
1713
|
lines.map((item) => (React__namespace.createElement(React.Fragment, { key: item.index },
|
|
1585
1714
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1586
|
-
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 }),
|
|
1587
1716
|
React__namespace.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1588
1717
|
React__namespace.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1589
1718
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1591,11 +1720,6 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1591
1720
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1592
1721
|
|
|
1593
1722
|
core._cacheMap.name = "@git-diff-view/react";
|
|
1594
|
-
exports.SplitSide = void 0;
|
|
1595
|
-
(function (SplitSide) {
|
|
1596
|
-
SplitSide[SplitSide["old"] = 1] = "old";
|
|
1597
|
-
SplitSide[SplitSide["new"] = 2] = "new";
|
|
1598
|
-
})(exports.SplitSide || (exports.SplitSide = {}));
|
|
1599
1723
|
exports.DiffModeEnum = void 0;
|
|
1600
1724
|
(function (DiffModeEnum) {
|
|
1601
1725
|
// github like
|
|
@@ -1606,7 +1730,7 @@ exports.DiffModeEnum = void 0;
|
|
|
1606
1730
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1607
1731
|
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1608
1732
|
const InternalDiffView = (props) => {
|
|
1609
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
|
|
1733
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1610
1734
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1611
1735
|
const wrapperRef = React.useRef();
|
|
1612
1736
|
// performance optimization
|
|
@@ -1614,7 +1738,7 @@ const InternalDiffView = (props) => {
|
|
|
1614
1738
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1615
1739
|
[]);
|
|
1616
1740
|
React.useEffect(() => {
|
|
1617
|
-
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, } = useDiffContext.getReadonlyState();
|
|
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();
|
|
1618
1742
|
if (diffFileId && diffFileId !== id) {
|
|
1619
1743
|
setId(diffFileId);
|
|
1620
1744
|
}
|
|
@@ -1642,6 +1766,9 @@ const InternalDiffView = (props) => {
|
|
|
1642
1766
|
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1643
1767
|
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1644
1768
|
}
|
|
1769
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1770
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1771
|
+
}
|
|
1645
1772
|
if (renderExtendLine !== _renderExtendLine) {
|
|
1646
1773
|
setRenderExtendLine(renderExtendLine);
|
|
1647
1774
|
}
|
|
@@ -1661,6 +1788,7 @@ const InternalDiffView = (props) => {
|
|
|
1661
1788
|
renderExtendLine,
|
|
1662
1789
|
extendData,
|
|
1663
1790
|
onAddWidgetClick,
|
|
1791
|
+
onCreateUseWidgetHook,
|
|
1664
1792
|
]);
|
|
1665
1793
|
React.useEffect(() => {
|
|
1666
1794
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1672,7 +1800,7 @@ const InternalDiffView = (props) => {
|
|
|
1672
1800
|
}, [diffFile]);
|
|
1673
1801
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1674
1802
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1675
|
-
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 },
|
|
1676
1804
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1677
1805
|
// @ts-ignore
|
|
1678
1806
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1738,8 +1866,12 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1738
1866
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1739
1867
|
InnerDiffView.displayName = "DiffView";
|
|
1740
1868
|
const DiffView = InnerDiffView;
|
|
1741
|
-
const version = "0.0.
|
|
1869
|
+
const version = "0.0.27";
|
|
1742
1870
|
|
|
1871
|
+
Object.defineProperty(exports, "SplitSide", {
|
|
1872
|
+
enumerable: true,
|
|
1873
|
+
get: function () { return core.SplitSide; }
|
|
1874
|
+
});
|
|
1743
1875
|
exports.DiffView = DiffView;
|
|
1744
1876
|
exports.version = version;
|
|
1745
1877
|
Object.keys(core).forEach(function (k) {
|