@git-diff-view/react 0.0.16 → 0.0.18

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.
@@ -1,4 +1,4 @@
1
- import { composeLen, DiffLineType, NewLineSymbol, checkDiffLineIncludeChange, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
1
+ import { DiffLineType, NewLineSymbol, checkDiffLineIncludeChange, composeLen, getSplitContentLines, getUnifiedContentLine, _cacheMap, DiffFile } from '@git-diff-view/core';
2
2
  export * from '@git-diff-view/core';
3
3
  import * as React from 'react';
4
4
  import { useRef, useEffect, createContext, useContext, useLayoutEffect, useState, useCallback, memo, Fragment, useMemo, forwardRef, useImperativeHandle } from 'react';
@@ -118,93 +118,9 @@ const useTextWidth = ({ text, font, }) => {
118
118
  return width;
119
119
  };
120
120
 
121
- const useDomWidth = ({ selector, enable }) => {
122
- const [width, setWidth] = useState(0);
123
- const { useDiffContext } = useDiffViewContext();
124
- const id = useDiffContext(useCallback((s) => s.id, []));
125
- useEffect(() => {
126
- if (enable) {
127
- const container = document.querySelector(`#diff-root${id}`);
128
- const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
129
- if (!wrapper)
130
- return;
131
- const typedWrapper = wrapper;
132
- const cb = () => {
133
- var _a;
134
- const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
135
- setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
136
- };
137
- cb();
138
- const cleanCb = () => {
139
- var _a;
140
- typedWrapper.__observeCallback.delete(cb);
141
- if (typedWrapper.__observeCallback.size === 0) {
142
- (_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
143
- typedWrapper.removeAttribute("data-observe");
144
- delete typedWrapper.__observeCallback;
145
- delete typedWrapper.__observeInstance;
146
- }
147
- };
148
- if (typedWrapper.__observeCallback) {
149
- typedWrapper.__observeCallback.add(cb);
150
- return () => cleanCb();
151
- }
152
- typedWrapper.__observeCallback = new Set();
153
- typedWrapper.__observeCallback.add(cb);
154
- const observer = new ResizeObserver(() => typedWrapper.__observeCallback.forEach((cb) => cb()));
155
- typedWrapper.__observeInstance = observer;
156
- observer.observe(typedWrapper);
157
- typedWrapper.setAttribute("data-observe", "height");
158
- return () => cleanCb();
159
- }
160
- }, [selector, enable, id]);
161
- return width;
162
- };
163
-
164
- // TODO
165
- const useSyncHeight = ({ selector, side, enable }) => {
166
- const { useDiffContext } = useDiffViewContext();
167
- const id = useDiffContext(useCallback((s) => s.id, []));
168
- useSafeLayout(() => {
169
- if (enable) {
170
- const container = document.querySelector(`#diff-root${id}`);
171
- const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
172
- if (elements.length === 2) {
173
- const ele1 = elements[0];
174
- const ele2 = elements[1];
175
- const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
176
- const cb = () => {
177
- ele1.style.height = "auto";
178
- ele2.style.height = "auto";
179
- const rect1 = ele1.getBoundingClientRect();
180
- const rect2 = ele2.getBoundingClientRect();
181
- if (rect1.height !== rect2.height) {
182
- const maxHeight = Math.max(rect1.height, rect2.height);
183
- ele1.style.height = maxHeight + "px";
184
- ele2.style.height = maxHeight + "px";
185
- ele1.setAttribute("data-sync-height", String(maxHeight));
186
- ele2.setAttribute("data-sync-height", String(maxHeight));
187
- }
188
- else {
189
- ele1.removeAttribute("data-sync-height");
190
- ele2.removeAttribute("data-sync-height");
191
- }
192
- };
193
- cb();
194
- const observer = new ResizeObserver(cb);
195
- observer.observe(target);
196
- target.setAttribute("data-observe", "height");
197
- return () => {
198
- observer.disconnect();
199
- target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
200
- };
201
- }
202
- }
203
- }, [selector, enable, side, id]);
204
- };
205
-
206
121
  const addContentBGName = "--diff-add-content--";
207
122
  const delContentBGName = "--diff-del-content--";
123
+ const borderColorName = "--diff-border--";
208
124
  const addLineNumberBGName = "--diff-add-lineNumber--";
209
125
  const delLineNumberBGName = "--diff-del-lineNumber--";
210
126
  const plainContentBGName = "--diff-plain-content--";
@@ -238,70 +154,6 @@ const getLineNumberBG = (isAdded, isDelete, hasDiff) => {
238
154
  : `var(${expandContentBGName})`;
239
155
  };
240
156
 
241
- const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
242
- const { useDiffContext } = useDiffViewContext();
243
- const oldLine = diffFile.getSplitLeftLine(index);
244
- const newLine = diffFile.getSplitRightLine(index);
245
- const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
246
- const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
247
- const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
248
- useSyncHeight({
249
- selector: `tr[data-line="${lineNumber}-extend"]`,
250
- side: SplitSide[side],
251
- enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
252
- });
253
- const width = useDomWidth({
254
- selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
255
- enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
256
- });
257
- if (!renderExtendLine)
258
- return null;
259
- return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
260
- React.createElement("div", { className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
261
- (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) &&
262
- (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
263
- diffFile,
264
- side,
265
- lineNumber: currentLineNumber,
266
- data: currentExtend.data,
267
- onUpdate: diffFile.notifyAll,
268
- }))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
269
- React.createElement("span", null, "\u2002")))));
270
- };
271
- const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
272
- const { useDiffContext } = useDiffViewContext();
273
- const oldLine = diffFile.getSplitLeftLine(index);
274
- const newLine = diffFile.getSplitRightLine(index);
275
- const { oldLineExtend, newLineExtend } = useDiffContext(React.useCallback((s) => {
276
- var _a, _b, _c, _d;
277
- return ({
278
- oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
279
- newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
280
- });
281
- }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
282
- const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
283
- // if the expand action not enabled, the `isHidden` property will never change
284
- const enableExpand = diffFile.getExpandEnabled();
285
- const currentLine = side === SplitSide.old ? oldLine : newLine;
286
- const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
287
- if (!currentIsShow)
288
- return null;
289
- return (React.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
290
- };
291
-
292
- const ExpandDown = ({ className }) => {
293
- return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
294
- React.createElement("path", { d: "m8.177 14.323 2.896-2.896a.25.25 0 0 0-.177-.427H8.75V7.764a.75.75 0 1 0-1.5 0V11H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0ZM2.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75ZM8.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
295
- };
296
- const ExpandUp = ({ className }) => {
297
- return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
298
- React.createElement("path", { d: "M7.823 1.677 4.927 4.573A.25.25 0 0 0 5.104 5H7.25v3.236a.75.75 0 1 0 1.5 0V5h2.146a.25.25 0 0 0 .177-.427L8.177 1.677a.25.25 0 0 0-.354 0ZM13.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Zm-3.75.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM7.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5ZM4 11.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM1.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Z" })));
299
- };
300
- const ExpandAll = ({ className }) => {
301
- return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
302
- 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" })));
303
- };
304
-
305
157
  const removeAllSelection = () => {
306
158
  const selection = window.getSelection();
307
159
  for (let i = 0; i < selection.rangeCount; i++) {
@@ -445,105 +297,6 @@ const createDiffSplitConfigStore = () => {
445
297
  const diffAsideWidthName = "--diff-aside-width--";
446
298
  const diffFontSizeName = "--diff-font-size--";
447
299
 
448
- const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
449
- var _a;
450
- const currentHunk = diffFile.getSplitHunkLine(index);
451
- const expandEnabled = diffFile.getExpandEnabled();
452
- useSyncHeight({
453
- selector: `tr[data-line="${lineNumber}-hunk"]`,
454
- side: SplitSide[SplitSide.old],
455
- enable: side === SplitSide.new,
456
- });
457
- const enableHunkAction = side === SplitSide.old;
458
- const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
459
- const isExpandAll = currentHunk &&
460
- currentHunk.splitInfo &&
461
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
462
- const isFirstLine = currentHunk && currentHunk.isFirst;
463
- const isLastLine = currentHunk && currentHunk.isLast;
464
- return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React.createElement(React.Fragment, null,
465
- React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
466
- backgroundColor: `var(${hunkLineNumberBGName})`,
467
- color: `var(${plainLineNumberColorName})`,
468
- width: `var(${diffAsideWidthName})`,
469
- minWidth: `var(${diffAsideWidthName})`,
470
- maxWidth: `var(${diffAsideWidthName})`,
471
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
472
- 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] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
473
- diffFile.onSplitHunkExpand("down", index);
474
- } },
475
- 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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
476
- React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
477
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
478
- React.createElement(ExpandDown, { className: "fill-current" })),
479
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
480
- React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
481
- React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
482
- React.createElement("div", { className: "pl-[1.5em]", style: {
483
- color: `var(${hunkContentColorName})`,
484
- } }, ((_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})` } },
485
- React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
486
- };
487
- const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
488
- var _a;
489
- const currentHunk = diffFile.getSplitHunkLine(index);
490
- const expandEnabled = diffFile.getExpandEnabled();
491
- useSyncHeight({
492
- selector: `tr[data-line="${lineNumber}-hunk"]`,
493
- side: SplitSide[side],
494
- enable: true,
495
- });
496
- const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
497
- const isExpandAll = currentHunk &&
498
- currentHunk.splitInfo &&
499
- currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
500
- const isFirstLine = currentHunk && currentHunk.isFirst;
501
- const isLastLine = currentHunk && currentHunk.isLast;
502
- return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" },
503
- React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
504
- backgroundColor: `var(${hunkLineNumberBGName})`,
505
- color: `var(${plainLineNumberColorName})`,
506
- width: `var(${diffAsideWidthName})`,
507
- minWidth: `var(${diffAsideWidthName})`,
508
- maxWidth: `var(${diffAsideWidthName})`,
509
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
510
- 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] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => {
511
- diffFile.onSplitHunkExpand("down", index);
512
- } },
513
- 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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
514
- React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
515
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
516
- React.createElement(ExpandDown, { className: "fill-current" })),
517
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
518
- React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
519
- React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
520
- React.createElement("div", { className: "pl-[1.5em]", style: {
521
- color: `var(${hunkContentColorName})`,
522
- } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
523
- };
524
- const _DiffSplitHunkLine = ({ index, diffFile, side, lineNumber, }) => {
525
- const { useDiffContext } = useDiffViewContext();
526
- const diffViewMode = useDiffContext(React.useCallback((s) => s.mode, []));
527
- if (diffViewMode === DiffModeEnum.SplitGitHub ||
528
- diffViewMode === DiffModeEnum.Split ||
529
- diffViewMode === DiffModeEnum.Unified) {
530
- return React.createElement(_DiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
531
- }
532
- else {
533
- return React.createElement(_DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
534
- }
535
- };
536
- const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
537
- const currentHunk = diffFile.getSplitHunkLine(index);
538
- const currentIsShow = currentHunk &&
539
- currentHunk.splitInfo &&
540
- currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
541
- const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
542
- if (!currentIsShow && !currentIsPureHunk)
543
- return null;
544
- return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
545
- };
546
-
547
300
  const DiffSplitAddWidget = ({ side, className, lineNumber, onWidgetClick, onOpenAddWidget, }) => {
548
301
  return (React.createElement("div", { className: "diff-add-widget-wrapper invisible select-none transition-transform hover:scale-110 group-hover:visible" +
549
302
  (className ? " " + className : ""), style: {
@@ -580,6 +333,8 @@ const DiffNoNewLine = () => {
580
333
 
581
334
  const temp = {};
582
335
  const formatStringToCamelCase = (str) => {
336
+ if (str.startsWith("--"))
337
+ return str;
583
338
  const splitted = str.split("-");
584
339
  if (splitted.length === 1)
585
340
  return splitted[0];
@@ -696,7 +451,9 @@ const DiffContent = ({ diffLine, rawLine, syntaxLine, enableWrap, enableHighligh
696
451
  const isAdded = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Add;
697
452
  const isDelete = (diffLine === null || diffLine === void 0 ? void 0 : diffLine.type) === DiffLineType.Delete;
698
453
  const isMaxLineLengthToIgnoreSyntax = ((_a = syntaxLine === null || syntaxLine === void 0 ? void 0 : syntaxLine.nodeList) === null || _a === void 0 ? void 0 : _a.length) > 150;
699
- return (React.createElement("div", { className: "diff-line-content-item pl-[2.0em]", "data-val": rawLine, style: {
454
+ return (React.createElement("div", { className: "diff-line-content-item pl-[2.0em]",
455
+ // data-val={rawLine}
456
+ style: {
700
457
  whiteSpace: enableWrap ? "pre-wrap" : "pre",
701
458
  wordBreak: enableWrap ? "break-all" : "initial",
702
459
  } },
@@ -720,11 +477,11 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
720
477
  const isAdded = ((_a = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Add;
721
478
  const isDelete = ((_b = currentLine === null || currentLine === void 0 ? void 0 : currentLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Delete;
722
479
  const { useDiffContext } = useDiffViewContext();
723
- const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React.useCallback((s) => ({
480
+ const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
724
481
  enableHighlight: s.enableHighlight,
725
482
  enableAddWidget: s.enableAddWidget,
726
483
  onAddWidgetClick: s.onAddWidgetClick,
727
- }), []));
484
+ }));
728
485
  const { useWidget } = useDiffWidgetContext();
729
486
  const setWidget = useWidget.getReadonlyState().setWidget;
730
487
  const contentBG = getContentBG(isAdded, isDelete, hasDiff);
@@ -744,7 +501,7 @@ const _DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
744
501
  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 },
745
502
  React.createElement("span", null, "\u2002")))));
746
503
  };
747
- const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
504
+ const DiffSplitContentLine$1 = ({ index, diffFile, lineNumber, side, }) => {
748
505
  const getCurrentLine = side === SplitSide.old ? diffFile.getSplitLeftLine : diffFile.getSplitRightLine;
749
506
  const currentLine = getCurrentLine(index);
750
507
  if (currentLine === null || currentLine === void 0 ? void 0 : currentLine.isHidden)
@@ -752,11 +509,258 @@ const DiffSplitLine$1 = ({ index, diffFile, lineNumber, side, }) => {
752
509
  return React.createElement(_DiffSplitLine$1, { index: index, diffFile: diffFile, lineNumber: lineNumber, side: side });
753
510
  };
754
511
 
512
+ const useDomWidth = ({ selector, enable }) => {
513
+ const [width, setWidth] = useState(0);
514
+ const { useDiffContext } = useDiffViewContext();
515
+ const id = useDiffContext(useCallback((s) => s.id, []));
516
+ useEffect(() => {
517
+ if (enable) {
518
+ const container = document.querySelector(`#diff-root${id}`);
519
+ const wrapper = container === null || container === void 0 ? void 0 : container.querySelector(selector);
520
+ if (!wrapper)
521
+ return;
522
+ const typedWrapper = wrapper;
523
+ const cb = () => {
524
+ var _a;
525
+ const rect = wrapper === null || wrapper === void 0 ? void 0 : wrapper.getBoundingClientRect();
526
+ setWidth((_a = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _a !== void 0 ? _a : 0);
527
+ };
528
+ cb();
529
+ const cleanCb = () => {
530
+ var _a;
531
+ typedWrapper.__observeCallback.delete(cb);
532
+ if (typedWrapper.__observeCallback.size === 0) {
533
+ (_a = typedWrapper.__observeInstance) === null || _a === void 0 ? void 0 : _a.disconnect();
534
+ typedWrapper.removeAttribute("data-observe");
535
+ delete typedWrapper.__observeCallback;
536
+ delete typedWrapper.__observeInstance;
537
+ }
538
+ };
539
+ if (typedWrapper.__observeCallback) {
540
+ typedWrapper.__observeCallback.add(cb);
541
+ return () => cleanCb();
542
+ }
543
+ typedWrapper.__observeCallback = new Set();
544
+ typedWrapper.__observeCallback.add(cb);
545
+ const observer = new ResizeObserver(() => typedWrapper.__observeCallback.forEach((cb) => cb()));
546
+ typedWrapper.__observeInstance = observer;
547
+ observer.observe(typedWrapper);
548
+ typedWrapper.setAttribute("data-observe", "height");
549
+ return () => cleanCb();
550
+ }
551
+ }, [selector, enable, id]);
552
+ return width;
553
+ };
554
+
555
+ // TODO
556
+ const useSyncHeight = ({ selector, wrapper, side, enable, }) => {
557
+ const { useDiffContext } = useDiffViewContext();
558
+ const id = useDiffContext(useCallback((s) => s.id, []));
559
+ useSafeLayout(() => {
560
+ if (enable) {
561
+ const container = document.querySelector(`#diff-root${id}`);
562
+ const elements = Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(selector)) || []);
563
+ const wrappers = wrapper ? Array.from((container === null || container === void 0 ? void 0 : container.querySelectorAll(wrapper)) || []) : elements;
564
+ if (elements.length === 2 && wrappers.length === 2) {
565
+ const ele1 = elements[0];
566
+ const ele2 = elements[1];
567
+ const wrapper1 = wrappers[0];
568
+ const wrapper2 = wrappers[1];
569
+ const target = ele1.getAttribute("data-side") === side ? ele1 : ele2;
570
+ const cb = () => {
571
+ ele1.style.height = "auto";
572
+ ele2.style.height = "auto";
573
+ const rect1 = ele1.getBoundingClientRect();
574
+ const rect2 = ele2.getBoundingClientRect();
575
+ const maxHeight = Math.max(rect1.height, rect2.height);
576
+ wrapper1.style.height = maxHeight + "px";
577
+ wrapper2.style.height = maxHeight + "px";
578
+ wrapper1.setAttribute("data-sync-height", String(maxHeight));
579
+ wrapper2.setAttribute("data-sync-height", String(maxHeight));
580
+ };
581
+ cb();
582
+ const observer = new ResizeObserver(cb);
583
+ observer.observe(target);
584
+ target.setAttribute("data-observe", "height");
585
+ return () => {
586
+ observer.disconnect();
587
+ target === null || target === void 0 ? void 0 : target.removeAttribute("data-observe");
588
+ };
589
+ }
590
+ }
591
+ }, [selector, enable, side, id, wrapper]);
592
+ };
593
+
594
+ const _DiffSplitExtendLine$1 = ({ index, diffFile, oldLineExtend, newLineExtend, side, lineNumber, }) => {
595
+ const { useDiffContext } = useDiffViewContext();
596
+ const oldLine = diffFile.getSplitLeftLine(index);
597
+ const newLine = diffFile.getSplitRightLine(index);
598
+ const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
599
+ const currentExtend = side === SplitSide.old ? oldLineExtend : newLineExtend;
600
+ const currentLineNumber = side === SplitSide.old ? oldLine.lineNumber : newLine.lineNumber;
601
+ useSyncHeight({
602
+ selector: `div[data-line="${lineNumber}-extend-content"]`,
603
+ wrapper: `tr[data-line="${lineNumber}-extend"]`,
604
+ side: SplitSide[side],
605
+ enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
606
+ });
607
+ const width = useDomWidth({
608
+ selector: side === SplitSide.old ? ".old-diff-table-wrapper" : ".new-diff-table-wrapper",
609
+ enable: !!(currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) && typeof renderExtendLine === "function",
610
+ });
611
+ if (!renderExtendLine)
612
+ return null;
613
+ return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", "data-side": SplitSide[side], className: "diff-line diff-line-extend" }, currentExtend ? (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-content p-0`, colSpan: 2 },
614
+ React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side], className: "diff-line-extend-wrapper sticky left-0", style: { width } }, width > 0 &&
615
+ (currentExtend === null || currentExtend === void 0 ? void 0 : currentExtend.data) &&
616
+ (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
617
+ diffFile,
618
+ side,
619
+ lineNumber: currentLineNumber,
620
+ data: currentExtend.data,
621
+ onUpdate: diffFile.notifyAll,
622
+ }))))) : (React.createElement("td", { className: `diff-line-extend-${SplitSide[side]}-placeholder select-none p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
623
+ React.createElement("div", { "data-line": `${lineNumber}-extend-content`, "data-side": SplitSide[side] })))));
624
+ };
625
+ const DiffSplitExtendLine$1 = ({ index, diffFile, side, lineNumber, }) => {
626
+ const { useDiffContext } = useDiffViewContext();
627
+ const oldLine = diffFile.getSplitLeftLine(index);
628
+ const newLine = diffFile.getSplitRightLine(index);
629
+ const { oldLineExtend, newLineExtend } = useDiffContext(React.useCallback((s) => {
630
+ var _a, _b, _c, _d;
631
+ return ({
632
+ oldLineExtend: (_b = (_a = s.extendData) === null || _a === void 0 ? void 0 : _a.oldFile) === null || _b === void 0 ? void 0 : _b[oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber],
633
+ newLineExtend: (_d = (_c = s.extendData) === null || _c === void 0 ? void 0 : _c.newFile) === null || _d === void 0 ? void 0 : _d[newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber],
634
+ });
635
+ }, [oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber, newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber]));
636
+ const hasExtend = (oldLineExtend === null || oldLineExtend === void 0 ? void 0 : oldLineExtend.data) || (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data);
637
+ // if the expand action not enabled, the `isHidden` property will never change
638
+ const enableExpand = diffFile.getExpandEnabled();
639
+ const currentLine = side === SplitSide.old ? oldLine : newLine;
640
+ const currentIsShow = hasExtend && (!currentLine.isHidden || !enableExpand);
641
+ if (!currentIsShow)
642
+ return null;
643
+ return (React.createElement(_DiffSplitExtendLine$1, { side: side, index: index, diffFile: diffFile, lineNumber: lineNumber, oldLineExtend: oldLineExtend, newLineExtend: newLineExtend }));
644
+ };
645
+
646
+ const ExpandDown = ({ className }) => {
647
+ return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
648
+ React.createElement("path", { d: "m8.177 14.323 2.896-2.896a.25.25 0 0 0-.177-.427H8.75V7.764a.75.75 0 1 0-1.5 0V11H5.104a.25.25 0 0 0-.177.427l2.896 2.896a.25.25 0 0 0 .354 0ZM2.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM6 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75ZM8.25 5a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5ZM12 4.25a.75.75 0 0 1-.75.75h-.5a.75.75 0 0 1 0-1.5h.5a.75.75 0 0 1 .75.75Zm2.25.75a.75.75 0 0 0 0-1.5h-.5a.75.75 0 0 0 0 1.5h.5Z" })));
649
+ };
650
+ const ExpandUp = ({ className }) => {
651
+ return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
652
+ React.createElement("path", { d: "M7.823 1.677 4.927 4.573A.25.25 0 0 0 5.104 5H7.25v3.236a.75.75 0 1 0 1.5 0V5h2.146a.25.25 0 0 0 .177-.427L8.177 1.677a.25.25 0 0 0-.354 0ZM13.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Zm-3.75.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM7.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5ZM4 11.75a.75.75 0 0 1 .75-.75h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1-.75-.75ZM1.75 11a.75.75 0 0 0 0 1.5h.5a.75.75 0 0 0 0-1.5h-.5Z" })));
653
+ };
654
+ const ExpandAll = ({ className }) => {
655
+ return (React.createElement("svg", { "aria-hidden": "true", height: "16", viewBox: "0 0 16 16", version: "1.1", width: "16", className: className },
656
+ 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" })));
657
+ };
658
+
659
+ const _DiffSplitHunkLineGitHub = ({ index, diffFile, side, lineNumber, }) => {
660
+ var _a;
661
+ const currentHunk = diffFile.getSplitHunkLine(index);
662
+ const expandEnabled = diffFile.getExpandEnabled();
663
+ useSyncHeight({
664
+ selector: `tr[data-line="${lineNumber}-hunk"]`,
665
+ side: SplitSide[SplitSide.old],
666
+ enable: side === SplitSide.new,
667
+ });
668
+ const enableHunkAction = side === SplitSide.old;
669
+ const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
670
+ const isExpandAll = currentHunk &&
671
+ currentHunk.splitInfo &&
672
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
673
+ const isFirstLine = currentHunk && currentHunk.isFirst;
674
+ const isLastLine = currentHunk && currentHunk.isLast;
675
+ return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" }, enableHunkAction ? (React.createElement(React.Fragment, null,
676
+ React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
677
+ backgroundColor: `var(${hunkLineNumberBGName})`,
678
+ color: `var(${plainLineNumberColorName})`,
679
+ width: `var(${diffAsideWidthName})`,
680
+ minWidth: `var(${diffAsideWidthName})`,
681
+ maxWidth: `var(${diffAsideWidthName})`,
682
+ } }, 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) },
683
+ 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: () => {
684
+ diffFile.onSplitHunkExpand("down", index);
685
+ } },
686
+ 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) },
687
+ React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
688
+ 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) },
689
+ React.createElement(ExpandDown, { className: "fill-current" })),
690
+ 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) },
691
+ React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
692
+ React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
693
+ React.createElement("div", { className: "pl-[1.5em]", style: {
694
+ color: `var(${hunkContentColorName})`,
695
+ } }, ((_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})` } },
696
+ React.createElement("div", { className: "min-h-[28px]" }, "\u2002")))));
697
+ };
698
+ const _DiffSplitHunkLineGitLab = ({ index, diffFile, side, lineNumber, }) => {
699
+ var _a;
700
+ const currentHunk = diffFile.getSplitHunkLine(index);
701
+ const expandEnabled = diffFile.getExpandEnabled();
702
+ useSyncHeight({
703
+ selector: `tr[data-line="${lineNumber}-hunk"]`,
704
+ side: SplitSide[side],
705
+ enable: true,
706
+ });
707
+ const couldExpand = expandEnabled && currentHunk && currentHunk.splitInfo;
708
+ const isExpandAll = currentHunk &&
709
+ currentHunk.splitInfo &&
710
+ currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
711
+ const isFirstLine = currentHunk && currentHunk.isFirst;
712
+ const isLastLine = currentHunk && currentHunk.isLast;
713
+ return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", "data-side": SplitSide[side], className: "diff-line diff-line-hunk" },
714
+ React.createElement("td", { className: "diff-line-hunk-action sticky left-0 w-[1%] min-w-[40px] select-none p-[1px]", style: {
715
+ backgroundColor: `var(${hunkLineNumberBGName})`,
716
+ color: `var(${plainLineNumberColorName})`,
717
+ width: `var(${diffAsideWidthName})`,
718
+ minWidth: `var(${diffAsideWidthName})`,
719
+ maxWidth: `var(${diffAsideWidthName})`,
720
+ } }, 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) },
721
+ 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: () => {
722
+ diffFile.onSplitHunkExpand("down", index);
723
+ } },
724
+ 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) },
725
+ React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
726
+ 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) },
727
+ React.createElement(ExpandDown, { className: "fill-current" })),
728
+ 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) },
729
+ React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
730
+ React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
731
+ React.createElement("div", { className: "pl-[1.5em]", style: {
732
+ color: `var(${hunkContentColorName})`,
733
+ } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text))));
734
+ };
735
+ const _DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
736
+ const { useDiffContext } = useDiffViewContext();
737
+ const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
738
+ if (diffViewMode === DiffModeEnum.SplitGitHub ||
739
+ diffViewMode === DiffModeEnum.Split ||
740
+ diffViewMode === DiffModeEnum.Unified) {
741
+ return React.createElement(_DiffSplitHunkLineGitHub, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
742
+ }
743
+ else {
744
+ return React.createElement(_DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
745
+ }
746
+ };
747
+ const DiffSplitHunkLine$1 = ({ index, diffFile, side, lineNumber, }) => {
748
+ const currentHunk = diffFile.getSplitHunkLine(index);
749
+ const currentIsShow = currentHunk &&
750
+ currentHunk.splitInfo &&
751
+ currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
752
+ const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
753
+ if (!currentIsShow && !currentIsPureHunk)
754
+ return null;
755
+ return React.createElement(_DiffSplitHunkLine$1, { index: index, diffFile: diffFile, side: side, lineNumber: lineNumber });
756
+ };
757
+
755
758
  const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWidget, currentWidget, }) => {
756
759
  const { useDiffContext } = useDiffViewContext();
757
- const renderWidgetLine = useDiffContext(React.useCallback((s) => s.renderWidgetLine, []));
760
+ const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
758
761
  useSyncHeight({
759
- selector: `tr[data-line="${lineNumber}-widget"]`,
762
+ selector: `div[data-line="${lineNumber}-widget-content"]`,
763
+ wrapper: `tr[data-line="${lineNumber}-widget"]`,
760
764
  side: SplitSide[side],
761
765
  enable: currentWidget && typeof renderWidgetLine === "function",
762
766
  });
@@ -767,18 +771,22 @@ const _DiffSplitWidgetLine$1 = ({ diffFile, side, lineNumber, currentLine, setWi
767
771
  if (!renderWidgetLine)
768
772
  return null;
769
773
  return (React.createElement("tr", { "data-line": `${lineNumber}-widget`, "data-state": "widget", "data-side": SplitSide[side], className: "diff-line diff-line-widget" }, currentWidget ? (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-content p-0`, colSpan: 2 },
770
- React.createElement("div", { className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
774
+ React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side], className: "diff-line-widget-wrapper sticky left-0", style: { width } }, width > 0 &&
771
775
  (renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
772
776
  diffFile,
773
777
  side,
774
778
  lineNumber: currentLine.lineNumber,
775
779
  onClose: () => setWidget({}),
776
780
  }))))) : (React.createElement("td", { className: `diff-line-widget-${SplitSide[side]}-placeholder p-0`, style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
777
- React.createElement("span", null, "\u2002")))));
781
+ React.createElement("div", { "data-line": `${lineNumber}-widget-content`, "data-side": SplitSide[side] })))));
778
782
  };
779
783
  const DiffSplitWidgetLine$1 = ({ index, diffFile, side, lineNumber, }) => {
780
784
  const { useWidget } = useDiffWidgetContext();
781
- const { widgetLineNumber, widgetSide, setWidget } = useWidget(React.useCallback((s) => ({ widgetLineNumber: s.widgetLineNumber, widgetSide: s.widgetSide, setWidget: s.setWidget }), []));
785
+ const { widgetLineNumber, widgetSide, setWidget } = useWidget.useShallowStableSelector((s) => ({
786
+ widgetLineNumber: s.widgetLineNumber,
787
+ widgetSide: s.widgetSide,
788
+ setWidget: s.setWidget,
789
+ }));
782
790
  const oldLine = diffFile.getSplitLeftLine(index);
783
791
  const newLine = diffFile.getSplitRightLine(index);
784
792
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
@@ -803,7 +811,7 @@ const onMouseDown$1 = (e) => {
803
811
  const DiffSplitViewTable = ({ side, diffFile }) => {
804
812
  const className = side === SplitSide.new ? "new-diff-table" : "old-diff-table";
805
813
  const lines = getSplitContentLines(diffFile);
806
- return (React.createElement("table", { className: className + " w-full border-collapse", "data-mode": SplitSide[side] },
814
+ return (React.createElement("table", { className: className + " w-full border-collapse border-spacing-0", "data-mode": SplitSide[side] },
807
815
  React.createElement("colgroup", null,
808
816
  React.createElement("col", { className: `diff-table-${SplitSide[side]}-num-col` }),
809
817
  React.createElement("col", { className: `diff-table-${SplitSide[side]}-content-col` })),
@@ -818,7 +826,7 @@ const DiffSplitViewTable = ({ side, diffFile }) => {
818
826
  React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown$1 },
819
827
  lines.map((line) => (React.createElement(Fragment, { key: line.index },
820
828
  React.createElement(DiffSplitHunkLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
821
- React.createElement(DiffSplitLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
829
+ React.createElement(DiffSplitContentLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
822
830
  React.createElement(DiffSplitWidgetLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile }),
823
831
  React.createElement(DiffSplitExtendLine$1, { index: line.index, side: side, lineNumber: line.lineNumber, diffFile: diffFile })))),
824
832
  React.createElement(DiffSplitHunkLine$1, { side: side, index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))));
@@ -828,7 +836,7 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
828
836
  const ref2 = useRef(null);
829
837
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
830
838
  const { useDiffContext } = useDiffViewContext();
831
- const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
839
+ const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
832
840
  useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
833
841
  useEffect(() => {
834
842
  const left = ref1.current;
@@ -843,8 +851,8 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
843
851
  font,
844
852
  });
845
853
  const width = Math.max(40, _width + 25);
846
- return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap flex w-full basis-[50%]" },
847
- React.createElement("div", { className: "old-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
854
+ return (React.createElement("div", { className: "split-diff-view split-diff-view-normal flex w-full basis-[50%]" },
855
+ React.createElement("div", { className: "old-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref1, style: {
848
856
  // @ts-ignore
849
857
  [diffAsideWidthName]: `${Math.round(width)}px`,
850
858
  overscrollBehaviorX: "none",
@@ -852,8 +860,8 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
852
860
  fontSize: `var(${diffFontSizeName})`,
853
861
  } },
854
862
  React.createElement(DiffSplitViewTable, { side: SplitSide.old, diffFile: diffFile })),
855
- React.createElement("div", { className: "diff-split-line w-[1.5px] bg-[rgb(222,222,222)]" }),
856
- React.createElement("div", { className: "new-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
863
+ React.createElement("div", { className: "diff-split-line w-[1.5px]", style: { backgroundColor: `var(${borderColorName})` } }),
864
+ React.createElement("div", { className: "new-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", ref: ref2, style: {
857
865
  // @ts-ignore
858
866
  [diffAsideWidthName]: `${Math.round(width)}px`,
859
867
  overscrollBehaviorX: "none",
@@ -864,12 +872,66 @@ const DiffSplitViewNormal = memo(({ diffFile }) => {
864
872
  });
865
873
  DiffSplitViewNormal.displayName = "DiffSplitViewNormal";
866
874
 
875
+ const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
876
+ var _a, _b;
877
+ const oldLine = diffFile.getSplitLeftLine(index);
878
+ const newLine = diffFile.getSplitRightLine(index);
879
+ const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
880
+ const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
881
+ const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
882
+ const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
883
+ const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
884
+ const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
885
+ const { useDiffContext } = useDiffViewContext();
886
+ const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
887
+ enableHighlight: s.enableHighlight,
888
+ enableAddWidget: s.enableAddWidget,
889
+ onAddWidgetClick: s.onAddWidgetClick,
890
+ }));
891
+ const { useWidget } = useDiffWidgetContext();
892
+ const setWidget = useWidget.getReadonlyState().setWidget;
893
+ const hasOldLine = !!oldLine.lineNumber;
894
+ const hasNewLine = !!newLine.lineNumber;
895
+ const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
896
+ const oldLineNumberBG = getLineNumberBG(false, oldLineIsDelete, hasDiff);
897
+ const newLineContentBG = getContentBG(newLineIsAdded, false, hasDiff);
898
+ const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
899
+ return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
900
+ hasOldLine ? (React.createElement(React.Fragment, null,
901
+ React.createElement("td", { className: "diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` } },
902
+ 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 left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
903
+ React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
904
+ React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
905
+ 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 }) })),
906
+ 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 },
907
+ React.createElement("span", null, "\u2002"))),
908
+ hasNewLine ? (React.createElement(React.Fragment, null,
909
+ 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: {
910
+ backgroundColor: newLineNumberBG,
911
+ color: `var(${plainLineNumberColorName})`,
912
+ borderLeftColor: `var(${borderColorName})`,
913
+ } },
914
+ 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 left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
915
+ React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
916
+ React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
917
+ 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 }) })),
918
+ 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: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
919
+ React.createElement("span", null, "\u2002")))));
920
+ };
921
+ const DiffSplitContentLine = ({ index, diffFile, lineNumber, }) => {
922
+ const oldLine = diffFile.getSplitLeftLine(index);
923
+ const newLine = diffFile.getSplitRightLine(index);
924
+ if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
925
+ return null;
926
+ return React.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
927
+ };
928
+
867
929
  const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
