@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
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { DiffLineType, getSyntaxDiffTemplate, getSyntaxLineTemplate, getPlainDiffTemplate, getPlainLineTemplate, SplitSide, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
|
|
3
3
|
export * from '@git-diff-view/core';
|
|
4
|
+
export { SplitSide } from '@git-diff-view/core';
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
import { useState, useEffect, useRef, useLayoutEffect, createContext, useContext, memo, Fragment, useMemo, useCallback, forwardRef, useImperativeHandle } from 'react';
|
|
6
7
|
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
7
|
-
import { flushSync } from 'react-dom';
|
|
8
8
|
import { createStore, ref } from 'reactivity-store';
|
|
9
9
|
|
|
10
10
|
/******************************************************************************
|
|
@@ -126,7 +126,9 @@ const delLineNumberBGName = "--diff-del-lineNumber--";
|
|
|
126
126
|
const plainContentBGName = "--diff-plain-content--";
|
|
127
127
|
const expandContentBGName = "--diff-expand-content--";
|
|
128
128
|
const plainLineNumberColorName = "--diff-plain-lineNumber-color--";
|
|
129
|
+
const expandLineNumberColorName = "--diff-expand-lineNumber-color--";
|
|
129
130
|
const plainLineNumberBGName = "--diff-plain-lineNumber--";
|
|
131
|
+
const expandLineNumberBGName = "--diff-expand-lineNumber--";
|
|
130
132
|
const hunkContentBGName = "--diff-hunk-content--";
|
|
131
133
|
const hunkContentColorName = "--diff-hunk-content-color--";
|
|
132
134
|
const hunkLineNumberBGName = "--diff-hunk-lineNumber--";
|
|
@@ -151,7 +153,7 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
|
|
|
151
153
|
? `var(${delLineNumberBGName})`
|
|
152
154
|
: hasDiff
|
|
153
155
|
? `var(${plainLineNumberBGName})`
|
|
154
|
-
: `var(${
|
|
156
|
+
: `var(${expandLineNumberBGName})`;
|
|
155
157
|
};
|
|
156
158
|
|
|
157
159
|
const removeAllSelection = () => {
|
|
@@ -201,6 +203,15 @@ const memoFunc = (func) => {
|
|
|
201
203
|
});
|
|
202
204
|
};
|
|
203
205
|
|
|
206
|
+
var NewLineSymbol;
|
|
207
|
+
(function (NewLineSymbol) {
|
|
208
|
+
NewLineSymbol[NewLineSymbol["CRLF"] = 1] = "CRLF";
|
|
209
|
+
NewLineSymbol[NewLineSymbol["CR"] = 2] = "CR";
|
|
210
|
+
NewLineSymbol[NewLineSymbol["LF"] = 3] = "LF";
|
|
211
|
+
NewLineSymbol[NewLineSymbol["NEWLINE"] = 4] = "NEWLINE";
|
|
212
|
+
NewLineSymbol[NewLineSymbol["NORMAL"] = 5] = "NORMAL";
|
|
213
|
+
NewLineSymbol[NewLineSymbol["NULL"] = 6] = "NULL";
|
|
214
|
+
})(NewLineSymbol || (NewLineSymbol = {}));
|
|
204
215
|
const getSymbol = (symbol) => {
|
|
205
216
|
switch (symbol) {
|
|
206
217
|
case NewLineSymbol.LF:
|
|
@@ -280,6 +291,7 @@ const DiffNoNewLine = () => {
|
|
|
280
291
|
React.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" })));
|
|
281
292
|
};
|
|
282
293
|
|
|
294
|
+
/* eslint-disable max-lines */
|
|
283
295
|
const temp = {};
|
|
284
296
|
const formatStringToCamelCase = (str) => {
|
|
285
297
|
if (str.startsWith("--"))
|
|
@@ -306,30 +318,52 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
306
318
|
});
|
|
307
319
|
return style;
|
|
308
320
|
});
|
|
309
|
-
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
321
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
310
322
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
311
323
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
312
|
-
const range = changes.range;
|
|
313
|
-
const str1 = rawLine.slice(0, range.location);
|
|
314
|
-
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
315
|
-
const str3 = rawLine.slice(range.location + range.length);
|
|
316
|
-
const isLast = str2.includes("\n");
|
|
317
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
318
324
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
325
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof getPlainDiffTemplate === "function") {
|
|
326
|
+
getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
327
|
+
}
|
|
328
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
329
|
+
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
330
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
331
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
332
|
+
width: `var(${diffFontSizeName})`,
|
|
333
|
+
height: `var(${diffFontSizeName})`,
|
|
334
|
+
} },
|
|
335
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
// TODO remove
|
|
339
|
+
const range = changes.range;
|
|
340
|
+
const str1 = rawLine.slice(0, range.location);
|
|
341
|
+
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
342
|
+
const str3 = rawLine.slice(range.location + range.length);
|
|
343
|
+
const isLast = str2.includes("\n");
|
|
344
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
345
|
+
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
346
|
+
React.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
347
|
+
str1,
|
|
348
|
+
React.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
349
|
+
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
350
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
351
|
+
_str2,
|
|
352
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
353
|
+
str3),
|
|
354
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
355
|
+
width: `var(${diffFontSizeName})`,
|
|
356
|
+
height: `var(${diffFontSizeName})`,
|
|
357
|
+
} },
|
|
358
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
362
|
+
plainLine.template = getPlainLineTemplate(plainLine.value);
|
|
363
|
+
}
|
|
364
|
+
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
319
365
|
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
320
|
-
React.createElement("span", { "data-
|
|
321
|
-
str1,
|
|
322
|
-
React.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
323
|
-
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
324
|
-
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
325
|
-
_str2,
|
|
326
|
-
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
327
|
-
str3),
|
|
328
|
-
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
329
|
-
width: `var(${diffFontSizeName})`,
|
|
330
|
-
height: `var(${diffFontSizeName})`,
|
|
331
|
-
} },
|
|
332
|
-
React.createElement(DiffNoNewLine, null)))));
|
|
366
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
333
367
|
}
|
|
334
368
|
return React.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
335
369
|
};
|
|
@@ -341,49 +375,73 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
341
375
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
342
376
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
343
377
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
344
|
-
|
|
378
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof getSyntaxDiffTemplate === "function") {
|
|
379
|
+
getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
380
|
+
}
|
|
381
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
382
|
+
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
383
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
384
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
385
|
+
width: `var(${diffFontSizeName})`,
|
|
386
|
+
height: `var(${diffFontSizeName})`,
|
|
387
|
+
} },
|
|
388
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
// TODO remove
|
|
392
|
+
const range = changes.range;
|
|
393
|
+
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
394
|
+
React.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length }, (_a = syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.map(({ node, wrapper }, index) => {
|
|
395
|
+
var _a, _b, _c, _d, _e, _f;
|
|
396
|
+
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
397
|
+
return (React.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));
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
const index1 = range.location - node.startIndex;
|
|
401
|
+
const index2 = index1 < 0 ? 0 : index1;
|
|
402
|
+
const str1 = node.value.slice(0, index2);
|
|
403
|
+
const str2 = node.value.slice(index2, index1 + range.length);
|
|
404
|
+
const str3 = node.value.slice(index1 + range.length);
|
|
405
|
+
const isStart = str1.length || range.location === node.startIndex;
|
|
406
|
+
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
407
|
+
const isLast = str2.includes("\n");
|
|
408
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
409
|
+
return (React.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) || "") },
|
|
410
|
+
str1,
|
|
411
|
+
React.createElement("span", { "data-diff-highlight": true, style: {
|
|
412
|
+
backgroundColor: operator === "add"
|
|
413
|
+
? `var(${addContentHighlightBGName})`
|
|
414
|
+
: `var(${delContentHighlightBGName})`,
|
|
415
|
+
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
416
|
+
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
417
|
+
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
418
|
+
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
419
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
420
|
+
_str2,
|
|
421
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
422
|
+
str3));
|
|
423
|
+
}
|
|
424
|
+
})),
|
|
425
|
+
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
426
|
+
width: `var(${diffFontSizeName})`,
|
|
427
|
+
height: `var(${diffFontSizeName})`,
|
|
428
|
+
} },
|
|
429
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (!syntaxLine.template) {
|
|
433
|
+
syntaxLine.template = getSyntaxLineTemplate(syntaxLine);
|
|
434
|
+
}
|
|
435
|
+
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
345
436
|
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
346
|
-
React.createElement("span", { "data-
|
|
347
|
-
var _a, _b, _c, _d, _e, _f;
|
|
348
|
-
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
349
|
-
return (React.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));
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
const index1 = range.location - node.startIndex;
|
|
353
|
-
const index2 = index1 < 0 ? 0 : index1;
|
|
354
|
-
const str1 = node.value.slice(0, index2);
|
|
355
|
-
const str2 = node.value.slice(index2, index1 + range.length);
|
|
356
|
-
const str3 = node.value.slice(index1 + range.length);
|
|
357
|
-
const isStart = str1.length || range.location === node.startIndex;
|
|
358
|
-
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
359
|
-
const isLast = str2.includes("\n");
|
|
360
|
-
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
361
|
-
return (React.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) || "") },
|
|
362
|
-
str1,
|
|
363
|
-
React.createElement("span", { "data-diff-highlight": true, style: {
|
|
364
|
-
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
365
|
-
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
366
|
-
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
367
|
-
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
368
|
-
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
369
|
-
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
370
|
-
_str2,
|
|
371
|
-
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
372
|
-
str3));
|
|
373
|
-
}
|
|
374
|
-
})),
|
|
375
|
-
isNewLineSymbolChanged === NewLineSymbol.NEWLINE && (React.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
376
|
-
width: `var(${diffFontSizeName})`,
|
|
377
|
-
height: `var(${diffFontSizeName})`,
|
|
378
|
-
} },
|
|
379
|
-
React.createElement(DiffNoNewLine, null)))));
|
|
437
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
380
438
|
}
|
|
381
439
|
return (React.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) => {
|
|
382
440
|
var _a, _b, _c;
|
|
383
441
|
return (React.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));
|
|
384
442
|
})));
|
|
385
443
|
};
|
|
386
|
-
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
444
|
+
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
387
445
|
var _a;
|
|
388
446
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Add;
|
|
389
447
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Delete;
|
|
@@ -395,7 +453,7 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
395
453
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
396
454
|
} },
|
|
397
455
|
React.createElement("span", { "data-operator": isAdded ? "+" : isDelete ? "-" : undefined, className: "diff-line-content-operator ml-[-1.5em] inline-block w-[1.5em] select-none indent-[0.2em]" }, isAdded ? "+" : isDelete ? "-" : " "),
|
|
398
|
-
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, enableWrap: enableWrap }))));
|
|
456
|
+
enableHighlight && syntaxLine && !isMaxLineLengthToIgnoreSyntax ? (React.createElement(DiffSyntax, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine, enableWrap: enableWrap })) : (React.createElement(DiffString, { operator: isAdded ? "add" : isDelete ? "del" : undefined, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, enableWrap: enableWrap }))));
|
|
399
457
|
};
|
|
400
458
|
|
|
401
459
|
const DiffViewContext = createContext(null);
|
|
@@ -406,9 +464,10 @@ const DiffWidgetContext = createContext(null);
|
|
|
406
464
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
407
465
|
const useDiffWidgetContext = () => useContext(DiffWidgetContext);
|
|
408
466
|
|
|
409
|
-
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
467
|
+
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
410
468
|
var _a, _b;
|
|
411
469
|
const getCurrentSyntaxLine = side === SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
470
|
+
const getCurrentPlainLine = side === SplitSide.old ? diffFile.getOldPlainLine : diffFile.getNewPlainLine;
|
|
412
471
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
413
472
|
const newLine = diffFile.getSplitRightLine(index);
|
|
414
473
|
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
@@ -418,20 +477,17 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
418
477
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
|
|
419
478
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
|
|
420
479
|
const { useDiffContext } = useDiffViewContext();
|
|
421
|
-
const
|
|
422
|
-
enableHighlight: s.enableHighlight,
|
|
423
|
-
enableAddWidget: s.enableAddWidget,
|
|
424
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
425
|
-
}));
|
|
480
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
426
481
|
const { useWidget } = useDiffWidgetContext();
|
|
427
482
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
428
483
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
429
484
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
430
485
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
486
|
+
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
431
487
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff || !hasContent ? "diff" : "plain", "data-side": SplitSide[side], className: "diff-line" + (hasContent ? " group" : "") }, hasContent ? (React.createElement(React.Fragment, null,
|
|
432
488
|
React.createElement("td", { className: `diff-line-${SplitSide[side]}-num sticky left-0 w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top`, style: {
|
|
433
489
|
backgroundColor: lineNumberBG,
|
|
434
|
-
color: `var(${plainLineNumberColorName})`,
|
|
490
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
435
491
|
width: `var(${diffAsideWidthName})`,
|
|
436
492
|
minWidth: `var(${diffAsideWidthName})`,
|
|
437
493
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
@@ -439,15 +495,15 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
439
495
|
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: currentLine.lineNumber, side: side, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
440
496
|
React.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
441
497
|
React.createElement("td", { className: `diff-line-${SplitSide[side]}-content pr-[10px] align-top`, style: { backgroundColor: contentBG } },
|
|
442
|
-
React.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: `diff-line-${SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
498
|
+
React.createElement(DiffContent, { enableWrap: false, diffFile: diffFile, rawLine: currentLine.value, diffLine: currentLine.diff, plainLine: plainLine, syntaxLine: syntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: `diff-line-${SplitSide[side]}-placeholder select-none`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
443
499
|
React.createElement("span", null, "\u2002")))));
|
|
444
500
|
};
|
|
445
|
-
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
501
|
+
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
446
502
|
const getCurrentLine = side === SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
447
503
|
const currentLine = getCurrentLine(index);
|
|
448
504
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
449
505
|
return null;
|
|
450
|
-
return React.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
506
|
+
return (React.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
451
507
|
};
|
|
452
508
|
|
|
453
509
|
const useDomWidth = ({ selector, enable }) => {
|
|
@@ -578,7 +634,7 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
578
634
|
if (!renderExtendLine)
|
|
579
635
|
return null;
|
|
580
636
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentSideHasExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
581
|
-
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side], className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 && currentExtendRendered))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
637
|
+
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side], className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } }, width > 0 && currentExtendRendered))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
582
638
|
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] })))));
|
|
583
639
|
};
|
|
584
640
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -745,7 +801,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
745
801
|
if (!renderWidgetLine)
|
|
746
802
|
return null;
|
|
747
803
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" }, currentHasWidget ? (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-content p-0`, colSpan: 2 },
|
|
748
|
-
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side], className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 && currentWidgetRendered))) : (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
804
|
+
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side], className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } }, width > 0 && currentWidgetRendered))) : (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
749
805
|
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
|
|
750
806
|
};
|
|
751
807
|
// TODO! improve performance
|
|
@@ -767,15 +823,7 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
767
823
|
};
|
|
768
824
|
|
|
769
825
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
770
|
-
const
|
|
771
|
-
const ele = e.target;
|
|
772
|
-
// need remove all the selection
|
|
773
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
774
|
-
removeAllSelection();
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
826
|
+
const DiffSplitViewTable = ({ side, diffFile, enableAddWidget, enableHighlight, onMouseDown, }) => {
|
|
779
827
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
780
828
|
const lines = getSplitContentLines(diffFile);
|
|
781
829
|
return (React.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": SplitSide[side] },
|
|
@@ -790,10 +838,10 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
790
838
|
React.createElement("th", { scope: "col" },
|
|
791
839
|
SplitSide[side],
|
|
792
840
|
" line content"))),
|
|
793
|
-
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown
|
|
841
|
+
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
794
842
|
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
795
843
|
React.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
796
|
-
React.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
844
|
+
React.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
797
845
|
React.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
798
846
|
React.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
799
847
|
React.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -801,9 +849,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
801
849
|
const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
802
850
|
const ref1 = useRef(null);
|
|
803
851
|
const ref2 = useRef(null);
|
|
852
|
+
const ref = useRef();
|
|
804
853
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
805
854
|
const { useDiffContext } = useDiffViewContext();
|
|
806
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) =>
|
|
855
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
856
|
+
fontSize: s.fontSize,
|
|
857
|
+
enableAddWidget: s.enableAddWidget,
|
|
858
|
+
enableHighlight: s.enableHighlight,
|
|
859
|
+
}));
|
|
807
860
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
808
861
|
useEffect(() => {
|
|
809
862
|
const left = ref1.current;
|
|
@@ -818,7 +871,46 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
818
871
|
font,
|
|
819
872
|
});
|
|
820
873
|
const width = Math.max(40, _width + 25);
|
|
874
|
+
const setStyle = (side) => {
|
|
875
|
+
if (!ref.current)
|
|
876
|
+
return;
|
|
877
|
+
if (!side) {
|
|
878
|
+
ref.current.textContent = "";
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
882
|
+
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}`;
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
const onMouseDown = (e) => {
|
|
886
|
+
let ele = e.target;
|
|
887
|
+
// need remove all the selection
|
|
888
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
889
|
+
removeAllSelection();
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
while (ele && ele instanceof HTMLElement) {
|
|
893
|
+
const state = ele.getAttribute("data-state");
|
|
894
|
+
const side = ele.getAttribute("data-side");
|
|
895
|
+
if (side) {
|
|
896
|
+
setStyle(SplitSide[side]);
|
|
897
|
+
removeAllSelection();
|
|
898
|
+
}
|
|
899
|
+
if (state) {
|
|
900
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
901
|
+
setStyle(undefined);
|
|
902
|
+
removeAllSelection();
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
ele = ele.parentElement;
|
|
910
|
+
}
|
|
911
|
+
};
|
|
821
912
|
return (React.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
|
|
913
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
822
914
|
React.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
823
915
|
// @ts-ignore
|
|
824
916
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -826,7 +918,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
826
918
|
fontFamily: "Menlo, Consolas, monospace",
|
|
827
919
|
fontSize: `var(${diffFontSizeName})`,
|
|
828
920
|
} },
|
|
829
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
921
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
830
922
|
React.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
831
923
|
React.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
832
924
|
// @ts-ignore
|
|
@@ -835,26 +927,24 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
835
927
|
fontFamily: "Menlo, Consolas, monospace",
|
|
836
928
|
fontSize: `var(${diffFontSizeName})`,
|
|
837
929
|
} },
|
|
838
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile }))));
|
|
930
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
839
931
|
});
|
|
840
932
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
841
933
|
|
|
842
|
-
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
934
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
843
935
|
var _a, _b;
|
|
844
936
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
845
937
|
const newLine = diffFile.getSplitRightLine(index);
|
|
846
938
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
939
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
847
940
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
941
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
848
942
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
849
943
|
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
850
944
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
|
|
851
945
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
|
|
852
946
|
const { useDiffContext } = useDiffViewContext();
|
|
853
|
-
const
|
|
854
|
-
enableHighlight: s.enableHighlight,
|
|
855
|
-
enableAddWidget: s.enableAddWidget,
|
|
856
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
857
|
-
}));
|
|
947
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
858
948
|
const { useWidget } = useDiffWidgetContext();
|
|
859
949
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
860
950
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -870,12 +960,12 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
870
960
|
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
871
961
|
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
872
962
|
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: oldLine.lineNumber, side: SplitSide.old, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] z-[1] translate-x-[50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
873
|
-
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
963
|
+
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: oldLine.value, diffLine: oldLine.diff, plainLine: oldPlainLine, syntaxLine: oldSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-old-placeholder select-none", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
|
|
874
964
|
React.createElement("span", null, "\u2002"))),
|
|
875
965
|
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
876
966
|
React.createElement("td", { className: "diff-line-new-num group relative w-[1%] min-w-[40px] select-none border-l-[1px] pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.new], style: {
|
|
877
967
|
backgroundColor: newLineNumberBG,
|
|
878
|
-
color: `var(${plainLineNumberColorName})`,
|
|
968
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
879
969
|
borderLeftColor: `var(${borderColorName})`,
|
|
880
970
|
borderLeftStyle: "solid",
|
|
881
971
|
} },
|
|
@@ -883,19 +973,19 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
883
973
|
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
884
974
|
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
885
975
|
hasDiff && enableAddWidget && (React.createElement(DiffSplitAddWidget, { index: index, lineNumber: newLine.lineNumber, side: SplitSide.new, diffFile: diffFile, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, className: "absolute right-[100%] z-[1] translate-x-[50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
|
|
886
|
-
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
976
|
+
React.createElement(DiffContent, { enableWrap: true, diffFile: diffFile, rawLine: newLine.value || "", diffLine: newLine.diff, plainLine: newPlainLine, syntaxLine: newSyntaxLine, enableHighlight: enableHighlight })))) : (React.createElement("td", { className: "diff-line-new-placeholder select-none border-l-[1px]", style: {
|
|
887
977
|
backgroundColor: `var(${emptyBGName})`,
|
|
888
978
|
borderLeftColor: `var(${borderColorName})`,
|
|
889
979
|
borderLeftStyle: "solid",
|
|
890
980
|
}, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
|
|
891
981
|
React.createElement("span", null, "\u2002")))));
|
|
892
982
|
};
|
|
893
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
983
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
894
984
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
895
985
|
const newLine = diffFile.getSplitRightLine(index);
|
|
896
986
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
897
987
|
return null;
|
|
898
|
-
return React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
988
|
+
return (React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
899
989
|
};
|
|
900
990
|
|
|
901
991
|
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -924,13 +1014,13 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
924
1014
|
}));
|
|
925
1015
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
926
1016
|
oldExtendRendered ? (React.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
927
|
-
React.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }
|
|
1017
|
+
React.createElement("div", { className: "diff-line-extend-wrapper" }, oldExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 })),
|
|
928
1018
|
newExtendRendered ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
|
|
929
1019
|
React.createElement("div", { className: "diff-line-extend-wrapper" }, newExtendRendered))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
930
1020
|
backgroundColor: `var(${emptyBGName})`,
|
|
931
1021
|
borderLeftColor: `var(${borderColorName})`,
|
|
932
1022
|
borderLeftStyle: "solid",
|
|
933
|
-
}, colSpan: 2 }
|
|
1023
|
+
}, colSpan: 2 }))));
|
|
934
1024
|
};
|
|
935
1025
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
936
1026
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1065,13 +1155,13 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1065
1155
|
return null;
|
|
1066
1156
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1067
1157
|
oldWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
1068
|
-
React.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 }
|
|
1158
|
+
React.createElement("div", { className: "diff-line-widget-wrapper" }, oldWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 })),
|
|
1069
1159
|
newWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
|
|
1070
1160
|
React.createElement("div", { className: "diff-line-widget-wrapper" }, newWidgetRendered))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: {
|
|
1071
1161
|
backgroundColor: `var(${emptyBGName})`,
|
|
1072
1162
|
borderLeftColor: `var(${borderColorName})`,
|
|
1073
1163
|
borderLeftStyle: "solid",
|
|
1074
|
-
}, colSpan: 2 }
|
|
1164
|
+
}, colSpan: 2 }))));
|
|
1075
1165
|
};
|
|
1076
1166
|
// TODO! improve performance
|
|
1077
1167
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1091,6 +1181,93 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1091
1181
|
return React.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1092
1182
|
};
|
|
1093
1183
|
|
|
1184
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1185
|
+
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1186
|
+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1187
|
+
const { useDiffContext } = useDiffViewContext();
|
|
1188
|
+
const ref = useRef(null);
|
|
1189
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1190
|
+
fontSize: s.fontSize,
|
|
1191
|
+
enableAddWidget: s.enableAddWidget,
|
|
1192
|
+
enableHighlight: s.enableHighlight,
|
|
1193
|
+
}));
|
|
1194
|
+
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1195
|
+
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1196
|
+
const _width = useTextWidth({
|
|
1197
|
+
text: splitLineLength.toString(),
|
|
1198
|
+
font,
|
|
1199
|
+
});
|
|
1200
|
+
const width = Math.max(40, _width + 25);
|
|
1201
|
+
const lines = getSplitContentLines(diffFile);
|
|
1202
|
+
const setStyle = (side) => {
|
|
1203
|
+
if (!ref.current)
|
|
1204
|
+
return;
|
|
1205
|
+
if (!side) {
|
|
1206
|
+
ref.current.textContent = "";
|
|
1207
|
+
}
|
|
1208
|
+
else {
|
|
1209
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1210
|
+
const targetSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
1211
|
+
ref.current.textContent = `#${id} [data-side="${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}`;
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
const onMouseDown = (e) => {
|
|
1215
|
+
let ele = e.target;
|
|
1216
|
+
// need remove all the selection
|
|
1217
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1218
|
+
removeAllSelection();
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1222
|
+
const state = ele.getAttribute("data-state");
|
|
1223
|
+
const side = ele.getAttribute("data-side");
|
|
1224
|
+
if (side) {
|
|
1225
|
+
setStyle(SplitSide[side]);
|
|
1226
|
+
removeAllSelection();
|
|
1227
|
+
}
|
|
1228
|
+
if (state) {
|
|
1229
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1230
|
+
setStyle(undefined);
|
|
1231
|
+
removeAllSelection();
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
ele = ele.parentElement;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1242
|
+
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1243
|
+
// @ts-ignore
|
|
1244
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1245
|
+
fontFamily: "Menlo, Consolas, monospace",
|
|
1246
|
+
fontSize: `var(${diffFontSizeName})`,
|
|
1247
|
+
} },
|
|
1248
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1249
|
+
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1250
|
+
React.createElement("colgroup", null,
|
|
1251
|
+
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1252
|
+
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1253
|
+
React.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1254
|
+
React.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1255
|
+
React.createElement("thead", { className: "hidden" },
|
|
1256
|
+
React.createElement("tr", null,
|
|
1257
|
+
React.createElement("th", { scope: "col" }, "old line number"),
|
|
1258
|
+
React.createElement("th", { scope: "col" }, "old line content"),
|
|
1259
|
+
React.createElement("th", { scope: "col" }, "new line number"),
|
|
1260
|
+
React.createElement("th", { scope: "col" }, "new line content"))),
|
|
1261
|
+
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1262
|
+
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
1263
|
+
React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1264
|
+
React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
1265
|
+
React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1266
|
+
React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1267
|
+
React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1268
|
+
});
|
|
1269
|
+
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1270
|
+
|
|
1094
1271
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1095
1272
|
return createStore(() => {
|
|
1096
1273
|
var _a, _b;
|
|
@@ -1138,6 +1315,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1138
1315
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1139
1316
|
const renderExtendLine = ref(props.renderExtendLine);
|
|
1140
1317
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1318
|
+
const onCreateUseWidgetHook = ref(props.onCreateUseWidgetHook);
|
|
1319
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1141
1320
|
// 避免无意义的订阅
|
|
1142
1321
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1143
1322
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1164,6 +1343,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1164
1343
|
setRenderExtendLine,
|
|
1165
1344
|
onAddWidgetClick,
|
|
1166
1345
|
setOnAddWidgetClick,
|
|
1346
|
+
onCreateUseWidgetHook,
|
|
1347
|
+
setOnCreateUseWidgetHook,
|
|
1167
1348
|
};
|
|
1168
1349
|
});
|
|
1169
1350
|
};
|
|
@@ -1182,95 +1363,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1182
1363
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1183
1364
|
});
|
|
1184
1365
|
};
|
|
1185
|
-
const createDiffSplitConfigStore = () => {
|
|
1186
|
-
return createStore(() => {
|
|
1187
|
-
const splitRef = ref(undefined);
|
|
1188
|
-
const setSplit = (side) => {
|
|
1189
|
-
flushSync(() => {
|
|
1190
|
-
splitRef.value = side;
|
|
1191
|
-
});
|
|
1192
|
-
};
|
|
1193
|
-
return { splitRef, setSplit };
|
|
1194
|
-
});
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1198
|
-
const Style = ({ useSelector, id, }) => {
|
|
1199
|
-
const splitRef = useSelector((s) => s.splitRef);
|
|
1200
|
-
return (React.createElement("style", { "data-select-style": true }, splitRef === SplitSide.old
|
|
1201
|
-
? `#${id} td[data-side="${SplitSide[SplitSide.new]}"] {user-select: none}`
|
|
1202
|
-
: splitRef === SplitSide.new
|
|
1203
|
-
? `#${id} td[data-side="${SplitSide[SplitSide.old]}"] {user-select: none}`
|
|
1204
|
-
: ""));
|
|
1205
|
-
};
|
|
1206
|
-
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1207
|
-
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1208
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1209
|
-
const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
|
|
1210
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
1211
|
-
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1212
|
-
const onMouseDown = useCallback((e) => {
|
|
1213
|
-
let ele = e.target;
|
|
1214
|
-
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1215
|
-
// need remove all the selection
|
|
1216
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1217
|
-
removeAllSelection();
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
while (ele && ele instanceof HTMLElement && ele.nodeName !== "TD") {
|
|
1221
|
-
ele = ele.parentElement;
|
|
1222
|
-
}
|
|
1223
|
-
if (ele instanceof HTMLElement) {
|
|
1224
|
-
const side = ele.getAttribute("data-side");
|
|
1225
|
-
if (side) {
|
|
1226
|
-
setSelectSide(SplitSide[side]);
|
|
1227
|
-
removeAllSelection();
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1231
|
-
}, []);
|
|
1232
|
-
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1233
|
-
const _width = useTextWidth({
|
|
1234
|
-
text: splitLineLength.toString(),
|
|
1235
|
-
font,
|
|
1236
|
-
});
|
|
1237
|
-
const width = Math.max(40, _width + 25);
|
|
1238
|
-
const lines = getSplitContentLines(diffFile);
|
|
1239
|
-
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1240
|
-
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1241
|
-
// @ts-ignore
|
|
1242
|
-
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1243
|
-
fontFamily: "Menlo, Consolas, monospace",
|
|
1244
|
-
fontSize: `var(${diffFontSizeName})`,
|
|
1245
|
-
} },
|
|
1246
|
-
React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1247
|
-
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1248
|
-
React.createElement("colgroup", null,
|
|
1249
|
-
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1250
|
-
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1251
|
-
React.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1252
|
-
React.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1253
|
-
React.createElement("thead", { className: "hidden" },
|
|
1254
|
-
React.createElement("tr", null,
|
|
1255
|
-
React.createElement("th", { scope: "col" }, "old line number"),
|
|
1256
|
-
React.createElement("th", { scope: "col" }, "old line content"),
|
|
1257
|
-
React.createElement("th", { scope: "col" }, "new line number"),
|
|
1258
|
-
React.createElement("th", { scope: "col" }, "new line content"))),
|
|
1259
|
-
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1260
|
-
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
1261
|
-
React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1262
|
-
React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1263
|
-
React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1264
|
-
React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1265
|
-
React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1266
|
-
});
|
|
1267
|
-
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1268
1366
|
|
|
1269
1367
|
const DiffSplitView = memo(({ diffFile }) => {
|
|
1270
1368
|
const { useDiffContext } = useDiffViewContext();
|
|
1271
1369
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1272
1370
|
useDiffContextRef.current = useDiffContext;
|
|
1273
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1371
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1372
|
+
enableWrap: s.enableWrap,
|
|
1373
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1374
|
+
}));
|
|
1274
1375
|
// performance optimization
|
|
1275
1376
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1276
1377
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1278,11 +1379,14 @@ const DiffSplitView = memo(({ diffFile }) => {
|
|
|
1278
1379
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1279
1380
|
setWidget({});
|
|
1280
1381
|
}, [diffFile, useWidget]);
|
|
1382
|
+
useEffect(() => {
|
|
1383
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1384
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1281
1385
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1282
1386
|
});
|
|
1283
1387
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1284
1388
|
|
|
1285
|
-
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1389
|
+
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1286
1390
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1287
1391
|
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1288
1392
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1297,9 +1401,9 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1297
1401
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1298
1402
|
React.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1299
1403
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1300
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1404
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1301
1405
|
};
|
|
1302
|
-
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1406
|
+
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1303
1407
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1304
1408
|
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1305
1409
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1314,17 +1418,12 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1314
1418
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1315
1419
|
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1316
1420
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1317
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1421
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1318
1422
|
};
|
|
1319
|
-
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
1423
|
+
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1320
1424
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1321
1425
|
const { useDiffContext } = useDiffViewContext();
|
|
1322
|
-
const
|
|
1323
|
-
enableWrap: s.enableWrap,
|
|
1324
|
-
enableHighlight: s.enableHighlight,
|
|
1325
|
-
enableAddWidget: s.enableAddWidget,
|
|
1326
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1327
|
-
}));
|
|
1426
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1328
1427
|
const { useWidget } = useDiffWidgetContext();
|
|
1329
1428
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1330
1429
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1338,18 +1437,23 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1338
1437
|
: oldLinenumber
|
|
1339
1438
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1340
1439
|
: undefined;
|
|
1440
|
+
const plainLine = newLineNumber
|
|
1441
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1442
|
+
: oldLinenumber
|
|
1443
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1444
|
+
: undefined;
|
|
1341
1445
|
if (hasChange) {
|
|
1342
1446
|
if (unifiedLine.oldLineNumber) {
|
|
1343
|
-
return (React.createElement(DiffUnifiedOldLine, { index: lineNumber, enableWrap: enableWrap, diffFile: diffFile, rawLine: rawLine, diffLine: diffLine, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.oldLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1447
|
+
return (React.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); } }));
|
|
1344
1448
|
}
|
|
1345
1449
|
else {
|
|
1346
|
-
return (React.createElement(DiffUnifiedNewLine, { index: lineNumber, enableWrap: enableWrap, rawLine: rawLine, diffLine: diffLine, diffFile: diffFile, setWidget: setWidget, syntaxLine: syntaxLine, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget, lineNumber: unifiedLine.newLineNumber, onAddWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); } }));
|
|
1450
|
+
return (React.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); } }));
|
|
1347
1451
|
}
|
|
1348
1452
|
}
|
|
1349
1453
|
else {
|
|
1350
1454
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1351
1455
|
React.createElement("td", { className: "diff-line-num sticky left-0 w-[1%] min-w-[100px] select-none whitespace-nowrap pl-[10px] pr-[10px] text-right align-top", style: {
|
|
1352
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1456
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1353
1457
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1354
1458
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1355
1459
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1363,15 +1467,15 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1363
1467
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1364
1468
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1365
1469
|
} },
|
|
1366
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1470
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1367
1471
|
}
|
|
1368
1472
|
});
|
|
1369
1473
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1370
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1474
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1371
1475
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1372
1476
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1373
1477
|
return null;
|
|
1374
|
-
return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1478
|
+
return (React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
|
|
1375
1479
|
};
|
|
1376
1480
|
|
|
1377
1481
|
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -1386,7 +1490,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1386
1490
|
return null;
|
|
1387
1491
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1388
1492
|
React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1389
|
-
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } },
|
|
1493
|
+
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1390
1494
|
width > 0 &&
|
|
1391
1495
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1392
1496
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
@@ -1489,7 +1593,7 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1489
1593
|
return null;
|
|
1490
1594
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1491
1595
|
React.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
|
|
1492
|
-
React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } },
|
|
1596
|
+
React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1493
1597
|
width > 0 &&
|
|
1494
1598
|
oldWidget &&
|
|
1495
1599
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
@@ -1514,30 +1618,29 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1514
1618
|
};
|
|
1515
1619
|
|
|
1516
1620
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1517
|
-
const onMouseDown = (e) => {
|
|
1518
|
-
const ele = e.target;
|
|
1519
|
-
// need remove all the selection
|
|
1520
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1521
|
-
removeAllSelection();
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
1621
|
const DiffUnifiedView = memo(({ diffFile }) => {
|
|
1526
1622
|
const { useDiffContext } = useDiffViewContext();
|
|
1623
|
+
const ref = useRef(null);
|
|
1527
1624
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1528
1625
|
useDiffContextRef.current = useDiffContext;
|
|
1529
1626
|
// performance optimization
|
|
1530
1627
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1531
1628
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1532
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1629
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1533
1630
|
fontSize: s.fontSize,
|
|
1534
1631
|
enableWrap: s.enableWrap,
|
|
1632
|
+
enableHighlight: s.enableHighlight,
|
|
1633
|
+
enableAddWidget: s.enableAddWidget,
|
|
1634
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1535
1635
|
}));
|
|
1536
1636
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1537
1637
|
useEffect(() => {
|
|
1538
1638
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1539
1639
|
setWidget({});
|
|
1540
1640
|
}, [diffFile, useWidget]);
|
|
1641
|
+
useEffect(() => {
|
|
1642
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1643
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1541
1644
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1542
1645
|
const _width = useTextWidth({
|
|
1543
1646
|
text: unifiedLineLength.toString(),
|
|
@@ -1545,8 +1648,44 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1545
1648
|
});
|
|
1546
1649
|
const width = Math.max(40, _width + 10);
|
|
1547
1650
|
const lines = getUnifiedContentLine(diffFile);
|
|
1651
|
+
const setStyle = (side) => {
|
|
1652
|
+
if (!ref.current)
|
|
1653
|
+
return;
|
|
1654
|
+
if (!side) {
|
|
1655
|
+
ref.current.textContent = "";
|
|
1656
|
+
}
|
|
1657
|
+
else {
|
|
1658
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1659
|
+
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}`;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
const onMouseDown = (e) => {
|
|
1663
|
+
let ele = e.target;
|
|
1664
|
+
// need remove all the selection
|
|
1665
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1666
|
+
removeAllSelection();
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1670
|
+
const state = ele.getAttribute("data-state");
|
|
1671
|
+
if (state) {
|
|
1672
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1673
|
+
setStyle(undefined);
|
|
1674
|
+
removeAllSelection();
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
else {
|
|
1678
|
+
setStyle(SplitSide.new);
|
|
1679
|
+
removeAllSelection();
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
ele = ele.parentElement;
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1548
1686
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1549
1687
|
React.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
|
|
1688
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1550
1689
|
React.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1551
1690
|
// @ts-ignore
|
|
1552
1691
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1564,7 +1703,7 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1564
1703
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1565
1704
|
lines.map((item) => (React.createElement(Fragment, { key: item.index },
|
|
1566
1705
|
React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1567
|
-
React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1706
|
+
React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }),
|
|
1568
1707
|
React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1569
1708
|
React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1570
1709
|
React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1572,11 +1711,6 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1572
1711
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1573
1712
|
|
|
1574
1713
|
_cacheMap.name = "@git-diff-view/react";
|
|
1575
|
-
var SplitSide;
|
|
1576
|
-
(function (SplitSide) {
|
|
1577
|
-
SplitSide[SplitSide["old"] = 1] = "old";
|
|
1578
|
-
SplitSide[SplitSide["new"] = 2] = "new";
|
|
1579
|
-
})(SplitSide || (SplitSide = {}));
|
|
1580
1714
|
var DiffModeEnum;
|
|
1581
1715
|
(function (DiffModeEnum) {
|
|
1582
1716
|
// github like
|
|
@@ -1587,7 +1721,7 @@ var DiffModeEnum;
|
|
|
1587
1721
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1588
1722
|
})(DiffModeEnum || (DiffModeEnum = {}));
|
|
1589
1723
|
const InternalDiffView = (props) => {
|
|
1590
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
|
|
1724
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1591
1725
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1592
1726
|
const wrapperRef = useRef();
|
|
1593
1727
|
// performance optimization
|
|
@@ -1595,7 +1729,7 @@ const InternalDiffView = (props) => {
|
|
|
1595
1729
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1596
1730
|
[]);
|
|
1597
1731
|
useEffect(() => {
|
|
1598
|
-
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();
|
|
1732
|
+
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();
|
|
1599
1733
|
if (diffFileId && diffFileId !== id) {
|
|
1600
1734
|
setId(diffFileId);
|
|
1601
1735
|
}
|
|
@@ -1623,6 +1757,9 @@ const InternalDiffView = (props) => {
|
|
|
1623
1757
|
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1624
1758
|
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1625
1759
|
}
|
|
1760
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1761
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1762
|
+
}
|
|
1626
1763
|
if (renderExtendLine !== _renderExtendLine) {
|
|
1627
1764
|
setRenderExtendLine(renderExtendLine);
|
|
1628
1765
|
}
|
|
@@ -1642,6 +1779,7 @@ const InternalDiffView = (props) => {
|
|
|
1642
1779
|
renderExtendLine,
|
|
1643
1780
|
extendData,
|
|
1644
1781
|
onAddWidgetClick,
|
|
1782
|
+
onCreateUseWidgetHook,
|
|
1645
1783
|
]);
|
|
1646
1784
|
useEffect(() => {
|
|
1647
1785
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1653,7 +1791,7 @@ const InternalDiffView = (props) => {
|
|
|
1653
1791
|
}, [diffFile]);
|
|
1654
1792
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1655
1793
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1656
|
-
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1794
|
+
React.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 },
|
|
1657
1795
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1658
1796
|
// @ts-ignore
|
|
1659
1797
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1719,7 +1857,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1719
1857
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
1720
1858
|
InnerDiffView.displayName = "DiffView";
|
|
1721
1859
|
const DiffView = InnerDiffView;
|
|
1722
|
-
const version = "0.0.
|
|
1860
|
+
const version = "0.0.28";
|
|
1723
1861
|
|
|
1724
|
-
export { DiffModeEnum, DiffView,
|
|
1862
|
+
export { DiffModeEnum, DiffView, version };
|
|
1725
1863
|
//# sourceMappingURL=index.mjs.map
|