Skip to content

Commit 110f280

Browse files
authored
Merge pull request #8 from typephp-php/improve-ux
Improve ux
2 parents ec8b723 + f7f87ff commit 110f280

7 files changed

Lines changed: 127 additions & 69 deletions

File tree

‎docs/.vitepress/theme/components/Playground.vue‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,16 +509,14 @@ function onSelectPreset(presetId: string) {
509509
510510
function runCode() {
511511
const now = performance.now();
512-
if (now - lastRunTimestamp < 150) return;
512+
if (now - lastRunTimestamp < 250 || isRunning.value || !isReady.value) return;
513513
lastRunTimestamp = now;
514514
515515
const activeWorker = worker;
516-
if (!activeWorker || !isReady.value || isRunning.value) return;
516+
if (!activeWorker) return;
517517
518518
isRunning.value = true;
519-
clearConsole();
520-
report.value = null;
521-
519+
522520
outputDrawerRef.value?.expand();
523521
524522
activeWorker.postMessage({

‎docs/.vitepress/theme/components/PlaygroundEditor.vue‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { ref, onMounted, onUnmounted, watch } from 'vue';
1212
import { EditorView, basicSetup } from 'codemirror';
1313
import { EditorState, Compartment, Prec } from '@codemirror/state';
1414
import { php } from '@codemirror/lang-php';
15-
import { oneDark } from './theme-one-dark';
16-
import { oneLight } from './theme-one-light';
15+
import { oneDark } from './scripts/theme-one-dark';
16+
import { oneLight } from './scripts/theme-one-light';
1717
import { keymap } from '@codemirror/view';
1818
import { useData } from 'vitepress';
19-
import { phpdocHighlighter } from './phpdoc-highlighter';
19+
import { phpdocHighlighter } from './scripts/phpdoc-highlighter';
2020
import { indentRange } from '@codemirror/language';
2121
2222
const props = withDefaults(defineProps<{

‎docs/.vitepress/theme/components/PlaygroundOutput.vue‎

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<div class="resize-grip"></div>
4242
</div>
4343

44+
<div v-if="isRunning" class="executing-progress-bar"></div>
45+
4446
<!-- Header with Multi-Tabs -->
4547
<div class="drawer-header" @click="mode === 'drawer' ? toggleCollapse() : null">
4648
<div class="header-left" @click.stop>
@@ -142,6 +144,16 @@
142144
&times;
143145
</button>
144146

147+
<!-- Quick Re-Run Button (Embedded Mode Only) -->
148+
<button v-if="mode === 'embedded'" class="console-run-btn" :disabled="isRunning" title="Re-run code"
149+
@click="$emit('run')">
150+
<span v-if="isRunning" class="spinner-small"></span>
151+
<svg v-else viewBox="0 0 24 24" width="10" height="10" fill="currentColor">
152+
<path d="M8 5v14l11-7z" />
153+
</svg>
154+
<span>{{ isRunning ? '...' : 'Run' }}</span>
155+
</button>
156+
145157
<!-- Collapse Toggle (Drawer only) -->
146158
<button v-if="mode === 'drawer'" class="icon-action-btn collapse-toggle-btn"
147159
:title="isCollapsed ? 'Expand' : 'Collapse'" @click="toggleCollapse">
@@ -156,14 +168,16 @@
156168
<!-- Body -->
157169
<div v-show="mode === 'embedded' || !isCollapsed" class="drawer-body">
158170
<!-- 1. Console Stream Tab View -->
159-
<div v-if="activeTab === 'console'" class="console-view">
160-
<div v-if="isRunning" class="running-indicator">
171+
<div v-if="activeTab === 'console'" class="console-view"
172+
:class="{ 'is-executing': isRunning && (stdout || stderr) }">
173+
<!-- Only show the big block indicator if console is completely empty on first run -->
174+
<div v-if="isRunning && !stdout && !stderr" class="running-indicator">
161175
<span class="spinner"></span> Executing in PHP 8.5 WebAssembly...
162176
</div>
163177

164178
<pre v-if="stdout" class="stdout-stream">{{ stdout }}</pre>
165179

166-
<!-- Segmented STDERR Output (Warnings in Amber, Fatal Errors in Red) -->
180+
<!-- Segmented STDERR Output -->
167181
<template v-for="(block, idx) in parsedStderrBlocks" :key="idx">
168182
<pre
169183
:class="['stderr-stream', block.type === 'warning' ? 'is-warning' : 'is-error']">{{ block.content }}</pre>
@@ -295,7 +309,7 @@ const props = withDefaults(defineProps<{
295309
report?: AuditReportDocument | null;
296310
isReportModeActive?: boolean;
297311
reportViewMode?: 'cards' | 'json';
298-
mode?: 'drawer' | 'embedded';
312+
mode?: 'drawer' | 'embedded';
299313
}>(), {
300314
position: 'bottom',
301315
report: null,
@@ -309,7 +323,8 @@ const emit = defineEmits<{
309323
(e: 'clear-report'): void;
310324
(e: 'toggle-position'): void;
311325
(e: 'update:reportViewMode', mode: 'cards' | 'json'): void;
312-
(e: 'close'): void;
326+
(e: 'close'): void;
327+
(e: 'run'): void;
313328
}>();
314329
315330
const activeTab = ref<'console' | 'report'>('console');
@@ -1336,4 +1351,66 @@ defineExpose({
13361351
font-size: 11px;
13371352
}
13381353
}
1354+
1355+
.console-run-btn {
1356+
display: inline-flex;
1357+
align-items: center;
1358+
gap: 4px;
1359+
height: 22px;
1360+
padding: 0 8px;
1361+
font-size: 10.5px;
1362+
font-weight: 600;
1363+
border-radius: 4px;
1364+
border: none;
1365+
background: var(--vp-c-brand-1);
1366+
color: #fff;
1367+
cursor: pointer;
1368+
transition: all 0.15s ease;
1369+
flex-shrink: 0;
1370+
}
1371+
1372+
.console-run-btn:hover:not(:disabled) {
1373+
background: var(--vp-c-brand-2);
1374+
}
1375+
1376+
.console-run-btn:disabled {
1377+
opacity: 0.6;
1378+
cursor: not-allowed;
1379+
}
1380+
1381+
.spinner-small {
1382+
width: 9px;
1383+
height: 9px;
1384+
border: 1.5px solid rgba(255, 255, 255, 0.3);
1385+
border-top-color: #fff;
1386+
border-radius: 50%;
1387+
animation: spin 0.8s linear infinite;
1388+
}
1389+
1390+
.executing-progress-bar {
1391+
position: absolute;
1392+
top: 0;
1393+
left: 0;
1394+
right: 0;
1395+
height: 2px;
1396+
background: linear-gradient(90deg, var(--vp-c-brand-1), #38bdf8, var(--vp-c-brand-1));
1397+
background-size: 200% 100%;
1398+
animation: progress-slide 1s linear infinite;
1399+
z-index: 40;
1400+
}
1401+
1402+
@keyframes progress-slide {
1403+
0% { background-position: 100% 0; }
1404+
100% { background-position: -100% 0; }
1405+
}
1406+
1407+
.console-view {
1408+
padding: 12px 14px;
1409+
transition: opacity 0.15s ease;
1410+
}
1411+
1412+
.console-view.is-executing {
1413+
opacity: 0.6;
1414+
pointer-events: none;
1415+
}
13391416
</style>

‎docs/.vitepress/theme/components/TypePHPSnippet.vue‎

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
<div class="snippet-header">
55
<div class="header-left">
66
<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">
89
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
910
<polyline points="14 2 14 8 20 8" />
1011
</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>
1214
</div>
1315

1416
<div v-if="activeConfigBadges.length > 0" class="snippet-config-badges">
@@ -35,42 +37,34 @@
3537

3638
<div class="actions-cluster">
3739
<!-- 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">
4544
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" />
4645
<path d="M3 3v5h5" />
4746
</svg>
4847
</button>
4948

5049
<!-- 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">
5754
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
5855
<polyline points="15 3 21 3 21 9" />
5956
<line x1="10" y1="14" x2="21" y2="3" />
6057
</svg>
6158
</button>
6259

6360
<!-- 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" />
7063

7164
<!-- Copy Button -->
7265
<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">
7468
<rect x="9" y="9" width="13" height="13" rx="2" />
7569
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
7670
</svg>
@@ -113,18 +107,9 @@
113107
</div>
114108

115109
<!-- 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" />
128113
</div>
129114

130115
<!-- 3. Transformed View -->
@@ -138,28 +123,17 @@
138123
<span>Generating AST transformation...</span>
139124
</div>
140125

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>
142128
</div>
143129
</div>
144130

145131
<!-- 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" />
163137
</div>
164138
</template>
165139

@@ -394,27 +368,32 @@ function openInPlayground() {
394368
window.open(url, '_blank');
395369
}
396370
371+
let lastRunTimestamp = 0;
372+
397373
async function runSnippet() {
374+
const now = performance.now();
375+
if (now - lastRunTimestamp < 250 || isRunning.value) return;
376+
lastRunTimestamp = now;
377+
398378
const codeToRun = editableCode.value || sourceCode.value || extractCode();
399379
if (!codeToRun) return;
400380
401381
isRunning.value = true;
402382
hasRun.value = true;
403-
stdout.value = '';
404-
stderr.value = '';
405-
report.value = null;
406383
407384
const engine = getTypePHPEngine(site.value.base || '/');
408385
409386
try {
410387
const cleanConfig = JSON.parse(JSON.stringify(localConfig.value));
411388
const res: RunResult = await engine.run(codeToRun, cleanConfig);
389+
412390
stdout.value = res.stdout;
413391
stderr.value = res.stderr;
414392
exitCode.value = res.exitCode;
415393
duration.value = res.duration;
416394
report.value = res.report || null;
417395
} catch (err: any) {
396+
stdout.value = '';
418397
stderr.value = `Execution Error: ${err?.message || err}`;
419398
exitCode.value = 255;
420399
} finally {
@@ -729,7 +708,11 @@ function copyCode() {
729708
border-top-color: var(--vp-c-brand-1);
730709
}
731710
732-
@keyframes spin { to { transform: rotate(360deg); } }
711+
@keyframes spin {
712+
to {
713+
transform: rotate(360deg);
714+
}
715+
}
733716
734717
/* Tablet & Mobile Responsiveness */
735718
@media (max-width: 768px) {

docs/.vitepress/theme/components/phpdoc-highlighter.ts renamed to docs/.vitepress/theme/components/scripts/phpdoc-highlighter.ts

File renamed without changes.

docs/.vitepress/theme/components/theme-one-dark.ts renamed to docs/.vitepress/theme/components/scripts/theme-one-dark.ts

File renamed without changes.

docs/.vitepress/theme/components/theme-one-light.ts renamed to docs/.vitepress/theme/components/scripts/theme-one-light.ts

File renamed without changes.

0 commit comments

Comments
 (0)