868
930
  const { useDiffContext } = useDiffViewContext();
869
931
  const oldLine = diffFile.getSplitLeftLine(index);
870
932
  const newLine = diffFile.getSplitRightLine(index);
871
933
  // 需要显示的时候才进行方法订阅,可以大幅度提高性能
872
- const renderExtendLine = useDiffContext(React.useCallback((s) => s.renderExtendLine, []));
934
+ const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
873
935
  if (!renderExtendLine)
874
936
  return null;
875
937
  return (React.createElement("tr", { "data-line": `${lineNumber}-extend`, "data-state": "extend", className: "diff-line diff-line-extend" },
@@ -883,7 +945,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
883
945
  onUpdate: diffFile.notifyAll,
884
946
  }))))) : (React.createElement("td", { className: "diff-line-extend-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
885
947
  React.createElement("span", null, "\u2002"))),
886
- newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
948
+ newLineExtend ? (React.createElement("td", { className: "diff-line-extend-new-content border-l-[1px] p-0", style: { borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
887
949
  React.createElement("div", { className: "diff-line-extend-wrapper" }, (newLineExtend === null || newLineExtend === void 0 ? void 0 : newLineExtend.data) &&
888
950
  (renderExtendLine === null || renderExtendLine === void 0 ? void 0 : renderExtendLine({
889
951
  diffFile,
@@ -891,7 +953,7 @@ const _DiffSplitExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newL
891
953
  lineNumber: newLine.lineNumber,
892
954
  data: newLineExtend.data,
893
955
  onUpdate: diffFile.notifyAll,
894
- }))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] border-l-[rgb(222,222,222)] p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
956
+ }))))) : (React.createElement("td", { className: "diff-line-extend-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
895
957
  React.createElement("span", null, "\u2002")))));
