@lukstei/dsh-client-review-git 0.0.0-stage → 0.2.2-rc.5.11
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/LICENSE +21 -0
- package/README.md +144 -2
- package/cordis.patch.yml +4 -0
- package/dist/client.js +3378 -0
- package/dist/host.js +1101 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +611 -0
- package/lib/typert.remote-client.d.ts +37 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +505 -0
- package/package.json +156 -3
- package/src/client/FileInspector.tsx +162 -0
- package/src/client/GitDiffPane.tsx +252 -0
- package/src/client/GitReviewCard.tsx +202 -0
- package/src/client/GitReviewRow.tsx +191 -0
- package/src/client/ReviewToolbar.tsx +470 -0
- package/src/client/contract.ts +27 -0
- package/src/client/css.d.ts +5 -0
- package/src/client/index.tsx +230 -0
- package/src/client/review-turn.ts +193 -0
- package/src/client/reviewSelection.ts +14 -0
- package/src/client/useLoad.ts +38 -0
- package/src/client/useReviewViewState.ts +244 -0
- package/src/git-service.ts +845 -0
- package/src/index.ts +67 -0
- package/src/review-tool.ts +85 -0
- package/src/workspace-review-service.ts +400 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { ReviewScope } from "@lukstei/util-review-ui/types";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export const REVIEW_STORAGE_PREFIX = "dsh-client-review-git:state:v1:";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const REVIEW_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
8
|
+
|
|
9
|
+
export interface GitReviewViewState {
|
|
10
|
+
version: 1;
|
|
11
|
+
selectedRepoCwd: string | null;
|
|
12
|
+
scope: ReviewScope | null;
|
|
13
|
+
expandedPaths: string[];
|
|
14
|
+
scrollTop: number;
|
|
15
|
+
wrapped: boolean;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isReviewScope(val: unknown): val is ReviewScope {
|
|
20
|
+
if (!val || typeof val !== "object") return false;
|
|
21
|
+
const obj = val as Record<string, unknown>;
|
|
22
|
+
if (typeof obj.repository !== "string") return false;
|
|
23
|
+
if (obj.kind === "uncommitted") {
|
|
24
|
+
return obj.stage === "staged" || obj.stage === "unstaged";
|
|
25
|
+
}
|
|
26
|
+
if (obj.kind === "branch") {
|
|
27
|
+
return (
|
|
28
|
+
typeof obj.ref === "string" && Boolean(obj.base) && Boolean(obj.revision)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
export function readPersistedReviewState(
|
|
36
|
+
sessionId: string,
|
|
37
|
+
): GitReviewViewState | null {
|
|
38
|
+
if (typeof localStorage === "undefined") return null;
|
|
39
|
+
try {
|
|
40
|
+
const raw = localStorage.getItem(`${REVIEW_STORAGE_PREFIX}${sessionId}`);
|
|
41
|
+
if (!raw) return null;
|
|
42
|
+
const parsed = JSON.parse(raw) as Partial<GitReviewViewState>;
|
|
43
|
+
if (parsed.version !== 1) return null;
|
|
44
|
+
if (
|
|
45
|
+
typeof parsed.updatedAt !== "number" ||
|
|
46
|
+
!Number.isFinite(parsed.updatedAt) ||
|
|
47
|
+
Date.now() - parsed.updatedAt > REVIEW_TTL_MS
|
|
48
|
+
) {
|
|
49
|
+
localStorage.removeItem(`${REVIEW_STORAGE_PREFIX}${sessionId}`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
version: 1,
|
|
54
|
+
selectedRepoCwd:
|
|
55
|
+
typeof parsed.selectedRepoCwd === "string"
|
|
56
|
+
? parsed.selectedRepoCwd
|
|
57
|
+
: null,
|
|
58
|
+
scope: isReviewScope(parsed.scope) ? parsed.scope : null,
|
|
59
|
+
expandedPaths: Array.isArray(parsed.expandedPaths)
|
|
60
|
+
? parsed.expandedPaths.filter((p): p is string => typeof p === "string")
|
|
61
|
+
: [],
|
|
62
|
+
scrollTop: typeof parsed.scrollTop === "number" ? parsed.scrollTop : 0,
|
|
63
|
+
wrapped: Boolean(parsed.wrapped),
|
|
64
|
+
updatedAt: parsed.updatedAt,
|
|
65
|
+
};
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
export function writePersistedReviewState(
|
|
73
|
+
sessionId: string,
|
|
74
|
+
state: {
|
|
75
|
+
selectedRepoCwd: string | null;
|
|
76
|
+
scope: ReviewScope | null;
|
|
77
|
+
expandedPaths: string[];
|
|
78
|
+
scrollTop: number;
|
|
79
|
+
wrapped: boolean;
|
|
80
|
+
},
|
|
81
|
+
): void {
|
|
82
|
+
if (typeof localStorage === "undefined") return;
|
|
83
|
+
try {
|
|
84
|
+
const payload: GitReviewViewState = {
|
|
85
|
+
version: 1,
|
|
86
|
+
selectedRepoCwd: state.selectedRepoCwd,
|
|
87
|
+
scope: state.scope,
|
|
88
|
+
expandedPaths: state.expandedPaths,
|
|
89
|
+
scrollTop: state.scrollTop,
|
|
90
|
+
wrapped: state.wrapped,
|
|
91
|
+
updatedAt: Date.now(),
|
|
92
|
+
};
|
|
93
|
+
localStorage.setItem(
|
|
94
|
+
`${REVIEW_STORAGE_PREFIX}${sessionId}`,
|
|
95
|
+
JSON.stringify(payload),
|
|
96
|
+
);
|
|
97
|
+
} catch {
|
|
98
|
+
// defensive storage isolation
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function useReviewViewState(
|
|
103
|
+
sessionId: string,
|
|
104
|
+
initialScope?: ReviewScope,
|
|
105
|
+
) {
|
|
106
|
+
const [initialState] = useState(() => readPersistedReviewState(sessionId));
|
|
107
|
+
|
|
108
|
+
const isScopeOverridden =
|
|
109
|
+
initialScope !== undefined &&
|
|
110
|
+
initialState?.scope !== null &&
|
|
111
|
+
initialState?.scope !== undefined &&
|
|
112
|
+
(initialState.scope.kind !== initialScope.kind ||
|
|
113
|
+
initialState.scope.repository !== initialScope.repository ||
|
|
114
|
+
(initialState.scope.kind === "branch" &&
|
|
115
|
+
initialScope.kind === "branch" &&
|
|
116
|
+
initialState.scope.ref !== initialScope.ref));
|
|
117
|
+
|
|
118
|
+
const [selectedRepoCwd, setSelectedRepoCwd] = useState<string | null>(() =>
|
|
119
|
+
initialScope !== undefined
|
|
120
|
+
? initialScope.repository
|
|
121
|
+
: (initialState?.selectedRepoCwd ?? null),
|
|
122
|
+
);
|
|
123
|
+
const [scope, setScope] = useState<ReviewScope | null>(
|
|
124
|
+
() => initialScope ?? initialState?.scope ?? null,
|
|
125
|
+
);
|
|
126
|
+
const [expandedPaths, setExpandedPaths] = useState<Set<string>>(() =>
|
|
127
|
+
isScopeOverridden ? new Set() : new Set(initialState?.expandedPaths ?? []),
|
|
128
|
+
);
|
|
129
|
+
const [wrapped, setWrapped] = useState<boolean>(
|
|
130
|
+
() => initialState?.wrapped ?? false,
|
|
131
|
+
);
|
|
132
|
+
const scrollTopRef = useRef<number>(
|
|
133
|
+
isScopeOverridden ? 0 : (initialState?.scrollTop ?? 0),
|
|
134
|
+
);
|
|
135
|
+
const debounceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
136
|
+
const isFirstMountRef = useRef(true);
|
|
137
|
+
|
|
138
|
+
const stateRef = useRef({
|
|
139
|
+
selectedRepoCwd,
|
|
140
|
+
scope,
|
|
141
|
+
expandedPaths,
|
|
142
|
+
scrollTop: scrollTopRef.current,
|
|
143
|
+
wrapped,
|
|
144
|
+
});
|
|
145
|
+
stateRef.current = {
|
|
146
|
+
selectedRepoCwd,
|
|
147
|
+
scope,
|
|
148
|
+
expandedPaths,
|
|
149
|
+
scrollTop: scrollTopRef.current,
|
|
150
|
+
wrapped,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const persist = useCallback(() => {
|
|
154
|
+
writePersistedReviewState(sessionId, {
|
|
155
|
+
selectedRepoCwd: stateRef.current.selectedRepoCwd,
|
|
156
|
+
scope: stateRef.current.scope,
|
|
157
|
+
expandedPaths: Array.from(stateRef.current.expandedPaths),
|
|
158
|
+
scrollTop: stateRef.current.scrollTop,
|
|
159
|
+
wrapped: stateRef.current.wrapped,
|
|
160
|
+
});
|
|
161
|
+
}, [sessionId]);
|
|
162
|
+
|
|
163
|
+
const debouncedPersist = useCallback(() => {
|
|
164
|
+
if (debounceTimerRef.current !== null) {
|
|
165
|
+
clearTimeout(debounceTimerRef.current);
|
|
166
|
+
}
|
|
167
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
168
|
+
debounceTimerRef.current = null;
|
|
169
|
+
persist();
|
|
170
|
+
}, 100);
|
|
171
|
+
}, [persist]);
|
|
172
|
+
|
|
173
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: state values are re-persist triggers; persist reads them via stateRef
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (isFirstMountRef.current) {
|
|
176
|
+
isFirstMountRef.current = false;
|
|
177
|
+
if (!isScopeOverridden) return;
|
|
178
|
+
}
|
|
179
|
+
persist();
|
|
180
|
+
}, [
|
|
181
|
+
selectedRepoCwd,
|
|
182
|
+
scope,
|
|
183
|
+
expandedPaths,
|
|
184
|
+
wrapped,
|
|
185
|
+
persist,
|
|
186
|
+
isScopeOverridden,
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
return () => {
|
|
191
|
+
if (debounceTimerRef.current !== null) {
|
|
192
|
+
clearTimeout(debounceTimerRef.current);
|
|
193
|
+
persist();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}, [persist]);
|
|
197
|
+
|
|
198
|
+
const isPathExpanded = useCallback(
|
|
199
|
+
(path: string): boolean => {
|
|
200
|
+
return expandedPaths.has(path);
|
|
201
|
+
},
|
|
202
|
+
[expandedPaths],
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const togglePathExpanded = useCallback((path: string, expand?: boolean) => {
|
|
206
|
+
setExpandedPaths((prev) => {
|
|
207
|
+
const next = new Set(prev);
|
|
208
|
+
const shouldExpand = expand ?? !next.has(path);
|
|
209
|
+
if (shouldExpand) {
|
|
210
|
+
next.add(path);
|
|
211
|
+
} else {
|
|
212
|
+
next.delete(path);
|
|
213
|
+
}
|
|
214
|
+
return next;
|
|
215
|
+
});
|
|
216
|
+
}, []);
|
|
217
|
+
|
|
218
|
+
const setScrollTop = useCallback(
|
|
219
|
+
(top: number) => {
|
|
220
|
+
scrollTopRef.current = top;
|
|
221
|
+
debouncedPersist();
|
|
222
|
+
},
|
|
223
|
+
[debouncedPersist],
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const toggleWrapped = useCallback(() => {
|
|
227
|
+
setWrapped((w) => !w);
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
selectedRepoCwd,
|
|
232
|
+
setSelectedRepoCwd,
|
|
233
|
+
scope,
|
|
234
|
+
setScope,
|
|
235
|
+
expandedPaths,
|
|
236
|
+
isPathExpanded,
|
|
237
|
+
setPathExpanded: togglePathExpanded,
|
|
238
|
+
togglePathExpanded,
|
|
239
|
+
scrollTop: scrollTopRef.current,
|
|
240
|
+
setScrollTop,
|
|
241
|
+
wrapped,
|
|
242
|
+
toggleWrapped,
|
|
243
|
+
};
|
|
244
|
+
}
|