| banksean | 2be768e | 2025-07-18 16:41:39 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Demo module for sketch-diff-range-picker component |
| 3 | */ |
| 4 | |
| 5 | import { DemoModule } from "./demo-framework/types"; |
| 6 | import { demoUtils } from "./demo-fixtures/index"; |
| 7 | import { MockGitDataService } from "./mock-git-data-service"; |
| 8 | |
| 9 | const demo: DemoModule = { |
| 10 | title: "Diff Range Picker Demo", |
| 11 | description: "Component for selecting commit ranges for diff views", |
| 12 | imports: ["../sketch-diff-range-picker"], |
| 13 | |
| 14 | setup: async (container: HTMLElement) => { |
| 15 | // Create demo sections |
| 16 | const basicSection = demoUtils.createDemoSection( |
| 17 | "Basic Range Picker", |
| 18 | "Select commit ranges for diff views with dropdown interface", |
| 19 | ); |
| 20 | |
| 21 | const statusSection = demoUtils.createDemoSection( |
| 22 | "Range Selection Status", |
| 23 | "Shows the currently selected range and events", |
| 24 | ); |
| 25 | |
| 26 | // Create mock git service |
| 27 | const mockGitService = new MockGitDataService(); |
| 28 | |
| 29 | // Create the component |
| 30 | const rangePickerElement = document.createElement( |
| 31 | "sketch-diff-range-picker", |
| 32 | ); |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 33 | rangePickerElement.className = ` |
| 34 | w-full max-w-3xl my-5 p-4 border border-gray-300 dark:border-gray-600 |
| 35 | rounded-lg bg-white dark:bg-gray-800 |
| banksean | 2be768e | 2025-07-18 16:41:39 +0000 | [diff] [blame] | 36 | `; |
| 37 | |
| 38 | // Set up the git service |
| 39 | (rangePickerElement as any).gitService = mockGitService; |
| 40 | |
| 41 | // Create status display |
| 42 | const statusDisplay = document.createElement("div"); |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 43 | statusDisplay.className = ` |
| 44 | p-3 my-4 bg-gray-50 dark:bg-gray-800 rounded border |
| 45 | border-gray-200 dark:border-gray-700 font-mono text-sm leading-relaxed |
| banksean | 2be768e | 2025-07-18 16:41:39 +0000 | [diff] [blame] | 46 | `; |
| 47 | statusDisplay.innerHTML = ` |
| 48 | <div><strong>Status:</strong> No range selected</div> |
| 49 | <div><strong>Events:</strong> None</div> |
| 50 | `; |
| 51 | |
| 52 | // Listen for range change events |
| 53 | rangePickerElement.addEventListener("range-change", (event: any) => { |
| 54 | const range = event.detail.range; |
| 55 | const fromShort = range.from ? range.from.substring(0, 7) : "N/A"; |
| 56 | const toShort = range.to ? range.to.substring(0, 7) : "Uncommitted"; |
| 57 | |
| 58 | statusDisplay.innerHTML = ` |
| 59 | <div><strong>Status:</strong> Range selected</div> |
| 60 | <div><strong>From:</strong> ${fromShort}</div> |
| 61 | <div><strong>To:</strong> ${toShort}</div> |
| 62 | <div><strong>Events:</strong> range-change fired at ${new Date().toLocaleTimeString()}</div> |
| 63 | `; |
| 64 | }); |
| 65 | |
| 66 | // Add components to sections |
| 67 | basicSection.appendChild(rangePickerElement); |
| 68 | statusSection.appendChild(statusDisplay); |
| 69 | |
| 70 | // Add sections to container |
| 71 | container.appendChild(basicSection); |
| 72 | container.appendChild(statusSection); |
| 73 | |
| 74 | // Add some demo instructions |
| 75 | const instructionsDiv = document.createElement("div"); |
| banksean | 3d1308e | 2025-07-29 17:20:10 +0000 | [diff] [blame] | 76 | instructionsDiv.className = ` |
| 77 | my-5 p-4 bg-blue-50 dark:bg-blue-900/20 rounded |
| 78 | border-l-4 border-blue-500 dark:border-blue-400 |
| banksean | 2be768e | 2025-07-18 16:41:39 +0000 | [diff] [blame] | 79 | `; |
| 80 | instructionsDiv.innerHTML = ` |
| 81 | <h3 style="margin: 0 0 8px 0; color: #1976d2;">Demo Instructions:</h3> |
| 82 | <ul style="margin: 8px 0; padding-left: 20px;"> |
| 83 | <li>Click on the dropdown to see available commits</li> |
| 84 | <li>Select different commits to see range changes</li> |
| 85 | <li>The component defaults to diffing against uncommitted changes</li> |
| 86 | <li>Watch the status display for real-time event updates</li> |
| 87 | </ul> |
| 88 | `; |
| 89 | container.appendChild(instructionsDiv); |
| 90 | }, |
| 91 | |
| 92 | cleanup: () => { |
| 93 | // Clean up any event listeners or resources if needed |
| 94 | console.log("Cleaning up sketch-diff-range-picker demo"); |
| 95 | }, |
| 96 | }; |
| 97 | |
| 98 | export default demo; |