896
958
  };
897
959
  const DiffSplitExtendLine = ({ index, diffFile, lineNumber, }) => {
@@ -922,25 +984,19 @@ const DiffSplitHunkLineGitHub = ({ index, diffFile, lineNumber, }) => {
922
984
  const isExpandAll = currentHunk &&
923
985
  currentHunk.splitInfo &&
924
986
  currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
925
- const currentIsShow = currentHunk &&
926
- currentHunk.splitInfo &&
927
- currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
928
- const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
929
987
  const isFirstLine = currentHunk && currentHunk.isFirst;
930
988
  const isLastLine = currentHunk && currentHunk.isLast;
931
- if (!currentIsShow && !currentIsPureHunk)
932
- return null;
933
989
  return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
934
990
  React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
935
991
  backgroundColor: `var(${hunkLineNumberBGName})`,
936
992
  color: `var(${plainLineNumberColorName})`,
937
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
938
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
939
- 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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
993
+ } }, 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) },
994
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip 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) },
995
+ 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) },
940
996
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
941
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
997
+ 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) },
942
998
  React.createElement(ExpandDown, { className: "fill-current" })),
943
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
999
+ 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) },
944
1000
  React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
945
1001
  React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` }, colSpan: 3 },
946
1002
  React.createElement("div", { className: "pl-[1.5em]", style: {
@@ -955,49 +1011,44 @@ const DiffSplitHunkLineGitLab = ({ index, diffFile, lineNumber, }) => {
955
1011
  const isExpandAll = currentHunk &&
956
1012
  currentHunk.splitInfo &&
957
1013
  currentHunk.splitInfo.endHiddenIndex - currentHunk.splitInfo.startHiddenIndex < composeLen;
958
- const currentIsShow = currentHunk &&
959
- currentHunk.splitInfo &&
960
- currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
961
- const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
962
1014
  const isFirstLine = currentHunk && currentHunk.isFirst;
963
1015
  const isLastLine = currentHunk && currentHunk.isLast;
964
- if (!currentIsShow && !currentIsPureHunk)
965
- return null;
966
1016
  return (React.createElement("tr", { "data-line": `${lineNumber}-hunk`, "data-state": "hunk", className: "diff-line diff-line-hunk" },
967
1017
  React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none p-[1px]", style: {
968
1018
  backgroundColor: `var(${hunkLineNumberBGName})`,
969
1019
  color: `var(${plainLineNumberColorName})`,
970
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
971
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
972
- 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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
1020
+ } }, 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) },
1021
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip 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) },
1022
+ 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) },
973
1023
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
974
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
1024
+ 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) },
975
1025
  React.createElement(ExpandDown, { className: "fill-current" })),
976
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
1026
+ 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) },
977
1027
  React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
978
1028
  React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
979
1029
  React.createElement("div", { className: "pl-[1.5em]", style: {
980
1030
  color: `var(${hunkContentColorName})`,
981
1031
  } }, ((_a = currentHunk.splitInfo) === null || _a === void 0 ? void 0 : _a.plainText) || currentHunk.text)),
982
- React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] border-l-[rgb(222,222,222)] p-[1px]", style: {
1032
+ React.createElement("td", { className: "diff-line-hunk-action relative w-[1%] min-w-[40px] select-none border-l-[1px] p-[1px]", style: {
983
1033
  backgroundColor: `var(${hunkLineNumberBGName})`,
984
1034
  color: `var(${plainLineNumberColorName})`,
985
- } }, couldExpand ? (isFirstLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
986
- React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[6px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
987
- 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] hover:bg-blue-300", title: "Expand All", "data-title": "Expand All", onClick: () => diffFile.onSplitHunkExpand("all", index) },
1035
+ borderLeftColor: `var(${borderColorName})`,
1036
+ } }, 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) },
1037
+ React.createElement(ExpandUp, { className: "fill-current" }))) : isLastLine ? (React.createElement("button", { className: "diff-widget-tooltip 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) },
1038
+ 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) },
988
1039
  React.createElement(ExpandAll, { className: "fill-current" }))) : (React.createElement(React.Fragment, null,
989
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Down", "data-title": "Expand Down", onClick: () => diffFile.onSplitHunkExpand("down", index) },
1040
+ 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) },
990
1041
  React.createElement(ExpandDown, { className: "fill-current" })),
991
- React.createElement("button", { className: "diff-widget-tooltip flex w-full cursor-pointer items-center justify-center rounded-[2px] py-[2px] hover:bg-blue-300", title: "Expand Up", "data-title": "Expand Up", onClick: () => diffFile.onSplitHunkExpand("up", index) },
1042
+ 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) },
992
1043
  React.createElement(ExpandUp, { className: "fill-current" }))))) : (React.createElement("div", { className: "min-h-[28px]" }, "\u2002"))),
993
1044
  React.createElement("td", { className: "diff-line-hunk-content pr-[10px] align-middle", style: { backgroundColor: `var(${hunkContentBGName})` } },
994
1045
  React.createElement("div", { className: "pl-[1.5em]", style: {
995
1046
  color: `var(${hunkContentColorName})`,
996
1047
  } }, ((_b = currentHunk.splitInfo) === null || _b === void 0 ? void 0 : _b.plainText) || currentHunk.text))));
997
1048
  };
998
- const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1049
+ const _DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
999
1050
  const { useDiffContext } = useDiffViewContext();
1000
- const diffViewMode = useDiffContext(React.useCallback((s) => s.mode, []));
1051
+ const diffViewMode = useDiffContext.useShallowStableSelector((s) => s.mode);
1001
1052
  if (diffViewMode === DiffModeEnum.SplitGitHub ||
1002
1053
  diffViewMode === DiffModeEnum.Split ||
1003
1054
  diffViewMode === DiffModeEnum.Unified) {
@@ -1007,62 +1058,22 @@ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1007
1058
  return React.createElement(DiffSplitHunkLineGitLab, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1008
1059
  }
1009
1060
  };
1010
-
1011
- const _DiffSplitLine = ({ index, diffFile, lineNumber }) => {
1012
- var _a, _b;
1013
- const oldLine = diffFile.getSplitLeftLine(index);
1014
- const newLine = diffFile.getSplitRightLine(index);
1015
- const oldSyntaxLine = diffFile.getOldSyntaxLine(oldLine === null || oldLine === void 0 ? void 0 : oldLine.lineNumber);
1016
- const newSyntaxLine = diffFile.getNewSyntaxLine(newLine === null || newLine === void 0 ? void 0 : newLine.lineNumber);
1017
- const hasDiff = !!(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || !!(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
1018
- const hasChange = checkDiffLineIncludeChange(oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) || checkDiffLineIncludeChange(newLine === null || newLine === void 0 ? void 0 : newLine.diff);
1019
- const oldLineIsDelete = ((_a = oldLine === null || oldLine === void 0 ? void 0 : oldLine.diff) === null || _a === void 0 ? void 0 : _a.type) === DiffLineType.Delete;
1020
- const newLineIsAdded = ((_b = newLine === null || newLine === void 0 ? void 0 : newLine.diff) === null || _b === void 0 ? void 0 : _b.type) === DiffLineType.Add;
1021
- const { useDiffContext } = useDiffViewContext();
1022
- const { enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React.useCallback((s) => ({
1023
- enableHighlight: s.enableHighlight,
1024
- enableAddWidget: s.enableAddWidget,
1025
- onAddWidgetClick: s.onAddWidgetClick,
1026
- }), []));
1027
- const { useWidget } = useDiffWidgetContext();
1028
- const setWidget = useWidget.getReadonlyState().setWidget;
1029
- const hasOldLine = !!oldLine.lineNumber;
1030
- const hasNewLine = !!newLine.lineNumber;
1031
- const oldLineContentBG = getContentBG(false, oldLineIsDelete, hasDiff);
1032
- const oldLineNumberBG = getLineNumberBG(false, oldLineIsDelete, hasDiff);
1033
- const newLineContentBG = getContentBG(newLineIsAdded, false, hasDiff);
1034
- const newLineNumberBG = getLineNumberBG(newLineIsAdded, false, hasDiff);
1035
- return (React.createElement("tr", { "data-line": lineNumber, "data-state": hasDiff ? "diff" : "plain", className: "diff-line" },
1036
- hasOldLine ? (React.createElement(React.Fragment, null,
1037
- React.createElement("td", { className: "diff-line-old-num group relative w-[1%] min-w-[40px] select-none pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineNumberBG, color: `var(${plainLineNumberColorName})` } },
1038
- 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 left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
1039
- React.createElement("span", { "data-line-num": oldLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, oldLine.lineNumber)),
1040
- React.createElement("td", { className: "diff-line-old-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.old], style: { backgroundColor: oldLineContentBG } },
1041
- 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 }) })),
1042
- 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 },
1043
- React.createElement("span", null, "\u2002"))),
1044
- hasNewLine ? (React.createElement(React.Fragment, null,
1045
- React.createElement("td", { className: "diff-line-new-num group relative w-[1%] min-w-[40px] select-none border-l-[1px] border-l-[rgb(222,222,222)] pl-[10px] pr-[10px] text-right align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineNumberBG, color: `var(${plainLineNumberColorName})` } },
1046
- 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 left-[100%] z-[1] translate-x-[-50%]", onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber: lineNumber, side: side }) })),
1047
- React.createElement("span", { "data-line-num": newLine.lineNumber, style: { opacity: hasChange ? undefined : 0.5 } }, newLine.lineNumber)),
1048
- React.createElement("td", { className: "diff-line-new-content group relative pr-[10px] align-top", "data-side": SplitSide[SplitSide.new], style: { backgroundColor: newLineContentBG } },
1049
- 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 }) })),
1050
- 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] border-l-[rgb(222,222,222)]", style: { backgroundColor: `var(${emptyBGName})` }, "data-side": SplitSide[SplitSide.new], colSpan: 2 },
1051
- React.createElement("span", null, "\u2002")))));
1052
- };
1053
- const DiffSplitLine = ({ index, diffFile, lineNumber, }) => {
1054
- const oldLine = diffFile.getSplitLeftLine(index);
1055
- const newLine = diffFile.getSplitRightLine(index);
1056
- if ((oldLine === null || oldLine === void 0 ? void 0 : oldLine.isHidden) && (newLine === null || newLine === void 0 ? void 0 : newLine.isHidden))
1061
+ const DiffSplitHunkLine = ({ index, diffFile, lineNumber, }) => {
1062
+ const currentHunk = diffFile.getSplitHunkLine(index);
1063
+ const currentIsShow = currentHunk &&
1064
+ currentHunk.splitInfo &&
1065
+ currentHunk.splitInfo.startHiddenIndex < currentHunk.splitInfo.endHiddenIndex;
1066
+ const currentIsPureHunk = currentHunk && diffFile._getIsPureDiffRender() && !currentHunk.splitInfo;
1067
+ if (!currentIsShow && !currentIsPureHunk)
1057
1068
  return null;
1058
- return React.createElement(_DiffSplitLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1069
+ return React.createElement(_DiffSplitHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1059
1070
  };
1060
1071
 
1061
1072
  const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newLineWidget, }) => {
1062
1073
  const { useWidget } = useDiffWidgetContext();
1063
1074
  const setWidget = useWidget.getReadonlyState().setWidget;
1064
1075
  const { useDiffContext } = useDiffViewContext();
1065
- const renderWidgetLine = useDiffContext(React.useCallback((s) => s.renderWidgetLine, []));
1076
+ const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
1066
1077
  const oldLine = diffFile.getSplitLeftLine(index);
1067
1078
  const newLine = diffFile.getSplitRightLine(index);
1068
1079
  if (!renderWidgetLine)
@@ -1076,18 +1087,21 @@ const _DiffSplitWidgetLine = ({ index, diffFile, lineNumber, oldLineWidget, newL
1076
1087
  onClose: () => setWidget({}),
1077
1088
  })))) : (React.createElement("td", { className: "diff-line-widget-old-placeholder select-none p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
1078
1089
  React.createElement("span", null, "\u2002"))),
1079
- newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] border-l-[rgb(222,222,222)] p-0", colSpan: 2 },
1090
+ newLineWidget ? (React.createElement("td", { className: "diff-line-widget-new-content border-l-[1px] p-0", colSpan: 2, style: { borderLeftColor: `var(${borderColorName})` } },
1080
1091
  React.createElement("div", { className: "diff-line-widget-wrapper" }, renderWidgetLine === null || renderWidgetLine === void 0 ? void 0 : renderWidgetLine({
1081
1092
  diffFile,
1082
1093
  side: SplitSide.new,
1083
1094
  lineNumber: newLine.lineNumber,
1084
1095
  onClose: () => setWidget({}),
1085
- })))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] border-l-[rgb(222,222,222)] p-0", style: { backgroundColor: `var(${emptyBGName})` }, colSpan: 2 },
1096
+ })))) : (React.createElement("td", { className: "diff-line-widget-new-placeholder select-none border-l-[1px] p-0", style: { backgroundColor: `var(${emptyBGName})`, borderLeftColor: `var(${borderColorName})` }, colSpan: 2 },
1086
1097
  React.createElement("span", null, "\u2002")))));
1087
1098
  };
1088
1099
  const DiffSplitWidgetLine = ({ index, diffFile, lineNumber, }) => {
1089
1100
  const { useWidget } = useDiffWidgetContext();
1090
- const { widgetLineNumber, widgetSide } = useWidget(React.useCallback((s) => ({ widgetLineNumber: s.widgetLineNumber, widgetSide: s.widgetSide }), []));
1101
+ const { widgetLineNumber, widgetSide } = useWidget((s) => ({
1102
+ widgetLineNumber: s.widgetLineNumber,
1103
+ widgetSide: s.widgetSide,
1104
+ }));
1091
1105
  const oldLine = diffFile.getSplitLeftLine(index);
1092
1106
  const newLine = diffFile.getSplitRightLine(index);
1093
1107
  const oldLineWidget = oldLine.lineNumber && widgetSide === SplitSide.old && widgetLineNumber === oldLine.lineNumber;
@@ -1111,7 +1125,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1111
1125
  const splitLineLength = Math.max(diffFile.splitLineLength, diffFile.fileLineLength);
1112
1126
  const { useDiffContext } = useDiffViewContext();
1113
1127
  const useSplitConfig = useMemo(() => createDiffSplitConfigStore(), []);
1114
- const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
1128
+ const fontSize = useDiffContext.useShallowStableSelector((s) => s.fontSize);
1115
1129
  useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
1116
1130
  const onMouseDown = useCallback((e) => {
1117
1131
  let ele = e.target;
@@ -1140,7 +1154,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1140
1154
  });
1141
1155
  const width = Math.max(40, _width + 25);
1142
1156
  const lines = getSplitContentLines(diffFile);
1143
- return (React.createElement("div", { className: "split-diff-view split-diff-view-normal w-full" },
1157
+ return (React.createElement("div", { className: "split-diff-view split-diff-view-wrap w-full" },
1144
1158
  React.createElement("div", { className: "diff-table-wrapper w-full", style: {
1145
1159
  // @ts-ignore
1146
1160
  [diffAsideWidthName]: `${Math.round(width)}px`,
@@ -1148,7 +1162,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1148
1162
  fontSize: `var(${diffFontSizeName})`,
1149
1163
  } },
1150
1164
  React.createElement(Style, { useSelector: useSplitConfig, id: `diff-root${diffFile.getId()}` }),
1151
- React.createElement("table", { className: "diff-table w-full table-fixed border-collapse" },
1165
+ React.createElement("table", { className: "diff-table w-full table-fixed border-collapse border-spacing-0" },
1152
1166
  React.createElement("colgroup", null,
1153
1167
  React.createElement("col", { className: "diff-table-old-num-col", width: Math.round(width) }),
1154
1168
  React.createElement("col", { className: "diff-table-old-content-col" }),
@@ -1163,7 +1177,7 @@ const DiffSplitViewWrap = memo(({ diffFile }) => {
1163
1177
  React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
1164
1178
  lines.map((line) => (React.createElement(Fragment, { key: line.index },
1165
1179
  React.createElement(DiffSplitHunkLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
1166
- React.createElement(DiffSplitLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
1180
+ React.createElement(DiffSplitContentLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
1167
1181
  React.createElement(DiffSplitWidgetLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile }),
1168
1182
  React.createElement(DiffSplitExtendLine, { index: line.index, lineNumber: line.lineNumber, diffFile: diffFile })))),
1169
1183
  React.createElement(DiffSplitHunkLine, { index: diffFile.splitLineLength, lineNumber: diffFile.splitLineLength, diffFile: diffFile }))))));
@@ -1174,7 +1188,7 @@ const DiffSplitView = memo(({ diffFile }) => {
1174
1188
  const { useDiffContext } = useDiffViewContext();
1175
1189
  const useDiffContextRef = useRef(useDiffContext);
1176
1190
  useDiffContextRef.current = useDiffContext;
1177
- const enableWrap = useDiffContext(useCallback((s) => s.enableWrap, []));
1191
+ const enableWrap = useDiffContext.useShallowStableSelector((s) => s.enableWrap);
1178
1192
  // performance optimization
1179
1193
  const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
1180
1194
  const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
@@ -1186,9 +1200,101 @@ const DiffSplitView = memo(({ diffFile }) => {
1186
1200
  });
1187
1201
  DiffSplitView.displayName = "DiffSplitView";
1188
1202
 
1203
+ const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1204
+ return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1205
+ 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: {
1206
+ color: `var(${plainLineNumberColorName})`,
1207
+ backgroundColor: `var(${delLineNumberBGName})`,
1208
+ width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1209
+ maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1210
+ minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1211
+ } },
1212
+ enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1213
+ React.createElement("div", { className: "flex" },
1214
+ React.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
1215
+ React.createElement("span", { className: "w-[10px] shrink-0" }),
1216
+ React.createElement("span", { className: "inline-block w-[50%]" }))),
1217
+ React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
1218
+ React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1219
+ };
1220
+ const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1221
+ return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1222
+ 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: {
1223
+ color: `var(${plainLineNumberColorName})`,
1224
+ backgroundColor: `var(${addLineNumberBGName})`,
1225
+ width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1226
+ maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1227
+ minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1228
+ } },
1229
+ enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1230
+ React.createElement("div", { className: "flex" },
1231
+ React.createElement("span", { className: "inline-block w-[50%]" }),
1232
+ React.createElement("span", { className: "w-[10px] shrink-0" }),
1233
+ React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
1234
+ React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
1235
+ React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1236
+ };
1237
+ const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
1238
+ const unifiedLine = diffFile.getUnifiedLine(index);
1239
+ const { useDiffContext } = useDiffViewContext();
1240
+ const { enableWrap, enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext.useShallowStableSelector((s) => ({
1241
+ enableWrap: s.enableWrap,
1242
+ enableHighlight: s.enableHighlight,
1243
+ enableAddWidget: s.enableAddWidget,
1244
+ onAddWidgetClick: s.onAddWidgetClick,
1245
+ }));
1246
+ const { useWidget } = useDiffWidgetContext();
1247
+ const setWidget = useWidget.getReadonlyState().setWidget;
1248
+ const hasDiff = unifiedLine.diff;
1249
+ const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
1250
+ const rawLine = unifiedLine.value || "";
1251
+ const diffLine = unifiedLine.diff;
1252
+ const newLineNumber = unifiedLine.newLineNumber;
1253
+ const oldLinenumber = unifiedLine.oldLineNumber;
1254
+ const syntaxLine = newLineNumber
1255
+ ? diffFile.getNewSyntaxLine(newLineNumber)
1256
+ : oldLinenumber
1257
+ ? diffFile.getOldSyntaxLine(oldLinenumber)
1258
+ : undefined;
1259
+ if (hasChange) {
1260
+ if (unifiedLine.oldLineNumber) {
1261
+ 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); } }));
1262
+ }
1263
+ else {
1264
+ 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); } }));
1265
+ }
1266
+ }
1267
+ else {
1268
+ return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
1269
+ 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: {
1270
+ color: `var(${plainLineNumberColorName})`,
1271
+ width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1272
+ maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1273
+ minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1274
+ backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
1275
+ } },
1276
+ enableAddWidget && hasDiff && (React.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: SplitSide.new, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1277
+ React.createElement("div", { className: "flex opacity-[0.5]" },
1278
+ React.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
1279
+ React.createElement("span", { className: "w-[10px] shrink-0" }),
1280
+ React.createElement("span", { "data-line-new-num": unifiedLine.newLineNumber, className: "inline-block w-[50%]" }, unifiedLine.newLineNumber))),
1281
+ React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
1282
+ backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
1283
+ } },
1284
+ React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1285
+ }
1286
+ });
1287
+ _DiffUnifiedLine.displayName = "_DiffUnifiedLine";
1288
+ const DiffUnifiedContentLine = ({ index, diffFile, lineNumber, }) => {
1289
+ const unifiedLine = diffFile.getUnifiedLine(index);
1290
+ if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1291
+ return null;
1292
+ return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1293
+ };
1294
+
1189
1295
  const _DiffUnifiedExtendLine = ({ index, diffFile, lineNumber, oldLineExtend, newLineExtend, }) => {
1190
1296
  const { useDiffContext } = useDiffViewContext();
1191
- const renderExtendLine = useDiffContext(useCallback((s) => s.renderExtendLine, []));
1297
+ const renderExtendLine = useDiffContext.useShallowStableSelector((s) => s.renderExtendLine);
1192
1298
  const unifiedItem = diffFile.getUnifiedLine(index);
1193
1299
  const width = useDomWidth({
1194
1300
  selector: ".unified-diff-table-wrapper",
@@ -1239,7 +1345,7 @@ const _DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1239
1345
  const currentHunk = diffFile.getUnifiedHunkLine(index);
1240
1346
  const expandEnabled = diffFile.getExpandEnabled();
1241
1347
  const { useDiffContext } = useDiffViewContext();
1242
- const enableWrap = useDiffContext(useCallback((s) => s.enableWrap, []));
1348
+ const enableWrap = useDiffContext.useShallowStableSelector((s) => s.enableWrap);
1243
1349
  const couldExpand = expandEnabled && currentHunk && currentHunk.unifiedInfo;
1244
1350
  const isExpandAll = currentHunk &&
1245
1351
  currentHunk.unifiedInfo &&
@@ -1279,104 +1385,12 @@ const DiffUnifiedHunkLine = ({ index, diffFile, lineNumber, }) => {
1279
1385
  return React.createElement(_DiffUnifiedHunkLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1280
1386
  };
1281
1387
 
1282
- const DiffUnifiedOldLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1283
- return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1284
- 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: {
1285
- color: `var(${plainLineNumberColorName})`,
1286
- backgroundColor: `var(${delLineNumberBGName})`,
1287
- width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1288
- maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1289
- minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1290
- } },
1291
- enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.old, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1292
- React.createElement("div", { className: "flex" },
1293
- React.createElement("span", { "data-line-old-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber),
1294
- React.createElement("span", { className: "w-[10px] shrink-0" }),
1295
- React.createElement("span", { className: "inline-block w-[50%]" }))),
1296
- React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${delContentBGName})` } },
1297
- React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1298
- };
1299
- const DiffUnifiedNewLine = ({ index, diffLine, rawLine, syntaxLine, lineNumber, diffFile, setWidget, enableWrap, enableAddWidget, enableHighlight, onAddWidgetClick, }) => {
1300
- return (React.createElement("tr", { "data-line": index, "data-state": "diff", className: "diff-line group" },
1301
- 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: {
1302
- color: `var(${plainLineNumberColorName})`,
1303
- backgroundColor: `var(${addLineNumberBGName})`,
1304
- width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1305
- maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1306
- minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1307
- } },
1308
- enableAddWidget && (React.createElement(DiffUnifiedAddWidget, { index: index - 1, lineNumber: lineNumber, diffFile: diffFile, side: SplitSide.new, onWidgetClick: onAddWidgetClick, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1309
- React.createElement("div", { className: "flex" },
1310
- React.createElement("span", { className: "inline-block w-[50%]" }),
1311
- React.createElement("span", { className: "w-[10px] shrink-0" }),
1312
- React.createElement("span", { "data-line-new-num": lineNumber, className: "inline-block w-[50%]" }, lineNumber))),
1313
- React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: { backgroundColor: `var(${addContentBGName})` } },
1314
- React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1315
- };
1316
- const _DiffUnifiedLine = memo(({ index, diffFile, lineNumber }) => {
1317
- const unifiedLine = diffFile.getUnifiedLine(index);
1318
- const { useDiffContext } = useDiffViewContext();
1319
- const { enableWrap, enableHighlight, enableAddWidget, onAddWidgetClick } = useDiffContext(React.useCallback((s) => ({
1320
- enableWrap: s.enableWrap,
1321
- enableHighlight: s.enableHighlight,
1322
- enableAddWidget: s.enableAddWidget,
1323
- onAddWidgetClick: s.onAddWidgetClick,
1324
- }), []));
1325
- const { useWidget } = useDiffWidgetContext();
1326
- const setWidget = useWidget.getReadonlyState().setWidget;
1327
- const hasDiff = unifiedLine.diff;
1328
- const hasChange = checkDiffLineIncludeChange(unifiedLine.diff);
1329
- const rawLine = unifiedLine.value || "";
1330
- const diffLine = unifiedLine.diff;
1331
- const newLineNumber = unifiedLine.newLineNumber;
1332
- const oldLinenumber = unifiedLine.oldLineNumber;
1333
- const syntaxLine = newLineNumber
1334
- ? diffFile.getNewSyntaxLine(newLineNumber)
1335
- : oldLinenumber
1336
- ? diffFile.getOldSyntaxLine(oldLinenumber)
1337
- : undefined;
1338
- if (hasChange) {
1339
- if (unifiedLine.oldLineNumber) {
1340
- 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); } }));
1341
- }
1342
- else {
1343
- 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); } }));
1344
- }
1345
- }
1346
- else {
1347
- return (React.createElement("tr", { "data-line": lineNumber, "data-state": unifiedLine.diff ? "diff" : "plain", className: "diff-line group" },
1348
- 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: {
1349
- color: `var(${plainLineNumberColorName})`,
1350
- width: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1351
- maxWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1352
- minWidth: `calc(calc(var(${diffAsideWidthName}) + 5px) * 2)`,
1353
- backgroundColor: hasDiff ? `var(${plainLineNumberBGName})` : `var(${expandContentBGName})`,
1354
- } },
1355
- enableAddWidget && hasDiff && (React.createElement(DiffUnifiedAddWidget, { index: index, diffFile: diffFile, lineNumber: unifiedLine.newLineNumber, side: SplitSide.new, onWidgetClick: (...props) => { var _a; return (_a = onAddWidgetClick.current) === null || _a === void 0 ? void 0 : _a.call(onAddWidgetClick, ...props); }, onOpenAddWidget: (lineNumber, side) => setWidget({ lineNumber, side }) })),
1356
- React.createElement("div", { className: "flex opacity-[0.5]" },
1357
- React.createElement("span", { "data-line-old-num": unifiedLine.oldLineNumber, className: "inline-block w-[50%]" }, unifiedLine.oldLineNumber),
1358
- React.createElement("span", { className: "w-[10px] shrink-0" }),
1359
- React.createElement("span", { "data-line-new-num": unifiedLine.newLineNumber, className: "inline-block w-[50%]" }, unifiedLine.newLineNumber))),
1360
- React.createElement("td", { className: "diff-line-content pr-[10px] align-top", style: {
1361
- backgroundColor: hasDiff ? `var(${plainContentBGName})` : `var(${expandContentBGName})`,
1362
- } },
1363
- React.createElement(DiffContent, { enableWrap: enableWrap, diffFile: diffFile, enableHighlight: enableHighlight, rawLine: rawLine, diffLine: diffLine, syntaxLine: syntaxLine }))));
1364
- }
1365
- });
1366
- _DiffUnifiedLine.displayName = "_DiffUnifiedLine";
1367
- const DiffUnifiedLine = ({ index, diffFile, lineNumber, }) => {
1368
- const unifiedLine = diffFile.getUnifiedLine(index);
1369
- if (unifiedLine === null || unifiedLine === void 0 ? void 0 : unifiedLine.isHidden)
1370
- return null;
1371
- return React.createElement(_DiffUnifiedLine, { index: index, diffFile: diffFile, lineNumber: lineNumber });
1372
- };
1373
-
1374
1388
  const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNumber, setWidget, }) => {
1375
1389
  const unifiedItem = diffFile.getUnifiedLine(index);
1376
1390
  const onClose = () => setWidget({});
1377
1391
  const { useDiffContext } = useDiffViewContext();
1378
1392
  // 需要显示的时候才进行方法订阅,可以大幅度提高性能
1379
- const renderWidgetLine = useDiffContext(useCallback((s) => s.renderWidgetLine, []));
1393
+ const renderWidgetLine = useDiffContext.useShallowStableSelector((s) => s.renderWidgetLine);
1380
1394
  const width = useDomWidth({
1381
1395
  selector: ".unified-diff-table-wrapper",
1382
1396
  enable: typeof renderWidgetLine === "function",
@@ -1395,7 +1409,11 @@ const _DiffUnifiedWidgetLine = ({ index, diffFile, oldWidget, newWidget, lineNum
1395
1409
  };
1396
1410
  const DiffUnifiedWidgetLine = ({ index, diffFile, lineNumber, }) => {
1397
1411
  const { useWidget } = useDiffWidgetContext();
1398
- const { widgetSide, widgetLineNumber, setWidget } = useWidget(React.useCallback((s) => ({ widgetLineNumber: s.widgetLineNumber, widgetSide: s.widgetSide, setWidget: s.setWidget }), []));
1412
+ const { widgetSide, widgetLineNumber, setWidget } = useWidget.useShallowStableSelector((s) => ({
1413
+ widgetLineNumber: s.widgetLineNumber,
1414
+ widgetSide: s.widgetSide,
1415
+ setWidget: s.setWidget,
1416
+ }));
1399
1417
  const unifiedItem = diffFile.getUnifiedLine(index);
1400
1418
  const oldWidget = unifiedItem.oldLineNumber && widgetSide === SplitSide.old && widgetLineNumber === unifiedItem.oldLineNumber;
1401
1419
  const newWidget = unifiedItem.newLineNumber && widgetSide === SplitSide.new && widgetLineNumber === unifiedItem.newLineNumber;
@@ -1421,7 +1439,10 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1421
1439
  // performance optimization
1422
1440
  const useWidget = useMemo(() => createDiffWidgetStore(useDiffContextRef), []);
1423
1441
  const contextValue = useMemo(() => ({ useWidget }), [useWidget]);
1424
- const fontSize = useDiffContext(useCallback((s) => s.fontSize, []));
1442
+ const { fontSize, enableWrap } = useDiffContext.useShallowStableSelector((s) => ({
1443
+ fontSize: s.fontSize,
1444
+ enableWrap: s.enableWrap,
1445
+ }));
1425
1446
  useSyncExternalStore(diffFile.subscribe, diffFile.getUpdateCount);
1426
1447
  useEffect(() => {
1427
1448
  const { setWidget } = useWidget.getReadonlyState();
@@ -1435,14 +1456,14 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1435
1456
  const width = Math.max(40, _width + 10);
1436
1457
  const lines = getUnifiedContentLine(diffFile);
1437
1458
  return (React.createElement(DiffWidgetContext.Provider, { value: contextValue },
1438
- React.createElement("div", { className: "unified-diff-view w-full" },
1439
- React.createElement("div", { className: "unified-diff-table-wrapper scrollbar-hide scrollbar-disable w-full overflow-x-auto overflow-y-hidden", style: {
1459
+ React.createElement("div", { className: `unified-diff-view ${enableWrap ? "unified-diff-view-wrap" : "unified-diff-view-normal"} w-full` },
1460
+ React.createElement("div", { className: "unified-diff-table-wrapper diff-table-scroll-container w-full overflow-x-auto overflow-y-hidden", style: {
1440
1461
  // @ts-ignore
1441
1462
  [diffAsideWidthName]: `${Math.round(width)}px`,
1442
1463
  fontFamily: "Menlo, Consolas, monospace",
1443
1464
  fontSize: `var(${diffFontSizeName})`,
1444
1465
  } },
1445
- React.createElement("table", { className: "unified-diff-table w-full border-collapse" },
1466
+ React.createElement("table", { className: `unified-diff-table w-full border-collapse border-spacing-0 ${enableWrap ? "table-fixed" : ""}` },
1446
1467
  React.createElement("colgroup", null,
1447
1468
  React.createElement("col", { className: "unified-diff-table-num-col" }),
1448
1469
  React.createElement("col", { className: "unified-diff-table-content-col" })),
@@ -1453,7 +1474,7 @@ const DiffUnifiedView = memo(({ diffFile }) => {
1453
1474
  React.createElement("tbody", { className: "diff-table-body leading-[1.4]", onMouseDownCapture: onMouseDown },
1454
1475
  lines.map((item) => (React.createElement(Fragment, { key: item.index },
1455
1476
  React.createElement(DiffUnifiedHunkLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1456
- React.createElement(DiffUnifiedLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1477
+ React.createElement(DiffUnifiedContentLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1457
1478
  React.createElement(DiffUnifiedWidgetLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile }),
1458
1479
  React.createElement(DiffUnifiedExtendLine, { index: item.index, lineNumber: item.lineNumber, diffFile: diffFile })))),
1459
1480
  React.createElement(DiffUnifiedHunkLine, { index: diffFile.unifiedLineLength, lineNumber: diffFile.unifiedLineLength, diffFile: diffFile })))))));
@@ -1469,6 +1490,7 @@ var SplitSide;
1469
1490
  const _InternalDiffView = (props) => {
1470
1491
  const { diffFile, className, style, diffViewMode, diffViewWrap, diffViewFontSize, diffViewHighlight, renderWidgetLine, renderExtendLine, extendData, diffViewAddWidget, onAddWidgetClick, } = props;
1471
1492
  const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
1493
+ const wrapperRef = useRef();
1472
1494
  // performance optimization
1473
1495
  const useDiffContext = useMemo(() => createDiffConfigStore(props, diffFileId),
1474
1496
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1498,9 +1520,16 @@ const _InternalDiffView = (props) => {
1498
1520
  extendData,
1499
1521
  onAddWidgetClick,
1500
1522
  ]);
1523
+ useEffect(() => {
1524
+ const cb = diffFile.subscribe(() => {
1525
+ var _a;
1526
+ (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("data-theme", diffFile._getTheme() || "light");
1527
+ });
1528
+ return cb;
1529
+ }, [diffFile]);
1501
1530
  const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
1502
1531
  return (React.createElement(DiffViewContext.Provider, { value: value },
1503
- React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-version": `${"0.0.16"}`, "data-highlighter": diffFile._getHighlighterName() },
1532
+ React.createElement("div", { className: "diff-tailwindcss-wrapper", "data-component": "git-diff-view", "data-theme": diffFile._getTheme() || "light", "data-version": "0.0.18", "data-highlighter": diffFile._getHighlighterName(), ref: wrapperRef },
1504
1533
  React.createElement("div", { className: "diff-style-root", style: {
1505
1534
  // @ts-ignore
1506
1535
  [diffFontSizeName]: diffViewFontSize + "px",
@@ -1510,7 +1539,7 @@ const _InternalDiffView = (props) => {
1510
1539
  const InternalDiffView = memo(_InternalDiffView);
1511
1540
  const DiffViewWithRef = (props, ref) => {
1512
1541
  var _a, _b;
1513
- const { registerHighlighter, data, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffFile"]);
1542
+ const { registerHighlighter, data, diffViewTheme, diffFile: _diffFile } = props, restProps = __rest(props, ["registerHighlighter", "data", "diffViewTheme", "diffFile"]);
1514
1543
  const diffFile = useMemo(() => {
1515
1544
  var _a, _b, _c, _d, _e, _f;
1516
1545
  if (_diffFile) {
@@ -1525,16 +1554,17 @@ const DiffViewWithRef = (props, ref) => {
1525
1554
  }, [data, _diffFile]);
1526
1555
  const diffFileRef = useRef(diffFile);
1527
1556
  if (diffFileRef.current && diffFileRef.current !== diffFile) {
1528
- (_b = (_a = diffFileRef.current)._destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
1557
+ (_b = (_a = diffFileRef.current).clear) === null || _b === void 0 ? void 0 : _b.call(_a);
1529
1558
  diffFileRef.current = diffFile;
1530
1559
  }
1531
1560
  useEffect(() => {
1532
1561
  if (!diffFile)
1533
1562
  return;
1563
+ diffFile.initTheme(diffViewTheme);
1534
1564
  diffFile.initRaw();
1535
1565
  diffFile.buildSplitDiffLines();
1536
1566
  diffFile.buildUnifiedDiffLines();
1537
- }, [diffFile]);
1567
+ }, [diffFile, diffViewTheme]);
1538
1568
  useEffect(() => {
1539
1569
  if (!diffFile)
1540
1570
  return;
@@ -1542,7 +1572,7 @@ const DiffViewWithRef = (props, ref) => {
1542
1572
  diffFile.initSyntax({ registerHighlighter });
1543
1573
  diffFile.notifyAll();
1544
1574
  }
1545
- }, [diffFile, props.diffViewHighlight, registerHighlighter]);
1575
+ }, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
1546
1576
  useEffect(() => {
1547
1577
  if (_diffFile && diffFile) {
1548
1578
  _diffFile._addClonedInstance(diffFile);
@@ -1551,6 +1581,7 @@ const DiffViewWithRef = (props, ref) => {
1551
1581
  };
1552
1582
  }
1553
1583
  }, [diffFile, _diffFile]);
1584
+ // fix react strict mode error
1554
1585
  useUnmount(() => { var _a; return (_a = diffFile === null || diffFile === void 0 ? void 0 : diffFile._destroy) === null || _a === void 0 ? void 0 : _a.call(diffFile); }, [diffFile]);
1555
1586
  useImperativeHandle(ref, () => ({ getDiffFileInstance: () => diffFile }), [diffFile]);
1556
1587
  if (!diffFile)
@@ -1559,7 +1590,7 @@ const DiffViewWithRef = (props, ref) => {
1559
1590
  };
1560
1591
  const DiffView = forwardRef(DiffViewWithRef);
1561
1592
  DiffView.displayName = "DiffView";
1562
- const version = "0.0.16";
1593
+ const version = "0.0.18";
1563
1594
 
1564
1595
  export { DiffModeEnum, DiffView, DiffViewContext, SplitSide, useDiffViewContext, version };
1565
1596
  //# sourceMappingURL=index.mjs.map