@git-diff-view/react 0.0.26 → 0.0.28
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 +431 -290
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +431 -290
- 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 +362 -224
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +303 -23
- 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 = () => {
|
|
@@ -220,13 +221,22 @@ const memoFunc = (func) => {
|
|
|
220
221
|
});
|
|
221
222
|
};
|
|
222
223
|
|
|
224
|
+
var NewLineSymbol;
|
|
225
|
+
(function (NewLineSymbol) {
|
|
226
|
+
NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
|
|
227
|
+
NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
|
|
228
|
+
NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
|
|
229
|
+
NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
|
|
230
|
+
NewLineSymbol[NewLineSymbol["NORMAL"] = 5] = "NORMAL";
|
|
231
|
+
NewLineSymbol[NewLineSymbol["NULL"] = 6] = "NULL";
|
|
232
|
+
})(NewLineSymbol || (NewLineSymbol = {}));
|
|
223
233
|
const getSymbol = (symbol) => {
|
|
224
234
|
switch (symbol) {
|
|
225
|
-
case
|
|
235
|
+
case NewLineSymbol.LF:
|
|
226
236
|
return "␊";
|
|
227
|
-
case
|
|
237
|
+
case NewLineSymbol.CR:
|
|
228
238
|
return "␍";
|
|
229
|
-
case
|
|
239
|
+
case NewLineSymbol.CRLF:
|
|
230
240
|
return "␍␊";
|
|
231
241
|
default:
|
|
232
242
|
return "";
|
|
@@ -299,6 +309,7 @@ const DiffNoNewLine = () => {
|
|
|
299
309
|
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
310
|
};
|
|
301
311
|
|
|
312
|
+
/* eslint-disable max-lines */
|
|
302
313
|
const temp = {};
|
|
303
314
|
const formatStringToCamelCase = (str) => {
|
|
304
315
|
if (str.startsWith("--"))
|
|
@@ -325,30 +336,52 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
325
336
|
});
|
|
326
337
|
return style;
|
|
327
338
|
});
|
|
328
|
-
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
339
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
329
340
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
330
341
|
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
342
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
343
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof core.getPlainDiffTemplate === "function") {
|
|
344
|
+
core.getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
345
|
+
}
|
|
346
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
347
|
+
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
348
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
349
|
+
isNewLineSymbolChanged === 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: {
|
|
350
|
+
width: `var(${diffFontSizeName})`,
|
|
351
|
+
height: `var(${diffFontSizeName})`,
|
|
352
|
+
} },
|
|
353
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
// TODO remove
|
|
357
|
+
const range = changes.range;
|
|
358
|
+
const str1 = rawLine.slice(0, range.location);
|
|
359
|
+
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
360
|
+
const str3 = rawLine.slice(range.location + range.length);
|
|
361
|
+
const isLast = str2.includes("\n");
|
|
362
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
363
|
+
return (React__namespace.createElement("span", { className: "diff-line-content-raw" },
|
|
364
|
+
React__namespace.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
365
|
+
str1,
|
|
366
|
+
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
367
|
+
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
368
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
369
|
+
_str2,
|
|
370
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
371
|
+
str3),
|
|
372
|
+
isNewLineSymbolChanged === 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: {
|
|
373
|
+
width: `var(${diffFontSizeName})`,
|
|
374
|
+
height: `var(${diffFontSizeName})`,
|
|
375
|
+
} },
|
|
376
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
380
|
+
plainLine.template = core.getPlainLineTemplate(plainLine.value);
|
|
381
|
+
}
|
|
382
|
+
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
338
383
|
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)))));
|
|
384
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
352
385
|
}
|
|
353
386
|
return React__namespace.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
354
387
|
};
|
|
@@ -360,49 +393,73 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
360
393
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
361
394
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
362
395
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
363
|
-
|
|
396
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof core.getSyntaxDiffTemplate === "function") {
|
|
397
|
+
core.getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
398
|
+
}
|
|
399
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
400
|
+
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
401
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
402
|
+
isNewLineSymbolChanged === 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: {
|
|
403
|
+
width: `var(${diffFontSizeName})`,
|
|
404
|
+
height: `var(${diffFontSizeName})`,
|
|
405
|
+
} },
|
|
406
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
// TODO remove
|
|
410
|
+
const range = changes.range;
|
|
411
|
+
return (React__namespace.createElement("span", { className: "diff-line-syntax-raw" },
|
|
412
|
+
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) => {
|
|
413
|
+
var _a, _b, _c, _d, _e, _f;
|
|
414
|
+
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
415
|
+
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));
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
const index1 = range.location - node.startIndex;
|
|
419
|
+
const index2 = index1 < 0 ? 0 : index1;
|
|
420
|
+
const str1 = node.value.slice(0, index2);
|
|
421
|
+
const str2 = node.value.slice(index2, index1 + range.length);
|
|
422
|
+
const str3 = node.value.slice(index1 + range.length);
|
|
423
|
+
const isStart = str1.length || range.location === node.startIndex;
|
|
424
|
+
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
425
|
+
const isLast = str2.includes("\n");
|
|
426
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
427
|
+
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) || "") },
|
|
428
|
+
str1,
|
|
429
|
+
React__namespace.createElement("span", { "data-diff-highlight": true, style: {
|
|
430
|
+
backgroundColor: operator === "add"
|
|
431
|
+
? `var(${addContentHighlightBGName})`
|
|
432
|
+
: `var(${delContentHighlightBGName})`,
|
|
433
|
+
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
434
|
+
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
435
|
+
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
436
|
+
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
437
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
438
|
+
_str2,
|
|
439
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
440
|
+
str3));
|
|
441
|
+
}
|
|
442
|
+
})),
|
|
443
|
+
isNewLineSymbolChanged === 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: {
|
|
444
|
+
width: `var(${diffFontSizeName})`,
|
|
445
|
+
height: `var(${diffFontSizeName})`,
|
|
446
|
+
} },
|
|
447
|
+
React__namespace.createElement(DiffNoNewLine, null)))));
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (!syntaxLine.template) {
|
|
451
|
+
syntaxLine.template = core.getSyntaxLineTemplate(syntaxLine);
|
|
452
|
+
}
|
|
453
|
+
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
364
454
|
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)))));
|
|
455
|
+
React__namespace.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
399
456
|
}
|
|
400
457
|
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
458
|
var _a, _b, _c;
|
|
402
459
|
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
460
|
})));
|
|
404
461
|
};
|
|
405
|
-
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
462
|
+
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
406
463
|
var _a;
|
|
407
464
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Add;
|
|
408
465
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === core.DiffLineType.Delete;
|
|
@@ -414,7 +471,7 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
414
471
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
415
472
|
} },
|
|
416
473
|
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 }))));
|
|
474
|
+
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
475
|
};
|
|
419
476
|
|
|
420
477
|
const DiffViewContext = React.createContext(null);
|
|
@@ -425,48 +482,46 @@ const DiffWidgetContext = React.createContext(null);
|
|
|
425
482
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
426
483
|
const useDiffWidgetContext = () => React.useContext(DiffWidgetContext);
|
|
427
484
|
|
|
428
|
-
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
485
|
+
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
429
486
|
var _a, _b;
|
|
430
|
-
const getCurrentSyntaxLine = side ===
|
|
487
|
+
const getCurrentSyntaxLine = side === core.SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
488
|
+
const getCurrentPlainLine = side === core.SplitSide.old ? diffFile.getOldPlainLine : diffFile.getNewPlainLine;
|
|
431
489
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
432
490
|
const newLine = diffFile.getSplitRightLine(index);
|
|
433
|
-
const currentLine = side ===
|
|
491
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
434
492
|
const hasDiff = !!(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
435
493
|
const hasContent = !!currentLine.lineNumber;
|
|
436
494
|
const hasChange = core.checkDiffLineIncludeChange(currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff);
|
|
437
495
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Add;
|
|
438
496
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Delete;
|
|
439
497
|
const { useDiffContext } = useDiffViewContext();
|
|
440
|
-
const
|
|
441
|
-
enableHighlight: s.enableHighlight,
|
|
442
|
-
enableAddWidget: s.enableAddWidget,
|
|
443
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
444
|
-
}));
|
|
498
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
445
499
|
const { useWidget } = useDiffWidgetContext();
|
|
446
500
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
447
501
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
448
502
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
449
503
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
450
|
-
|
|
451
|
-
|
|
504
|
+
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
505
|
+
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,
|
|
506
|
+
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
507
|
backgroundColor: lineNumberBG,
|
|
453
|
-
color: `var(${plainLineNumberColorName})`,
|
|
508
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
454
509
|
width: `var(${diffAsideWidthName})`,
|
|
455
510
|
minWidth: `var(${diffAsideWidthName})`,
|
|
456
511
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
457
512
|
} },
|
|
458
513
|
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
514
|
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-${
|
|
515
|
+
React__namespace.createElement("td", { className: `diff-line-${core.SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
516
|
+
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
517
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
463
518
|
};
|
|
464
|
-
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
465
|
-
const getCurrentLine = side ===
|
|
519
|
+
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
520
|
+
const getCurrentLine = side === core.SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
466
521
|
const currentLine = getCurrentLine(index);
|
|
467
522
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
468
523
|
return null;
|
|
469
|
-
return React__namespace.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
524
|
+
return (React__namespace.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
470
525
|
};
|
|
471
526
|
|
|
472
527
|
const useDomWidth = ({ selector, enable }) => {
|
|
@@ -570,9 +625,9 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
570
625
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
571
626
|
const newLine = diffFile.getSplitRightLine(index);
|
|
572
627
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
573
|
-
const currentExtend = side ===
|
|
574
|
-
const otherSide = side ===
|
|
575
|
-
const currentLineNumber = side ===
|
|
628
|
+
const currentExtend = side === core.SplitSide.old ? oldLineExtend : newLineExtend;
|
|
629
|
+
const otherSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
630
|
+
const currentLineNumber = side === core.SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
576
631
|
const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
|
|
577
632
|
const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
|
|
578
633
|
((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
|
|
@@ -587,18 +642,18 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
587
642
|
useSyncHeight({
|
|
588
643
|
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
589
644
|
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
590
|
-
side:
|
|
645
|
+
side: core.SplitSide[currentSideHasExtend ? side : otherSide],
|
|
591
646
|
enable: hasExtend && typeof renderExtendLine === "function",
|
|
592
647
|
});
|
|
593
648
|
const width = useDomWidth({
|
|
594
|
-
selector: side ===
|
|
649
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
595
650
|
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
596
651
|
});
|
|
597
652
|
if (!renderExtendLine)
|
|
598
653
|
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":
|
|
654
|
+
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 },
|
|
655
|
+
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 },
|
|
656
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": core.SplitSide[side] })))));
|
|
602
657
|
};
|
|
603
658
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
604
659
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -614,7 +669,7 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
614
669
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
615
670
|
// if the expand action not enabled, the `isHidden` property will never change
|
|
616
671
|
const enableExpand = diffFile.getExpandEnabled();
|
|
617
|
-
const currentLine = side ===
|
|
672
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
618
673
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
619
674
|
if (!currentIsShow)
|
|
620
675
|
return null;
|
|
@@ -640,17 +695,17 @@ const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, })
|
|
|
640
695
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
641
696
|
useSyncHeight({
|
|
642
697
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
643
|
-
side:
|
|
644
|
-
enable: side ===
|
|
698
|
+
side: core.SplitSide[core.SplitSide.old],
|
|
699
|
+
enable: side === core.SplitSide.new,
|
|
645
700
|
});
|
|
646
|
-
const enableHunkAction = side ===
|
|
701
|
+
const enableHunkAction = side === core.SplitSide.old;
|
|
647
702
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
648
703
|
const isExpandAll = currentHunk &&
|
|
649
704
|
currentHunk.splitInfo &&
|
|
650
705
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
651
706
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
652
707
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
653
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side":
|
|
708
|
+
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
709
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
655
710
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
656
711
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -677,7 +732,7 @@ const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, })
|
|
|
677
732
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
678
733
|
useSyncHeight({
|
|
679
734
|
selector: `tr[data-line="${lineNumber}-hunk"]`,
|
|
680
|
-
side:
|
|
735
|
+
side: core.SplitSide[side],
|
|
681
736
|
enable: true,
|
|
682
737
|
});
|
|
683
738
|
const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
|
|
@@ -686,7 +741,7 @@ const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, })
|
|
|
686
741
|
currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < core.composeLen;
|
|
687
742
|
const isFirstLine = currentHunk && currentHunk.isFirst;
|
|
688
743
|
const isLastLine = currentHunk && currentHunk.isLast;
|
|
689
|
-
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side":
|
|
744
|
+
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": core.SplitSide[side], className: "diff-line diff-line-hunk" },
|
|
690
745
|
React__namespace.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
|
|
691
746
|
backgroundColor: `var(${hunkLineNumberBGName})`,
|
|
692
747
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -737,11 +792,11 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
737
792
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
738
793
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
739
794
|
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 ===
|
|
795
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
796
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
797
|
+
const currentLine = side === core.SplitSide.old ? oldLine : newLine;
|
|
798
|
+
const otherSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
799
|
+
const currentHasWidget = side === core.SplitSide.old ? oldLineWidget : newLineWidget;
|
|
745
800
|
const hasWidget = oldLineWidget || newLineWidget;
|
|
746
801
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
747
802
|
const currentWidgetRendered = currentHasWidget &&
|
|
@@ -754,18 +809,18 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
754
809
|
useSyncHeight({
|
|
755
810
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
756
811
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
757
|
-
side:
|
|
812
|
+
side: core.SplitSide[currentHasWidget ? side : otherSide],
|
|
758
813
|
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
759
814
|
});
|
|
760
815
|
const width = useDomWidth({
|
|
761
|
-
selector: side ===
|
|
816
|
+
selector: side === core.SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
762
817
|
enable: !!currentHasWidget && typeof renderWidgetLine === "function",
|
|
763
818
|
});
|
|
764
819
|
if (!renderWidgetLine)
|
|
765
820
|
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":
|
|
821
|
+
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 },
|
|
822
|
+
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 },
|
|
823
|
+
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": core.SplitSide[side] })))));
|
|
769
824
|
};
|
|
770
825
|
// TODO! improve performance
|
|
771
826
|
const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
@@ -775,8 +830,8 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
775
830
|
const widgetSide = s.widgetSide;
|
|
776
831
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
777
832
|
const newLine = diffFile.getSplitRightLine(index);
|
|
778
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
779
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
833
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
834
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
780
835
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
781
836
|
return currentIsShow;
|
|
782
837
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -786,33 +841,25 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
786
841
|
};
|
|
787
842
|
|
|
788
843
|
/* 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";
|
|
844
|
+
const DiffSplitViewTable = ({ side, diffFile, enableAddWidget, enableHighlight, onMouseDown, }) => {
|
|
845
|
+
const className = side === core.SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
799
846
|
const lines = core.getSplitContentLines(diffFile);
|
|
800
|
-
return (React__namespace.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode":
|
|
847
|
+
return (React__namespace.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": core.SplitSide[side] },
|
|
801
848
|
React__namespace.createElement("colgroup", null,
|
|
802
|
-
React__namespace.createElement("col", { className: `diff-table-${
|
|
803
|
-
React__namespace.createElement("col", { className: `diff-table-${
|
|
849
|
+
React__namespace.createElement("col", { className: `diff-table-${core.SplitSide[side]}-num-col` }),
|
|
850
|
+
React__namespace.createElement("col", { className: `diff-table-${core.SplitSide[side]}-content-col` })),
|
|
804
851
|
React__namespace.createElement("thead", { className: "hidden" },
|
|
805
852
|
React__namespace.createElement("tr", null,
|
|
806
853
|
React__namespace.createElement("th", { scope: "col" },
|
|
807
|
-
|
|
854
|
+
core.SplitSide[side],
|
|
808
855
|
" line number"),
|
|
809
856
|
React__namespace.createElement("th", { scope: "col" },
|
|
810
|
-
|
|
857
|
+
core.SplitSide[side],
|
|
811
858
|
" line content"))),
|
|
812
|
-
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown
|
|
859
|
+
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
813
860
|
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
814
861
|
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 }),
|
|
862
|
+
React__namespace.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
816
863
|
React__namespace.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
817
864
|
React__namespace.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
818
865
|
React__namespace.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -820,9 +867,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
820
867
|
const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
821
868
|
const ref1 = React.useRef(null);
|
|
822
869
|
const ref2 = React.useRef(null);
|
|
870
|
+
const ref = React.useRef();
|
|
823
871
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
824
872
|
const { useDiffContext } = useDiffViewContext();
|
|
825
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) =>
|
|
873
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
874
|
+
fontSize: s.fontSize,
|
|
875
|
+
enableAddWidget: s.enableAddWidget,
|
|
876
|
+
enableHighlight: s.enableHighlight,
|
|
877
|
+
}));
|
|
826
878
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
827
879
|
React.useEffect(() => {
|
|
828
880
|
const left = ref1.current;
|
|
@@ -837,7 +889,46 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
837
889
|
font,
|
|
838
890
|
});
|
|
839
891
|
const width = Math.max(40, _width + 25);
|
|
892
|
+
const setStyle = (side) => {
|
|
893
|
+
if (!ref.current)
|
|
894
|
+
return;
|
|
895
|
+
if (!side) {
|
|
896
|
+
ref.current.textContent = "";
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
900
|
+
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}`;
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
const onMouseDown = (e) => {
|
|
904
|
+
let ele = e.target;
|
|
905
|
+
// need remove all the selection
|
|
906
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
907
|
+
removeAllSelection();
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
while (ele && ele instanceof HTMLElement) {
|
|
911
|
+
const state = ele.getAttribute("data-state");
|
|
912
|
+
const side = ele.getAttribute("data-side");
|
|
913
|
+
if (side) {
|
|
914
|
+
setStyle(core.SplitSide[side]);
|
|
915
|
+
removeAllSelection();
|
|
916
|
+
}
|
|
917
|
+
if (state) {
|
|
918
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
919
|
+
setStyle(undefined);
|
|
920
|
+
removeAllSelection();
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
ele = ele.parentElement;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
840
930
|
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
|
|
931
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
841
932
|
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
933
|
// @ts-ignore
|
|
843
934
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -845,7 +936,7 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
845
936
|
fontFamily: "Menlo, Consolas, monospace",
|
|
846
937
|
fontSize: `var(${diffFontSizeName})`,
|
|
847
938
|
} },
|
|
848
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
939
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
849
940
|
React__namespace.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
850
941
|
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
942
|
// @ts-ignore
|
|
@@ -854,26 +945,24 @@ const DiffSplitViewNormal = React.memo(({ diffFile }) => {
|
|
|
854
945
|
fontFamily: "Menlo, Consolas, monospace",
|
|
855
946
|
fontSize: `var(${diffFontSizeName})`,
|
|
856
947
|
} },
|
|
857
|
-
React__namespace.createElement(DiffSplitViewTable, { side:
|
|
948
|
+
React__namespace.createElement(DiffSplitViewTable, { side: core.SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
858
949
|
});
|
|
859
950
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
860
951
|
|
|
861
|
-
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
952
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
862
953
|
var _a, _b;
|
|
863
954
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
864
955
|
const newLine = diffFile.getSplitRightLine(index);
|
|
865
956
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
957
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
866
958
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
959
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
867
960
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
868
961
|
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
962
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === core.DiffLineType.Delete;
|
|
870
963
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === core.DiffLineType.Add;
|
|
871
964
|
const { useDiffContext } = useDiffViewContext();
|
|
872
|
-
const
|
|
873
|
-
enableHighlight: s.enableHighlight,
|
|
874
|
-
enableAddWidget: s.enableAddWidget,
|
|
875
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
876
|
-
}));
|
|
965
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
877
966
|
const { useWidget } = useDiffWidgetContext();
|
|
878
967
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
879
968
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -884,37 +973,37 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
884
973
|
const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
|
|
885
974
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
|
|
886
975
|
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:
|
|
976
|
+
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})` } },
|
|
977
|
+
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
978
|
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":
|
|
979
|
+
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 } },
|
|
980
|
+
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 }) })),
|
|
981
|
+
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
982
|
React__namespace.createElement("span", null, "\u2002"))),
|
|
894
983
|
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":
|
|
984
|
+
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
985
|
backgroundColor: newLineNumberBG,
|
|
897
|
-
color: `var(${plainLineNumberColorName})`,
|
|
986
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
898
987
|
borderLeftColor: `var(${borderColorName})`,
|
|
899
988
|
borderLeftStyle: "solid",
|
|
900
989
|
} },
|
|
901
|
-
hasDiff && enableAddWidget && (React__namespace.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side:
|
|
990
|
+
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
991
|
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: {
|
|
992
|
+
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 } },
|
|
993
|
+
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 }) })),
|
|
994
|
+
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
995
|
backgroundColor: `var(${emptyBGName})`,
|
|
907
996
|
borderLeftColor: `var(${borderColorName})`,
|
|
908
997
|
borderLeftStyle: "solid",
|
|
909
|
-
}, "data-side":
|
|
998
|
+
}, "data-side": core.SplitSide[core.SplitSide.new], colSpan: 2 },
|
|
910
999
|
React__namespace.createElement("span", null, "\u2002")))));
|
|
911
1000
|
};
|
|
912
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1001
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
913
1002
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
914
1003
|
const newLine = diffFile.getSplitRightLine(index);
|
|
915
1004
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
916
1005
|
return null;
|
|
917
|
-
return React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1006
|
+
return (React__namespace.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
918
1007
|
};
|
|
919
1008
|
|
|
920
1009
|
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -928,7 +1017,7 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
928
1017
|
const oldExtendRendered = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) &&
|
|
929
1018
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
930
1019
|
diffFile,
|
|
931
|
-
side:
|
|
1020
|
+
side: core.SplitSide.old,
|
|
932
1021
|
lineNumber: oldLine.lineNumber,
|
|
933
1022
|
data: oldLineExtend.data,
|
|
934
1023
|
onUpdate: diffFile.notifyAll,
|
|
@@ -936,20 +1025,20 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
936
1025
|
const newExtendRendered = (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
|
|
937
1026
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
938
1027
|
diffFile,
|
|
939
|
-
side:
|
|
1028
|
+
side: core.SplitSide.new,
|
|
940
1029
|
lineNumber: newLine.lineNumber,
|
|
941
1030
|
data: newLineExtend.data,
|
|
942
1031
|
onUpdate: diffFile.notifyAll,
|
|
943
1032
|
}));
|
|
944
1033
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
945
1034
|
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 }
|
|
1035
|
+
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
1036
|
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
1037
|
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
1038
|
backgroundColor: `var(${emptyBGName})`,
|
|
950
1039
|
borderLeftColor: `var(${borderColorName})`,
|
|
951
1040
|
borderLeftStyle: "solid",
|
|
952
|
-
}, colSpan: 2 }
|
|
1041
|
+
}, colSpan: 2 }))));
|
|
953
1042
|
};
|
|
954
1043
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
955
1044
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1074,23 +1163,23 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1074
1163
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1075
1164
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1076
1165
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1077
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1078
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
1166
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1167
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1079
1168
|
const oldWidgetRendered = oldLineWidget &&
|
|
1080
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1169
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.old, lineNumber: oldLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1081
1170
|
const newWidgetRendered = newLineWidget &&
|
|
1082
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1171
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.new, lineNumber: newLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1083
1172
|
if (!renderWidgetLine)
|
|
1084
1173
|
return null;
|
|
1085
1174
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1086
1175
|
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 }
|
|
1176
|
+
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
1177
|
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
1178
|
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
1179
|
backgroundColor: `var(${emptyBGName})`,
|
|
1091
1180
|
borderLeftColor: `var(${borderColorName})`,
|
|
1092
1181
|
borderLeftStyle: "solid",
|
|
1093
|
-
}, colSpan: 2 }
|
|
1182
|
+
}, colSpan: 2 }))));
|
|
1094
1183
|
};
|
|
1095
1184
|
// TODO! improve performance
|
|
1096
1185
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1100,8 +1189,8 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1100
1189
|
const widgetSide = s.widgetSide;
|
|
1101
1190
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1102
1191
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1103
|
-
const oldLineWidget = oldLine.lineNumber && widgetSide ===
|
|
1104
|
-
const newLineWidget = newLine.lineNumber && widgetSide ===
|
|
1192
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1193
|
+
const newLineWidget = newLine.lineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1105
1194
|
const currentIsShow = oldLineWidget || newLineWidget;
|
|
1106
1195
|
return currentIsShow;
|
|
1107
1196
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -1110,6 +1199,93 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1110
1199
|
return React__namespace.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1111
1200
|
};
|
|
1112
1201
|
|
|
1202
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1203
|
+
const DiffSplitViewWrap = React.memo(({ diffFile }) => {
|
|
1204
|
+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1205
|
+
const { useDiffContext } = useDiffViewContext();
|
|
1206
|
+
const ref = React.useRef(null);
|
|
1207
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1208
|
+
fontSize: s.fontSize,
|
|
1209
|
+
enableAddWidget: s.enableAddWidget,
|
|
1210
|
+
enableHighlight: s.enableHighlight,
|
|
1211
|
+
}));
|
|
1212
|
+
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1213
|
+
const font = React.useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1214
|
+
const _width = useTextWidth({
|
|
1215
|
+
text: splitLineLength.toString(),
|
|
1216
|
+
font,
|
|
1217
|
+
});
|
|
1218
|
+
const width = Math.max(40, _width + 25);
|
|
1219
|
+
const lines = core.getSplitContentLines(diffFile);
|
|
1220
|
+
const setStyle = (side) => {
|
|
1221
|
+
if (!ref.current)
|
|
1222
|
+
return;
|
|
1223
|
+
if (!side) {
|
|
1224
|
+
ref.current.textContent = "";
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1228
|
+
const targetSide = side === core.SplitSide.old ? core.SplitSide.new : core.SplitSide.old;
|
|
1229
|
+
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}`;
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
const onMouseDown = (e) => {
|
|
1233
|
+
let ele = e.target;
|
|
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) {
|
|
1240
|
+
const state = ele.getAttribute("data-state");
|
|
1241
|
+
const side = ele.getAttribute("data-side");
|
|
1242
|
+
if (side) {
|
|
1243
|
+
setStyle(core.SplitSide[side]);
|
|
1244
|
+
removeAllSelection();
|
|
1245
|
+
}
|
|
1246
|
+
if (state) {
|
|
1247
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1248
|
+
setStyle(undefined);
|
|
1249
|
+
removeAllSelection();
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
else {
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
ele = ele.parentElement;
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
return (React__namespace.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1260
|
+
React__namespace.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1261
|
+
// @ts-ignore
|
|
1262
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1263
|
+
fontFamily: "Menlo, Consolas, monospace",
|
|
1264
|
+
fontSize: `var(${diffFontSizeName})`,
|
|
1265
|
+
} },
|
|
1266
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1267
|
+
React__namespace.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1268
|
+
React__namespace.createElement("colgroup", null,
|
|
1269
|
+
React__namespace.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1270
|
+
React__namespace.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1271
|
+
React__namespace.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1272
|
+
React__namespace.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1273
|
+
React__namespace.createElement("thead", { className: "hidden" },
|
|
1274
|
+
React__namespace.createElement("tr", null,
|
|
1275
|
+
React__namespace.createElement("th", { scope: "col" }, "old line number"),
|
|
1276
|
+
React__namespace.createElement("th", { scope: "col" }, "old line content"),
|
|
1277
|
+
React__namespace.createElement("th", { scope: "col" }, "new line number"),
|
|
1278
|
+
React__namespace.createElement("th", { scope: "col" }, "new line content"))),
|
|
1279
|
+
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1280
|
+
lines.map((line) => (React__namespace.createElement(React.Fragment, { key: line.index },
|
|
1281
|
+
React__namespace.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1282
|
+
React__namespace.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
1283
|
+
React__namespace.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1284
|
+
React__namespace.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1285
|
+
React__namespace.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1286
|
+
});
|
|
1287
|
+
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1288
|
+
|
|
1113
1289
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1114
1290
|
return reactivityStore.createStore(() => {
|
|
1115
1291
|
var _a, _b;
|
|
@@ -1157,6 +1333,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1157
1333
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1158
1334
|
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
1159
1335
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1336
|
+
const onCreateUseWidgetHook = reactivityStore.ref(props.onCreateUseWidgetHook);
|
|
1337
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1160
1338
|
// 避免无意义的订阅
|
|
1161
1339
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1162
1340
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1183,6 +1361,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1183
1361
|
setRenderExtendLine,
|
|
1184
1362
|
onAddWidgetClick,
|
|
1185
1363
|
setOnAddWidgetClick,
|
|
1364
|
+
onCreateUseWidgetHook,
|
|
1365
|
+
setOnCreateUseWidgetHook,
|
|
1186
1366
|
};
|
|
1187
1367
|
});
|
|
1188
1368
|
};
|
|
@@ -1201,95 +1381,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1201
1381
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1202
1382
|
});
|
|
1203
1383
|
};
|
|
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
1384
|
|
|
1288
1385
|
const DiffSplitView = React.memo(({ diffFile }) => {
|
|
1289
1386
|
const { useDiffContext } = useDiffViewContext();
|
|
1290
1387
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1291
1388
|
useDiffContextRef.current = useDiffContext;
|
|
1292
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1389
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1390
|
+
enableWrap: s.enableWrap,
|
|
1391
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1392
|
+
}));
|
|
1293
1393
|
// performance optimization
|
|
1294
1394
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1295
1395
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1297,11 +1397,14 @@ const DiffSplitView = React.memo(({ diffFile }) => {
|
|
|
1297
1397
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1298
1398
|
setWidget({});
|
|
1299
1399
|
}, [diffFile, useWidget]);
|
|
1400
|
+
React.useEffect(() => {
|
|
1401
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1402
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1300
1403
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React__namespace.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React__namespace.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1301
1404
|
});
|
|
1302
1405
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1303
1406
|
|
|
1304
|
-
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1407
|
+
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1305
1408
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1306
1409
|
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
1410
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1310,15 +1413,15 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1310
1413
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1311
1414
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1312
1415
|
} },
|
|
1313
|
-
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side:
|
|
1416
|
+
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
1417
|
React__namespace.createElement("div", { className: "flex" },
|
|
1315
1418
|
React__namespace.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
|
|
1316
1419
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1317
1420
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1318
1421
|
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 }))));
|
|
1422
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1320
1423
|
};
|
|
1321
|
-
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1424
|
+
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1322
1425
|
return (React__namespace.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1323
1426
|
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
1427
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1327,23 +1430,18 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1327
1430
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1328
1431
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1329
1432
|
} },
|
|
1330
|
-
enableAddWidget && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side:
|
|
1433
|
+
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
1434
|
React__namespace.createElement("div", { className: "flex" },
|
|
1332
1435
|
React__namespace.createElement("span", { className: "inline-block w-[50%]" }),
|
|
1333
1436
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1334
1437
|
React__namespace.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1335
1438
|
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 }))));
|
|
1439
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1337
1440
|
};
|
|
1338
|
-
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
1441
|
+
const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1339
1442
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1340
1443
|
const { useDiffContext } = useDiffViewContext();
|
|
1341
|
-
const
|
|
1342
|
-
enableWrap: s.enableWrap,
|
|
1343
|
-
enableHighlight: s.enableHighlight,
|
|
1344
|
-
enableAddWidget: s.enableAddWidget,
|
|
1345
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1346
|
-
}));
|
|
1444
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1347
1445
|
const { useWidget } = useDiffWidgetContext();
|
|
1348
1446
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1349
1447
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1357,24 +1455,29 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1357
1455
|
: oldLinenumber
|
|
1358
1456
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1359
1457
|
: undefined;
|
|
1458
|
+
const plainLine = newLineNumber
|
|
1459
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1460
|
+
: oldLinenumber
|
|
1461
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1462
|
+
: undefined;
|
|
1360
1463
|
if (hasChange) {
|
|
1361
1464
|
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); } }));
|
|
1465
|
+
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
1466
|
}
|
|
1364
1467
|
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); } }));
|
|
1468
|
+
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
1469
|
}
|
|
1367
1470
|
}
|
|
1368
1471
|
else {
|
|
1369
1472
|
return (React__namespace.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1370
1473
|
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})`,
|
|
1474
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1372
1475
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1373
1476
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1374
1477
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1375
1478
|
backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
|
|
1376
1479
|
} },
|
|
1377
|
-
enableAddWidget && hasDiff && (React__namespace.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side:
|
|
1480
|
+
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
1481
|
React__namespace.createElement("div", { className: "flex opacity-[0.5]" },
|
|
1379
1482
|
React__namespace.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
|
|
1380
1483
|
React__namespace.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
@@ -1382,15 +1485,15 @@ const _DiffUnifiedLine = React.memo(({ index, diffFile, lineNumber }) => {
|
|
|
1382
1485
|
React__namespace.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1383
1486
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1384
1487
|
} },
|
|
1385
|
-
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1488
|
+
React__namespace.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1386
1489
|
}
|
|
1387
1490
|
});
|
|
1388
1491
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1389
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1492
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1390
1493
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1391
1494
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1392
1495
|
return null;
|
|
1393
|
-
return React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1496
|
+
return (React__namespace.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
|
|
1394
1497
|
};
|
|
1395
1498
|
|
|
1396
1499
|
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -1405,13 +1508,13 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1405
1508
|
return null;
|
|
1406
1509
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1407
1510
|
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 } },
|
|
1511
|
+
React__namespace.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1409
1512
|
width > 0 &&
|
|
1410
1513
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1411
1514
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
1412
1515
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1413
1516
|
diffFile,
|
|
1414
|
-
side:
|
|
1517
|
+
side: core.SplitSide.old,
|
|
1415
1518
|
lineNumber: unifiedItem.oldLineNumber,
|
|
1416
1519
|
data: oldLineExtend.data,
|
|
1417
1520
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1421,7 +1524,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1421
1524
|
(newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null &&
|
|
1422
1525
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
1423
1526
|
diffFile,
|
|
1424
|
-
side:
|
|
1527
|
+
side: core.SplitSide.new,
|
|
1425
1528
|
lineNumber: unifiedItem.newLineNumber,
|
|
1426
1529
|
data: newLineExtend.data,
|
|
1427
1530
|
onUpdate: diffFile.notifyAll,
|
|
@@ -1495,8 +1598,8 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1495
1598
|
const onClose = () => setWidget({});
|
|
1496
1599
|
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1497
1600
|
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1498
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1499
|
-
const newWidget = unifiedItem.newLineNumber && widgetSide ===
|
|
1601
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1602
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1500
1603
|
const { useDiffContext } = useDiffViewContext();
|
|
1501
1604
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1502
1605
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
@@ -1508,13 +1611,13 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1508
1611
|
return null;
|
|
1509
1612
|
return (React__namespace.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1510
1613
|
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 } },
|
|
1614
|
+
React__namespace.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1512
1615
|
width > 0 &&
|
|
1513
1616
|
oldWidget &&
|
|
1514
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1617
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
1515
1618
|
width > 0 &&
|
|
1516
1619
|
newWidget &&
|
|
1517
|
-
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side:
|
|
1620
|
+
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: core.SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose }))))));
|
|
1518
1621
|
};
|
|
1519
1622
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1520
1623
|
const { useWidget } = useDiffWidgetContext();
|
|
@@ -1522,8 +1625,8 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1522
1625
|
const widgetLineNumber = s.widgetLineNumber;
|
|
1523
1626
|
const widgetSide = s.widgetSide;
|
|
1524
1627
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1525
|
-
const oldWidget = unifiedItem.oldLineNumber && widgetSide ===
|
|
1526
|
-
const newWidget = unifiedItem.newLineNumber && widgetSide ===
|
|
1628
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === core.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1629
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === core.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1527
1630
|
const currentIsShow = oldWidget || newWidget;
|
|
1528
1631
|
return currentIsShow;
|
|
1529
1632
|
}, [diffFile, index]), (p, c) => p === c);
|
|
@@ -1533,30 +1636,29 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1533
1636
|
};
|
|
1534
1637
|
|
|
1535
1638
|
/* 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
1639
|
const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
1545
1640
|
const { useDiffContext } = useDiffViewContext();
|
|
1641
|
+
const ref = React.useRef(null);
|
|
1546
1642
|
const useDiffContextRef = React.useRef(useDiffContext);
|
|
1547
1643
|
useDiffContextRef.current = useDiffContext;
|
|
1548
1644
|
// performance optimization
|
|
1549
1645
|
const useWidget = React.useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1550
1646
|
const contextValue = React.useMemo(() => ({ useWidget }), [useWidget]);
|
|
1551
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1647
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1552
1648
|
fontSize: s.fontSize,
|
|
1553
1649
|
enableWrap: s.enableWrap,
|
|
1650
|
+
enableHighlight: s.enableHighlight,
|
|
1651
|
+
enableAddWidget: s.enableAddWidget,
|
|
1652
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1554
1653
|
}));
|
|
1555
1654
|
index_js.useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1556
1655
|
React.useEffect(() => {
|
|
1557
1656
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1558
1657
|
setWidget({});
|
|
1559
1658
|
}, [diffFile, useWidget]);
|
|
1659
|
+
React.useEffect(() => {
|
|
1660
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1661
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1560
1662
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1561
1663
|
const _width = useTextWidth({
|
|
1562
1664
|
text: unifiedLineLength.toString(),
|
|
@@ -1564,8 +1666,44 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1564
1666
|
});
|
|
1565
1667
|
const width = Math.max(40, _width + 10);
|
|
1566
1668
|
const lines = core.getUnifiedContentLine(diffFile);
|
|
1669
|
+
const setStyle = (side) => {
|
|
1670
|
+
if (!ref.current)
|
|
1671
|
+
return;
|
|
1672
|
+
if (!side) {
|
|
1673
|
+
ref.current.textContent = "";
|
|
1674
|
+
}
|
|
1675
|
+
else {
|
|
1676
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1677
|
+
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}`;
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
const onMouseDown = (e) => {
|
|
1681
|
+
let ele = e.target;
|
|
1682
|
+
// need remove all the selection
|
|
1683
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1684
|
+
removeAllSelection();
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1688
|
+
const state = ele.getAttribute("data-state");
|
|
1689
|
+
if (state) {
|
|
1690
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1691
|
+
setStyle(undefined);
|
|
1692
|
+
removeAllSelection();
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
else {
|
|
1696
|
+
setStyle(core.SplitSide.new);
|
|
1697
|
+
removeAllSelection();
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
ele = ele.parentElement;
|
|
1702
|
+
}
|
|
1703
|
+
};
|
|
1567
1704
|
return (React__namespace.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1568
1705
|
React__namespace.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
|
|
1706
|
+
React__namespace.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1569
1707
|
React__namespace.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1570
1708
|
// @ts-ignore
|
|
1571
1709
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1583,7 +1721,7 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1583
1721
|
React__namespace.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1584
1722
|
lines.map((item) => (React__namespace.createElement(React.Fragment, { key: item.index },
|
|
1585
1723
|
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 }),
|
|
1724
|
+
React__namespace.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }),
|
|
1587
1725
|
React__namespace.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1588
1726
|
React__namespace.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1589
1727
|
React__namespace.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1591,11 +1729,6 @@ const DiffUnifiedView = React.memo(({ diffFile }) => {
|
|
|
1591
1729
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1592
1730
|
|
|
1593
1731
|
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
1732
|
exports.DiffModeEnum = void 0;
|
|
1600
1733
|
(function (DiffModeEnum) {
|
|
1601
1734
|
// github like
|
|
@@ -1606,7 +1739,7 @@ exports.DiffModeEnum = void 0;
|
|
|
1606
1739
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1607
1740
|
})(exports.DiffModeEnum || (exports.DiffModeEnum = {}));
|
|
1608
1741
|
const InternalDiffView = (props) => {
|
|
1609
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
|
|
1742
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1610
1743
|
const diffFileId = React.useMemo(() => diffFile.getId(), [diffFile]);
|
|
1611
1744
|
const wrapperRef = React.useRef();
|
|
1612
1745
|
// performance optimization
|
|
@@ -1614,7 +1747,7 @@ const InternalDiffView = (props) => {
|
|
|
1614
1747
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1615
1748
|
[]);
|
|
1616
1749
|
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();
|
|
1750
|
+
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
1751
|
if (diffFileId && diffFileId !== id) {
|
|
1619
1752
|
setId(diffFileId);
|
|
1620
1753
|
}
|
|
@@ -1642,6 +1775,9 @@ const InternalDiffView = (props) => {
|
|
|
1642
1775
|
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1643
1776
|
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1644
1777
|
}
|
|
1778
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1779
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1780
|
+
}
|
|
1645
1781
|
if (renderExtendLine !== _renderExtendLine) {
|
|
1646
1782
|
setRenderExtendLine(renderExtendLine);
|
|
1647
1783
|
}
|
|
@@ -1661,6 +1797,7 @@ const InternalDiffView = (props) => {
|
|
|
1661
1797
|
renderExtendLine,
|
|
1662
1798
|
extendData,
|
|
1663
1799
|
onAddWidgetClick,
|
|
1800
|
+
onCreateUseWidgetHook,
|
|
1664
1801
|
]);
|
|
1665
1802
|
React.useEffect(() => {
|
|
1666
1803
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1672,7 +1809,7 @@ const InternalDiffView = (props) => {
|
|
|
1672
1809
|
}, [diffFile]);
|
|
1673
1810
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1674
1811
|
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.
|
|
1812
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.28", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1676
1813
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1677
1814
|
// @ts-ignore
|
|
1678
1815
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1738,8 +1875,12 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1738
1875
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1739
1876
|
InnerDiffView.displayName = "DiffView";
|
|
1740
1877
|
const DiffView = InnerDiffView;
|
|
1741
|
-
const version = "0.0.
|
|
1878
|
+
const version = "0.0.28";
|
|
1742
1879
|
|
|
1880
|
+
Object.defineProperty(exports, "SplitSide", {
|
|
1881
|
+
enumerable: true,
|
|
1882
|
+
get: function () { return core.SplitSide; }
|
|
1883
|
+
});
|
|
1743
1884
|
exports.DiffView = DiffView;
|
|
1744
1885
|
exports.version = version;
|
|
1745
1886
|
Object.keys(core).forEach(function (k) {
|