|
4 | 4 | import { FLOW_CODE, getStepFromLine, FLOW_SECTIONS } from '$lib/data/flow-code'; |
5 | 5 | import type { createFlowState } from '$lib/stores/pgflow-state-improved.svelte'; |
6 | 6 | import StatusBadge from '$lib/components/StatusBadge.svelte'; |
| 7 | + import PulseDot from '$lib/components/PulseDot.svelte'; |
7 | 8 |
|
8 | 9 | interface Props { |
9 | 10 | flowState: ReturnType<typeof createFlowState>; |
|
20 | 21 |
|
21 | 22 | let highlightedCode = $state(''); |
22 | 23 | let highlightedSections = $state<Record<string, string>>({}); |
| 24 | + let highlightedSectionsExpanded = $state<Record<string, string>>({}); |
23 | 25 | let codeContainer: HTMLElement | undefined = $state(undefined); |
24 | 26 | let isMobile = $state(false); |
25 | 27 |
|
| 28 | + // Section order for mobile rendering |
| 29 | + const SECTION_ORDER = ['flow_config', 'fetch_article', 'summarize', 'extract_keywords', 'publish']; |
| 30 | +
|
26 | 31 | // Calculate step blocks (groups of lines) for status icon positioning |
27 | 32 | const stepBlocks = $derived.by(() => { |
28 | 33 | const blocks: Array<{ stepSlug: string; startLine: number; endLine: number }> = []; |
|
80 | 85 | ] |
81 | 86 | }); |
82 | 87 |
|
83 | | - // Generate separate highlighted sections for mobile (use mobileCode if available) |
| 88 | + // Generate separate highlighted sections |
84 | 89 | for (const [slug, section] of Object.entries(FLOW_SECTIONS)) { |
85 | | - const codeToRender = section.mobileCode || section.code; |
86 | | - highlightedSections[slug] = await codeToHtml(codeToRender, { |
| 90 | + // Compact code for main mobile panel |
| 91 | + highlightedSections[slug] = await codeToHtml(section.code, { |
| 92 | + lang: 'typescript', |
| 93 | + theme: 'night-owl' |
| 94 | + }); |
| 95 | +
|
| 96 | + // Expanded code for explanation panel (mobile-selected) |
| 97 | + const expandedCode = section.mobileCode || section.code; |
| 98 | + highlightedSectionsExpanded[slug] = await codeToHtml(expandedCode, { |
87 | 99 | lang: 'typescript', |
88 | 100 | theme: 'night-owl' |
89 | 101 | }); |
|
190 | 202 |
|
191 | 203 | <div class="code-panel-wrapper"> |
192 | 204 | {#if isMobile && selectedStep} |
193 | | - <!-- Mobile: Show only selected section (including flow_config) --> |
| 205 | + <!-- Mobile: Show only selected section in explanation panel (expanded version) --> |
194 | 206 | <div class="code-panel mobile-selected"> |
195 | | - {#if highlightedSections[selectedStep]} |
| 207 | + {#if highlightedSectionsExpanded[selectedStep]} |
196 | 208 | <!-- eslint-disable-next-line svelte/no-at-html-tags --> |
197 | | - {@html highlightedSections[selectedStep]} |
| 209 | + {@html highlightedSectionsExpanded[selectedStep]} |
198 | 210 | {/if} |
199 | 211 | </div> |
| 212 | + {:else if isMobile} |
| 213 | + <!-- Mobile: Show all sections as separate blocks --> |
| 214 | + <div class="code-panel mobile-sections"> |
| 215 | + {#each SECTION_ORDER as sectionSlug, index (sectionSlug)} |
| 216 | + {@const stepStatus = getStepStatus(sectionSlug)} |
| 217 | + {@const isDimmed = selectedStep && sectionSlug !== selectedStep} |
| 218 | + {@const isFirst = index === 0} |
| 219 | + {@const isLast = index === SECTION_ORDER.length - 1} |
| 220 | + <div |
| 221 | + class="code-section" |
| 222 | + class:section-dimmed={isDimmed} |
| 223 | + class:section-selected={selectedStep === sectionSlug} |
| 224 | + class:section-first={isFirst} |
| 225 | + class:section-last={isLast} |
| 226 | + data-step={sectionSlug} |
| 227 | + onclick={() => dispatch('step-selected', { stepSlug: sectionSlug })} |
| 228 | + role="button" |
| 229 | + tabindex="0" |
| 230 | + > |
| 231 | + <!-- Status indicator: left border --> |
| 232 | + {#if stepStatus} |
| 233 | + <div class="section-status-border status-{stepStatus}"></div> |
| 234 | + {/if} |
| 235 | + |
| 236 | + <!-- Pulse dot (centered) --> |
| 237 | + <div class="pulse-dot-container"> |
| 238 | + <PulseDot /> |
| 239 | + </div> |
| 240 | + |
| 241 | + <!-- Code content --> |
| 242 | + <!-- eslint-disable-next-line svelte/no-at-html-tags --> |
| 243 | + {@html highlightedSections[sectionSlug]} |
| 244 | + </div> |
| 245 | + {/each} |
| 246 | + </div> |
200 | 247 | {:else} |
201 | | - <!-- Desktop or no selection: Show full code --> |
| 248 | + <!-- Desktop: Show full code (unchanged) --> |
202 | 249 | <div class="code-panel" bind:this={codeContainer}> |
203 | 250 | <!-- eslint-disable-next-line svelte/no-at-html-tags --> |
204 | 251 | {@html highlightedCode} |
|
222 | 269 | > |
223 | 270 | <StatusBadge status={stepStatus} variant="icon-only" size="xl" /> |
224 | 271 | </div> |
225 | | - |
226 | | - <!-- Mobile: Vertical colored border --> |
227 | | - <div |
228 | | - class="step-status-border md:hidden status-{stepStatus}" |
229 | | - class:status-dimmed={isDimmed} |
230 | | - data-step={block.stepSlug} |
231 | | - style="top: calc({blockTop}em + 12px); height: calc({blockHeight}em);" |
232 | | - ></div> |
233 | 272 | {/if} |
234 | 273 | {/each} |
235 | 274 | </div> |
|
249 | 288 | .code-panel.mobile-selected { |
250 | 289 | /* Compact height when showing only selected step on mobile */ |
251 | 290 | min-height: auto; |
252 | | - font-size: 15px; |
| 291 | + font-size: 13px; |
253 | 292 | background: #0d1117; |
254 | 293 | position: relative; |
255 | 294 | } |
256 | 295 |
|
| 296 | + .code-panel.mobile-sections { |
| 297 | + /* Mobile: Container for separate section blocks */ |
| 298 | + font-size: 11px; |
| 299 | + border-radius: 0; |
| 300 | + } |
| 301 | +
|
257 | 302 | /* Mobile: Smaller font, no border radius (touches edges) */ |
258 | 303 | @media (max-width: 768px) { |
259 | 304 | .code-panel { |
|
262 | 307 | } |
263 | 308 | } |
264 | 309 |
|
| 310 | + /* Mobile: Individual code section */ |
| 311 | + .code-section { |
| 312 | + position: relative; |
| 313 | + cursor: pointer; |
| 314 | + transition: |
| 315 | + opacity 200ms ease, |
| 316 | + background-color 200ms ease; |
| 317 | + } |
| 318 | +
|
| 319 | + .code-section.section-dimmed { |
| 320 | + opacity: 0.4; |
| 321 | + } |
| 322 | +
|
| 323 | + .code-section.section-selected { |
| 324 | + background-color: rgba(88, 166, 255, 0.22); |
| 325 | + opacity: 1; |
| 326 | + } |
| 327 | +
|
| 328 | + /* Status border for mobile sections */ |
| 329 | + .section-status-border { |
| 330 | + position: absolute; |
| 331 | + left: 0; |
| 332 | + top: 0; |
| 333 | + bottom: 0; |
| 334 | + width: 2px; |
| 335 | + pointer-events: none; |
| 336 | + } |
| 337 | +
|
| 338 | + .section-status-border.status-completed { |
| 339 | + background: #10b981; /* Green */ |
| 340 | + } |
| 341 | +
|
| 342 | + .section-status-border.status-started { |
| 343 | + background: #3b82f6; /* Blue */ |
| 344 | + } |
| 345 | +
|
| 346 | + /* Pulse dot container - centers the dot */ |
| 347 | + .pulse-dot-container { |
| 348 | + position: absolute; |
| 349 | + top: 50%; |
| 350 | + left: 50%; |
| 351 | + transform: translate(-50%, -50%); |
| 352 | + pointer-events: none; |
| 353 | + z-index: 10; |
| 354 | + } |
| 355 | +
|
265 | 356 | /* Override Shiki's default pre styling */ |
266 | 357 | .code-panel :global(pre) { |
267 | 358 | margin: 0; |
|
278 | 369 | } |
279 | 370 | } |
280 | 371 |
|
| 372 | + /* Mobile sections: Seamless styling */ |
| 373 | + .mobile-sections .code-section :global(pre) { |
| 374 | + margin: 0; |
| 375 | + padding: 16px 8px; |
| 376 | + background: #0d1117 !important; |
| 377 | + border-radius: 0; |
| 378 | + line-height: 1.5; |
| 379 | + } |
| 380 | +
|
| 381 | + /* First section: keep top padding, remove bottom */ |
| 382 | + .mobile-sections .code-section.section-first :global(pre) { |
| 383 | + padding-bottom: 0; |
| 384 | + } |
| 385 | +
|
| 386 | + /* Middle sections: remove all vertical padding */ |
| 387 | + .mobile-sections .code-section:not(.section-first):not(.section-last) :global(pre) { |
| 388 | + padding-top: 0; |
| 389 | + padding-bottom: 0; |
| 390 | + } |
| 391 | +
|
| 392 | + /* Last section: keep bottom padding, remove top */ |
| 393 | + .mobile-sections .code-section.section-last :global(pre) { |
| 394 | + padding-top: 0; |
| 395 | + } |
| 396 | +
|
281 | 397 | .code-panel :global(code) { |
282 | 398 | font-family: 'Fira Code', 'Monaco', 'Menlo', 'Courier New', monospace; |
283 | 399 | } |
|
0 commit comments