@git-diff-view/react 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +419 -287
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +419 -287
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +4 -0
- package/dist/css/diff-view.css +4 -0
- package/dist/esm/index.mjs +353 -224
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +296 -16
- package/package.json +4 -3
- package/src/_base.css +3 -0
- package/src/_base_pure.css +2 -0
- package/src/_com.css +172 -0
- package/src/_theme.css +2 -0
- package/src/components/DiffAddWidget.tsx +86 -0
- package/src/components/DiffContent.tsx +367 -0
- package/src/components/DiffContent_v2.tsx +344 -0
- package/src/components/DiffExpand.tsx +25 -0
- package/src/components/DiffNoNewLine.tsx +10 -0
- package/src/components/DiffSplitContentLineNormal.tsx +164 -0
- package/src/components/DiffSplitContentLineWrap.tsx +234 -0
- package/src/components/DiffSplitExtendLineNormal.tsx +150 -0
- package/src/components/DiffSplitExtendLineWrap.tsx +133 -0
- package/src/components/DiffSplitHunkLineNormal.tsx +316 -0
- package/src/components/DiffSplitHunkLineWrap.tsx +340 -0
- package/src/components/DiffSplitView.tsx +46 -0
- package/src/components/DiffSplitViewNormal.tsx +205 -0
- package/src/components/DiffSplitViewWrap.tsx +141 -0
- package/src/components/DiffSplitWidgetLineNormal.tsx +149 -0
- package/src/components/DiffSplitWidgetLineWrap.tsx +127 -0
- package/src/components/DiffUnifiedContentLine.tsx +342 -0
- package/src/components/DiffUnifiedExtendLine.tsx +103 -0
- package/src/components/DiffUnifiedHunkLine.tsx +148 -0
- package/src/components/DiffUnifiedView.tsx +159 -0
- package/src/components/DiffUnifiedWidgetLine.tsx +104 -0
- package/src/components/DiffView.tsx +365 -0
- package/src/components/DiffViewContext.ts +11 -0
- package/src/components/DiffWidgetContext.ts +17 -0
- package/src/components/tools.ts +132 -0
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +152 -0
- package/src/components/v2/DiffSplitContentLineWrap_v2.tsx +259 -0
- package/src/components/v2/DiffSplitExtendLineNormal_v2.tsx +146 -0
- package/src/components/v2/DiffSplitExtendLineWrap_v2.tsx +123 -0
- package/src/components/v2/DiffSplitHunkLineNormal_v2.tsx +302 -0
- package/src/components/v2/DiffSplitHunkLineWrap_v2.tsx +326 -0
- package/src/components/v2/DiffSplitViewLineNormal_v2.tsx +33 -0
- package/src/components/v2/DiffSplitViewLineWrap_v2.tsx +24 -0
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +159 -0
- package/src/components/v2/DiffSplitViewWrap_v2.tsx +104 -0
- package/src/components/v2/DiffSplitView_v2.tsx +47 -0
- package/src/components/v2/DiffSplitWidgetLineNormal_v2.tsx +132 -0
- package/src/components/v2/DiffSplitWidgetLineWrap_v2.tsx +119 -0
- package/src/global.d.ts +12 -0
- package/src/hooks/useCallbackRef.ts +18 -0
- package/src/hooks/useDomWidth.ts +67 -0
- package/src/hooks/useIsMounted.ts +11 -0
- package/src/hooks/useSafeLayout.ts +5 -0
- package/src/hooks/useSyncHeight.ts +87 -0
- package/src/hooks/useTextWidth.ts +27 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/index.ts +3 -0
- package/src/tailwind.css +3 -0
- package/src/tailwind_pure.css +3 -0
- package/styles/diff-view-pure.css +4 -0
- package/styles/diff-view.css +4 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { NewLineSymbol, DiffLineType, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
|
|
2
|
+
import { NewLineSymbol, 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 = () => {
|
|
@@ -280,6 +282,7 @@ const DiffNoNewLine = () => {
|
|
|
280
282
|
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
283
|
};
|
|
282
284
|
|
|
285
|
+
/* eslint-disable max-lines */
|
|
283
286
|
const temp = {};
|
|
284
287
|
const formatStringToCamelCase = (str) => {
|
|
285
288
|
if (str.startsWith("--"))
|
|
@@ -306,30 +309,52 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
306
309
|
});
|
|
307
310
|
return style;
|
|
308
311
|
});
|
|
309
|
-
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
312
|
+
const DiffString = ({ rawLine, diffLine, operator, plainLine, enableWrap, }) => {
|
|
310
313
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
311
314
|
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
315
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
316
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) && typeof getPlainDiffTemplate === "function") {
|
|
317
|
+
getPlainDiffTemplate({ diffLine, rawLine, operator });
|
|
318
|
+
}
|
|
319
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.plainTemplate) {
|
|
320
|
+
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
321
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.plainTemplate } }),
|
|
322
|
+
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: {
|
|
323
|
+
width: `var(${diffFontSizeName})`,
|
|
324
|
+
height: `var(${diffFontSizeName})`,
|
|
325
|
+
} },
|
|
326
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
// TODO remove
|
|
330
|
+
const range = changes.range;
|
|
331
|
+
const str1 = rawLine.slice(0, range.location);
|
|
332
|
+
const str2 = rawLine.slice(range.location, range.location + range.length);
|
|
333
|
+
const str3 = rawLine.slice(range.location + range.length);
|
|
334
|
+
const isLast = str2.includes("\n");
|
|
335
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
336
|
+
return (React.createElement("span", { className: "diff-line-content-raw" },
|
|
337
|
+
React.createElement("span", { "data-range-start": range.location, "data-range-end": range.location + range.length },
|
|
338
|
+
str1,
|
|
339
|
+
React.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
340
|
+
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
341
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
342
|
+
_str2,
|
|
343
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
344
|
+
str3),
|
|
345
|
+
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: {
|
|
346
|
+
width: `var(${diffFontSizeName})`,
|
|
347
|
+
height: `var(${diffFontSizeName})`,
|
|
348
|
+
} },
|
|
349
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (plainLine && !(plainLine === null || plainLine === void 0 ? void 0 : plainLine.template)) {
|
|
353
|
+
plainLine.template = getPlainLineTemplate(plainLine.value);
|
|
354
|
+
}
|
|
355
|
+
if (plainLine === null || plainLine === void 0 ? void 0 : plainLine.template) {
|
|
319
356
|
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)))));
|
|
357
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: plainLine.template } })));
|
|
333
358
|
}
|
|
334
359
|
return React.createElement("span", { className: "diff-line-content-raw" }, rawLine);
|
|
335
360
|
};
|
|
@@ -341,49 +366,73 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
341
366
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
342
367
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
343
368
|
const isNewLineSymbolChanged = changes.newLineSymbol;
|
|
344
|
-
|
|
369
|
+
if (!(diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) && typeof getSyntaxDiffTemplate === "function") {
|
|
370
|
+
getSyntaxDiffTemplate({ diffLine, syntaxLine, operator });
|
|
371
|
+
}
|
|
372
|
+
if (diffLine === null || diffLine === void 0 ? void 0 : diffLine.syntaxTemplate) {
|
|
373
|
+
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
374
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: diffLine.syntaxTemplate } }),
|
|
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)))));
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// TODO remove
|
|
383
|
+
const range = changes.range;
|
|
384
|
+
return (React.createElement("span", { className: "diff-line-syntax-raw" },
|
|
385
|
+
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) => {
|
|
386
|
+
var _a, _b, _c, _d, _e, _f;
|
|
387
|
+
if (node.endIndex < range.location || range.location + range.length < node.startIndex) {
|
|
388
|
+
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));
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
const index1 = range.location - node.startIndex;
|
|
392
|
+
const index2 = index1 < 0 ? 0 : index1;
|
|
393
|
+
const str1 = node.value.slice(0, index2);
|
|
394
|
+
const str2 = node.value.slice(index2, index1 + range.length);
|
|
395
|
+
const str3 = node.value.slice(index1 + range.length);
|
|
396
|
+
const isStart = str1.length || range.location === node.startIndex;
|
|
397
|
+
const isEnd = str3.length || node.endIndex === range.location + range.length - 1;
|
|
398
|
+
const isLast = str2.includes("\n");
|
|
399
|
+
const _str2 = isLast ? str2.replace("\n", "").replace("\r", "") : str2;
|
|
400
|
+
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) || "") },
|
|
401
|
+
str1,
|
|
402
|
+
React.createElement("span", { "data-diff-highlight": true, style: {
|
|
403
|
+
backgroundColor: operator === "add"
|
|
404
|
+
? `var(${addContentHighlightBGName})`
|
|
405
|
+
: `var(${delContentHighlightBGName})`,
|
|
406
|
+
borderTopLeftRadius: isStart ? "0.2em" : undefined,
|
|
407
|
+
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
408
|
+
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
409
|
+
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
410
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
411
|
+
_str2,
|
|
412
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
413
|
+
str3));
|
|
414
|
+
}
|
|
415
|
+
})),
|
|
416
|
+
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: {
|
|
417
|
+
width: `var(${diffFontSizeName})`,
|
|
418
|
+
height: `var(${diffFontSizeName})`,
|
|
419
|
+
} },
|
|
420
|
+
React.createElement(DiffNoNewLine, null)))));
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (!syntaxLine.template) {
|
|
424
|
+
syntaxLine.template = getSyntaxLineTemplate(syntaxLine);
|
|
425
|
+
}
|
|
426
|
+
if (syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.template) {
|
|
345
427
|
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)))));
|
|
428
|
+
React.createElement("span", { "data-template": true, dangerouslySetInnerHTML: { __html: syntaxLine.template } })));
|
|
380
429
|
}
|
|
381
430
|
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
431
|
var _a, _b, _c;
|
|
383
432
|
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
433
|
})));
|
|
385
434
|
};
|
|
386
|
-
const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
435
|
+
const DiffContent = ({ diffLine, rawLine, plainLine, syntaxLine, enableWrap, enableHighlight, }) => {
|
|
387
436
|
var _a;
|
|
388
437
|
const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Add;
|
|
389
438
|
const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Delete;
|
|
@@ -395,7 +444,7 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
|
|
|
395
444
|
wordBreak: enableWrap ? "break-all" : "initial",
|
|
396
445
|
} },
|
|
397
446
|
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 }))));
|
|
447
|
+
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
448
|
};
|
|
400
449
|
|
|
401
450
|
const DiffViewContext = createContext(null);
|
|
@@ -406,9 +455,10 @@ const DiffWidgetContext = createContext(null);
|
|
|
406
455
|
DiffWidgetContext.displayName = "DiffWidgetContext";
|
|
407
456
|
const useDiffWidgetContext = () => useContext(DiffWidgetContext);
|
|
408
457
|
|
|
409
|
-
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
458
|
+
const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
410
459
|
var _a, _b;
|
|
411
460
|
const getCurrentSyntaxLine = side === SplitSide.old ? diffFile.getOldSyntaxLine : diffFile.getNewSyntaxLine;
|
|
461
|
+
const getCurrentPlainLine = side === SplitSide.old ? diffFile.getOldPlainLine : diffFile.getNewPlainLine;
|
|
412
462
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
413
463
|
const newLine = diffFile.getSplitRightLine(index);
|
|
414
464
|
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
@@ -418,20 +468,17 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
418
468
|
const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
|
|
419
469
|
const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
|
|
420
470
|
const { useDiffContext } = useDiffViewContext();
|
|
421
|
-
const
|
|
422
|
-
enableHighlight: s.enableHighlight,
|
|
423
|
-
enableAddWidget: s.enableAddWidget,
|
|
424
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
425
|
-
}));
|
|
471
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
426
472
|
const { useWidget } = useDiffWidgetContext();
|
|
427
473
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
428
474
|
const contentBG = getContentBG(isAdded, isDelete, hasDiff);
|
|
429
475
|
const lineNumberBG = getLineNumberBG(isAdded, isDelete, hasDiff);
|
|
430
476
|
const syntaxLine = getCurrentSyntaxLine(currentLine.lineNumber);
|
|
477
|
+
const plainLine = getCurrentPlainLine(currentLine.lineNumber);
|
|
431
478
|
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
479
|
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
480
|
backgroundColor: lineNumberBG,
|
|
434
|
-
color: `var(${plainLineNumberColorName})`,
|
|
481
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
435
482
|
width: `var(${diffAsideWidthName})`,
|
|
436
483
|
minWidth: `var(${diffAsideWidthName})`,
|
|
437
484
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
@@ -439,15 +486,15 @@ const InternalDiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
|
439
486
|
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
487
|
React.createElement("span", { "data-line-num": currentLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, currentLine.lineNumber)),
|
|
441
488
|
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 },
|
|
489
|
+
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
490
|
React.createElement("span", null, "\u2002")))));
|
|
444
491
|
};
|
|
445
|
-
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
|
|
492
|
+
const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, enableAddWidget, enableHighlight, }) => {
|
|
446
493
|
const getCurrentLine = side === SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
|
|
447
494
|
const currentLine = getCurrentLine(index);
|
|
448
495
|
if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
|
|
449
496
|
return null;
|
|
450
|
-
return React.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
|
|
497
|
+
return (React.createElement(InternalDiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
451
498
|
};
|
|
452
499
|
|
|
453
500
|
const useDomWidth = ({ selector, enable }) => {
|
|
@@ -578,7 +625,7 @@ const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLine
|
|
|
578
625
|
if (!renderExtendLine)
|
|
579
626
|
return null;
|
|
580
627
|
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 },
|
|
628
|
+
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
629
|
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] })))));
|
|
583
630
|
};
|
|
584
631
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -745,7 +792,7 @@ const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) =
|
|
|
745
792
|
if (!renderWidgetLine)
|
|
746
793
|
return null;
|
|
747
794
|
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 },
|
|
795
|
+
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
796
|
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
|
|
750
797
|
};
|
|
751
798
|
// TODO! improve performance
|
|
@@ -767,15 +814,7 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
767
814
|
};
|
|
768
815
|
|
|
769
816
|
/* 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 }) => {
|
|
817
|
+
const DiffSplitViewTable = ({ side, diffFile, enableAddWidget, enableHighlight, onMouseDown, }) => {
|
|
779
818
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
780
819
|
const lines = getSplitContentLines(diffFile);
|
|
781
820
|
return (React.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": SplitSide[side] },
|
|
@@ -790,10 +829,10 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
790
829
|
React.createElement("th", { scope: "col" },
|
|
791
830
|
SplitSide[side],
|
|
792
831
|
" line content"))),
|
|
793
|
-
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown
|
|
832
|
+
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
794
833
|
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
795
834
|
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 }),
|
|
835
|
+
React.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
797
836
|
React.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
798
837
|
React.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
799
838
|
React.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -801,9 +840,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
801
840
|
const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
802
841
|
const ref1 = useRef(null);
|
|
803
842
|
const ref2 = useRef(null);
|
|
843
|
+
const ref = useRef();
|
|
804
844
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
805
845
|
const { useDiffContext } = useDiffViewContext();
|
|
806
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) =>
|
|
846
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
847
|
+
fontSize: s.fontSize,
|
|
848
|
+
enableAddWidget: s.enableAddWidget,
|
|
849
|
+
enableHighlight: s.enableHighlight,
|
|
850
|
+
}));
|
|
807
851
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
808
852
|
useEffect(() => {
|
|
809
853
|
const left = ref1.current;
|
|
@@ -818,7 +862,46 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
818
862
|
font,
|
|
819
863
|
});
|
|
820
864
|
const width = Math.max(40, _width + 25);
|
|
865
|
+
const setStyle = (side) => {
|
|
866
|
+
if (!ref.current)
|
|
867
|
+
return;
|
|
868
|
+
if (!side) {
|
|
869
|
+
ref.current.textContent = "";
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
873
|
+
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}`;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
const onMouseDown = (e) => {
|
|
877
|
+
let ele = e.target;
|
|
878
|
+
// need remove all the selection
|
|
879
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
880
|
+
removeAllSelection();
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
while (ele && ele instanceof HTMLElement) {
|
|
884
|
+
const state = ele.getAttribute("data-state");
|
|
885
|
+
const side = ele.getAttribute("data-side");
|
|
886
|
+
if (side) {
|
|
887
|
+
setStyle(SplitSide[side]);
|
|
888
|
+
removeAllSelection();
|
|
889
|
+
}
|
|
890
|
+
if (state) {
|
|
891
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
892
|
+
setStyle(undefined);
|
|
893
|
+
removeAllSelection();
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
else {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
ele = ele.parentElement;
|
|
901
|
+
}
|
|
902
|
+
};
|
|
821
903
|
return (React.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
|
|
904
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
822
905
|
React.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
823
906
|
// @ts-ignore
|
|
824
907
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -826,7 +909,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
826
909
|
fontFamily: "Menlo, Consolas, monospace",
|
|
827
910
|
fontSize: `var(${diffFontSizeName})`,
|
|
828
911
|
} },
|
|
829
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
912
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
830
913
|
React.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
831
914
|
React.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
832
915
|
// @ts-ignore
|
|
@@ -835,26 +918,24 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
835
918
|
fontFamily: "Menlo, Consolas, monospace",
|
|
836
919
|
fontSize: `var(${diffFontSizeName})`,
|
|
837
920
|
} },
|
|
838
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile }))));
|
|
921
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
839
922
|
});
|
|
840
923
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
841
924
|
|
|
842
|
-
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
925
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
843
926
|
var _a, _b;
|
|
844
927
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
845
928
|
const newLine = diffFile.getSplitRightLine(index);
|
|
846
929
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
930
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
847
931
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
932
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
848
933
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
849
934
|
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
850
935
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
|
|
851
936
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
|
|
852
937
|
const { useDiffContext } = useDiffViewContext();
|
|
853
|
-
const
|
|
854
|
-
enableHighlight: s.enableHighlight,
|
|
855
|
-
enableAddWidget: s.enableAddWidget,
|
|
856
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
857
|
-
}));
|
|
938
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
858
939
|
const { useWidget } = useDiffWidgetContext();
|
|
859
940
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
860
941
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -870,12 +951,12 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
870
951
|
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
871
952
|
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
872
953
|
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 },
|
|
954
|
+
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
955
|
React.createElement("span", null, "\u2002"))),
|
|
875
956
|
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
876
957
|
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
958
|
backgroundColor: newLineNumberBG,
|
|
878
|
-
color: `var(${plainLineNumberColorName})`,
|
|
959
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
879
960
|
borderLeftColor: `var(${borderColorName})`,
|
|
880
961
|
borderLeftStyle: "solid",
|
|
881
962
|
} },
|
|
@@ -883,19 +964,19 @@ const InternalDiffSplitLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
883
964
|
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
884
965
|
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
885
966
|
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: {
|
|
967
|
+
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
968
|
backgroundColor: `var(${emptyBGName})`,
|
|
888
969
|
borderLeftColor: `var(${borderColorName})`,
|
|
889
970
|
borderLeftStyle: "solid",
|
|
890
971
|
}, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
|
|
891
972
|
React.createElement("span", null, "\u2002")))));
|
|
892
973
|
};
|
|
893
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
974
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
894
975
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
895
976
|
const newLine = diffFile.getSplitRightLine(index);
|
|
896
977
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
897
978
|
return null;
|
|
898
|
-
return React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
979
|
+
return (React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
899
980
|
};
|
|
900
981
|
|
|
901
982
|
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -924,13 +1005,13 @@ const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExten
|
|
|
924
1005
|
}));
|
|
925
1006
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
926
1007
|
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 }
|
|
1008
|
+
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
1009
|
newExtendRendered ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
|
|
929
1010
|
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
1011
|
backgroundColor: `var(${emptyBGName})`,
|
|
931
1012
|
borderLeftColor: `var(${borderColorName})`,
|
|
932
1013
|
borderLeftStyle: "solid",
|
|
933
|
-
}, colSpan: 2 }
|
|
1014
|
+
}, colSpan: 2 }))));
|
|
934
1015
|
};
|
|
935
1016
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
936
1017
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1065,13 +1146,13 @@ const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1065
1146
|
return null;
|
|
1066
1147
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1067
1148
|
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 }
|
|
1149
|
+
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
1150
|
newWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
|
|
1070
1151
|
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
1152
|
backgroundColor: `var(${emptyBGName})`,
|
|
1072
1153
|
borderLeftColor: `var(${borderColorName})`,
|
|
1073
1154
|
borderLeftStyle: "solid",
|
|
1074
|
-
}, colSpan: 2 }
|
|
1155
|
+
}, colSpan: 2 }))));
|
|
1075
1156
|
};
|
|
1076
1157
|
// TODO! improve performance
|
|
1077
1158
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1091,6 +1172,93 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1091
1172
|
return React.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1092
1173
|
};
|
|
1093
1174
|
|
|
1175
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1176
|
+
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1177
|
+
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1178
|
+
const { useDiffContext } = useDiffViewContext();
|
|
1179
|
+
const ref = useRef(null);
|
|
1180
|
+
const { fontSize, enableAddWidget, enableHighlight } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1181
|
+
fontSize: s.fontSize,
|
|
1182
|
+
enableAddWidget: s.enableAddWidget,
|
|
1183
|
+
enableHighlight: s.enableHighlight,
|
|
1184
|
+
}));
|
|
1185
|
+
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1186
|
+
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1187
|
+
const _width = useTextWidth({
|
|
1188
|
+
text: splitLineLength.toString(),
|
|
1189
|
+
font,
|
|
1190
|
+
});
|
|
1191
|
+
const width = Math.max(40, _width + 25);
|
|
1192
|
+
const lines = getSplitContentLines(diffFile);
|
|
1193
|
+
const setStyle = (side) => {
|
|
1194
|
+
if (!ref.current)
|
|
1195
|
+
return;
|
|
1196
|
+
if (!side) {
|
|
1197
|
+
ref.current.textContent = "";
|
|
1198
|
+
}
|
|
1199
|
+
else {
|
|
1200
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1201
|
+
const targetSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
1202
|
+
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}`;
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
const onMouseDown = (e) => {
|
|
1206
|
+
let ele = e.target;
|
|
1207
|
+
// need remove all the selection
|
|
1208
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1209
|
+
removeAllSelection();
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1213
|
+
const state = ele.getAttribute("data-state");
|
|
1214
|
+
const side = ele.getAttribute("data-side");
|
|
1215
|
+
if (side) {
|
|
1216
|
+
setStyle(SplitSide[side]);
|
|
1217
|
+
removeAllSelection();
|
|
1218
|
+
}
|
|
1219
|
+
if (state) {
|
|
1220
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1221
|
+
setStyle(undefined);
|
|
1222
|
+
removeAllSelection();
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
ele = ele.parentElement;
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1233
|
+
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1234
|
+
// @ts-ignore
|
|
1235
|
+
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1236
|
+
fontFamily: "Menlo, Consolas, monospace",
|
|
1237
|
+
fontSize: `var(${diffFontSizeName})`,
|
|
1238
|
+
} },
|
|
1239
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1240
|
+
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1241
|
+
React.createElement("colgroup", null,
|
|
1242
|
+
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1243
|
+
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1244
|
+
React.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1245
|
+
React.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1246
|
+
React.createElement("thead", { className: "hidden" },
|
|
1247
|
+
React.createElement("tr", null,
|
|
1248
|
+
React.createElement("th", { scope: "col" }, "old line number"),
|
|
1249
|
+
React.createElement("th", { scope: "col" }, "old line content"),
|
|
1250
|
+
React.createElement("th", { scope: "col" }, "new line number"),
|
|
1251
|
+
React.createElement("th", { scope: "col" }, "new line content"))),
|
|
1252
|
+
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1253
|
+
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
1254
|
+
React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1255
|
+
React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }),
|
|
1256
|
+
React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1257
|
+
React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1258
|
+
React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1259
|
+
});
|
|
1260
|
+
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1261
|
+
|
|
1094
1262
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1095
1263
|
return createStore(() => {
|
|
1096
1264
|
var _a, _b;
|
|
@@ -1138,6 +1306,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1138
1306
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1139
1307
|
const renderExtendLine = ref(props.renderExtendLine);
|
|
1140
1308
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1309
|
+
const onCreateUseWidgetHook = ref(props.onCreateUseWidgetHook);
|
|
1310
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1141
1311
|
// 避免无意义的订阅
|
|
1142
1312
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1143
1313
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1164,6 +1334,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1164
1334
|
setRenderExtendLine,
|
|
1165
1335
|
onAddWidgetClick,
|
|
1166
1336
|
setOnAddWidgetClick,
|
|
1337
|
+
onCreateUseWidgetHook,
|
|
1338
|
+
setOnCreateUseWidgetHook,
|
|
1167
1339
|
};
|
|
1168
1340
|
});
|
|
1169
1341
|
};
|
|
@@ -1182,95 +1354,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1182
1354
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1183
1355
|
});
|
|
1184
1356
|
};
|
|
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
1357
|
|
|
1269
1358
|
const DiffSplitView = memo(({ diffFile }) => {
|
|
1270
1359
|
const { useDiffContext } = useDiffViewContext();
|
|
1271
1360
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1272
1361
|
useDiffContextRef.current = useDiffContext;
|
|
1273
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1362
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1363
|
+
enableWrap: s.enableWrap,
|
|
1364
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1365
|
+
}));
|
|
1274
1366
|
// performance optimization
|
|
1275
1367
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1276
1368
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1278,11 +1370,14 @@ const DiffSplitView = memo(({ diffFile }) => {
|
|
|
1278
1370
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1279
1371
|
setWidget({});
|
|
1280
1372
|
}, [diffFile, useWidget]);
|
|
1373
|
+
useEffect(() => {
|
|
1374
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1375
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1281
1376
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1282
1377
|
});
|
|
1283
1378
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1284
1379
|
|
|
1285
|
-
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1380
|
+
const DiffUnifiedOldLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1286
1381
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1287
1382
|
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
1383
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1297,9 +1392,9 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1297
1392
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1298
1393
|
React.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1299
1394
|
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 }))));
|
|
1395
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1301
1396
|
};
|
|
1302
|
-
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1397
|
+
const DiffUnifiedNewLine = ({ index, diffLine, rawLine, plainLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
|
|
1303
1398
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1304
1399
|
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
1400
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1314,17 +1409,12 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1314
1409
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1315
1410
|
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1316
1411
|
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 }))));
|
|
1412
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1318
1413
|
};
|
|
1319
|
-
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
1414
|
+
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1320
1415
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1321
1416
|
const { useDiffContext } = useDiffViewContext();
|
|
1322
|
-
const
|
|
1323
|
-
enableWrap: s.enableWrap,
|
|
1324
|
-
enableHighlight: s.enableHighlight,
|
|
1325
|
-
enableAddWidget: s.enableAddWidget,
|
|
1326
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1327
|
-
}));
|
|
1417
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1328
1418
|
const { useWidget } = useDiffWidgetContext();
|
|
1329
1419
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1330
1420
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1338,18 +1428,23 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1338
1428
|
: oldLinenumber
|
|
1339
1429
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1340
1430
|
: undefined;
|
|
1431
|
+
const plainLine = newLineNumber
|
|
1432
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1433
|
+
: oldLinenumber
|
|
1434
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1435
|
+
: undefined;
|
|
1341
1436
|
if (hasChange) {
|
|
1342
1437
|
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); } }));
|
|
1438
|
+
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
1439
|
}
|
|
1345
1440
|
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); } }));
|
|
1441
|
+
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
1442
|
}
|
|
1348
1443
|
}
|
|
1349
1444
|
else {
|
|
1350
1445
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1351
1446
|
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})`,
|
|
1447
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1353
1448
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1354
1449
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1355
1450
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1363,15 +1458,15 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1363
1458
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1364
1459
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1365
1460
|
} },
|
|
1366
|
-
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
|
|
1461
|
+
React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, plainLine: plainLine, syntaxLine: syntaxLine }))));
|
|
1367
1462
|
}
|
|
1368
1463
|
});
|
|
1369
1464
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1370
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1465
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1371
1466
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1372
1467
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1373
1468
|
return null;
|
|
1374
|
-
return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1469
|
+
return (React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }));
|
|
1375
1470
|
};
|
|
1376
1471
|
|
|
1377
1472
|
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
@@ -1386,7 +1481,7 @@ const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExt
|
|
|
1386
1481
|
return null;
|
|
1387
1482
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1388
1483
|
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 } },
|
|
1484
|
+
React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1390
1485
|
width > 0 &&
|
|
1391
1486
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1392
1487
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
@@ -1489,7 +1584,7 @@ const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1489
1584
|
return null;
|
|
1490
1585
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1491
1586
|
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 } },
|
|
1587
|
+
React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0 z-[1]", style: { width } },
|
|
1493
1588
|
width > 0 &&
|
|
1494
1589
|
oldWidget &&
|
|
1495
1590
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
@@ -1514,30 +1609,29 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1514
1609
|
};
|
|
1515
1610
|
|
|
1516
1611
|
/* 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
1612
|
const DiffUnifiedView = memo(({ diffFile }) => {
|
|
1526
1613
|
const { useDiffContext } = useDiffViewContext();
|
|
1614
|
+
const ref = useRef(null);
|
|
1527
1615
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1528
1616
|
useDiffContextRef.current = useDiffContext;
|
|
1529
1617
|
// performance optimization
|
|
1530
1618
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1531
1619
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1532
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1620
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1533
1621
|
fontSize: s.fontSize,
|
|
1534
1622
|
enableWrap: s.enableWrap,
|
|
1623
|
+
enableHighlight: s.enableHighlight,
|
|
1624
|
+
enableAddWidget: s.enableAddWidget,
|
|
1625
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1535
1626
|
}));
|
|
1536
1627
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1537
1628
|
useEffect(() => {
|
|
1538
1629
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1539
1630
|
setWidget({});
|
|
1540
1631
|
}, [diffFile, useWidget]);
|
|
1632
|
+
useEffect(() => {
|
|
1633
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1634
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1541
1635
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1542
1636
|
const _width = useTextWidth({
|
|
1543
1637
|
text: unifiedLineLength.toString(),
|
|
@@ -1545,8 +1639,44 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1545
1639
|
});
|
|
1546
1640
|
const width = Math.max(40, _width + 10);
|
|
1547
1641
|
const lines = getUnifiedContentLine(diffFile);
|
|
1642
|
+
const setStyle = (side) => {
|
|
1643
|
+
if (!ref.current)
|
|
1644
|
+
return;
|
|
1645
|
+
if (!side) {
|
|
1646
|
+
ref.current.textContent = "";
|
|
1647
|
+
}
|
|
1648
|
+
else {
|
|
1649
|
+
const id = `diff-root${diffFile.getId()}`;
|
|
1650
|
+
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}`;
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
const onMouseDown = (e) => {
|
|
1654
|
+
let ele = e.target;
|
|
1655
|
+
// need remove all the selection
|
|
1656
|
+
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1657
|
+
removeAllSelection();
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
while (ele && ele instanceof HTMLElement) {
|
|
1661
|
+
const state = ele.getAttribute("data-state");
|
|
1662
|
+
if (state) {
|
|
1663
|
+
if (state === "extend" || state === "hunk" || state === "widget") {
|
|
1664
|
+
setStyle(undefined);
|
|
1665
|
+
removeAllSelection();
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
else {
|
|
1669
|
+
setStyle(SplitSide.new);
|
|
1670
|
+
removeAllSelection();
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
ele = ele.parentElement;
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1548
1677
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1549
1678
|
React.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
|
|
1679
|
+
React.createElement("style", { "data-select-style": true, ref: ref }),
|
|
1550
1680
|
React.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1551
1681
|
// @ts-ignore
|
|
1552
1682
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1564,7 +1694,7 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1564
1694
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1565
1695
|
lines.map((item) => (React.createElement(Fragment, { key: item.index },
|
|
1566
1696
|
React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1567
|
-
React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1697
|
+
React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile, enableWrap: enableWrap, enableHighlight: enableHighlight, enableAddWidget: enableAddWidget }),
|
|
1568
1698
|
React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1569
1699
|
React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1570
1700
|
React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1572,11 +1702,6 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1572
1702
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1573
1703
|
|
|
1574
1704
|
_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
1705
|
var DiffModeEnum;
|
|
1581
1706
|
(function (DiffModeEnum) {
|
|
1582
1707
|
// github like
|
|
@@ -1587,7 +1712,7 @@ var DiffModeEnum;
|
|
|
1587
1712
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1588
1713
|
})(DiffModeEnum || (DiffModeEnum = {}));
|
|
1589
1714
|
const InternalDiffView = (props) => {
|
|
1590
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, isMounted, } = props;
|
|
1715
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1591
1716
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1592
1717
|
const wrapperRef = useRef();
|
|
1593
1718
|
// performance optimization
|
|
@@ -1595,7 +1720,7 @@ const InternalDiffView = (props) => {
|
|
|
1595
1720
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1596
1721
|
[]);
|
|
1597
1722
|
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();
|
|
1723
|
+
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
1724
|
if (diffFileId && diffFileId !== id) {
|
|
1600
1725
|
setId(diffFileId);
|
|
1601
1726
|
}
|
|
@@ -1623,6 +1748,9 @@ const InternalDiffView = (props) => {
|
|
|
1623
1748
|
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1624
1749
|
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1625
1750
|
}
|
|
1751
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1752
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1753
|
+
}
|
|
1626
1754
|
if (renderExtendLine !== _renderExtendLine) {
|
|
1627
1755
|
setRenderExtendLine(renderExtendLine);
|
|
1628
1756
|
}
|
|
@@ -1642,6 +1770,7 @@ const InternalDiffView = (props) => {
|
|
|
1642
1770
|
renderExtendLine,
|
|
1643
1771
|
extendData,
|
|
1644
1772
|
onAddWidgetClick,
|
|
1773
|
+
onCreateUseWidgetHook,
|
|
1645
1774
|
]);
|
|
1646
1775
|
useEffect(() => {
|
|
1647
1776
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1653,7 +1782,7 @@ const InternalDiffView = (props) => {
|
|
|
1653
1782
|
}, [diffFile]);
|
|
1654
1783
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1655
1784
|
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.
|
|
1785
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.27", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1657
1786
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1658
1787
|
// @ts-ignore
|
|
1659
1788
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1719,7 +1848,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1719
1848
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
1720
1849
|
InnerDiffView.displayName = "DiffView";
|
|
1721
1850
|
const DiffView = InnerDiffView;
|
|
1722
|
-
const version = "0.0.
|
|
1851
|
+
const version = "0.0.27";
|
|
1723
1852
|
|
|
1724
|
-
export { DiffModeEnum, DiffView,
|
|
1853
|
+
export { DiffModeEnum, DiffView, version };
|
|
1725
1854
|
//# sourceMappingURL=index.mjs.map
|