|
4 | 4 | <div class="snippet-header"> |
5 | 5 | <div class="header-left"> |
6 | 6 | <div class="title-cluster"> |
7 | | - <svg class="php-icon" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"> |
| 7 | + <svg class="php-icon" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" |
| 8 | + stroke-width="2"> |
8 | 9 | <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" /> |
9 | 10 | <polyline points="14 2 14 8 20 8" /> |
10 | 11 | </svg> |
11 | | - <span class="snippet-title" :title="title || 'TypePHP Interactive'">{{ title || 'TypePHP Interactive' }}</span> |
| 12 | + <span class="snippet-title" :title="title || 'TypePHP Interactive'">{{ title || 'TypePHP Interactive' |
| 13 | + }}</span> |
12 | 14 | </div> |
13 | 15 |
|
14 | 16 | <div v-if="activeConfigBadges.length > 0" class="snippet-config-badges"> |
|
35 | 37 |
|
36 | 38 | <div class="actions-cluster"> |
37 | 39 | <!-- Reset Modified Code Button --> |
38 | | - <button |
39 | | - v-if="isModified" |
40 | | - class="icon-btn reset-btn" |
41 | | - title="Reset code to original tutorial snippet" |
42 | | - @click="resetCode" |
43 | | - > |
44 | | - <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 40 | + <button v-if="isModified" class="icon-btn reset-btn" title="Reset code to original tutorial snippet" |
| 41 | + @click="resetCode"> |
| 42 | + <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" |
| 43 | + stroke-linecap="round" stroke-linejoin="round"> |
45 | 44 | <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> |
46 | 45 | <path d="M3 3v5h5" /> |
47 | 46 | </svg> |
48 | 47 | </button> |
49 | 48 |
|
50 | 49 | <!-- Open in Full-Screen Playground --> |
51 | | - <button |
52 | | - class="icon-btn playground-link-btn" |
53 | | - title="Open in full Playground (new tab)" |
54 | | - @click="openInPlayground" |
55 | | - > |
56 | | - <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 50 | + <button class="icon-btn playground-link-btn" title="Open in full Playground (new tab)" |
| 51 | + @click="openInPlayground"> |
| 52 | + <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" |
| 53 | + stroke-linecap="round" stroke-linejoin="round"> |
57 | 54 | <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" /> |
58 | 55 | <polyline points="15 3 21 3 21 9" /> |
59 | 56 | <line x1="10" y1="14" x2="21" y2="3" /> |
60 | 57 | </svg> |
61 | 58 | </button> |
62 | 59 |
|
63 | 60 | <!-- Config Popover --> |
64 | | - <PlaygroundConfigPopover |
65 | | - v-model="localConfig" |
66 | | - :has-custom-config="hasCustomConfig" |
67 | | - :compact="true" |
68 | | - @reset="resetToSnippetDefaults" |
69 | | - /> |
| 61 | + <PlaygroundConfigPopover v-model="localConfig" :has-custom-config="hasCustomConfig" :compact="true" |
| 62 | + @reset="resetToSnippetDefaults" /> |
70 | 63 |
|
71 | 64 | <!-- Copy Button --> |
72 | 65 | <button class="icon-btn" :title="copied ? 'Copied!' : 'Copy Code'" @click="copyCode"> |
73 | | - <svg v-if="!copied" viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2"> |
| 66 | + <svg v-if="!copied" viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" |
| 67 | + stroke-width="2"> |
74 | 68 | <rect x="9" y="9" width="13" height="13" rx="2" /> |
75 | 69 | <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" /> |
76 | 70 | </svg> |
|
113 | 107 | </div> |
114 | 108 |
|
115 | 109 | <!-- 2. Lazy On-Demand Edit View --> |
116 | | - <div |
117 | | - v-if="hasMountedEditor" |
118 | | - v-show="currentView === 'edit'" |
119 | | - class="snippet-editor-pane" |
120 | | - :style="{ height: editorHeight }" |
121 | | - > |
122 | | - <PlaygroundEditor |
123 | | - v-model="editableCode" |
124 | | - :font-size="13" |
125 | | - @run="runSnippet" |
126 | | - @update:model-value="onCodeEdited" |
127 | | - /> |
| 110 | + <div v-if="hasMountedEditor" v-show="currentView === 'edit'" class="snippet-editor-pane" |
| 111 | + :style="{ height: editorHeight }"> |
| 112 | + <PlaygroundEditor v-model="editableCode" :font-size="13" @run="runSnippet" @update:model-value="onCodeEdited" /> |
128 | 113 | </div> |
129 | 114 |
|
130 | 115 | <!-- 3. Transformed View --> |
|
138 | 123 | <span>Generating AST transformation...</span> |
139 | 124 | </div> |
140 | 125 |
|
141 | | - <pre v-else class="snippet-pre"><code v-html="highlightedTransformedCode || 'Generating AST transformation...'"></code></pre> |
| 126 | + <pre v-else |
| 127 | + class="snippet-pre"><code v-html="highlightedTransformedCode || 'Generating AST transformation...'"></code></pre> |
142 | 128 | </div> |
143 | 129 | </div> |
144 | 130 |
|
145 | 131 | <!-- Output Drawer --> |
146 | | - <PlaygroundOutput |
147 | | - v-if="hasRun" |
148 | | - mode="embedded" |
149 | | - :stdout="stdout" |
150 | | - :stderr="stderr" |
151 | | - :exit-code="exitCode" |
152 | | - :duration="duration" |
153 | | - :status-message="''" |
154 | | - :is-running="isRunning" |
155 | | - :report="report" |
156 | | - :is-report-mode-active="localConfig.onViolation === 'report'" |
157 | | - :report-view-mode="snippetReportViewMode" |
158 | | - @clear="clearConsole" |
159 | | - @clear-report="report = null" |
160 | | - @update:report-view-mode="snippetReportViewMode = $event" |
161 | | - @close="hasRun = false" |
162 | | - /> |
| 132 | + <PlaygroundOutput v-if="hasRun" mode="embedded" :stdout="stdout" :stderr="stderr" :exit-code="exitCode" |
| 133 | + :duration="duration" :status-message="''" :is-running="isRunning" :report="report" |
| 134 | + :is-report-mode-active="localConfig.onViolation === 'report'" :report-view-mode="snippetReportViewMode" |
| 135 | + @run="runSnippet" @clear="clearConsole" @clear-report="report = null" |
| 136 | + @update:report-view-mode="snippetReportViewMode = $event" @close="hasRun = false" /> |
163 | 137 | </div> |
164 | 138 | </template> |
165 | 139 |
|
@@ -394,27 +368,32 @@ function openInPlayground() { |
394 | 368 | window.open(url, '_blank'); |
395 | 369 | } |
396 | 370 |
|
| 371 | +let lastRunTimestamp = 0; |
| 372 | +
|
397 | 373 | async function runSnippet() { |
| 374 | + const now = performance.now(); |
| 375 | + if (now - lastRunTimestamp < 250 || isRunning.value) return; |
| 376 | + lastRunTimestamp = now; |
| 377 | +
|
398 | 378 | const codeToRun = editableCode.value || sourceCode.value || extractCode(); |
399 | 379 | if (!codeToRun) return; |
400 | 380 |
|
401 | 381 | isRunning.value = true; |
402 | 382 | hasRun.value = true; |
403 | | - stdout.value = ''; |
404 | | - stderr.value = ''; |
405 | | - report.value = null; |
406 | 383 |
|
407 | 384 | const engine = getTypePHPEngine(site.value.base || '/'); |
408 | 385 |
|
409 | 386 | try { |
410 | 387 | const cleanConfig = JSON.parse(JSON.stringify(localConfig.value)); |
411 | 388 | const res: RunResult = await engine.run(codeToRun, cleanConfig); |
| 389 | +
|
412 | 390 | stdout.value = res.stdout; |
413 | 391 | stderr.value = res.stderr; |
414 | 392 | exitCode.value = res.exitCode; |
415 | 393 | duration.value = res.duration; |
416 | 394 | report.value = res.report || null; |
417 | 395 | } catch (err: any) { |
| 396 | + stdout.value = ''; |
418 | 397 | stderr.value = `Execution Error: ${err?.message || err}`; |
419 | 398 | exitCode.value = 255; |
420 | 399 | } finally { |
@@ -729,7 +708,11 @@ function copyCode() { |
729 | 708 | border-top-color: var(--vp-c-brand-1); |
730 | 709 | } |
731 | 710 |
|
732 | | -@keyframes spin { to { transform: rotate(360deg); } } |
| 711 | +@keyframes spin { |
| 712 | + to { |
| 713 | + transform: rotate(360deg); |
| 714 | + } |
| 715 | +} |
733 | 716 |
|
734 | 717 | /* Tablet & Mobile Responsiveness */ |
735 | 718 | @media (max-width: 768px) { |
|
0 commit comments