@git-diff-view/react 0.0.15 → 0.0.17

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