blob: 5c51de4daaf6f6aefb673e94e92605e60e4ca162 [file] [log] [blame]
Philip Zeyliger272a90e2025-05-16 14:49:51 -07001// sketch-diff-range-picker.ts
2// Component for selecting commit range for diffs
3
banksean2be768e2025-07-18 16:41:39 +00004import { html } from "lit";
Philip Zeyliger272a90e2025-05-16 14:49:51 -07005import { customElement, property, state } from "lit/decorators.js";
philip.zeyliger26bc6592025-06-30 20:15:30 -07006import { GitDataService } from "./git-data-service";
Philip Zeyliger272a90e2025-05-16 14:49:51 -07007import { GitLogEntry } from "../types";
banksean2be768e2025-07-18 16:41:39 +00008import { SketchTailwindElement } from "./sketch-tailwind-element";
Philip Zeyliger272a90e2025-05-16 14:49:51 -07009
10/**
11 * Range type for diff views
12 */
David Crawshaw216d2fc2025-06-15 18:45:53 +000013export type DiffRange = { type: "range"; from: string; to: string };
Philip Zeyliger272a90e2025-05-16 14:49:51 -070014
15/**
16 * Component for selecting commit range for diffs
17 */
18@customElement("sketch-diff-range-picker")
banksean2be768e2025-07-18 16:41:39 +000019export class SketchDiffRangePicker extends SketchTailwindElement {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070020 @property({ type: Array })
21 commits: GitLogEntry[] = [];
22
23 @state()
Autoformatter8c463622025-05-16 21:54:17 +000024 private fromCommit: string = "";
Philip Zeyliger272a90e2025-05-16 14:49:51 -070025
26 @state()
Autoformatter8c463622025-05-16 21:54:17 +000027 private toCommit: string = "";
Philip Zeyliger272a90e2025-05-16 14:49:51 -070028
Philip Zeyliger364b35a2025-06-21 16:39:04 -070029 @state()
30 private dropdownOpen: boolean = false;
31
Philip Zeyliger38499cc2025-06-15 21:17:05 -070032 // Removed commitsExpanded state - always expanded now
Philip Zeyliger272a90e2025-05-16 14:49:51 -070033
34 @state()
35 private loading: boolean = true;
36
37 @state()
38 private error: string | null = null;
Autoformatter8c463622025-05-16 21:54:17 +000039
Philip Zeyliger272a90e2025-05-16 14:49:51 -070040 @property({ attribute: false, type: Object })
41 gitService!: GitDataService;
Autoformatter8c463622025-05-16 21:54:17 +000042
Philip Zeyliger272a90e2025-05-16 14:49:51 -070043 constructor() {
44 super();
Autoformatter8c463622025-05-16 21:54:17 +000045 console.log("SketchDiffRangePicker initialized");
Philip Zeyliger272a90e2025-05-16 14:49:51 -070046 }
47
banksean2be768e2025-07-18 16:41:39 +000048 // Ensure global styles are injected when component is used
49 private ensureGlobalStyles() {
50 if (!document.querySelector("#sketch-diff-range-picker-styles")) {
51 const floatingMessageStyles = document.createElement("style");
52 floatingMessageStyles.id = "sketch-diff-range-picker-styles";
53 floatingMessageStyles.textContent = this.getGlobalStylesContent();
54 document.head.appendChild(floatingMessageStyles);
55 }
56 }
57
58 // Get the global styles content
59 private getGlobalStylesContent(): string {
60 return `
61 sketch-diff-range-picker {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070062 display: block;
63 width: 100%;
64 font-family: var(--font-family, system-ui, sans-serif);
65 color: var(--text-color, #333);
banksean2be768e2025-07-18 16:41:39 +000066 }`;
67 }
Philip Zeyliger272a90e2025-05-16 14:49:51 -070068
69 connectedCallback() {
70 super.connectedCallback();
banksean2be768e2025-07-18 16:41:39 +000071 this.ensureGlobalStyles();
Philip Zeyliger272a90e2025-05-16 14:49:51 -070072 // Wait for DOM to be fully loaded to ensure proper initialization order
Autoformatter8c463622025-05-16 21:54:17 +000073 if (document.readyState === "complete") {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070074 this.loadCommits();
75 } else {
Autoformatter8c463622025-05-16 21:54:17 +000076 window.addEventListener("load", () => {
Philip Zeyliger272a90e2025-05-16 14:49:51 -070077 setTimeout(() => this.loadCommits(), 0); // Give time for provider initialization
78 });
79 }
Autoformatter9abf8032025-06-14 23:24:08 +000080
David Crawshaw938d2dc2025-06-14 22:17:33 +000081 // Listen for popstate events to handle browser back/forward navigation
Autoformatter9abf8032025-06-14 23:24:08 +000082 window.addEventListener("popstate", this.handlePopState.bind(this));
David Crawshaw938d2dc2025-06-14 22:17:33 +000083 }
84
85 disconnectedCallback() {
86 super.disconnectedCallback();
Autoformatter9abf8032025-06-14 23:24:08 +000087 window.removeEventListener("popstate", this.handlePopState.bind(this));
David Crawshaw938d2dc2025-06-14 22:17:33 +000088 }
89
90 /**
91 * Handle browser back/forward navigation
92 */
93 private handlePopState() {
94 // Re-initialize from URL parameters when user navigates
95 if (this.commits.length > 0) {
96 const initializedFromUrl = this.initializeFromUrlParams();
97 if (initializedFromUrl) {
98 // Force re-render and dispatch event
99 this.requestUpdate();
100 this.dispatchRangeEvent();
101 }
102 }
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700103 }
104
105 render() {
106 return html`
banksean2be768e2025-07-18 16:41:39 +0000107 <div class="block w-full font-system text-gray-800">
108 <div class="flex flex-col gap-3 w-full">
109 ${this.loading
110 ? html`<div class="italic text-gray-500">Loading commits...</div>`
111 : this.error
112 ? html`<div class="text-red-600 text-sm">${this.error}</div>`
113 : this.renderRangePicker()}
114 </div>
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700115 </div>
116 `;
117 }
118
119 renderRangePicker() {
120 return html`
banksean2be768e2025-07-18 16:41:39 +0000121 <div class="flex flex-row items-center gap-3 flex-1">
122 ${this.renderRangeSelectors()}
123 </div>
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700124 `;
125 }
126
127 renderRangeSelectors() {
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700128 // Always diff against uncommitted changes
129 this.toCommit = "";
130
131 const selectedCommit = this.commits.find((c) => c.hash === this.fromCommit);
132 const isDefaultCommit =
133 selectedCommit && this.isSketchBaseCommit(selectedCommit);
134
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700135 return html`
banksean2be768e2025-07-18 16:41:39 +0000136 <div class="flex items-center gap-2 flex-1 relative">
137 <label for="fromCommit" class="font-medium text-sm text-gray-700"
138 >Diff from:</label
139 >
140 <div
141 class="relative w-full min-w-[300px]"
142 @click=${this.toggleDropdown}
143 >
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700144 <button
banksean2be768e2025-07-18 16:41:39 +0000145 class="w-full py-2 px-3 pr-8 border rounded text-left min-h-[36px] text-sm relative cursor-pointer bg-white ${isDefaultCommit
146 ? "border-blue-500 bg-blue-50"
147 : "border-gray-300 hover:border-gray-400"} focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700148 @click=${this.toggleDropdown}
149 @blur=${this.handleBlur}
150 >
banksean2be768e2025-07-18 16:41:39 +0000151 <div class="flex items-center gap-2 pr-6">
152 ${selectedCommit
153 ? this.renderCommitButton(selectedCommit)
154 : "Select commit..."}
155 </div>
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700156 <svg
banksean2be768e2025-07-18 16:41:39 +0000157 class="absolute right-2 top-1/2 transform -translate-y-1/2 transition-transform duration-200 ${this
158 .dropdownOpen
159 ? "rotate-180"
160 : ""}"
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700161 width="12"
162 height="12"
163 viewBox="0 0 12 12"
164 >
165 <path d="M6 8l-4-4h8z" fill="currentColor" />
166 </svg>
167 </button>
168 ${this.dropdownOpen
169 ? html`
banksean2be768e2025-07-18 16:41:39 +0000170 <div
171 class="absolute top-full left-0 right-0 bg-white border border-gray-300 rounded shadow-lg z-50 max-h-[300px] overflow-y-auto mt-0.5"
172 >
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700173 ${this.commits.map(
174 (commit) => html`
175 <div
banksean2be768e2025-07-18 16:41:39 +0000176 class="px-3 py-2.5 cursor-pointer border-b border-gray-100 last:border-b-0 flex items-start gap-2 text-sm leading-5 hover:bg-gray-50 ${commit.hash ===
177 this.fromCommit
178 ? "bg-blue-50"
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700179 : ""} ${this.isSketchBaseCommit(commit)
banksean2be768e2025-07-18 16:41:39 +0000180 ? "bg-blue-50 border-l-4 border-l-blue-500 pl-2"
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700181 : ""}"
182 @click=${() => this.selectCommit(commit.hash)}
183 >
184 ${this.renderCommitOption(commit)}
185 </div>
186 `,
187 )}
188 </div>
189 `
190 : ""}
191 </div>
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700192 </div>
193 `;
194 }
195
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700196 /**
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700197 * Format a commit for display in the dropdown (legacy method, kept for compatibility)
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700198 */
199 formatCommitOption(commit: GitLogEntry): string {
200 const shortHash = commit.hash.substring(0, 7);
Autoformatter8c463622025-05-16 21:54:17 +0000201
David Crawshawdbca8972025-06-14 23:46:58 +0000202 // Truncate subject if it's too long
203 let subject = commit.subject;
204 if (subject.length > 50) {
205 subject = subject.substring(0, 47) + "...";
206 }
207
208 let label = `${shortHash} ${subject}`;
209
210 // Add refs but keep them concise
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700211 if (commit.refs && commit.refs.length > 0) {
David Crawshawdbca8972025-06-14 23:46:58 +0000212 const refs = commit.refs.map((ref) => {
213 // Shorten common prefixes
214 if (ref.startsWith("origin/")) {
215 return ref.substring(7);
216 }
217 if (ref.startsWith("refs/heads/")) {
218 return ref.substring(11);
219 }
220 if (ref.startsWith("refs/remotes/origin/")) {
221 return ref.substring(20);
222 }
223 return ref;
224 });
225
226 // Limit to first 2 refs to avoid overcrowding
227 const displayRefs = refs.slice(0, 2);
228 if (refs.length > 2) {
229 displayRefs.push(`+${refs.length - 2} more`);
230 }
231
232 label += ` (${displayRefs.join(", ")})`;
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700233 }
Autoformatter8c463622025-05-16 21:54:17 +0000234
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700235 return label;
236 }
237
238 /**
239 * Load commits from the Git data service
240 */
241 async loadCommits() {
242 this.loading = true;
243 this.error = null;
244
245 if (!this.gitService) {
Autoformatter8c463622025-05-16 21:54:17 +0000246 console.error("GitService was not provided to sketch-diff-range-picker");
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700247 throw Error();
248 }
249
250 try {
251 // Get the base commit reference
252 const baseCommitRef = await this.gitService.getBaseCommitRef();
Autoformatter8c463622025-05-16 21:54:17 +0000253
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700254 // Load commit history
255 this.commits = await this.gitService.getCommitHistory(baseCommitRef);
Autoformatter8c463622025-05-16 21:54:17 +0000256
David Crawshaw938d2dc2025-06-14 22:17:33 +0000257 // Check if we should initialize from URL parameters first
258 const initializedFromUrl = this.initializeFromUrlParams();
Autoformatter9abf8032025-06-14 23:24:08 +0000259
David Crawshaw938d2dc2025-06-14 22:17:33 +0000260 // Set default selections only if not initialized from URL
261 if (this.commits.length > 0 && !initializedFromUrl) {
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700262 // For range, default is base to HEAD
263 // TODO: is sketch-base right in the unsafe context, where it's sketch-base-...
264 // should this be startswith?
Autoformatter8c463622025-05-16 21:54:17 +0000265 const baseCommit = this.commits.find(
266 (c) => c.refs && c.refs.some((ref) => ref.includes("sketch-base")),
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700267 );
Autoformatter8c463622025-05-16 21:54:17 +0000268
269 this.fromCommit = baseCommit
270 ? baseCommit.hash
271 : this.commits[this.commits.length - 1].hash;
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700272 // Default to Uncommitted Changes by setting toCommit to empty string
Autoformatter8c463622025-05-16 21:54:17 +0000273 this.toCommit = ""; // Empty string represents uncommitted changes
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700274 }
Autoformatter9abf8032025-06-14 23:24:08 +0000275
David Crawshaw938d2dc2025-06-14 22:17:33 +0000276 // Always dispatch range event to ensure diff view is updated
277 this.dispatchRangeEvent();
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700278 } catch (error) {
Autoformatter8c463622025-05-16 21:54:17 +0000279 console.error("Error loading commits:", error);
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700280 this.error = `Error loading commits: ${error.message}`;
281 } finally {
282 this.loading = false;
283 }
284 }
285
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700286 /**
287 * Handle From commit change
288 */
289 handleFromChange(event: Event) {
290 const select = event.target as HTMLSelectElement;
291 this.fromCommit = select.value;
292 this.dispatchRangeEvent();
293 }
294
295 /**
296 * Handle To commit change
297 */
298 handleToChange(event: Event) {
299 const select = event.target as HTMLSelectElement;
300 this.toCommit = select.value;
301 this.dispatchRangeEvent();
302 }
303
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700304 /**
305 * Toggle dropdown open/closed
306 */
307 toggleDropdown(event: Event) {
308 event.stopPropagation();
309 this.dropdownOpen = !this.dropdownOpen;
310
311 if (this.dropdownOpen) {
312 // Close dropdown when clicking outside
313 setTimeout(() => {
314 document.addEventListener("click", this.closeDropdown, { once: true });
315 }, 0);
316 }
317 }
318
319 /**
320 * Close dropdown
321 */
322 closeDropdown = () => {
323 this.dropdownOpen = false;
324 };
325
326 /**
327 * Handle blur event on select button
328 */
philip.zeyliger26bc6592025-06-30 20:15:30 -0700329 handleBlur(_event: FocusEvent) {
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700330 // Small delay to allow click events to process
331 setTimeout(() => {
332 if (!this.shadowRoot?.activeElement?.closest(".custom-select")) {
333 this.dropdownOpen = false;
334 }
335 }, 150);
336 }
337
338 /**
339 * Select a commit from dropdown
340 */
341 selectCommit(hash: string) {
342 this.fromCommit = hash;
343 this.dropdownOpen = false;
344 this.dispatchRangeEvent();
345 }
346
347 /**
348 * Check if a commit is a sketch-base commit
349 */
350 isSketchBaseCommit(commit: GitLogEntry): boolean {
351 return commit.refs?.some((ref) => ref.includes("sketch-base")) || false;
352 }
353
354 /**
355 * Render commit for the dropdown button
356 */
357 renderCommitButton(commit: GitLogEntry) {
358 const shortHash = commit.hash.substring(0, 7);
359 let subject = commit.subject;
360 if (subject.length > 40) {
361 subject = subject.substring(0, 37) + "...";
362 }
363
364 return html`
banksean2be768e2025-07-18 16:41:39 +0000365 <span class="font-mono text-gray-600 text-xs">${shortHash}</span>
366 <span class="text-gray-800 text-xs truncate">${subject}</span>
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700367 ${this.isSketchBaseCommit(commit)
banksean2be768e2025-07-18 16:41:39 +0000368 ? html`
369 <span
370 class="bg-blue-600 text-white px-1.5 py-0.5 rounded-full text-xs font-semibold"
371 >base</span
372 >
373 `
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700374 : ""}
375 `;
376 }
377
378 /**
379 * Render commit option in dropdown
380 */
381 renderCommitOption(commit: GitLogEntry) {
382 const shortHash = commit.hash.substring(0, 7);
383 let subject = commit.subject;
384 if (subject.length > 50) {
385 subject = subject.substring(0, 47) + "...";
386 }
387
388 return html`
banksean2be768e2025-07-18 16:41:39 +0000389 <span class="font-mono text-gray-600 text-xs">${shortHash}</span>
390 <span class="text-gray-800 text-xs flex-1 truncate min-w-[200px]"
391 >${subject}</span
392 >
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700393 ${commit.refs && commit.refs.length > 0
banksean2be768e2025-07-18 16:41:39 +0000394 ? html`
395 <div class="flex gap-1 flex-wrap">
396 ${this.renderRefs(commit.refs)}
397 </div>
398 `
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700399 : ""}
400 `;
401 }
402
403 /**
404 * Render all refs naturally without truncation
405 */
406 renderRefs(refs: string[]) {
407 return html`
banksean2be768e2025-07-18 16:41:39 +0000408 <div class="flex gap-1 flex-wrap flex-shrink-0">
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700409 ${refs.map((ref) => {
410 const shortRef = this.getShortRefName(ref);
411 const isSketchBase = ref.includes("sketch-base");
412 const refClass = isSketchBase
banksean2be768e2025-07-18 16:41:39 +0000413 ? "bg-blue-600 text-white font-semibold"
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700414 : ref.includes("tag")
banksean2be768e2025-07-18 16:41:39 +0000415 ? "bg-amber-100 text-amber-800"
416 : "bg-green-100 text-green-800";
417 return html`<span
418 class="px-1.5 py-0.5 rounded-full text-xs font-medium ${refClass}"
419 >${shortRef}</span
420 >`;
Philip Zeyliger364b35a2025-06-21 16:39:04 -0700421 })}
422 </div>
423 `;
424 }
425
426 /**
427 * Get shortened reference name for compact display
428 */
429 getShortRefName(ref: string): string {
430 if (ref.startsWith("refs/heads/")) {
431 return ref.substring(11);
432 }
433 if (ref.startsWith("refs/remotes/origin/")) {
434 return ref.substring(20);
435 }
436 if (ref.startsWith("refs/tags/")) {
437 return ref.substring(10);
438 }
439 return ref;
440 }
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700441
442 /**
David Crawshaw216d2fc2025-06-15 18:45:53 +0000443 * Get a summary of the current commit range for display
Philip Zeyligere89b3082025-05-29 03:16:06 +0000444 */
David Crawshaw216d2fc2025-06-15 18:45:53 +0000445 getCommitSummary(): string {
446 if (!this.fromCommit && !this.toCommit) {
Autoformatter62554112025-06-15 19:23:33 +0000447 return "No commits selected";
David Crawshaw216d2fc2025-06-15 18:45:53 +0000448 }
449
Autoformatter62554112025-06-15 19:23:33 +0000450 const fromShort = this.fromCommit ? this.fromCommit.substring(0, 7) : "";
451 const toShort = this.toCommit
452 ? this.toCommit.substring(0, 7)
453 : "Uncommitted";
454
David Crawshaw216d2fc2025-06-15 18:45:53 +0000455 return `${fromShort}..${toShort}`;
Philip Zeyligere89b3082025-05-29 03:16:06 +0000456 }
457
458 /**
David Crawshaw938d2dc2025-06-14 22:17:33 +0000459 * Validate that a commit hash exists in the loaded commits
460 */
461 private isValidCommitHash(hash: string): boolean {
Autoformatter9abf8032025-06-14 23:24:08 +0000462 if (!hash || hash.trim() === "") return true; // Empty is valid (uncommitted changes)
463 return this.commits.some(
464 (commit) => commit.hash.startsWith(hash) || commit.hash === hash,
465 );
David Crawshaw938d2dc2025-06-14 22:17:33 +0000466 }
467
468 /**
469 * Dispatch range change event and update URL parameters
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700470 */
471 dispatchRangeEvent() {
Autoformatter62554112025-06-15 19:23:33 +0000472 const range: DiffRange = {
473 type: "range",
474 from: this.fromCommit,
475 to: this.toCommit,
476 };
Autoformatter8c463622025-05-16 21:54:17 +0000477
David Crawshaw938d2dc2025-06-14 22:17:33 +0000478 // Update URL parameters
479 this.updateUrlParams(range);
480
Autoformatter8c463622025-05-16 21:54:17 +0000481 const event = new CustomEvent("range-change", {
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700482 detail: { range },
483 bubbles: true,
Autoformatter8c463622025-05-16 21:54:17 +0000484 composed: true,
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700485 });
Autoformatter8c463622025-05-16 21:54:17 +0000486
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700487 this.dispatchEvent(event);
488 }
David Crawshaw938d2dc2025-06-14 22:17:33 +0000489
490 /**
491 * Update URL parameters for from and to commits
492 */
493 private updateUrlParams(range: DiffRange) {
494 const url = new URL(window.location.href);
Autoformatter9abf8032025-06-14 23:24:08 +0000495
David Crawshaw938d2dc2025-06-14 22:17:33 +0000496 // Remove existing range parameters
Autoformatter9abf8032025-06-14 23:24:08 +0000497 url.searchParams.delete("from");
498 url.searchParams.delete("to");
499 url.searchParams.delete("commit");
500
David Crawshaw216d2fc2025-06-15 18:45:53 +0000501 // Add from parameter if not empty
502 if (range.from && range.from.trim() !== "") {
503 url.searchParams.set("from", range.from);
504 }
505 // Add to parameter if not empty (empty string means uncommitted changes)
506 if (range.to && range.to.trim() !== "") {
507 url.searchParams.set("to", range.to);
David Crawshaw938d2dc2025-06-14 22:17:33 +0000508 }
Autoformatter9abf8032025-06-14 23:24:08 +0000509
David Crawshaw938d2dc2025-06-14 22:17:33 +0000510 // Update the browser history without reloading the page
Autoformatter9abf8032025-06-14 23:24:08 +0000511 window.history.replaceState(window.history.state, "", url.toString());
David Crawshaw938d2dc2025-06-14 22:17:33 +0000512 }
513
514 /**
515 * Initialize from URL parameters if available
516 */
517 private initializeFromUrlParams() {
518 const url = new URL(window.location.href);
Autoformatter9abf8032025-06-14 23:24:08 +0000519 const fromParam = url.searchParams.get("from");
520 const toParam = url.searchParams.get("to");
Autoformatter9abf8032025-06-14 23:24:08 +0000521
David Crawshaw216d2fc2025-06-15 18:45:53 +0000522 // If from or to parameters are present, use them
David Crawshaw938d2dc2025-06-14 22:17:33 +0000523 if (fromParam || toParam) {
David Crawshaw938d2dc2025-06-14 22:17:33 +0000524 if (fromParam) {
525 this.fromCommit = fromParam;
526 }
527 if (toParam) {
528 this.toCommit = toParam;
529 } else {
530 // If no 'to' param, default to uncommitted changes (empty string)
Autoformatter9abf8032025-06-14 23:24:08 +0000531 this.toCommit = "";
David Crawshaw938d2dc2025-06-14 22:17:33 +0000532 }
533 return true; // Indicate that we initialized from URL
534 }
Autoformatter9abf8032025-06-14 23:24:08 +0000535
David Crawshaw938d2dc2025-06-14 22:17:33 +0000536 return false; // No URL params found
537 }
Philip Zeyliger272a90e2025-05-16 14:49:51 -0700538}
539
540declare global {
541 interface HTMLElementTagNameMap {
542 "sketch-diff-range-picker": SketchDiffRangePicker;
543 }
544}