@git-diff-view/react 0.0.21 → 0.0.23
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 +231 -181
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +231 -181
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/esm/index.mjs +245 -195
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +5 -5
- package/package.json +9 -8
- package/readme.md +6 -6
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { NewLineSymbol, DiffLineType, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
|
|
3
3
|
export * from '@git-diff-view/core';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { useRef, useEffect, createContext, useContext, useLayoutEffect, useState, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
|
|
@@ -36,6 +36,28 @@ function __rest(s, e) {
|
|
|
36
36
|
return t;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/******************************************************************************
|
|
45
|
+
Copyright (c) Microsoft Corporation.
|
|
46
|
+
|
|
47
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
48
|
+
purpose with or without fee is hereby granted.
|
|
49
|
+
|
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
51
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
52
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
53
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
54
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
55
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
56
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
57
|
+
***************************************************************************** */
|
|
58
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
59
|
+
|
|
60
|
+
|
|
39
61
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
40
62
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
41
63
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
@@ -43,10 +65,8 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
46
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
47
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
48
68
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
49
|
-
return (
|
|
69
|
+
return (state.set(receiver, value)), value;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
@@ -54,29 +74,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
54
74
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
75
|
};
|
|
56
76
|
|
|
57
|
-
const useUnmount = (cb, deps) => {
|
|
58
|
-
const ref = useRef(cb);
|
|
59
|
-
ref.current = cb;
|
|
60
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
-
useEffect(() => ref.current, deps);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var DiffModeEnum;
|
|
65
|
-
(function (DiffModeEnum) {
|
|
66
|
-
// github like
|
|
67
|
-
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
68
|
-
// gitlab like
|
|
69
|
-
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
70
|
-
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
71
|
-
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
72
|
-
})(DiffModeEnum || (DiffModeEnum = {}));
|
|
73
|
-
const DiffViewContext = createContext(null);
|
|
74
|
-
DiffViewContext.displayName = "DiffViewContext";
|
|
75
|
-
const useDiffViewContext = () => useContext(DiffViewContext);
|
|
76
|
-
|
|
77
|
-
const isClient = typeof window !== "undefined";
|
|
78
|
-
const useSafeLayout = isClient ? useLayoutEffect : useEffect;
|
|
79
|
-
|
|
80
77
|
var _TextMeasure_instances, _TextMeasure_key, _TextMeasure_map, _TextMeasure_getInstance;
|
|
81
78
|
let canvasCtx = null;
|
|
82
79
|
const getKey = (font, text) => {
|
|
@@ -100,7 +97,7 @@ class TextMeasure {
|
|
|
100
97
|
if (font) {
|
|
101
98
|
const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
|
|
102
99
|
if (__classPrivateFieldGet(this, _TextMeasure_key, "f") !== currentFontKey) {
|
|
103
|
-
__classPrivateFieldSet(this, _TextMeasure_key, currentFontKey
|
|
100
|
+
__classPrivateFieldSet(this, _TextMeasure_key, currentFontKey);
|
|
104
101
|
instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
|
|
105
102
|
}
|
|
106
103
|
}
|
|
@@ -115,19 +112,10 @@ _TextMeasure_key = new WeakMap(), _TextMeasure_map = new WeakMap(), _TextMeasure
|
|
|
115
112
|
canvasCtx = canvasCtx || document.createElement("canvas").getContext("2d");
|
|
116
113
|
return canvasCtx;
|
|
117
114
|
};
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let baseSize = 6;
|
|
123
|
-
baseSize += fontSize > 10 ? (fontSize - 10) * 0.6 : 0;
|
|
124
|
-
return baseSize * text.length;
|
|
125
|
-
});
|
|
126
|
-
useSafeLayout(() => {
|
|
127
|
-
const width = measureInstance.measure(text, font);
|
|
128
|
-
setWidth(width);
|
|
129
|
-
}, [text, font]);
|
|
130
|
-
return width;
|
|
115
|
+
let instance = null;
|
|
116
|
+
const getTextMeasureInstance = () => {
|
|
117
|
+
instance = instance || new TextMeasure();
|
|
118
|
+
return instance;
|
|
131
119
|
};
|
|
132
120
|
|
|
133
121
|
const addContentBGName = "--diff-add-content--";
|
|
@@ -196,6 +184,10 @@ const syncScroll = (left, right) => {
|
|
|
196
184
|
right.onscroll = null;
|
|
197
185
|
};
|
|
198
186
|
};
|
|
187
|
+
|
|
188
|
+
const diffFontSizeName = "--diff-font-size--";
|
|
189
|
+
const diffAsideWidthName = "--diff-aside-width--";
|
|
190
|
+
|
|
199
191
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
200
192
|
const memoFunc = (func) => {
|
|
201
193
|
const cache = {};
|
|
@@ -208,106 +200,56 @@ const memoFunc = (func) => {
|
|
|
208
200
|
return result;
|
|
209
201
|
});
|
|
210
202
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
224
|
-
const fontSize = ref(props.diffViewFontSize);
|
|
225
|
-
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
226
|
-
const extendData = ref({
|
|
227
|
-
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
228
|
-
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
229
|
-
});
|
|
230
|
-
const setExtendData = (_extendData) => {
|
|
231
|
-
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
232
|
-
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
233
|
-
for (const key of existOldKeys) {
|
|
234
|
-
if (!inComingOldKeys.includes(key)) {
|
|
235
|
-
delete extendData.value.oldFile[key];
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
for (const key of inComingOldKeys) {
|
|
239
|
-
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
240
|
-
}
|
|
241
|
-
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
242
|
-
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
243
|
-
for (const key of existNewKeys) {
|
|
244
|
-
if (!inComingNewKeys.includes(key)) {
|
|
245
|
-
delete extendData.value.newFile[key];
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
for (const key of inComingNewKeys) {
|
|
249
|
-
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
const renderWidgetLine = ref(props.renderWidgetLine);
|
|
253
|
-
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
254
|
-
const renderExtendLine = ref(props.renderExtendLine);
|
|
255
|
-
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
256
|
-
// 避免无意义的订阅
|
|
257
|
-
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
258
|
-
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
259
|
-
return {
|
|
260
|
-
id,
|
|
261
|
-
setId,
|
|
262
|
-
mode,
|
|
263
|
-
setMode,
|
|
264
|
-
enableWrap,
|
|
265
|
-
setEnableWrap,
|
|
266
|
-
enableAddWidget,
|
|
267
|
-
setEnableAddWidget,
|
|
268
|
-
enableHighlight,
|
|
269
|
-
setEnableHighlight,
|
|
270
|
-
fontSize,
|
|
271
|
-
setFontSize,
|
|
272
|
-
extendData,
|
|
273
|
-
setExtendData,
|
|
274
|
-
renderWidgetLine,
|
|
275
|
-
setRenderWidgetLine,
|
|
276
|
-
renderExtendLine,
|
|
277
|
-
setRenderExtendLine,
|
|
278
|
-
onAddWidgetClick,
|
|
279
|
-
setOnAddWidgetClick,
|
|
280
|
-
};
|
|
281
|
-
});
|
|
203
|
+
|
|
204
|
+
const getSymbol = (symbol) => {
|
|
205
|
+
switch (symbol) {
|
|
206
|
+
case NewLineSymbol.LF:
|
|
207
|
+
return "␊";
|
|
208
|
+
case NewLineSymbol.CR:
|
|
209
|
+
return "␍";
|
|
210
|
+
case NewLineSymbol.CRLF:
|
|
211
|
+
return "␍␊";
|
|
212
|
+
default:
|
|
213
|
+
return "";
|
|
214
|
+
}
|
|
282
215
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const { renderWidgetLine } = ((_b = (_a = useDiffContextRef.current) === null || _a === void 0 ? void 0 : _a.getReadonlyState) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
|
|
290
|
-
if (typeof renderWidgetLine !== "function")
|
|
291
|
-
return;
|
|
292
|
-
widgetSide.value = side;
|
|
293
|
-
widgetLineNumber.value = lineNumber;
|
|
294
|
-
};
|
|
295
|
-
return { widgetSide, widgetLineNumber, setWidget };
|
|
296
|
-
});
|
|
216
|
+
|
|
217
|
+
const useUnmount = (cb, deps) => {
|
|
218
|
+
const ref = useRef(cb);
|
|
219
|
+
ref.current = cb;
|
|
220
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
221
|
+
useEffect(() => ref.current, deps);
|
|
297
222
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
223
|
+
|
|
224
|
+
var DiffModeEnum;
|
|
225
|
+
(function (DiffModeEnum) {
|
|
226
|
+
// github like
|
|
227
|
+
DiffModeEnum[DiffModeEnum["SplitGitHub"] = 1] = "SplitGitHub";
|
|
228
|
+
// gitlab like
|
|
229
|
+
DiffModeEnum[DiffModeEnum["SplitGitLab"] = 2] = "SplitGitLab";
|
|
230
|
+
DiffModeEnum[DiffModeEnum["Split"] = 3] = "Split";
|
|
231
|
+
DiffModeEnum[DiffModeEnum["Unified"] = 4] = "Unified";
|
|
232
|
+
})(DiffModeEnum || (DiffModeEnum = {}));
|
|
233
|
+
const DiffViewContext = createContext(null);
|
|
234
|
+
DiffViewContext.displayName = "DiffViewContext";
|
|
235
|
+
const useDiffViewContext = () => useContext(DiffViewContext);
|
|
236
|
+
|
|
237
|
+
const isClient = typeof window !== "undefined";
|
|
238
|
+
const useSafeLayout = isClient ? useLayoutEffect : useEffect;
|
|
239
|
+
|
|
240
|
+
const useTextWidth = ({ text, font, }) => {
|
|
241
|
+
const [width, setWidth] = useState(() => {
|
|
242
|
+
const fontSize = parseInt(font.fontSize);
|
|
243
|
+
let baseSize = 6;
|
|
244
|
+
baseSize += fontSize > 10 ? (fontSize - 10) * 0.6 : 0;
|
|
245
|
+
return baseSize * text.length;
|
|
307
246
|
});
|
|
247
|
+
useSafeLayout(() => {
|
|
248
|
+
const width = getTextMeasureInstance().measure(text, font);
|
|
249
|
+
setWidth(width);
|
|
250
|
+
}, [text, font]);
|
|
251
|
+
return width;
|
|
308
252
|
};
|
|
309
|
-
const diffAsideWidthName = "--diff-aside-width--";
|
|
310
|
-
const diffFontSizeName = "--diff-font-size--";
|
|
311
253
|
|
|
312
254
|
const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
|
|
313
255
|
return (React.createElement("div", { className: "diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
|
|
@@ -369,18 +311,6 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
369
311
|
});
|
|
370
312
|
return style;
|
|
371
313
|
});
|
|
372
|
-
const getSymbol = (symbol) => {
|
|
373
|
-
switch (symbol) {
|
|
374
|
-
case NewLineSymbol.LF:
|
|
375
|
-
return "␊";
|
|
376
|
-
case NewLineSymbol.CR:
|
|
377
|
-
return "␍";
|
|
378
|
-
case NewLineSymbol.CRLF:
|
|
379
|
-
return "␍␊";
|
|
380
|
-
default:
|
|
381
|
-
return "";
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
314
|
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
385
315
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
386
316
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
@@ -396,7 +326,9 @@ const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
|
396
326
|
str1,
|
|
397
327
|
React.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
398
328
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
399
|
-
} }, isLast ?
|
|
329
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
330
|
+
_str2,
|
|
331
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
400
332
|
str3),
|
|
401
333
|
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: {
|
|
402
334
|
width: `var(${diffFontSizeName})`,
|
|
@@ -439,7 +371,9 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
439
371
|
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
440
372
|
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
441
373
|
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
442
|
-
} }, isLast ?
|
|
374
|
+
} }, isLast ? (React.createElement(React.Fragment, null,
|
|
375
|
+
_str2,
|
|
376
|
+
React.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
443
377
|
str3));
|
|
444
378
|
}
|
|
445
379
|
})),
|
|
@@ -772,8 +706,18 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
772
706
|
return React.createElement(_DiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
773
707
|
};
|
|
774
708
|
|
|
775
|
-
const _DiffSplitWidgetLine$1 = ({
|
|
709
|
+
const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
710
|
+
const { useWidget } = useDiffWidgetContext();
|
|
776
711
|
const { useDiffContext } = useDiffViewContext();
|
|
712
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
713
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
714
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
715
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
716
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
717
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
718
|
+
const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
719
|
+
const currentLine = side === SplitSide.old ? oldLine : newLine;
|
|
720
|
+
const currentWidget = side === SplitSide.old ? oldLineWidget : newLineWidget;
|
|
777
721
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
778
722
|
const currentWidgetRendered = currentWidget &&
|
|
779
723
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
@@ -799,23 +743,21 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
|
|
|
799
743
|
React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
|
|
800
744
|
};
|
|
801
745
|
// TODO! improve performance
|
|
802
|
-
const DiffSplitWidgetLine$1 = ({ index,
|
|
746
|
+
const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
803
747
|
const { useWidget } = useDiffWidgetContext();
|
|
804
|
-
const
|
|
805
|
-
widgetLineNumber
|
|
806
|
-
widgetSide
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const currentWidget = side === SplitSide.old ? oldLineWidget : newLineWidget;
|
|
815
|
-
const currentIsShow = oldLineWidget || newLineWidget;
|
|
748
|
+
const currentIsShow = useWidget.useShallowSelector(React.useCallback((s) => {
|
|
749
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
750
|
+
const widgetSide = s.widgetSide;
|
|
751
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
752
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
753
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
754
|
+
const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
755
|
+
const currentIsShow = oldLineWidget || newLineWidget;
|
|
756
|
+
return currentIsShow;
|
|
757
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
816
758
|
if (!currentIsShow)
|
|
817
759
|
return null;
|
|
818
|
-
return
|
|
760
|
+
return React.createElement(_DiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
|
|
819
761
|
};
|
|
820
762
|
|
|
821
763
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1060,7 +1002,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1060
1002
|
React.createElement(ExpandDown, { className: "fill-current" })),
|
|
1061
1003
|
React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px]", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
|
|
1062
1004
|
React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
1063
|
-
React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1005
|
+
React.createElement("td", { className: "diff-line-hunk-content relative pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1064
1006
|
React.createElement("div", { className: "pl-[1.5em]", style: {
|
|
1065
1007
|
color: `var(${hunkContentColorName})`,
|
|
1066
1008
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
@@ -1088,13 +1030,17 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1088
1030
|
return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1089
1031
|
};
|
|
1090
1032
|
|
|
1091
|
-
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber,
|
|
1033
|
+
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1092
1034
|
const { useWidget } = useDiffWidgetContext();
|
|
1093
1035
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1094
1036
|
const { useDiffContext } = useDiffViewContext();
|
|
1095
1037
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1096
1038
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1097
1039
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1040
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1041
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1042
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1043
|
+
const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1098
1044
|
const oldWidgetRendered = oldLineWidget &&
|
|
1099
1045
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: SplitSide.old, lineNumber: oldLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1100
1046
|
const newWidgetRendered = newLineWidget &&
|
|
@@ -1110,18 +1056,118 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
|
|
|
1110
1056
|
// TODO! improve performance
|
|
1111
1057
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1112
1058
|
const { useWidget } = useDiffWidgetContext();
|
|
1113
|
-
const
|
|
1114
|
-
widgetLineNumber
|
|
1115
|
-
widgetSide
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1059
|
+
const currentIsShow = useWidget.useShallowSelector(React.useCallback((s) => {
|
|
1060
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
1061
|
+
const widgetSide = s.widgetSide;
|
|
1062
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1063
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
1064
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1065
|
+
const newLineWidget = newLine.lineNumber && widgetSide === SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1066
|
+
const currentIsShow = oldLineWidget || newLineWidget;
|
|
1067
|
+
return currentIsShow;
|
|
1068
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
1122
1069
|
if (!currentIsShow)
|
|
1123
1070
|
return null;
|
|
1124
|
-
return
|
|
1071
|
+
return React.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
const createDiffConfigStore = (props, diffFileId) => {
|
|
1075
|
+
return createStore(() => {
|
|
1076
|
+
var _a, _b;
|
|
1077
|
+
const id = ref(diffFileId);
|
|
1078
|
+
const setId = (_id) => (id.value = _id);
|
|
1079
|
+
const mode = ref(props.diffViewMode);
|
|
1080
|
+
const setMode = (_mode) => (mode.value = _mode);
|
|
1081
|
+
const enableWrap = ref(props.diffViewWrap);
|
|
1082
|
+
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1083
|
+
const enableAddWidget = ref(props.diffViewAddWidget);
|
|
1084
|
+
const setEnableAddWidget = (_enableAddWidget) => (enableAddWidget.value = _enableAddWidget);
|
|
1085
|
+
const enableHighlight = ref(props.diffViewHighlight);
|
|
1086
|
+
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
1087
|
+
const fontSize = ref(props.diffViewFontSize);
|
|
1088
|
+
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
1089
|
+
const extendData = ref({
|
|
1090
|
+
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
1091
|
+
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
1092
|
+
});
|
|
1093
|
+
const setExtendData = (_extendData) => {
|
|
1094
|
+
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
1095
|
+
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
1096
|
+
for (const key of existOldKeys) {
|
|
1097
|
+
if (!inComingOldKeys.includes(key)) {
|
|
1098
|
+
delete extendData.value.oldFile[key];
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
for (const key of inComingOldKeys) {
|
|
1102
|
+
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
1103
|
+
}
|
|
1104
|
+
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
1105
|
+
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
1106
|
+
for (const key of existNewKeys) {
|
|
1107
|
+
if (!inComingNewKeys.includes(key)) {
|
|
1108
|
+
delete extendData.value.newFile[key];
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
for (const key of inComingNewKeys) {
|
|
1112
|
+
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
const renderWidgetLine = ref(props.renderWidgetLine);
|
|
1116
|
+
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1117
|
+
const renderExtendLine = ref(props.renderExtendLine);
|
|
1118
|
+
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1119
|
+
// 避免无意义的订阅
|
|
1120
|
+
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1121
|
+
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
1122
|
+
return {
|
|
1123
|
+
id,
|
|
1124
|
+
setId,
|
|
1125
|
+
mode,
|
|
1126
|
+
setMode,
|
|
1127
|
+
enableWrap,
|
|
1128
|
+
setEnableWrap,
|
|
1129
|
+
enableAddWidget,
|
|
1130
|
+
setEnableAddWidget,
|
|
1131
|
+
enableHighlight,
|
|
1132
|
+
setEnableHighlight,
|
|
1133
|
+
fontSize,
|
|
1134
|
+
setFontSize,
|
|
1135
|
+
extendData,
|
|
1136
|
+
setExtendData,
|
|
1137
|
+
renderWidgetLine,
|
|
1138
|
+
setRenderWidgetLine,
|
|
1139
|
+
renderExtendLine,
|
|
1140
|
+
setRenderExtendLine,
|
|
1141
|
+
onAddWidgetClick,
|
|
1142
|
+
setOnAddWidgetClick,
|
|
1143
|
+
};
|
|
1144
|
+
});
|
|
1145
|
+
};
|
|
1146
|
+
const createDiffWidgetStore = (useDiffContextRef) => {
|
|
1147
|
+
return createStore(() => {
|
|
1148
|
+
const widgetSide = ref(undefined);
|
|
1149
|
+
const widgetLineNumber = ref(undefined);
|
|
1150
|
+
const setWidget = ({ side, lineNumber }) => {
|
|
1151
|
+
var _a, _b;
|
|
1152
|
+
const { renderWidgetLine } = ((_b = (_a = useDiffContextRef.current) === null || _a === void 0 ? void 0 : _a.getReadonlyState) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
|
|
1153
|
+
if (typeof renderWidgetLine !== "function")
|
|
1154
|
+
return;
|
|
1155
|
+
widgetSide.value = side;
|
|
1156
|
+
widgetLineNumber.value = lineNumber;
|
|
1157
|
+
};
|
|
1158
|
+
return { widgetSide, widgetLineNumber, setWidget };
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
const createDiffSplitConfigStore = () => {
|
|
1162
|
+
return createStore(() => {
|
|
1163
|
+
const splitRef = ref(undefined);
|
|
1164
|
+
const setSplit = (side) => {
|
|
1165
|
+
flushSync(() => {
|
|
1166
|
+
splitRef.value = side;
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1169
|
+
return { splitRef, setSplit };
|
|
1170
|
+
});
|
|
1125
1171
|
};
|
|
1126
1172
|
|
|
1127
1173
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1399,9 +1445,15 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1399
1445
|
return React.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1400
1446
|
};
|
|
1401
1447
|
|
|
1402
|
-
const _DiffUnifiedWidgetLine = ({ index, diffFile,
|
|
1448
|
+
const _DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1449
|
+
const { useWidget } = useDiffWidgetContext();
|
|
1450
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1403
1451
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1404
1452
|
const onClose = () => setWidget({});
|
|
1453
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1454
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1455
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1456
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1405
1457
|
const { useDiffContext } = useDiffViewContext();
|
|
1406
1458
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1407
1459
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
@@ -1423,18 +1475,18 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
|
|
|
1423
1475
|
};
|
|
1424
1476
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1425
1477
|
const { useWidget } = useDiffWidgetContext();
|
|
1426
|
-
const
|
|
1427
|
-
widgetLineNumber
|
|
1428
|
-
widgetSide
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1478
|
+
const currentIsShow = useWidget.useShallowSelector(React.useCallback((s) => {
|
|
1479
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
1480
|
+
const widgetSide = s.widgetSide;
|
|
1481
|
+
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1482
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1483
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1484
|
+
const currentIsShow = oldWidget || newWidget;
|
|
1485
|
+
return currentIsShow;
|
|
1486
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
1435
1487
|
if (!currentIsShow)
|
|
1436
1488
|
return null;
|
|
1437
|
-
return
|
|
1489
|
+
return React.createElement(_DiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1438
1490
|
};
|
|
1439
1491
|
|
|
1440
1492
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1544,7 +1596,7 @@ const _InternalDiffView = (props) => {
|
|
|
1544
1596
|
}, [diffFile]);
|
|
1545
1597
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1546
1598
|
return (React.createElement(DiffViewContext.Provider, { value: value },
|
|
1547
|
-
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1599
|
+
React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.23", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1548
1600
|
React.createElement("div", { className: "diff-style-root", style: {
|
|
1549
1601
|
// @ts-ignore
|
|
1550
1602
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1607,11 +1659,9 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1607
1659
|
return (React.createElement(InternalDiffView, Object.assign({ key: diffFile.getId() }, restProps, { diffFile: diffFile, diffViewMode: restProps.diffViewMode || DiffModeEnum.SplitGitHub, diffViewFontSize: restProps.diffViewFontSize || 14 })));
|
|
1608
1660
|
};
|
|
1609
1661
|
const InnerDiffView = forwardRef(DiffViewWithRef);
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
DiffView.displayName = "DiffView";
|
|
1614
|
-
const version = "0.0.21";
|
|
1662
|
+
InnerDiffView.displayName = "DiffView";
|
|
1663
|
+
const DiffView = InnerDiffView;
|
|
1664
|
+
const version = "0.0.23";
|
|
1615
1665
|
|
|
1616
1666
|
export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
|
|
1617
1667
|
//# sourceMappingURL=index.mjs.map
|