11<template >
22 <div :class =" $style.playgroundRoot" >
33 <div :class =" $style.playgroundButtons" >
4- <button @click =" run" >Run</button >
4+ <button :class =" [$style.playgroundButton, $style.playgroundButtonPrimary]" @click =" run" >Run</button >
5+ <button :class =" [$style.playgroundButton]" :disabled =" loading" @click =" stop" >Abort</button >
6+ <button :class =" [$style.playgroundButton]" :disabled =" loading" @click =" clearLog" >Clear</button >
57 </div >
68 <div :class =" $style.playgroundLogs" >
79 <div v-for =" log in logs" :key =" log" :class =" $style.playgroundLogItem" >{{ log }}</div >
@@ -18,6 +20,7 @@ const props = defineProps<{
1820}>();
1921
2022const logs = ref <string []>([]);
23+ const loading = ref (false );
2124
2225let ParserClass: typeof Parser | null = null ;
2326let InterpreterClass: typeof Interpreter | null = null ;
@@ -27,6 +30,7 @@ let parser: Parser | null = null;
2730let interpreter: Interpreter | null = null ;
2831
2932async function run() {
33+ loading .value = true ;
3034 logs .value = [' [Playground] Loading...' ];
3135 if (! ParserClass || ! InterpreterClass || ! utils ) {
3236 const [
@@ -54,10 +58,21 @@ async function run() {
5458 });
5559
5660 logs .value = [];
61+ loading .value = false ;
5762
5863 const ast = parser .parse (props .code );
5964 await interpreter .exec (ast );
6065}
66+
67+ function stop() {
68+ if (interpreter ) {
69+ interpreter .abort ();
70+ }
71+ }
72+
73+ function clearLog() {
74+ logs .value = [];
75+ }
6176 </script >
6277
6378<style module>
@@ -69,17 +84,38 @@ async function run() {
6984 gap : 12px ;
7085}
7186
72- .playgroundButtons button {
73- background-color : var (--vp-button-brand-bg );
74- color : var (--vp-button-brand-text );
75- font-weight : 700 ;
87+ .playgroundButtons {
88+ display : flex ;
89+ flex-direction : column ;
90+ gap : 6px ;
91+ }
92+
93+ .playgroundButton {
7694 transition : background-color 0.25s ;
7795 padding : 4px 16px ;
7896 border-radius : 8px ;
79- cursor : pointer ;
8097}
8198
82- .playgroundButtons button :hover {
99+ .playgroundButton :disabled {
100+ opacity : 0.5 ;
101+ }
102+
103+ .playgroundButton :hover {
104+ background-color : var (--vp-button-alt-hover-bg );
105+ }
106+
107+ .playgroundButton :not (.playgroundButtonPrimary ) {
108+ font-size : 80% ;
109+ line-height : 1.5 ;
110+ }
111+
112+ .playgroundButtonPrimary {
113+ background-color : var (--vp-button-brand-bg );
114+ color : var (--vp-button-brand-text );
115+ font-weight : 700 ;
116+ }
117+
118+ .playgroundButtonPrimary :hover {
83119 color : var (--vp-button-brand-hover-text );
84120 background-color : var (--vp-button-brand-hover-bg );
85121}
0 commit comments