| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 1 | import { html } from "lit"; |
| Sean McCullough | d9f1337 | 2025-04-21 15:08:49 -0700 | [diff] [blame] | 2 | import { customElement, property } from "lit/decorators.js"; |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 3 | import "./sketch-container-status"; |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 4 | import { SketchTailwindElement } from "./sketch-tailwind-element"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 5 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 6 | @customElement("sketch-view-mode-select") |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 7 | export class SketchViewModeSelect extends SketchTailwindElement { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 8 | // Current active mode |
| 9 | @property() |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 10 | activeMode: "chat" | "diff2" | "terminal" = "chat"; |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 11 | |
| 12 | // Diff stats |
| 13 | @property({ type: Number }) |
| 14 | diffLinesAdded: number = 0; |
| 15 | |
| 16 | @property({ type: Number }) |
| 17 | diffLinesRemoved: number = 0; |
| 18 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 19 | // Header bar: view mode buttons |
| 20 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 21 | constructor() { |
| 22 | super(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 23 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 24 | // Binding methods |
| 25 | this._handleViewModeClick = this._handleViewModeClick.bind(this); |
| 26 | this._handleUpdateActiveMode = this._handleUpdateActiveMode.bind(this); |
| 27 | } |
| 28 | |
| 29 | // See https://lit.dev/docs/components/lifecycle/ |
| 30 | connectedCallback() { |
| 31 | super.connectedCallback(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 32 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 33 | // Listen for update-active-mode events |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 34 | this.addEventListener( |
| 35 | "update-active-mode", |
| 36 | this._handleUpdateActiveMode as EventListener, |
| 37 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 38 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 39 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Handle view mode button clicks |
| 42 | */ |
| Philip Zeyliger | 00bcaef | 2025-05-30 04:21:15 +0000 | [diff] [blame] | 43 | private _handleViewModeClick(mode: "chat" | "diff2" | "terminal") { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 44 | // Dispatch a custom event to notify the app shell to change the view |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 45 | const event = new CustomEvent("view-mode-select", { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 46 | detail: { mode }, |
| 47 | bubbles: true, |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 48 | composed: true, |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 49 | }); |
| 50 | this.dispatchEvent(event); |
| 51 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 52 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Handle updates to the active mode |
| 55 | */ |
| 56 | private _handleUpdateActiveMode(event: CustomEvent) { |
| 57 | const { mode } = event.detail; |
| 58 | if (mode) { |
| 59 | this.activeMode = mode; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // See https://lit.dev/docs/components/lifecycle/ |
| 64 | disconnectedCallback() { |
| 65 | super.disconnectedCallback(); |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 66 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 67 | // Remove event listeners |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 68 | this.removeEventListener( |
| 69 | "update-active-mode", |
| 70 | this._handleUpdateActiveMode as EventListener, |
| 71 | ); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | render() { |
| 75 | return html` |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 76 | <div |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 77 | class="flex mr-2.5 bg-gray-100 dark:bg-gray-800 rounded border border-gray-300 dark:border-gray-600 overflow-hidden" |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 78 | > |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 79 | <button |
| 80 | id="showConversationButton" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 81 | class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 82 | .activeMode === "chat" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 83 | ? "border-b-blue-600 dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700" |
| 84 | : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 85 | title="Conversation View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 86 | @click=${() => this._handleViewModeClick("chat")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 87 | > |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 88 | <span class="tab-icon text-base">💬</span> |
| 89 | <span class="max-sm:hidden sm:max-xl:hidden">Chat</span> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 90 | </button> |
| 91 | <button |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 92 | id="showDiff2Button" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 93 | class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 94 | .activeMode === "diff2" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 95 | ? "border-b-blue-600 dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700" |
| 96 | : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0" |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 97 | title="Diff View - ${this.diffLinesAdded > 0 || |
| 98 | this.diffLinesRemoved > 0 |
| 99 | ? `+${this.diffLinesAdded} -${this.diffLinesRemoved}` |
| 100 | : "No changes"}" |
| Philip Zeyliger | 272a90e | 2025-05-16 14:49:51 -0700 | [diff] [blame] | 101 | @click=${() => this._handleViewModeClick("diff2")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 102 | > |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 103 | <span class="tab-icon text-base">±</span> |
| 104 | <span class="diff-tex max-sm:hidden sm:max-xl:hidden">Diff</span> |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 105 | ${this.diffLinesAdded > 0 || this.diffLinesRemoved > 0 |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 106 | ? html`<span |
| 107 | class="diff-stats text-xs ml-1 opacity-80 ${this.activeMode === |
| 108 | "diff2" |
| 109 | ? "opacity-100" |
| 110 | : ""}" |
| Philip Zeyliger | 64f6046 | 2025-06-16 13:57:10 -0700 | [diff] [blame] | 111 | >+${this.diffLinesAdded} -${this.diffLinesRemoved}</span |
| 112 | >` |
| 113 | : ""} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 114 | </button> |
| Autoformatter | 8c46362 | 2025-05-16 21:54:17 +0000 | [diff] [blame] | 115 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 116 | <button |
| 117 | id="showTerminalButton" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 118 | class="px-3 py-2 bg-none border-0 border-b-2 cursor-pointer text-xs flex items-center gap-1.5 text-gray-600 dark:text-gray-400 border-transparent transition-all whitespace-nowrap ${this |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 119 | .activeMode === "terminal" |
| banksean | 3eaa433 | 2025-07-19 02:19:06 +0000 | [diff] [blame] | 120 | ? "border-b-blue-600 !dark:border-b-gray-500 text-blue-600 font-medium bg-blue-50 dark:bg-gray-700" |
| 121 | : "hover:bg-gray-200 dark:hover:bg-gray-700"} @xl:px-3 @xl:py-2 @max-xl:px-2.5 @max-xl:[&>span:not(.tab-icon):not(.diff-stats)]:hidden @max-xl:[&>.diff-stats]:inline @max-xl:[&>.diff-stats]:text-xs @max-xl:[&>.diff-stats]:ml-0.5 border-r border-gray-200 dark:border-gray-600 last-of-type:border-r-0" |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 122 | title="Terminal View" |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 123 | @click=${() => this._handleViewModeClick("terminal")} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 124 | > |
| banksean | d5c849d | 2025-06-26 15:48:31 +0000 | [diff] [blame] | 125 | <span class="tab-icon text-base">💻</span> |
| 126 | <span class="max-sm:hidden sm:max-xl:hidden">Terminal</span> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 127 | </button> |
| 128 | </div> |
| 129 | `; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | declare global { |
| 134 | interface HTMLElementTagNameMap { |
| 135 | "sketch-view-mode-select": SketchViewModeSelect; |
| 136 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 137 | } |