@git-diff-view/react 0.0.22 → 0.0.24
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 +229 -177
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +229 -177
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/esm/index.mjs +243 -191
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +2 -0
- package/package.json +8 -8
- package/readme.md +1 -1
|
@@ -55,6 +55,28 @@ function __rest(s, e) {
|
|
|
55
55
|
return t;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
59
|
+
var e = new Error(message);
|
|
60
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/******************************************************************************
|
|
64
|
+
Copyright (c) Microsoft Corporation.
|
|
65
|
+
|
|
66
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
67
|
+
purpose with or without fee is hereby granted.
|
|
68
|
+
|
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
70
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
71
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
72
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
73
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
74
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
75
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
76
|
+
***************************************************************************** */
|
|
77
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
78
|
+
|
|
79
|
+
|
|
58
80
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
59
81
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
60
82
|
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");
|
|
@@ -62,10 +84,8 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
|
62
84
|
}
|
|
63
85
|
|
|
64
86
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
65
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
66
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
67
87
|
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");
|
|
68
|
-
return (
|
|
88
|
+
return (state.set(receiver, value)), value;
|
|
69
89
|
}
|
|
70
90
|
|
|
71
91
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
@@ -73,16 +93,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
73
93
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
74
94
|
};
|
|
75
95
|
|
|
76
|
-
const useUnmount = (cb, deps) => {
|
|
77
|
-
const ref = React.useRef(cb);
|
|
78
|
-
ref.current = cb;
|
|
79
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
-
React.useEffect(() => ref.current, deps);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const isClient = typeof window !== "undefined";
|
|
84
|
-
const useSafeLayout = isClient ? React.useLayoutEffect : React.useEffect;
|
|
85
|
-
|
|
86
96
|
var _TextMeasure_instances, _TextMeasure_key, _TextMeasure_map, _TextMeasure_getInstance;
|
|
87
97
|
let canvasCtx = null;
|
|
88
98
|
const getKey = (font, text) => {
|
|
@@ -106,7 +116,7 @@ class TextMeasure {
|
|
|
106
116
|
if (font) {
|
|
107
117
|
const currentFontKey = `${font.fontFamily}-${font.fontStyle}-${font.fontSize}`;
|
|
108
118
|
if (__classPrivateFieldGet(this, _TextMeasure_key, "f") !== currentFontKey) {
|
|
109
|
-
__classPrivateFieldSet(this, _TextMeasure_key, currentFontKey
|
|
119
|
+
__classPrivateFieldSet(this, _TextMeasure_key, currentFontKey);
|
|
110
120
|
instance.font = `${font.fontStyle || ""} ${font.fontSize || ""} ${font.fontFamily || ""}`;
|
|
111
121
|
}
|
|
112
122
|
}
|
|
@@ -121,19 +131,10 @@ _TextMeasure_key = new WeakMap(), _TextMeasure_map = new WeakMap(), _TextMeasure
|
|
|
121
131
|
canvasCtx = canvasCtx || document.createElement("canvas").getContext("2d");
|
|
122
132
|
return canvasCtx;
|
|
123
133
|
};
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
let baseSize = 6;
|
|
129
|
-
baseSize += fontSize > 10 ? (fontSize - 10) * 0.6 : 0;
|
|
130
|
-
return baseSize * text.length;
|
|
131
|
-
});
|
|
132
|
-
useSafeLayout(() => {
|
|
133
|
-
const width = measureInstance.measure(text, font);
|
|
134
|
-
setWidth(width);
|
|
135
|
-
}, [text, font]);
|
|
136
|
-
return width;
|
|
134
|
+
let instance = null;
|
|
135
|
+
const getTextMeasureInstance = () => {
|
|
136
|
+
instance = instance || new TextMeasure();
|
|
137
|
+
return instance;
|
|
137
138
|
};
|
|
138
139
|
|
|
139
140
|
const addContentBGName = "--diff-add-content--";
|
|
@@ -202,6 +203,10 @@ const syncScroll = (left, right) => {
|
|
|
202
203
|
right.onscroll = null;
|
|
203
204
|
};
|
|
204
205
|
};
|
|
206
|
+
|
|
207
|
+
const diffFontSizeName = "--diff-font-size--";
|
|
208
|
+
const diffAsideWidthName = "--diff-aside-width--";
|
|
209
|
+
|
|
205
210
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
206
211
|
const memoFunc = (func) => {
|
|
207
212
|
const cache = {};
|
|
@@ -214,106 +219,43 @@ const memoFunc = (func) => {
|
|
|
214
219
|
return result;
|
|
215
220
|
});
|
|
216
221
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
230
|
-
const fontSize = reactivityStore.ref(props.diffViewFontSize);
|
|
231
|
-
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
232
|
-
const extendData = reactivityStore.ref({
|
|
233
|
-
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
234
|
-
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
235
|
-
});
|
|
236
|
-
const setExtendData = (_extendData) => {
|
|
237
|
-
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
238
|
-
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
239
|
-
for (const key of existOldKeys) {
|
|
240
|
-
if (!inComingOldKeys.includes(key)) {
|
|
241
|
-
delete extendData.value.oldFile[key];
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
for (const key of inComingOldKeys) {
|
|
245
|
-
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
246
|
-
}
|
|
247
|
-
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
248
|
-
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
249
|
-
for (const key of existNewKeys) {
|
|
250
|
-
if (!inComingNewKeys.includes(key)) {
|
|
251
|
-
delete extendData.value.newFile[key];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
for (const key of inComingNewKeys) {
|
|
255
|
-
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
const renderWidgetLine = reactivityStore.ref(props.renderWidgetLine);
|
|
259
|
-
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
260
|
-
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
261
|
-
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
262
|
-
// 避免无意义的订阅
|
|
263
|
-
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
264
|
-
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
265
|
-
return {
|
|
266
|
-
id,
|
|
267
|
-
setId,
|
|
268
|
-
mode,
|
|
269
|
-
setMode,
|
|
270
|
-
enableWrap,
|
|
271
|
-
setEnableWrap,
|
|
272
|
-
enableAddWidget,
|
|
273
|
-
setEnableAddWidget,
|
|
274
|
-
enableHighlight,
|
|
275
|
-
setEnableHighlight,
|
|
276
|
-
fontSize,
|
|
277
|
-
setFontSize,
|
|
278
|
-
extendData,
|
|
279
|
-
setExtendData,
|
|
280
|
-
renderWidgetLine,
|
|
281
|
-
setRenderWidgetLine,
|
|
282
|
-
renderExtendLine,
|
|
283
|
-
setRenderExtendLine,
|
|
284
|
-
onAddWidgetClick,
|
|
285
|
-
setOnAddWidgetClick,
|
|
286
|
-
};
|
|
287
|
-
});
|
|
222
|
+
|
|
223
|
+
const getSymbol = (symbol) => {
|
|
224
|
+
switch (symbol) {
|
|
225
|
+
case core.NewLineSymbol.LF:
|
|
226
|
+
return "␊";
|
|
227
|
+
case core.NewLineSymbol.CR:
|
|
228
|
+
return "␍";
|
|
229
|
+
case core.NewLineSymbol.CRLF:
|
|
230
|
+
return "␍␊";
|
|
231
|
+
default:
|
|
232
|
+
return "";
|
|
233
|
+
}
|
|
288
234
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const { renderWidgetLine } = ((_b = (_a = useDiffContextRef.current) === null || _a === void 0 ? void 0 : _a.getReadonlyState) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
|
|
296
|
-
if (typeof renderWidgetLine !== "function")
|
|
297
|
-
return;
|
|
298
|
-
widgetSide.value = side;
|
|
299
|
-
widgetLineNumber.value = lineNumber;
|
|
300
|
-
};
|
|
301
|
-
return { widgetSide, widgetLineNumber, setWidget };
|
|
302
|
-
});
|
|
235
|
+
|
|
236
|
+
const useUnmount = (cb, deps) => {
|
|
237
|
+
const ref = React.useRef(cb);
|
|
238
|
+
ref.current = cb;
|
|
239
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
240
|
+
React.useEffect(() => ref.current, deps);
|
|
303
241
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
242
|
+
|
|
243
|
+
const isClient = typeof window !== "undefined";
|
|
244
|
+
const useSafeLayout = isClient ? React.useLayoutEffect : React.useEffect;
|
|
245
|
+
|
|
246
|
+
const useTextWidth = ({ text, font, }) => {
|
|
247
|
+
const [width, setWidth] = React.useState(() => {
|
|
248
|
+
const fontSize = parseInt(font.fontSize);
|
|
249
|
+
let baseSize = 6;
|
|
250
|
+
baseSize += fontSize > 10 ? (fontSize - 10) * 0.6 : 0;
|
|
251
|
+
return baseSize * text.length;
|
|
313
252
|
});
|
|
253
|
+
useSafeLayout(() => {
|
|
254
|
+
const width = getTextMeasureInstance().measure(text, font);
|
|
255
|
+
setWidth(width);
|
|
256
|
+
}, [text, font]);
|
|
257
|
+
return width;
|
|
314
258
|
};
|
|
315
|
-
const diffAsideWidthName = "--diff-aside-width--";
|
|
316
|
-
const diffFontSizeName = "--diff-font-size--";
|
|
317
259
|
|
|
318
260
|
const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
|
|
319
261
|
return (React__namespace.createElement("div", { className: "diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
|
|
@@ -375,18 +317,6 @@ const getStyleObjectFromString = memoFunc((str) => {
|
|
|
375
317
|
});
|
|
376
318
|
return style;
|
|
377
319
|
});
|
|
378
|
-
const getSymbol = (symbol) => {
|
|
379
|
-
switch (symbol) {
|
|
380
|
-
case core.NewLineSymbol.LF:
|
|
381
|
-
return "␊";
|
|
382
|
-
case core.NewLineSymbol.CR:
|
|
383
|
-
return "␍";
|
|
384
|
-
case core.NewLineSymbol.CRLF:
|
|
385
|
-
return "␍␊";
|
|
386
|
-
default:
|
|
387
|
-
return "";
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
320
|
const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
391
321
|
const changes = diffLine === null || diffLine === void 0 ? void 0 : diffLine.changes;
|
|
392
322
|
if (changes === null || changes === void 0 ? void 0 : changes.hasLineChange) {
|
|
@@ -402,7 +332,9 @@ const DiffString = ({ rawLine, diffLine, operator, enableWrap, }) => {
|
|
|
402
332
|
str1,
|
|
403
333
|
React__namespace.createElement("span", { "data-diff-highlight": true, className: "rounded-[0.2em]", style: {
|
|
404
334
|
backgroundColor: operator === "add" ? `var(${addContentHighlightBGName})` : `var(${delContentHighlightBGName})`,
|
|
405
|
-
} }, isLast ?
|
|
335
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
336
|
+
_str2,
|
|
337
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
406
338
|
str3),
|
|
407
339
|
isNewLineSymbolChanged === core.NewLineSymbol.NEWLINE && (React__namespace.createElement("span", { "data-no-newline-at-end-of-file-symbol": true, className: enableWrap ? "block !text-red-500" : "inline-block align-middle !text-red-500", style: {
|
|
408
340
|
width: `var(${diffFontSizeName})`,
|
|
@@ -445,7 +377,9 @@ const DiffSyntax = ({ rawLine, diffLine, operator, syntaxLine, enableWrap, }) =>
|
|
|
445
377
|
borderBottomLeftRadius: isStart ? "0.2em" : undefined,
|
|
446
378
|
borderTopRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
447
379
|
borderBottomRightRadius: isEnd || isLast ? "0.2em" : undefined,
|
|
448
|
-
} }, isLast ?
|
|
380
|
+
} }, isLast ? (React__namespace.createElement(React__namespace.Fragment, null,
|
|
381
|
+
_str2,
|
|
382
|
+
React__namespace.createElement("span", { "data-newline-symbol": true }, getSymbol(isNewLineSymbolChanged)))) : (str2)),
|
|
449
383
|
str3));
|
|
450
384
|
}
|
|
451
385
|
})),
|
|
@@ -791,8 +725,18 @@ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
|
|
|
791
725
|
return React__namespace.createElement(_DiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
|
|
792
726
|
};
|
|
793
727
|
|
|
794
|
-
const _DiffSplitWidgetLine$1 = ({
|
|
728
|
+
const _DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
729
|
+
const { useWidget } = useDiffWidgetContext();
|
|
795
730
|
const { useDiffContext } = useDiffViewContext();
|
|
731
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
732
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
733
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
734
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
735
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
736
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
737
|
+
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
738
|
+
const currentLine = side === exports.SplitSide.old ? oldLine : newLine;
|
|
739
|
+
const currentWidget = side === exports.SplitSide.old ? oldLineWidget : newLineWidget;
|
|
796
740
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
797
741
|
const currentWidgetRendered = currentWidget &&
|
|
798
742
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
|
|
@@ -818,23 +762,21 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
|
|
|
818
762
|
React__namespace.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": exports.SplitSide[side] })))));
|
|
819
763
|
};
|
|
820
764
|
// TODO! improve performance
|
|
821
|
-
const DiffSplitWidgetLine$1 = ({ index,
|
|
765
|
+
const DiffSplitWidgetLine$1 = ({ index, side, diffFile, lineNumber, }) => {
|
|
822
766
|
const { useWidget } = useDiffWidgetContext();
|
|
823
|
-
const
|
|
824
|
-
widgetLineNumber
|
|
825
|
-
widgetSide
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
const currentWidget = side === exports.SplitSide.old ? oldLineWidget : newLineWidget;
|
|
834
|
-
const currentIsShow = oldLineWidget || newLineWidget;
|
|
767
|
+
const currentIsShow = useWidget.useShallowSelector(React__namespace.useCallback((s) => {
|
|
768
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
769
|
+
const widgetSide = s.widgetSide;
|
|
770
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
771
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
772
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
773
|
+
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
774
|
+
const currentIsShow = oldLineWidget || newLineWidget;
|
|
775
|
+
return currentIsShow;
|
|
776
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
835
777
|
if (!currentIsShow)
|
|
836
778
|
return null;
|
|
837
|
-
return
|
|
779
|
+
return React__namespace.createElement(_DiffSplitWidgetLine$1, { index: index, side: side, diffFile: diffFile, lineNumber: lineNumber });
|
|
838
780
|
};
|
|
839
781
|
|
|
840
782
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1079,7 +1021,7 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
|
|
|
1079
1021
|
React__namespace.createElement(ExpandDown, { className: "fill-current" })),
|
|
1080
1022
|
React__namespace.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) },
|
|
1081
1023
|
React__namespace.createElement(ExpandUp, { className: "fill-current" }))))) : (React__namespace.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
|
|
1082
|
-
React__namespace.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1024
|
+
React__namespace.createElement("td", { className: "diff-line-hunk-content relative pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
|
|
1083
1025
|
React__namespace.createElement("div", { className: "pl-[1.5em]", style: {
|
|
1084
1026
|
color: `var(${hunkContentColorName})`,
|
|
1085
1027
|
} }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
|
|
@@ -1107,13 +1049,17 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1107
1049
|
return React__namespace.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1108
1050
|
};
|
|
1109
1051
|
|
|
1110
|
-
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber,
|
|
1052
|
+
const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1111
1053
|
const { useWidget } = useDiffWidgetContext();
|
|
1112
1054
|
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1113
1055
|
const { useDiffContext } = useDiffViewContext();
|
|
1114
1056
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
1115
1057
|
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1116
1058
|
const newLine = diffFile.getSplitRightLine(index);
|
|
1059
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1060
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1061
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1062
|
+
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1117
1063
|
const oldWidgetRendered = oldLineWidget &&
|
|
1118
1064
|
(renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({ diffFile, side: exports.SplitSide.old, lineNumber: oldLine.lineNumber, onClose: () => setWidget({}) }));
|
|
1119
1065
|
const newWidgetRendered = newLineWidget &&
|
|
@@ -1129,18 +1075,118 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
|
|
|
1129
1075
|
// TODO! improve performance
|
|
1130
1076
|
const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1131
1077
|
const { useWidget } = useDiffWidgetContext();
|
|
1132
|
-
const
|
|
1133
|
-
widgetLineNumber
|
|
1134
|
-
widgetSide
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1078
|
+
const currentIsShow = useWidget.useShallowSelector(React__namespace.useCallback((s) => {
|
|
1079
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
1080
|
+
const widgetSide = s.widgetSide;
|
|
1081
|
+
const oldLine = diffFile.getSplitLeftLine(index);
|
|
1082
|
+
const newLine = diffFile.getSplitRightLine(index);
|
|
1083
|
+
const oldLineWidget = oldLine.lineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === oldLine.lineNumber;
|
|
1084
|
+
const newLineWidget = newLine.lineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === newLine.lineNumber;
|
|
1085
|
+
const currentIsShow = oldLineWidget || newLineWidget;
|
|
1086
|
+
return currentIsShow;
|
|
1087
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
1141
1088
|
if (!currentIsShow)
|
|
1142
1089
|
return null;
|
|
1143
|
-
return
|
|
1090
|
+
return React__namespace.createElement(_DiffSplitWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
const createDiffConfigStore = (props, diffFileId) => {
|
|
1094
|
+
return reactivityStore.createStore(() => {
|
|
1095
|
+
var _a, _b;
|
|
1096
|
+
const id = reactivityStore.ref(diffFileId);
|
|
1097
|
+
const setId = (_id) => (id.value = _id);
|
|
1098
|
+
const mode = reactivityStore.ref(props.diffViewMode);
|
|
1099
|
+
const setMode = (_mode) => (mode.value = _mode);
|
|
1100
|
+
const enableWrap = reactivityStore.ref(props.diffViewWrap);
|
|
1101
|
+
const setEnableWrap = (_enableWrap) => (enableWrap.value = _enableWrap);
|
|
1102
|
+
const enableAddWidget = reactivityStore.ref(props.diffViewAddWidget);
|
|
1103
|
+
const setEnableAddWidget = (_enableAddWidget) => (enableAddWidget.value = _enableAddWidget);
|
|
1104
|
+
const enableHighlight = reactivityStore.ref(props.diffViewHighlight);
|
|
1105
|
+
const setEnableHighlight = (_enableHighlight) => (enableHighlight.value = _enableHighlight);
|
|
1106
|
+
const fontSize = reactivityStore.ref(props.diffViewFontSize);
|
|
1107
|
+
const setFontSize = (_fontSize) => (fontSize.value = _fontSize);
|
|
1108
|
+
const extendData = reactivityStore.ref({
|
|
1109
|
+
oldFile: Object.assign({}, (_a = props.extendData) === null || _a === void 0 ? void 0 : _a.oldFile),
|
|
1110
|
+
newFile: Object.assign({}, (_b = props.extendData) === null || _b === void 0 ? void 0 : _b.newFile),
|
|
1111
|
+
});
|
|
1112
|
+
const setExtendData = (_extendData) => {
|
|
1113
|
+
const existOldKeys = Object.keys(extendData.value.oldFile || {});
|
|
1114
|
+
const inComingOldKeys = Object.keys(_extendData.oldFile || {});
|
|
1115
|
+
for (const key of existOldKeys) {
|
|
1116
|
+
if (!inComingOldKeys.includes(key)) {
|
|
1117
|
+
delete extendData.value.oldFile[key];
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
for (const key of inComingOldKeys) {
|
|
1121
|
+
extendData.value.oldFile[key] = _extendData.oldFile[key];
|
|
1122
|
+
}
|
|
1123
|
+
const existNewKeys = Object.keys(extendData.value.newFile || {});
|
|
1124
|
+
const inComingNewKeys = Object.keys(_extendData.newFile || {});
|
|
1125
|
+
for (const key of existNewKeys) {
|
|
1126
|
+
if (!inComingNewKeys.includes(key)) {
|
|
1127
|
+
delete extendData.value.newFile[key];
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
for (const key of inComingNewKeys) {
|
|
1131
|
+
extendData.value.newFile[key] = _extendData.newFile[key];
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
const renderWidgetLine = reactivityStore.ref(props.renderWidgetLine);
|
|
1135
|
+
const setRenderWidgetLine = (_renderWidgetLine) => (renderWidgetLine.value = _renderWidgetLine);
|
|
1136
|
+
const renderExtendLine = reactivityStore.ref(props.renderExtendLine);
|
|
1137
|
+
const setRenderExtendLine = (_renderExtendLine) => (renderExtendLine.value = _renderExtendLine);
|
|
1138
|
+
// 避免无意义的订阅
|
|
1139
|
+
const onAddWidgetClick = { current: props.onAddWidgetClick };
|
|
1140
|
+
const setOnAddWidgetClick = (_onAddWidgetClick) => (onAddWidgetClick.current = _onAddWidgetClick.current);
|
|
1141
|
+
return {
|
|
1142
|
+
id,
|
|
1143
|
+
setId,
|
|
1144
|
+
mode,
|
|
1145
|
+
setMode,
|
|
1146
|
+
enableWrap,
|
|
1147
|
+
setEnableWrap,
|
|
1148
|
+
enableAddWidget,
|
|
1149
|
+
setEnableAddWidget,
|
|
1150
|
+
enableHighlight,
|
|
1151
|
+
setEnableHighlight,
|
|
1152
|
+
fontSize,
|
|
1153
|
+
setFontSize,
|
|
1154
|
+
extendData,
|
|
1155
|
+
setExtendData,
|
|
1156
|
+
renderWidgetLine,
|
|
1157
|
+
setRenderWidgetLine,
|
|
1158
|
+
renderExtendLine,
|
|
1159
|
+
setRenderExtendLine,
|
|
1160
|
+
onAddWidgetClick,
|
|
1161
|
+
setOnAddWidgetClick,
|
|
1162
|
+
};
|
|
1163
|
+
});
|
|
1164
|
+
};
|
|
1165
|
+
const createDiffWidgetStore = (useDiffContextRef) => {
|
|
1166
|
+
return reactivityStore.createStore(() => {
|
|
1167
|
+
const widgetSide = reactivityStore.ref(undefined);
|
|
1168
|
+
const widgetLineNumber = reactivityStore.ref(undefined);
|
|
1169
|
+
const setWidget = ({ side, lineNumber }) => {
|
|
1170
|
+
var _a, _b;
|
|
1171
|
+
const { renderWidgetLine } = ((_b = (_a = useDiffContextRef.current) === null || _a === void 0 ? void 0 : _a.getReadonlyState) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
|
|
1172
|
+
if (typeof renderWidgetLine !== "function")
|
|
1173
|
+
return;
|
|
1174
|
+
widgetSide.value = side;
|
|
1175
|
+
widgetLineNumber.value = lineNumber;
|
|
1176
|
+
};
|
|
1177
|
+
return { widgetSide, widgetLineNumber, setWidget };
|
|
1178
|
+
});
|
|
1179
|
+
};
|
|
1180
|
+
const createDiffSplitConfigStore = () => {
|
|
1181
|
+
return reactivityStore.createStore(() => {
|
|
1182
|
+
const splitRef = reactivityStore.ref(undefined);
|
|
1183
|
+
const setSplit = (side) => {
|
|
1184
|
+
reactDom.flushSync(() => {
|
|
1185
|
+
splitRef.value = side;
|
|
1186
|
+
});
|
|
1187
|
+
};
|
|
1188
|
+
return { splitRef, setSplit };
|
|
1189
|
+
});
|
|
1144
1190
|
};
|
|
1145
1191
|
|
|
1146
1192
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1418,9 +1464,15 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
|
|
|
1418
1464
|
return React__namespace.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1419
1465
|
};
|
|
1420
1466
|
|
|
1421
|
-
const _DiffUnifiedWidgetLine = ({ index, diffFile,
|
|
1467
|
+
const _DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1468
|
+
const { useWidget } = useDiffWidgetContext();
|
|
1469
|
+
const setWidget = useWidget.getReadonlyState().setWidget;
|
|
1422
1470
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1423
1471
|
const onClose = () => setWidget({});
|
|
1472
|
+
const widgetSide = useWidget.getReadonlyState().widgetSide;
|
|
1473
|
+
const widgetLineNumber = useWidget.getReadonlyState().widgetLineNumber;
|
|
1474
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1475
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1424
1476
|
const { useDiffContext } = useDiffViewContext();
|
|
1425
1477
|
// 需要显示的时候才进行方法订阅,可以大幅度提高性能
|
|
1426
1478
|
const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
|
|
@@ -1442,18 +1494,18 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
|
|
|
1442
1494
|
};
|
|
1443
1495
|
const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
|
|
1444
1496
|
const { useWidget } = useDiffWidgetContext();
|
|
1445
|
-
const
|
|
1446
|
-
widgetLineNumber
|
|
1447
|
-
widgetSide
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1497
|
+
const currentIsShow = useWidget.useShallowSelector(React__namespace.useCallback((s) => {
|
|
1498
|
+
const widgetLineNumber = s.widgetLineNumber;
|
|
1499
|
+
const widgetSide = s.widgetSide;
|
|
1500
|
+
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
1501
|
+
const oldWidget = unifiedItem.oldLineNumber && widgetSide === exports.SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
|
|
1502
|
+
const newWidget = unifiedItem.newLineNumber && widgetSide === exports.SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
|
|
1503
|
+
const currentIsShow = oldWidget || newWidget;
|
|
1504
|
+
return currentIsShow;
|
|
1505
|
+
}, [diffFile, index]), (p, c) => p === c);
|
|
1454
1506
|
if (!currentIsShow)
|
|
1455
1507
|
return null;
|
|
1456
|
-
return
|
|
1508
|
+
return React__namespace.createElement(_DiffUnifiedWidgetLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
|
|
1457
1509
|
};
|
|
1458
1510
|
|
|
1459
1511
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
@@ -1563,7 +1615,7 @@ const _InternalDiffView = (props) => {
|
|
|
1563
1615
|
}, [diffFile]);
|
|
1564
1616
|
const value = React.useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
1565
1617
|
return (React__namespace.createElement(DiffViewContext.Provider, { value: value },
|
|
1566
|
-
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.
|
|
1618
|
+
React__namespace.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.24", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
|
|
1567
1619
|
React__namespace.createElement("div", { className: "diff-style-root", style: {
|
|
1568
1620
|
// @ts-ignore
|
|
1569
1621
|
[diffFontSizeName]: diffViewFontSize + "px",
|
|
@@ -1628,7 +1680,7 @@ const DiffViewWithRef = (props, ref) => {
|
|
|
1628
1680
|
const InnerDiffView = React.forwardRef(DiffViewWithRef);
|
|
1629
1681
|
InnerDiffView.displayName = "DiffView";
|
|
1630
1682
|
const DiffView = InnerDiffView;
|
|
1631
|
-
const version = "0.0.
|
|
1683
|
+
const version = "0.0.24";
|
|
1632
1684
|
|
|
1633
1685
|
exports.DiffView = DiffView;
|
|
1634
1686
|
exports.DiffViewContext = DiffViewContext;
|