@git-diff-view/react 0.0.31 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +53 -23
- package/dist/cjs/index.development.js.map +1 -1
- package/dist/cjs/index.production.js +53 -23
- package/dist/cjs/index.production.js.map +1 -1
- package/dist/css/diff-view-pure.css +0 -3
- package/dist/css/diff-view.css +0 -3
- package/dist/esm/index.mjs +53 -23
- package/dist/esm/index.mjs.map +1 -1
- package/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/components/DiffAddWidget.tsx +3 -1
- package/src/components/DiffUnifiedExtendLine.tsx +9 -3
- package/src/components/DiffUnifiedView.tsx +12 -2
- package/src/components/DiffUnifiedWidgetLine.tsx +10 -4
- package/src/components/DiffView.tsx +4 -0
- package/src/components/tools.ts +6 -0
- package/src/hooks/useDomWidth.ts +10 -3
- package/src/hooks/useSyncHeight.ts +10 -3
- package/styles/diff-view-pure.css +0 -3
- package/styles/diff-view.css +0 -3
package/index.d.ts
CHANGED
|
@@ -821,6 +821,8 @@ declare const createDiffConfigStore: (props: DiffViewProps<any> & {
|
|
|
821
821
|
}, diffFileId: string) => import("reactivity-store").UseSelectorWithStore<{
|
|
822
822
|
id: import("reactivity-store").Ref<string, string>;
|
|
823
823
|
setId: (_id: string) => string;
|
|
824
|
+
dom: import("reactivity-store").Ref<HTMLElement, HTMLElement>;
|
|
825
|
+
setDom: (_dom: HTMLElement) => HTMLElement;
|
|
824
826
|
mode: import("reactivity-store").Ref<DiffModeEnum, DiffModeEnum>;
|
|
825
827
|
setMode: (_mode: DiffModeEnum) => DiffModeEnum;
|
|
826
828
|
mounted: import("reactivity-store").Ref<boolean, boolean>;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "@git-diff-view/react",
|
|
4
4
|
"author": "MrWangJustToDo",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.32",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"types": "index.d.ts",
|
|
9
9
|
"files": [
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react diff component"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@git-diff-view/core": "^0.0.
|
|
64
|
+
"@git-diff-view/core": "^0.0.32",
|
|
65
65
|
"@types/hast": "^3.0.0",
|
|
66
66
|
"fast-diff": "^1.3.0",
|
|
67
67
|
"highlight.js": "^11.11.0",
|
|
@@ -28,6 +28,7 @@ export const DiffSplitAddWidget = ({
|
|
|
28
28
|
style={{
|
|
29
29
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
30
30
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
31
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
31
32
|
}}
|
|
32
33
|
>
|
|
33
34
|
<button
|
|
@@ -62,10 +63,11 @@ export const DiffUnifiedAddWidget = ({
|
|
|
62
63
|
}) => {
|
|
63
64
|
return (
|
|
64
65
|
<div
|
|
65
|
-
className="diff-add-widget-wrapper invisible absolute left-[100%]
|
|
66
|
+
className="diff-add-widget-wrapper invisible absolute left-[100%] translate-x-[-50%] select-none transition-transform hover:scale-110 group-hover:visible"
|
|
66
67
|
style={{
|
|
67
68
|
width: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
68
69
|
height: `calc(var(${diffFontSizeName}) * 1.4)`,
|
|
70
|
+
top: `calc(var(${diffFontSizeName}) * 0.1)`,
|
|
69
71
|
}}
|
|
70
72
|
>
|
|
71
73
|
<button
|
|
@@ -12,12 +12,14 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
12
12
|
index,
|
|
13
13
|
diffFile,
|
|
14
14
|
lineNumber,
|
|
15
|
+
enableWrap,
|
|
15
16
|
oldLineExtend,
|
|
16
17
|
newLineExtend,
|
|
17
18
|
}: {
|
|
18
19
|
index: number;
|
|
19
20
|
diffFile: DiffFile;
|
|
20
21
|
lineNumber: number;
|
|
22
|
+
enableWrap: boolean;
|
|
21
23
|
oldLineExtend: { data: any };
|
|
22
24
|
newLineExtend: { data: any };
|
|
23
25
|
}) => {
|
|
@@ -27,9 +29,10 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
27
29
|
|
|
28
30
|
const unifiedItem = diffFile.getUnifiedLine(index);
|
|
29
31
|
|
|
32
|
+
// TODO use css variable to get width
|
|
30
33
|
const width = useDomWidth({
|
|
31
34
|
selector: ".unified-diff-table-wrapper",
|
|
32
|
-
enable: typeof renderExtendLine === "function",
|
|
35
|
+
enable: typeof renderExtendLine === "function" && !enableWrap,
|
|
33
36
|
});
|
|
34
37
|
|
|
35
38
|
if (!renderExtendLine) return null;
|
|
@@ -38,7 +41,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
38
41
|
<tr data-line={`${lineNumber}-extend`} data-state="extend" className="diff-line diff-line-extend">
|
|
39
42
|
<td className="diff-line-extend-content p-0 align-top" colSpan={2}>
|
|
40
43
|
<div className="diff-line-extend-wrapper sticky left-0 z-[1]" style={{ width }}>
|
|
41
|
-
{width > 0 &&
|
|
44
|
+
{(enableWrap ? true : width > 0) &&
|
|
42
45
|
oldLineExtend?.data !== undefined &&
|
|
43
46
|
oldLineExtend?.data !== null &&
|
|
44
47
|
renderExtendLine?.({
|
|
@@ -48,7 +51,7 @@ const InternalDiffUnifiedExtendLine = ({
|
|
|
48
51
|
data: oldLineExtend.data,
|
|
49
52
|
onUpdate: diffFile.notifyAll,
|
|
50
53
|
})}
|
|
51
|
-
{width > 0 &&
|
|
54
|
+
{(enableWrap ? true : width > 0) &&
|
|
52
55
|
newLineExtend?.data !== undefined &&
|
|
53
56
|
newLineExtend?.data !== null &&
|
|
54
57
|
renderExtendLine?.({
|
|
@@ -68,10 +71,12 @@ export const DiffUnifiedExtendLine = ({
|
|
|
68
71
|
index,
|
|
69
72
|
diffFile,
|
|
70
73
|
lineNumber,
|
|
74
|
+
enableWrap,
|
|
71
75
|
}: {
|
|
72
76
|
index: number;
|
|
73
77
|
diffFile: DiffFile;
|
|
74
78
|
lineNumber: number;
|
|
79
|
+
enableWrap: boolean;
|
|
75
80
|
}) => {
|
|
76
81
|
const { useDiffContext } = useDiffViewContext();
|
|
77
82
|
|
|
@@ -96,6 +101,7 @@ export const DiffUnifiedExtendLine = ({
|
|
|
96
101
|
index={index}
|
|
97
102
|
diffFile={diffFile}
|
|
98
103
|
lineNumber={lineNumber}
|
|
104
|
+
enableWrap={enableWrap}
|
|
99
105
|
oldLineExtend={oldLineExtend}
|
|
100
106
|
newLineExtend={newLineExtend}
|
|
101
107
|
/>
|
|
@@ -147,8 +147,18 @@ export const DiffUnifiedView = memo(({ diffFile }: { diffFile: DiffFile }) => {
|
|
|
147
147
|
enableHighlight={enableHighlight}
|
|
148
148
|
enableAddWidget={enableAddWidget}
|
|
149
149
|
/>
|
|
150
|
-
<DiffUnifiedWidgetLine
|
|
151
|
-
|
|
150
|
+
<DiffUnifiedWidgetLine
|
|
151
|
+
index={item.index}
|
|
152
|
+
lineNumber={item.lineNumber}
|
|
153
|
+
diffFile={diffFile}
|
|
154
|
+
enableWrap={enableWrap}
|
|
155
|
+
/>
|
|
156
|
+
<DiffUnifiedExtendLine
|
|
157
|
+
index={item.index}
|
|
158
|
+
lineNumber={item.lineNumber}
|
|
159
|
+
diffFile={diffFile}
|
|
160
|
+
enableWrap={enableWrap}
|
|
161
|
+
/>
|
|
152
162
|
</Fragment>
|
|
153
163
|
))}
|
|
154
164
|
<DiffUnifiedHunkLine
|
|
@@ -12,10 +12,12 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
12
12
|
index,
|
|
13
13
|
diffFile,
|
|
14
14
|
lineNumber,
|
|
15
|
+
enableWrap,
|
|
15
16
|
}: {
|
|
16
17
|
index: number;
|
|
17
18
|
diffFile: DiffFile;
|
|
18
19
|
lineNumber: number;
|
|
20
|
+
enableWrap: boolean;
|
|
19
21
|
}) => {
|
|
20
22
|
const { useWidget } = useDiffWidgetContext();
|
|
21
23
|
|
|
@@ -42,7 +44,7 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
42
44
|
|
|
43
45
|
const width = useDomWidth({
|
|
44
46
|
selector: ".unified-diff-table-wrapper",
|
|
45
|
-
enable: typeof renderWidgetLine === "function",
|
|
47
|
+
enable: typeof renderWidgetLine === "function" && !enableWrap,
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
if (!renderWidgetLine) return null;
|
|
@@ -51,10 +53,10 @@ const InternalDiffUnifiedWidgetLine = ({
|
|
|
51
53
|
<tr data-line={`${lineNumber}-widget`} data-state="widget" className="diff-line diff-line-widget">
|
|
52
54
|
<td className="diff-line-widget-content p-0" colSpan={2}>
|
|
53
55
|
<div className="diff-line-widget-wrapper sticky left-0 z-[1]" style={{ width }}>
|
|
54
|
-
{width > 0 &&
|
|
56
|
+
{(enableWrap ? true : width > 0) &&
|
|
55
57
|
oldWidget &&
|
|
56
58
|
renderWidgetLine?.({ diffFile, side: SplitSide.old, lineNumber: unifiedItem.oldLineNumber, onClose })}
|
|
57
|
-
{width > 0 &&
|
|
59
|
+
{(enableWrap ? true : width > 0) &&
|
|
58
60
|
newWidget &&
|
|
59
61
|
renderWidgetLine?.({ diffFile, side: SplitSide.new, lineNumber: unifiedItem.newLineNumber, onClose })}
|
|
60
62
|
</div>
|
|
@@ -67,10 +69,12 @@ export const DiffUnifiedWidgetLine = ({
|
|
|
67
69
|
index,
|
|
68
70
|
diffFile,
|
|
69
71
|
lineNumber,
|
|
72
|
+
enableWrap,
|
|
70
73
|
}: {
|
|
71
74
|
index: number;
|
|
72
75
|
diffFile: DiffFile;
|
|
73
76
|
lineNumber: number;
|
|
77
|
+
enableWrap: boolean;
|
|
74
78
|
}) => {
|
|
75
79
|
const { useWidget } = useDiffWidgetContext();
|
|
76
80
|
|
|
@@ -100,5 +104,7 @@ export const DiffUnifiedWidgetLine = ({
|
|
|
100
104
|
|
|
101
105
|
if (!currentIsShow) return null;
|
|
102
106
|
|
|
103
|
-
return
|
|
107
|
+
return (
|
|
108
|
+
<InternalDiffUnifiedWidgetLine index={index} diffFile={diffFile} lineNumber={lineNumber} enableWrap={enableWrap} />
|
|
109
|
+
);
|
|
104
110
|
};
|
|
@@ -210,6 +210,10 @@ const InternalDiffView = <T extends unknown>(
|
|
|
210
210
|
onCreateUseWidgetHook,
|
|
211
211
|
]);
|
|
212
212
|
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
useDiffContext.getReadonlyState().setDom(wrapperRef?.current);
|
|
215
|
+
}, [useDiffContext, wrapperRef]);
|
|
216
|
+
|
|
213
217
|
const value = useMemo(() => ({ useDiffContext }), [useDiffContext]);
|
|
214
218
|
|
|
215
219
|
return (
|
package/src/components/tools.ts
CHANGED
|
@@ -5,6 +5,10 @@ import type { RefObject } from "react";
|
|
|
5
5
|
|
|
6
6
|
export const createDiffConfigStore = (props: DiffViewProps<any> & { isMounted: boolean }, diffFileId: string) => {
|
|
7
7
|
return createStore(() => {
|
|
8
|
+
const dom = ref<HTMLElement>();
|
|
9
|
+
|
|
10
|
+
const setDom = (_dom: HTMLElement) => (dom.value = _dom);
|
|
11
|
+
|
|
8
12
|
const id = ref(diffFileId);
|
|
9
13
|
|
|
10
14
|
const setId = (_id: string) => (id.value = _id);
|
|
@@ -85,6 +89,8 @@ export const createDiffConfigStore = (props: DiffViewProps<any> & { isMounted: b
|
|
|
85
89
|
return {
|
|
86
90
|
id,
|
|
87
91
|
setId,
|
|
92
|
+
dom,
|
|
93
|
+
setDom,
|
|
88
94
|
mode,
|
|
89
95
|
setMode,
|
|
90
96
|
mounted,
|
package/src/hooks/useDomWidth.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getElementRoot } from "@git-diff-view/utils";
|
|
1
2
|
import { useEffect, useState } from "react";
|
|
2
3
|
|
|
3
4
|
import { useDiffViewContext } from "../components/DiffViewContext";
|
|
@@ -12,11 +13,17 @@ export const useDomWidth = ({ selector, enable }: { selector: string; enable: bo
|
|
|
12
13
|
|
|
13
14
|
const { useDiffContext } = useDiffViewContext();
|
|
14
15
|
|
|
15
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
16
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
17
|
+
id: s.id,
|
|
18
|
+
mounted: s.mounted,
|
|
19
|
+
dom: s.dom,
|
|
20
|
+
}));
|
|
16
21
|
|
|
17
22
|
useEffect(() => {
|
|
18
23
|
if (enable) {
|
|
19
|
-
const
|
|
24
|
+
const rootDocument = getElementRoot(dom as HTMLDivElement);
|
|
25
|
+
|
|
26
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
20
27
|
|
|
21
28
|
const wrapper = container?.querySelector(selector);
|
|
22
29
|
|
|
@@ -61,7 +68,7 @@ export const useDomWidth = ({ selector, enable }: { selector: string; enable: bo
|
|
|
61
68
|
|
|
62
69
|
return () => cleanCb();
|
|
63
70
|
}
|
|
64
|
-
}, [selector, enable, id, mounted]);
|
|
71
|
+
}, [selector, enable, id, mounted, dom]);
|
|
65
72
|
|
|
66
73
|
return width;
|
|
67
74
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getElementRoot } from "@git-diff-view/utils";
|
|
1
2
|
import { useEffect } from "react";
|
|
2
3
|
|
|
3
4
|
import { useDiffViewContext } from "../components/DiffViewContext";
|
|
@@ -17,11 +18,17 @@ export const useSyncHeight = ({
|
|
|
17
18
|
}) => {
|
|
18
19
|
const { useDiffContext } = useDiffViewContext();
|
|
19
20
|
|
|
20
|
-
const { id, mounted } = useDiffContext.useShallowStableSelector((s) => ({
|
|
21
|
+
const { id, mounted, dom } = useDiffContext.useShallowStableSelector((s) => ({
|
|
22
|
+
id: s.id,
|
|
23
|
+
mounted: s.mounted,
|
|
24
|
+
dom: s.dom,
|
|
25
|
+
}));
|
|
21
26
|
|
|
22
27
|
useEffect(() => {
|
|
23
28
|
if (enable) {
|
|
24
|
-
const
|
|
29
|
+
const rootDocument = getElementRoot(dom as HTMLDivElement);
|
|
30
|
+
|
|
31
|
+
const container = rootDocument.querySelector(`#diff-root${id}`);
|
|
25
32
|
|
|
26
33
|
const elements = Array.from(container?.querySelectorAll(selector) || []);
|
|
27
34
|
|
|
@@ -83,5 +90,5 @@ export const useSyncHeight = ({
|
|
|
83
90
|
return () => cleanCb();
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
}, [selector, enable, side, id, wrapper, mounted]);
|
|
93
|
+
}, [selector, enable, side, id, wrapper, mounted, dom]);
|
|
87
94
|
};
|