@git-diff-view/react 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +543 -376
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +543 -376
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +5 -1
- package/dist/css/diff-view.css +6 -2
- package/dist/esm/index.mjs +485 -321
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +317 -23
- package/package.json +8 -7
- package/src/_base.css +3 -0
- package/src/_base_pure.css +2 -0
- package/src/_com.css +172 -0
- package/src/_theme.css +2 -0
- package/src/components/DiffAddWidget.tsx +86 -0
- package/src/components/DiffContent.tsx +367 -0
- package/src/components/DiffContent_v2.tsx +344 -0
- package/src/components/DiffExpand.tsx +25 -0
- package/src/components/DiffNoNewLine.tsx +10 -0
- package/src/components/DiffSplitContentLineNormal.tsx +164 -0
- package/src/components/DiffSplitContentLineWrap.tsx +234 -0
- package/src/components/DiffSplitExtendLineNormal.tsx +150 -0
- package/src/components/DiffSplitExtendLineWrap.tsx +133 -0
- package/src/components/DiffSplitHunkLineNormal.tsx +316 -0
- package/src/components/DiffSplitHunkLineWrap.tsx +340 -0
- package/src/components/DiffSplitView.tsx +46 -0
- package/src/components/DiffSplitViewNormal.tsx +205 -0
- package/src/components/DiffSplitViewWrap.tsx +141 -0
- package/src/components/DiffSplitWidgetLineNormal.tsx +149 -0
- package/src/components/DiffSplitWidgetLineWrap.tsx +127 -0
- package/src/components/DiffUnifiedContentLine.tsx +342 -0
- package/src/components/DiffUnifiedExtendLine.tsx +103 -0
- package/src/components/DiffUnifiedHunkLine.tsx +148 -0
- package/src/components/DiffUnifiedView.tsx +159 -0
- package/src/components/DiffUnifiedWidgetLine.tsx +104 -0
- package/src/components/DiffView.tsx +365 -0
- package/src/components/DiffViewContext.ts +11 -0
- package/src/components/DiffWidgetContext.ts +17 -0
- package/src/components/tools.ts +132 -0
- package/src/components/v2/DiffSplitContentLineNormal_v2.tsx +152 -0
- package/src/components/v2/DiffSplitContentLineWrap_v2.tsx +259 -0
- package/src/components/v2/DiffSplitExtendLineNormal_v2.tsx +146 -0
- package/src/components/v2/DiffSplitExtendLineWrap_v2.tsx +123 -0
- package/src/components/v2/DiffSplitHunkLineNormal_v2.tsx +302 -0
- package/src/components/v2/DiffSplitHunkLineWrap_v2.tsx +326 -0
- package/src/components/v2/DiffSplitViewLineNormal_v2.tsx +33 -0
- package/src/components/v2/DiffSplitViewLineWrap_v2.tsx +24 -0
- package/src/components/v2/DiffSplitViewNormal_v2.tsx +159 -0
- package/src/components/v2/DiffSplitViewWrap_v2.tsx +104 -0
- package/src/components/v2/DiffSplitView_v2.tsx +47 -0
- package/src/components/v2/DiffSplitWidgetLineNormal_v2.tsx +132 -0
- package/src/components/v2/DiffSplitWidgetLineWrap_v2.tsx +119 -0
- package/src/global.d.ts +12 -0
- package/src/hooks/useCallbackRef.ts +18 -0
- package/src/hooks/useDomWidth.ts +67 -0
- package/src/hooks/useIsMounted.ts +11 -0
- package/src/hooks/useSafeLayout.ts +5 -0
- package/src/hooks/useSyncHeight.ts +87 -0
- package/src/hooks/useTextWidth.ts +27 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/index.ts +3 -0
- package/src/tailwind.css +3 -0
- package/src/tailwind_pure.css +3 -0
- package/styles/diff-view-pure.css +5 -1
- package/styles/diff-view.css +6 -2
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
|
-
import { useState, useEffect, useRef, useLayoutEffect, createContext, useContext,
|
|
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
|
/******************************************************************************
|
|
@@ -65,7 +65,7 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
68
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
68
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
69
69
|
return (state.set(receiver, value)), value;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -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 = () => {
|
|
@@ -188,7 +190,7 @@ const syncScroll = (left, right) => {
|
|
|
188
190
|
const diffFontSizeName = "--diff-font-size--";
|
|
189
191
|
const diffAsideWidthName = "--diff-aside-width--";
|
|
190
192
|
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
192
194
|
const memoFunc = (func) => {
|
|
193
195
|
const cache = {};
|
|
194
196
|
return ((key) => {
|
|
@@ -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
|
|
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 _DiffSplitLine$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,21 +486,21 @@ const _DiffSplitLine$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(
|
|
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 }) => {
|
|
454
501
|
const [width, setWidth] = useState(0);
|
|
455
502
|
const { useDiffContext } = useDiffViewContext();
|
|
456
|
-
const id = useDiffContext(
|
|
503
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
457
504
|
useEffect(() => {
|
|
458
505
|
if (enable) {
|
|
459
506
|
const container = document.querySelector(`#diff-root${id}`);
|
|
@@ -489,87 +536,96 @@ const useDomWidth = ({ selector, enable }) => {
|
|
|
489
536
|
typedWrapper.setAttribute("data-observe", "height");
|
|
490
537
|
return () => cleanCb();
|
|
491
538
|
}
|
|
492
|
-
}, [selector, enable, id]);
|
|
539
|
+
}, [selector, enable, id, mounted]);
|
|
493
540
|
return width;
|
|
494
541
|
};
|
|
495
542
|
|
|
496
|
-
// TODO
|
|
497
543
|
const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
|
|
498
544
|
const { useDiffContext } = useDiffViewContext();
|
|
499
|
-
const id = useDiffContext(
|
|
545
|
+
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({ id: s.id, mounted: s.mounted }));
|
|
500
546
|
useEffect(() => {
|
|
501
547
|
if (enable) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
548
|
+
const container = document.querySelector(`#diff-root${id}`);
|
|
549
|
+
const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
|
|
550
|
+
const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
|
|
551
|
+
if (elements.length === 2 && wrappers.length === 2) {
|
|
552
|
+
const ele1 = elements[0];
|
|
553
|
+
const ele2 = elements[1];
|
|
554
|
+
const wrapper1 = wrappers[0];
|
|
555
|
+
const wrapper2 = wrappers[1];
|
|
556
|
+
const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
|
|
557
|
+
const typedTarget = target;
|
|
558
|
+
const cb = () => {
|
|
559
|
+
ele1.style.height = "auto";
|
|
560
|
+
ele2.style.height = "auto";
|
|
561
|
+
const rect1 = ele1.getBoundingClientRect();
|
|
562
|
+
const rect2 = ele2.getBoundingClientRect();
|
|
563
|
+
const maxHeight = Math.max(rect1.height, rect2.height);
|
|
564
|
+
wrapper1.style.height = maxHeight + "px";
|
|
565
|
+
wrapper2.style.height = maxHeight + "px";
|
|
566
|
+
wrapper1.setAttribute("data-sync-height", String(maxHeight));
|
|
567
|
+
wrapper2.setAttribute("data-sync-height", String(maxHeight));
|
|
568
|
+
};
|
|
569
|
+
cb();
|
|
570
|
+
const cleanCb = () => {
|
|
571
|
+
var _a;
|
|
572
|
+
typedTarget.__observeCallback.delete(cb);
|
|
573
|
+
if (typedTarget.__observeCallback.size === 0) {
|
|
574
|
+
(_a = typedTarget.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
575
|
+
typedTarget.removeAttribute("data-observe");
|
|
576
|
+
delete typedTarget.__observeCallback;
|
|
577
|
+
delete typedTarget.__observeInstance;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
if (typedTarget.__observeCallback) {
|
|
581
|
+
typedTarget.__observeCallback.add(cb);
|
|
582
|
+
return () => cleanCb();
|
|
533
583
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
584
|
+
typedTarget.__observeCallback = new Set();
|
|
585
|
+
typedTarget.__observeCallback.add(cb);
|
|
586
|
+
const observer = new ResizeObserver(() => typedTarget.__observeCallback.forEach((cb) => cb()));
|
|
587
|
+
typedTarget.__observeInstance = observer;
|
|
588
|
+
observer.observe(target);
|
|
589
|
+
target.setAttribute("data-observe", "height");
|
|
590
|
+
return () => cleanCb();
|
|
591
|
+
}
|
|
539
592
|
}
|
|
540
|
-
}, [selector, enable, side, id, wrapper]);
|
|
593
|
+
}, [selector, enable, side, id, wrapper, mounted]);
|
|
541
594
|
};
|
|
542
595
|
|
|
543
|
-
const
|
|
596
|
+
const InternalDiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
|
|
544
597
|
const { useDiffContext } = useDiffViewContext();
|
|
545
598
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
546
599
|
const newLine = diffFile.getSplitRightLine(index);
|
|
547
600
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
548
601
|
const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
|
|
602
|
+
const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
549
603
|
const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
|
|
550
|
-
const
|
|
604
|
+
const currentSideHasExtend = (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== undefined && (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) !== null;
|
|
605
|
+
const hasExtend = ((oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined && (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null) ||
|
|
606
|
+
((newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== undefined && (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) !== null);
|
|
551
607
|
const currentExtendRendered = hasExtend &&
|
|
552
608
|
(renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
|
|
553
609
|
diffFile,
|
|
554
610
|
side,
|
|
555
611
|
lineNumber: currentLineNumber,
|
|
556
|
-
data: currentExtend.data,
|
|
612
|
+
data: currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data,
|
|
557
613
|
onUpdate: diffFile.notifyAll,
|
|
558
614
|
}));
|
|
559
615
|
useSyncHeight({
|
|
560
616
|
selector: `div[data-line="${lineNumber}-extend-content"]`,
|
|
561
617
|
wrapper: `tr[data-line="${lineNumber}-extend"]`,
|
|
562
|
-
side: SplitSide[side],
|
|
618
|
+
side: SplitSide[currentSideHasExtend ? side : otherSide],
|
|
563
619
|
enable: hasExtend && typeof renderExtendLine === "function",
|
|
564
620
|
});
|
|
565
621
|
const width = useDomWidth({
|
|
566
622
|
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
567
|
-
enable:
|
|
623
|
+
enable: currentSideHasExtend && typeof renderExtendLine === "function",
|
|
568
624
|
});
|
|
569
625
|
if (!renderExtendLine)
|
|
570
626
|
return null;
|
|
571
|
-
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" },
|
|
572
|
-
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 },
|
|
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 },
|
|
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 },
|
|
573
629
|
React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] })))));
|
|
574
630
|
};
|
|
575
631
|
const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -590,7 +646,7 @@ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
590
646
|
const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
|
|
591
647
|
if (!currentIsShow)
|
|
592
648
|
return null;
|
|
593
|
-
return (React.createElement(
|
|
649
|
+
return (React.createElement(InternalDiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
594
650
|
};
|
|
595
651
|
|
|
596
652
|
const ExpandDown = ({ className }) => {
|
|
@@ -606,7 +662,7 @@ const ExpandAll = ({ className }) => {
|
|
|
606
662
|
React.createElement("path", { d: "m8.177.677 2.896 2.896a.25.25 0 0 1-.177.427H8.75v1.25a.75.75 0 0 1-1.5 0V4H5.104a.25.25 0 0 1-.177-.427L7.823.677a.25.25 0 0 1 .354 0ZM7.25 10.75a.75.75 0 0 1 1.5 0V12h2.146a.25.25 0 0 1 .177.427l-2.896 2.896a.25.25 0 0 1-.354 0l-2.896-2.896A.25.25 0 0 1 5.104 12H7.25v-1.25Zm-5-2a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 6 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 8a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5A.75.75 0 0 1 12 8Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
|
|
607
663
|
};
|
|
608
664
|
|
|
609
|
-
const
|
|
665
|
+
const InternalDiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
610
666
|
var _a;
|
|
611
667
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
612
668
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -630,9 +686,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
630
686
|
minWidth: `var(${diffAsideWidthName})`,
|
|
631
687
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
632
688
|
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
633
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () =>
|
|
634
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
635
|
-
} },
|
|
689
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
636
690
|
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
637
691
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
638
692
|
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
@@ -645,7 +699,7 @@ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
645
699
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)))) : (React.createElement("td", { className: "diff-line-hunk-placeholder select-none", colSpan: 2, style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
646
700
|
React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
|
|
647
701
|
};
|
|
648
|
-
const
|
|
702
|
+
const InternalDiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
649
703
|
var _a;
|
|
650
704
|
const currentHunk = diffFile.getSplitHunkLine(index);
|
|
651
705
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -668,9 +722,7 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
668
722
|
minWidth: `var(${diffAsideWidthName})`,
|
|
669
723
|
maxWidth: `var(${diffAsideWidthName})`,
|
|
670
724
|
} }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
671
|
-
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () =>
|
|
672
|
-
diffFile.onSplitHunkExpand("down", index);
|
|
673
|
-
} },
|
|
725
|
+
React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip relative flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
674
726
|
React.createElement(ExpandDown, { className: "fill-current" }))) : isExpandAll ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px]", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
|
|
675
727
|
React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
|
|
676
728
|
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
|
|
@@ -682,16 +734,16 @@ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
682
734
|
color: `var(${hunkContentColorName})`,
|
|
683
735
|
} }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
|
|
684
736
|
};
|
|
685
|
-
const
|
|
737
|
+
const InternalDiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
686
738
|
const { useDiffContext } = useDiffViewContext();
|
|
687
739
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
688
740
|
if (diffViewMode === DiffModeEnum.SplitGitHub ||
|
|
689
741
|
diffViewMode === DiffModeEnum.Split ||
|
|
690
742
|
diffViewMode === DiffModeEnum.Unified) {
|
|
691
|
-
return React.createElement(
|
|
743
|
+
return React.createElement(InternalDiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
692
744
|
}
|
|
693
745
|
else {
|
|
694
|
-
return React.createElement(
|
|
746
|
+
return React.createElement(InternalDiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
695
747
|
}
|
|
696
748
|
};
|
|
697
749
|
const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
@@ -702,10 +754,10 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
702
754
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
703
755
|
if (!currentIsShow && !currentIsPureHunk)
|
|
704
756
|
return null;
|
|
705
|
-
return React.createElement(
|
|
757
|
+
return React.createElement(InternalDiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
706
758
|
};
|
|
707
759
|
|
|
708
|
-
const
|
|
760
|
+
const InternalDiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
709
761
|
const { useWidget } = useDiffWidgetContext();
|
|
710
762
|
const { useDiffContext } = useDiffViewContext();
|
|
711
763
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
@@ -716,9 +768,11 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
716
768
|
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
717
769
|
const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
718
770
|
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
719
|
-
const
|
|
771
|
+
const otherSide = side === SplitSide.old ? SplitSide.new : SplitSide.old;
|
|
772
|
+
const currentHasWidget = side === SplitSide.old ? oldLineWidget : newLineWidget;
|
|
773
|
+
const hasWidget = oldLineWidget || newLineWidget;
|
|
720
774
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
721
|
-
const currentWidgetRendered =
|
|
775
|
+
const currentWidgetRendered = currentHasWidget &&
|
|
722
776
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
723
777
|
diffFile,
|
|
724
778
|
side,
|
|
@@ -728,17 +782,17 @@ const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
728
782
|
useSyncHeight({
|
|
729
783
|
selector: `div[data-line="${lineNumber}-widget-content"]`,
|
|
730
784
|
wrapper: `tr[data-line="${lineNumber}-widget"]`,
|
|
731
|
-
side: SplitSide[side],
|
|
732
|
-
enable:
|
|
785
|
+
side: SplitSide[currentHasWidget ? side : otherSide],
|
|
786
|
+
enable: hasWidget && typeof renderWidgetLine === "function",
|
|
733
787
|
});
|
|
734
788
|
const width = useDomWidth({
|
|
735
789
|
selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
|
|
736
|
-
enable: !!
|
|
790
|
+
enable: !!currentHasWidget && typeof renderWidgetLine === "function",
|
|
737
791
|
});
|
|
738
792
|
if (!renderWidgetLine)
|
|
739
793
|
return null;
|
|
740
|
-
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" },
|
|
741
|
-
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 },
|
|
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 },
|
|
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 },
|
|
742
796
|
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
|
|
743
797
|
};
|
|
744
798
|
// TODO! improve performance
|
|
@@ -756,19 +810,11 @@ const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
|
756
810
|
}, [diffFile, index]), (p, c) => p === c);
|
|
757
811
|
if (!currentIsShow)
|
|
758
812
|
return null;
|
|
759
|
-
return React.createElement(
|
|
813
|
+
return React.createElement(InternalDiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
|
|
760
814
|
};
|
|
761
815
|
|
|
762
816
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
763
|
-
const
|
|
764
|
-
const ele = e.target;
|
|
765
|
-
// need remove all the selection
|
|
766
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
767
|
-
removeAllSelection();
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
817
|
+
const DiffSplitViewTable = ({ side, diffFile, enableAddWidget, enableHighlight, onMouseDown, }) => {
|
|
772
818
|
const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
|
|
773
819
|
const lines = getSplitContentLines(diffFile);
|
|
774
820
|
return (React.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": SplitSide[side] },
|
|
@@ -783,10 +829,10 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
783
829
|
React.createElement("th", { scope: "col" },
|
|
784
830
|
SplitSide[side],
|
|
785
831
|
" line content"))),
|
|
786
|
-
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 },
|
|
787
833
|
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
788
834
|
React.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
789
|
-
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 }),
|
|
790
836
|
React.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
791
837
|
React.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
792
838
|
React.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
|
|
@@ -794,9 +840,14 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
|
|
|
794
840
|
const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
795
841
|
const ref1 = useRef(null);
|
|
796
842
|
const ref2 = useRef(null);
|
|
843
|
+
const ref = useRef();
|
|
797
844
|
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
798
845
|
const { useDiffContext } = useDiffViewContext();
|
|
799
|
-
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
|
+
}));
|
|
800
851
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
801
852
|
useEffect(() => {
|
|
802
853
|
const left = ref1.current;
|
|
@@ -811,7 +862,46 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
811
862
|
font,
|
|
812
863
|
});
|
|
813
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
|
+
};
|
|
814
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 }),
|
|
815
905
|
React.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
|
|
816
906
|
// @ts-ignore
|
|
817
907
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -819,7 +909,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
819
909
|
fontFamily: "Menlo, Consolas, monospace",
|
|
820
910
|
fontSize: `var(${diffFontSizeName})`,
|
|
821
911
|
} },
|
|
822
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
|
|
912
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown })),
|
|
823
913
|
React.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
|
|
824
914
|
React.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
|
|
825
915
|
// @ts-ignore
|
|
@@ -828,26 +918,24 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
|
|
|
828
918
|
fontFamily: "Menlo, Consolas, monospace",
|
|
829
919
|
fontSize: `var(${diffFontSizeName})`,
|
|
830
920
|
} },
|
|
831
|
-
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile }))));
|
|
921
|
+
React.createElement(DiffSplitViewTable, { side: SplitSide.new, diffFile: diffFile, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight, onMouseDown: onMouseDown }))));
|
|
832
922
|
});
|
|
833
923
|
DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
|
|
834
924
|
|
|
835
|
-
const
|
|
925
|
+
const InternalDiffSplitLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
836
926
|
var _a, _b;
|
|
837
927
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
838
928
|
const newLine = diffFile.getSplitRightLine(index);
|
|
839
929
|
const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
|
|
930
|
+
const oldPlainLine = diffFile.getOldPlainLine(oldLine.lineNumber);
|
|
840
931
|
const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
|
|
932
|
+
const newPlainLine = diffFile.getNewPlainLine(newLine.lineNumber);
|
|
841
933
|
const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
842
934
|
const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
|
|
843
935
|
const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
|
|
844
936
|
const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
|
|
845
937
|
const { useDiffContext } = useDiffViewContext();
|
|
846
|
-
const
|
|
847
|
-
enableHighlight: s.enableHighlight,
|
|
848
|
-
enableAddWidget: s.enableAddWidget,
|
|
849
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
850
|
-
}));
|
|
938
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
851
939
|
const { useWidget } = useDiffWidgetContext();
|
|
852
940
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
853
941
|
const hasOldLine = !!oldLine.lineNumber;
|
|
@@ -863,12 +951,12 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
863
951
|
React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
|
|
864
952
|
React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
|
|
865
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 }) })),
|
|
866
|
-
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 },
|
|
867
955
|
React.createElement("span", null, "\u2002"))),
|
|
868
956
|
hasNewLine ? (React.createElement(React.Fragment, null,
|
|
869
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: {
|
|
870
958
|
backgroundColor: newLineNumberBG,
|
|
871
|
-
color: `var(${plainLineNumberColorName})`,
|
|
959
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
872
960
|
borderLeftColor: `var(${borderColorName})`,
|
|
873
961
|
borderLeftStyle: "solid",
|
|
874
962
|
} },
|
|
@@ -876,22 +964,22 @@ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
|
|
|
876
964
|
React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
|
|
877
965
|
React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
|
|
878
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 }) })),
|
|
879
|
-
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: {
|
|
880
968
|
backgroundColor: `var(${emptyBGName})`,
|
|
881
969
|
borderLeftColor: `var(${borderColorName})`,
|
|
882
970
|
borderLeftStyle: "solid",
|
|
883
971
|
}, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
|
|
884
972
|
React.createElement("span", null, "\u2002")))));
|
|
885
973
|
};
|
|
886
|
-
const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
974
|
+
const DiffSplitContentLine = ({ index, diffFile, lineNumber, enableAddWidget, enableHighlight, }) => {
|
|
887
975
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
888
976
|
const newLine = diffFile.getSplitRightLine(index);
|
|
889
977
|
if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
|
|
890
978
|
return null;
|
|
891
|
-
return React.createElement(
|
|
979
|
+
return (React.createElement(InternalDiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, enableAddWidget: enableAddWidget, enableHighlight: enableHighlight }));
|
|
892
980
|
};
|
|
893
981
|
|
|
894
|
-
const
|
|
982
|
+
const InternalDiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
895
983
|
const { useDiffContext } = useDiffViewContext();
|
|
896
984
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
897
985
|
const newLine = diffFile.getSplitRightLine(index);
|
|
@@ -917,13 +1005,13 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
|
|
|
917
1005
|
}));
|
|
918
1006
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
919
1007
|
oldExtendRendered ? (React.createElement("td", { className: "diff-line-extend-old-content p-0", colSpan: 2 },
|
|
920
|
-
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 })),
|
|
921
1009
|
newExtendRendered ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" }, colSpan: 2 },
|
|
922
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: {
|
|
923
1011
|
backgroundColor: `var(${emptyBGName})`,
|
|
924
1012
|
borderLeftColor: `var(${borderColorName})`,
|
|
925
1013
|
borderLeftStyle: "solid",
|
|
926
|
-
}, colSpan: 2 }
|
|
1014
|
+
}, colSpan: 2 }))));
|
|
927
1015
|
};
|
|
928
1016
|
const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
929
1017
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -942,7 +1030,7 @@ const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
942
1030
|
const currentIsShow = hasExtend && ((!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && !(newLine === null || newLine === void 0 ? void 0 : newLine.isHidden)) || !enableExpand);
|
|
943
1031
|
if (!currentIsShow)
|
|
944
1032
|
return null;
|
|
945
|
-
return (React.createElement(
|
|
1033
|
+
return (React.createElement(InternalDiffSplitExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
946
1034
|
};
|
|
947
1035
|
|
|
948
1036
|
const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1016,7 +1104,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1016
1104
|
color: `var(${hunkContentColorName})`,
|
|
1017
1105
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
1018
1106
|
};
|
|
1019
|
-
const
|
|
1107
|
+
const InternalDiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1020
1108
|
const { useDiffContext } = useDiffViewContext();
|
|
1021
1109
|
const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
|
|
1022
1110
|
if (diffViewMode === DiffModeEnum.SplitGitHub ||
|
|
@@ -1036,10 +1124,10 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1036
1124
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
|
|
1037
1125
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1038
1126
|
return null;
|
|
1039
|
-
return React.createElement(
|
|
1127
|
+
return React.createElement(InternalDiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1040
1128
|
};
|
|
1041
1129
|
|
|
1042
|
-
const
|
|
1130
|
+
const InternalDiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1043
1131
|
const { useWidget } = useDiffWidgetContext();
|
|
1044
1132
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1045
1133
|
const { useDiffContext } = useDiffViewContext();
|
|
@@ -1058,13 +1146,13 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1058
1146
|
return null;
|
|
1059
1147
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1060
1148
|
oldWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-old-content p-0", colSpan: 2 },
|
|
1061
|
-
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 })),
|
|
1062
1150
|
newWidgetRendered ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})`, borderLeftStyle: "solid" } },
|
|
1063
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: {
|
|
1064
1152
|
backgroundColor: `var(${emptyBGName})`,
|
|
1065
1153
|
borderLeftColor: `var(${borderColorName})`,
|
|
1066
1154
|
borderLeftStyle: "solid",
|
|
1067
|
-
}, colSpan: 2 }
|
|
1155
|
+
}, colSpan: 2 }))));
|
|
1068
1156
|
};
|
|
1069
1157
|
// TODO! improve performance
|
|
1070
1158
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
@@ -1081,9 +1169,96 @@ const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1081
1169
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1082
1170
|
if (!currentIsShow)
|
|
1083
1171
|
return null;
|
|
1084
|
-
return React.createElement(
|
|
1172
|
+
return React.createElement(InternalDiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1085
1173
|
};
|
|
1086
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
|
+
|
|
1087
1262
|
const createDiffConfigStore = (props, diffFileId) => {
|
|
1088
1263
|
return createStore(() => {
|
|
1089
1264
|
var _a, _b;
|
|
@@ -1091,6 +1266,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1091
1266
|
const setId = (_id) => (id.value = _id);
|
|
1092
1267
|
const mode = ref(props.diffViewMode);
|
|
1093
1268
|
const setMode = (_mode) => (mode.value = _mode);
|
|
1269
|
+
const mounted = ref(props.isMounted);
|
|
1270
|
+
const setMounted = (_mounted) => (mounted.value = _mounted);
|
|
1094
1271
|
const enableWrap = ref(props.diffViewWrap);
|
|
1095
1272
|
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1096
1273
|
const enableAddWidget = ref(props.diffViewAddWidget);
|
|
@@ -1129,6 +1306,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1129
1306
|
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1130
1307
|
const renderExtendLine = ref(props.renderExtendLine);
|
|
1131
1308
|
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1309
|
+
const onCreateUseWidgetHook = ref(props.onCreateUseWidgetHook);
|
|
1310
|
+
const setOnCreateUseWidgetHook = (_onCreateUseWidgetHook) => (onCreateUseWidgetHook.value = _onCreateUseWidgetHook);
|
|
1132
1311
|
// 避免无意义的订阅
|
|
1133
1312
|
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1134
1313
|
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
@@ -1137,6 +1316,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1137
1316
|
setId,
|
|
1138
1317
|
mode,
|
|
1139
1318
|
setMode,
|
|
1319
|
+
mounted,
|
|
1320
|
+
setMounted,
|
|
1140
1321
|
enableWrap,
|
|
1141
1322
|
setEnableWrap,
|
|
1142
1323
|
enableAddWidget,
|
|
@@ -1153,6 +1334,8 @@ const createDiffConfigStore = (props, diffFileId) => {
|
|
|
1153
1334
|
setRenderExtendLine,
|
|
1154
1335
|
onAddWidgetClick,
|
|
1155
1336
|
setOnAddWidgetClick,
|
|
1337
|
+
onCreateUseWidgetHook,
|
|
1338
|
+
setOnCreateUseWidgetHook,
|
|
1156
1339
|
};
|
|
1157
1340
|
});
|
|
1158
1341
|
};
|
|
@@ -1171,95 +1354,15 @@ const createDiffWidgetStore = (useDiffContextRef) => {
|
|
|
1171
1354
|
return { widgetSide, widgetLineNumber, setWidget };
|
|
1172
1355
|
});
|
|
1173
1356
|
};
|
|
1174
|
-
const createDiffSplitConfigStore = () => {
|
|
1175
|
-
return createStore(() => {
|
|
1176
|
-
const splitRef = ref(undefined);
|
|
1177
|
-
const setSplit = (side) => {
|
|
1178
|
-
flushSync(() => {
|
|
1179
|
-
splitRef.value = side;
|
|
1180
|
-
});
|
|
1181
|
-
};
|
|
1182
|
-
return { splitRef, setSplit };
|
|
1183
|
-
});
|
|
1184
|
-
};
|
|
1185
|
-
|
|
1186
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1187
|
-
const Style = ({ useSelector, id, }) => {
|
|
1188
|
-
const splitRef = useSelector((s) => s.splitRef);
|
|
1189
|
-
return (React.createElement("style", { "data-select-style": true }, splitRef === SplitSide.old
|
|
1190
|
-
? `#${id} td[data-side="${SplitSide[SplitSide.new]}"] {user-select: none}`
|
|
1191
|
-
: splitRef === SplitSide.new
|
|
1192
|
-
? `#${id} td[data-side="${SplitSide[SplitSide.old]}"] {user-select: none}`
|
|
1193
|
-
: ""));
|
|
1194
|
-
};
|
|
1195
|
-
const DiffSplitViewWrap = memo(({ diffFile }) => {
|
|
1196
|
-
const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
|
|
1197
|
-
const { useDiffContext } = useDiffViewContext();
|
|
1198
|
-
const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
|
|
1199
|
-
const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
|
|
1200
|
-
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1201
|
-
const onMouseDown = useCallback((e) => {
|
|
1202
|
-
let ele = e.target;
|
|
1203
|
-
const setSelectSide = useSplitConfig.getReadonlyState().setSplit;
|
|
1204
|
-
// need remove all the selection
|
|
1205
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1206
|
-
removeAllSelection();
|
|
1207
|
-
return;
|
|
1208
|
-
}
|
|
1209
|
-
while (ele && ele instanceof HTMLElement && ele.nodeName !== "TD") {
|
|
1210
|
-
ele = ele.parentElement;
|
|
1211
|
-
}
|
|
1212
|
-
if (ele instanceof HTMLElement) {
|
|
1213
|
-
const side = ele.getAttribute("data-side");
|
|
1214
|
-
if (side) {
|
|
1215
|
-
setSelectSide(SplitSide[side]);
|
|
1216
|
-
removeAllSelection();
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1220
|
-
}, []);
|
|
1221
|
-
const font = useMemo(() => ({ fontSize: fontSize + "px", fontFamily: "Menlo, Consolas, monospace" }), [fontSize]);
|
|
1222
|
-
const _width = useTextWidth({
|
|
1223
|
-
text: splitLineLength.toString(),
|
|
1224
|
-
font,
|
|
1225
|
-
});
|
|
1226
|
-
const width = Math.max(40, _width + 25);
|
|
1227
|
-
const lines = getSplitContentLines(diffFile);
|
|
1228
|
-
return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
|
|
1229
|
-
React.createElement("div", { className: "diff-table-wrapper w-full", style: {
|
|
1230
|
-
// @ts-ignore
|
|
1231
|
-
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
1232
|
-
fontFamily: "Menlo, Consolas, monospace",
|
|
1233
|
-
fontSize: `var(${diffFontSizeName})`,
|
|
1234
|
-
} },
|
|
1235
|
-
React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
|
|
1236
|
-
React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
|
|
1237
|
-
React.createElement("colgroup", null,
|
|
1238
|
-
React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
|
|
1239
|
-
React.createElement("col", { className: "diff-table-old-content-col" }),
|
|
1240
|
-
React.createElement("col", { className: "diff-table-new-num-col", width: Math.round(width) }),
|
|
1241
|
-
React.createElement("col", { className: "diff-table-new-content-col" })),
|
|
1242
|
-
React.createElement("thead", { className: "hidden" },
|
|
1243
|
-
React.createElement("tr", null,
|
|
1244
|
-
React.createElement("th", { scope: "col" }, "old line number"),
|
|
1245
|
-
React.createElement("th", { scope: "col" }, "old line content"),
|
|
1246
|
-
React.createElement("th", { scope: "col" }, "new line number"),
|
|
1247
|
-
React.createElement("th", { scope: "col" }, "new line content"))),
|
|
1248
|
-
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1249
|
-
lines.map((line) => (React.createElement(Fragment, { key: line.index },
|
|
1250
|
-
React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1251
|
-
React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1252
|
-
React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
|
|
1253
|
-
React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
|
|
1254
|
-
React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
|
|
1255
|
-
});
|
|
1256
|
-
DiffSplitViewWrap.displayName = "DiffSplitViewWrap";
|
|
1257
1357
|
|
|
1258
1358
|
const DiffSplitView = memo(({ diffFile }) => {
|
|
1259
1359
|
const { useDiffContext } = useDiffViewContext();
|
|
1260
1360
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1261
1361
|
useDiffContextRef.current = useDiffContext;
|
|
1262
|
-
const enableWrap = useDiffContext.useShallowStableSelector((s) =>
|
|
1362
|
+
const { enableWrap, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1363
|
+
enableWrap: s.enableWrap,
|
|
1364
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1365
|
+
}));
|
|
1263
1366
|
// performance optimization
|
|
1264
1367
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1265
1368
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
@@ -1267,11 +1370,14 @@ const DiffSplitView = memo(({ diffFile }) => {
|
|
|
1267
1370
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1268
1371
|
setWidget({});
|
|
1269
1372
|
}, [diffFile, useWidget]);
|
|
1373
|
+
useEffect(() => {
|
|
1374
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1375
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1270
1376
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue }, enableWrap ? React.createElement(DiffSplitViewWrap, { diffFile: diffFile }) : React.createElement(DiffSplitViewNormal, { diffFile: diffFile })));
|
|
1271
1377
|
});
|
|
1272
1378
|
DiffSplitView.displayName = "DiffSplitView";
|
|
1273
1379
|
|
|
1274
|
-
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, }) => {
|
|
1275
1381
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1276
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: {
|
|
1277
1383
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1286,9 +1392,9 @@ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1286
1392
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1287
1393
|
React.createElement("span", { className: "inline-block w-[50%]" }))),
|
|
1288
1394
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
|
|
1289
|
-
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 }))));
|
|
1290
1396
|
};
|
|
1291
|
-
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, }) => {
|
|
1292
1398
|
return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
|
|
1293
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: {
|
|
1294
1400
|
color: `var(${plainLineNumberColorName})`,
|
|
@@ -1303,17 +1409,12 @@ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber,
|
|
|
1303
1409
|
React.createElement("span", { className: "w-[10px] shrink-0" }),
|
|
1304
1410
|
React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
|
|
1305
1411
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
|
|
1306
|
-
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 }))));
|
|
1307
1413
|
};
|
|
1308
|
-
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
1414
|
+
const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber, enableWrap, enableAddWidget, enableHighlight, }) => {
|
|
1309
1415
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1310
1416
|
const { useDiffContext } = useDiffViewContext();
|
|
1311
|
-
const
|
|
1312
|
-
enableWrap: s.enableWrap,
|
|
1313
|
-
enableHighlight: s.enableHighlight,
|
|
1314
|
-
enableAddWidget: s.enableAddWidget,
|
|
1315
|
-
onAddWidgetClick: s.onAddWidgetClick,
|
|
1316
|
-
}));
|
|
1417
|
+
const onAddWidgetClick = useDiffContext.getReadonlyState().onAddWidgetClick;
|
|
1317
1418
|
const { useWidget } = useDiffWidgetContext();
|
|
1318
1419
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1319
1420
|
const hasDiff = unifiedLine.diff;
|
|
@@ -1327,18 +1428,23 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1327
1428
|
: oldLinenumber
|
|
1328
1429
|
? diffFile.getOldSyntaxLine(oldLinenumber)
|
|
1329
1430
|
: undefined;
|
|
1431
|
+
const plainLine = newLineNumber
|
|
1432
|
+
? diffFile.getNewPlainLine(newLineNumber)
|
|
1433
|
+
: oldLinenumber
|
|
1434
|
+
? diffFile.getOldPlainLine(oldLinenumber)
|
|
1435
|
+
: undefined;
|
|
1330
1436
|
if (hasChange) {
|
|
1331
1437
|
if (unifiedLine.oldLineNumber) {
|
|
1332
|
-
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); } }));
|
|
1333
1439
|
}
|
|
1334
1440
|
else {
|
|
1335
|
-
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); } }));
|
|
1336
1442
|
}
|
|
1337
1443
|
}
|
|
1338
1444
|
else {
|
|
1339
1445
|
return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
|
|
1340
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: {
|
|
1341
|
-
color: `var(${plainLineNumberColorName})`,
|
|
1447
|
+
color: `var(${hasDiff ? plainLineNumberColorName : expandLineNumberColorName})`,
|
|
1342
1448
|
width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1343
1449
|
maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
1344
1450
|
minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
|
|
@@ -1352,18 +1458,18 @@ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
|
|
|
1352
1458
|
React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
|
|
1353
1459
|
backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
|
|
1354
1460
|
} },
|
|
1355
|
-
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 }))));
|
|
1356
1462
|
}
|
|
1357
1463
|
});
|
|
1358
1464
|
_DiffUnifiedLine.displayName = "_DiffUnifiedLine";
|
|
1359
|
-
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
|
|
1465
|
+
const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, enableWrap, enableHighlight, enableAddWidget, }) => {
|
|
1360
1466
|
const unifiedLine = diffFile.getUnifiedLine(index);
|
|
1361
1467
|
if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
|
|
1362
1468
|
return null;
|
|
1363
|
-
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 }));
|
|
1364
1470
|
};
|
|
1365
1471
|
|
|
1366
|
-
const
|
|
1472
|
+
const InternalDiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
|
|
1367
1473
|
const { useDiffContext } = useDiffViewContext();
|
|
1368
1474
|
const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
|
|
1369
1475
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1375,7 +1481,7 @@ const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, ne
|
|
|
1375
1481
|
return null;
|
|
1376
1482
|
return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
|
|
1377
1483
|
React.createElement("td", { className: "diff-line-extend-content p-0 align-top", colSpan: 2 },
|
|
1378
|
-
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 } },
|
|
1379
1485
|
width > 0 &&
|
|
1380
1486
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== undefined &&
|
|
1381
1487
|
(oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) !== null &&
|
|
@@ -1410,10 +1516,10 @@ const DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1410
1516
|
const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
|
|
1411
1517
|
if (!hasExtend || !unifiedItem || unifiedItem.isHidden)
|
|
1412
1518
|
return null;
|
|
1413
|
-
return (React.createElement(
|
|
1519
|
+
return (React.createElement(InternalDiffUnifiedExtendLine, { index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
|
|
1414
1520
|
};
|
|
1415
1521
|
|
|
1416
|
-
const
|
|
1522
|
+
const InternalDiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
1417
1523
|
var _a;
|
|
1418
1524
|
const currentHunk = diffFile.getUnifiedHunkLine(index);
|
|
1419
1525
|
const expandEnabled = diffFile.getExpandEnabled();
|
|
@@ -1455,10 +1561,10 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1455
1561
|
const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.unifiedInfo;
|
|
1456
1562
|
if (!currentIsShow && !currentIsPureHunk)
|
|
1457
1563
|
return null;
|
|
1458
|
-
return React.createElement(
|
|
1564
|
+
return React.createElement(InternalDiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1459
1565
|
};
|
|
1460
1566
|
|
|
1461
|
-
const
|
|
1567
|
+
const InternalDiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1462
1568
|
const { useWidget } = useDiffWidgetContext();
|
|
1463
1569
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1464
1570
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
@@ -1478,7 +1584,7 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1478
1584
|
return null;
|
|
1479
1585
|
return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", className: "diff-line diff-line-widget" },
|
|
1480
1586
|
React.createElement("td", { className: "diff-line-widget-content p-0", colSpan: 2 },
|
|
1481
|
-
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 } },
|
|
1482
1588
|
width > 0 &&
|
|
1483
1589
|
oldWidget &&
|
|
1484
1590
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })),
|
|
@@ -1499,34 +1605,33 @@ const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1499
1605
|
}, [diffFile, index]), (p, c) => p === c);
|
|
1500
1606
|
if (!currentIsShow)
|
|
1501
1607
|
return null;
|
|
1502
|
-
return React.createElement(
|
|
1608
|
+
return React.createElement(InternalDiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1503
1609
|
};
|
|
1504
1610
|
|
|
1505
1611
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1506
|
-
const onMouseDown = (e) => {
|
|
1507
|
-
const ele = e.target;
|
|
1508
|
-
// need remove all the selection
|
|
1509
|
-
if (ele && ele instanceof HTMLElement && ele.nodeName === "BUTTON") {
|
|
1510
|
-
removeAllSelection();
|
|
1511
|
-
return;
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
1612
|
const DiffUnifiedView = memo(({ diffFile }) => {
|
|
1515
1613
|
const { useDiffContext } = useDiffViewContext();
|
|
1614
|
+
const ref = useRef(null);
|
|
1516
1615
|
const useDiffContextRef = useRef(useDiffContext);
|
|
1517
1616
|
useDiffContextRef.current = useDiffContext;
|
|
1518
1617
|
// performance optimization
|
|
1519
1618
|
const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
|
|
1520
1619
|
const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
|
|
1521
|
-
const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1620
|
+
const { fontSize, enableWrap, enableHighlight, enableAddWidget, onCreateUseWidgetHook } = useDiffContext.useShallowStableSelector((s) => ({
|
|
1522
1621
|
fontSize: s.fontSize,
|
|
1523
1622
|
enableWrap: s.enableWrap,
|
|
1623
|
+
enableHighlight: s.enableHighlight,
|
|
1624
|
+
enableAddWidget: s.enableAddWidget,
|
|
1625
|
+
onCreateUseWidgetHook: s.onCreateUseWidgetHook,
|
|
1524
1626
|
}));
|
|
1525
1627
|
useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount, diffFile.getUpdateCount);
|
|
1526
1628
|
useEffect(() => {
|
|
1527
1629
|
const { setWidget } = useWidget.getReadonlyState();
|
|
1528
1630
|
setWidget({});
|
|
1529
1631
|
}, [diffFile, useWidget]);
|
|
1632
|
+
useEffect(() => {
|
|
1633
|
+
onCreateUseWidgetHook === null || onCreateUseWidgetHook === void 0 ? void 0 : onCreateUseWidgetHook(useWidget);
|
|
1634
|
+
}, [useWidget, onCreateUseWidgetHook]);
|
|
1530
1635
|
const unifiedLineLength = Math.max(diffFile.unifiedLineLength, diffFile.fileLineLength);
|
|
1531
1636
|
const _width = useTextWidth({
|
|
1532
1637
|
text: unifiedLineLength.toString(),
|
|
@@ -1534,8 +1639,44 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1534
1639
|
});
|
|
1535
1640
|
const width = Math.max(40, _width + 10);
|
|
1536
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
|
+
};
|
|
1537
1677
|
return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
|
|
1538
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 }),
|
|
1539
1680
|
React.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
|
|
1540
1681
|
// @ts-ignore
|
|
1541
1682
|
[diffAsideWidthName]: `${Math.round(width)}px`,
|
|
@@ -1553,7 +1694,7 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1553
1694
|
React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
|
|
1554
1695
|
lines.map((item) => (React.createElement(Fragment, { key: item.index },
|
|
1555
1696
|
React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1556
|
-
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 }),
|
|
1557
1698
|
React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
|
|
1558
1699
|
React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
|
|
1559
1700
|
React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
|
|
@@ -1561,11 +1702,6 @@ const DiffUnifiedView = memo(({ diffFile }) => {
|
|
|
1561
1702
|
DiffUnifiedView.displayName = "DiffUnifiedView";
|
|
1562
1703
|
|
|
1563
1704
|
_cacheMap.name = "@git-diff-view/react";
|
|
1564
|
-
var SplitSide;
|
|
1565
|
-
(function (SplitSide) {
|
|
1566
|
-
SplitSide[SplitSide["old"] = 1] = "old";
|
|
1567
|
-
SplitSide[SplitSide["new"] = 2] = "new";
|
|
1568
|
-
})(SplitSide || (SplitSide = {}));
|
|
1569
1705
|
var DiffModeEnum;
|
|
1570
1706
|
(function (DiffModeEnum) {
|
|
1571
1707
|
// github like
|
|
@@ -1575,27 +1711,52 @@ var DiffModeEnum;
|
|
|
1575
1711
|
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
1576
1712
|
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
1577
1713
|
})(DiffModeEnum || (DiffModeEnum = {}));
|
|
1578
|
-
const
|
|
1579
|
-
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
|
|
1714
|
+
const InternalDiffView = (props) => {
|
|
1715
|
+
const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, onCreateUseWidgetHook, isMounted, } = props;
|
|
1580
1716
|
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
|
|
1581
|
-
const isMounted = useIsMounted();
|
|
1582
1717
|
const wrapperRef = useRef();
|
|
1583
1718
|
// performance optimization
|
|
1584
1719
|
const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
|
|
1585
1720
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1586
1721
|
[]);
|
|
1587
1722
|
useEffect(() => {
|
|
1588
|
-
const { id, setId, mode, setMode, enableAddWidget, setEnableAddWidget, enableHighlight, setEnableHighlight, enableWrap, setEnableWrap, setExtendData, fontSize, setFontSize, onAddWidgetClick: _onAddWidgetClick, setOnAddWidgetClick, renderExtendLine: _renderExtendLine, setRenderExtendLine, renderWidgetLine: _renderWidgetLine, setRenderWidgetLine, } = useDiffContext.getReadonlyState();
|
|
1589
|
-
diffFileId && diffFileId !== id
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
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();
|
|
1724
|
+
if (diffFileId && diffFileId !== id) {
|
|
1725
|
+
setId(diffFileId);
|
|
1726
|
+
}
|
|
1727
|
+
if (diffViewMode && diffViewMode !== mode) {
|
|
1728
|
+
setMode(diffViewMode);
|
|
1729
|
+
}
|
|
1730
|
+
if (mounted !== isMounted) {
|
|
1731
|
+
setMounted(isMounted);
|
|
1732
|
+
}
|
|
1733
|
+
if (diffViewAddWidget !== enableAddWidget) {
|
|
1734
|
+
setEnableAddWidget(diffViewAddWidget);
|
|
1735
|
+
}
|
|
1736
|
+
if (diffViewHighlight !== enableHighlight) {
|
|
1737
|
+
setEnableHighlight(diffViewHighlight);
|
|
1738
|
+
}
|
|
1739
|
+
if (diffViewWrap !== enableWrap) {
|
|
1740
|
+
setEnableWrap(diffViewWrap);
|
|
1741
|
+
}
|
|
1742
|
+
if (extendData) {
|
|
1743
|
+
setExtendData(extendData);
|
|
1744
|
+
}
|
|
1745
|
+
if (diffViewFontSize && diffViewFontSize !== fontSize) {
|
|
1746
|
+
setFontSize(diffViewFontSize);
|
|
1747
|
+
}
|
|
1748
|
+
if (onAddWidgetClick !== _onAddWidgetClick.current) {
|
|
1749
|
+
setOnAddWidgetClick({ current: onAddWidgetClick });
|
|
1750
|
+
}
|
|
1751
|
+
if (onCreateUseWidgetHook !== _onCreateUseWidgetHook) {
|
|
1752
|
+
setOnCreateUseWidgetHook(onCreateUseWidgetHook);
|
|
1753
|
+
}
|
|
1754
|
+
if (renderExtendLine !== _renderExtendLine) {
|
|
1755
|
+
setRenderExtendLine(renderExtendLine);
|
|
1756
|
+
}
|
|
1757
|
+
if (renderWidgetLine !== _renderWidgetLine) {
|
|
1758
|
+
setRenderWidgetLine(renderWidgetLine);
|
|
1759
|
+
}
|
|
1599
1760
|
}, [
|
|
1600
1761
|
useDiffContext,
|
|
1601
1762
|
diffViewFontSize,
|
|
@@ -1604,10 +1765,12 @@ const _InternalDiffView = (props) => {
|
|
|
1604
1765
|
diffViewWrap,
|
|
1605
1766
|
diffViewAddWidget,
|
|
1606
1767
|
diffFileId,
|
|
1768
|
+
isMounted,
|
|
1607
1769
|
renderWidgetLine,
|
|
1608
1770
|
renderExtendLine,
|
|
1609
1771
|
extendData,
|
|
1610
1772
|
onAddWidgetClick,
|
|
1773
|
+
onCreateUseWidgetHook,
|
|
1611
1774
|
]);
|
|
1612
1775
|
useEffect(() => {
|
|
1613
1776
|
const cb = diffFile.subscribe(() => {
|
|
@@ -1619,14 +1782,14 @@ const _InternalDiffView = (props) => {
|
|
|
1619
1782
|
}, [diffFile]);
|
|
1620
1783
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1621
1784
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1622
|
-
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 },
|
|
1623
1786
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1624
1787
|
// @ts-ignore
|
|
1625
1788
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
1626
1789
|
} },
|
|
1627
1790
|
React.createElement("div", { id: isMounted ? `diff-root${diffFileId}` : undefined, className: "diff-view-wrapper" + (className ? ` ${className}` : ""), style: style }, diffViewMode & DiffModeEnum.Split ? (React.createElement(DiffSplitView, { diffFile: diffFile })) : (React.createElement(DiffUnifiedView, { diffFile: diffFile })))))));
|
|
1628
1791
|
};
|
|
1629
|
-
const
|
|
1792
|
+
const MemoedInternalDiffView = memo(InternalDiffView);
|
|
1630
1793
|
const DiffViewWithRef = (props, ref) => {
|
|
1631
1794
|
var _a, _b;
|
|
1632
1795
|
const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
|
|
@@ -1650,6 +1813,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1650
1813
|
(_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1651
1814
|
diffFileRef.current = diffFile;
|
|
1652
1815
|
}
|
|
1816
|
+
const isMounted = useIsMounted();
|
|
1653
1817
|
useEffect(() => {
|
|
1654
1818
|
if (_diffFile && diffFile) {
|
|
1655
1819
|
_diffFile._addClonedInstance(diffFile);
|
|
@@ -1679,12 +1843,12 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1679
1843
|
useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
|
|
1680
1844
|
if (!diffFile)
|
|
1681
1845
|
return null;
|
|
1682
|
-
return (React.createElement(
|
|
1846
|
+
return (React.createElement(MemoedInternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, isMounted: isMounted, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
1683
1847
|
};
|
|
1684
1848
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
1685
1849
|
InnerDiffView.displayName = "DiffView";
|
|
1686
1850
|
const DiffView = InnerDiffView;
|
|
1687
|
-
const version = "0.0.
|
|
1851
|
+
const version = "0.0.27";
|
|
1688
1852
|
|
|
1689
|
-
export { DiffModeEnum, DiffView,
|
|
1853
|
+
export { DiffModeEnum, DiffView, version };
|
|
1690
1854
|
//# sourceMappingURL=index.mjs.map
|