33 <div id =" grid1" >
44 <Editor
55 v-model =" script"
6- :samples =" samples"
6+ :samples =" v. samples"
77 :parseError =" syntaxErrorMessage"
88 @run =" run"
99 />
@@ -55,7 +55,8 @@ export type Log = {
5555};
5656 </script >
5757<script setup lang="ts">
58- import { ref , watch } from " vue" ;
58+ import { ref , computed , watch } from " vue" ;
59+ import { useStorage } from ' @vueuse/core' ;
5960import Editor from " @common/Editor.vue" ;
6061import Container from " @common/Container.vue" ;
6162// import * as Next from "@/versions/next/index.ts";
@@ -70,7 +71,8 @@ import * as V0_14_1 from "@/versions/0.14.1/index.ts";
7071const props = defineProps <{
7172 ver: (typeof versions )[number ];
7273}>();
73- const { parse, exec, version, samples } = {
74+
75+ const vmodules = {
7476 // next: Next,
7577 develop: Develop ,
7678 " 0.19.0" : V0_19_0 ,
@@ -79,36 +81,34 @@ const { parse, exec, version, samples } = {
7981 " 0.16.0" : V0_16_0 ,
8082 " 0.15.0" : V0_15_0 ,
8183 " 0.14.1" : V0_14_1 ,
82- }[props .ver ];
83-
84- const script = ref (
85- window .localStorage .getItem (version ) ?? ' <: "Hello, AiScript!"' ,
86- );
84+ } as const ;
85+ const v = computed (() => vmodules [props .ver ]);
8786
87+ const vscripts = Object .fromEntries (versions .map (
88+ (_v ) => [_v , useStorage <string >(_v , ' <: "Hello, AiScript!"' )]
89+ ));
90+ const script = computed ({
91+ get(): string { return vscripts [props .ver ]! .value },
92+ set(newVal : string ): void { vscripts [props .ver ]! .value = newVal },
93+ });
8894const logs = ref <Log []>([]);
89- const ast = ref <string >(" " );
9095const syntaxErrorMessage = ref <string | null >(null );
91-
92- watch (
93- script ,
94- () => {
95- window .localStorage .setItem (version , script .value );
96- try {
97- ast .value = parse (script .value );
98- syntaxErrorMessage .value = null ;
99- } catch (e ) {
100- const err = e as Error ;
101- syntaxErrorMessage .value = err .message ;
102- console .error (" info" in err ? err .info : err );
103- return ;
104- }
105- },
106- { immediate: true },
107- );
96+ const ast = computed <string >(() => {
97+ try {
98+ const _ast = v .value .parse (script .value );
99+ syntaxErrorMessage .value = null ;
100+ return _ast ;
101+ } catch (e ) {
102+ const err = e as Error ;
103+ syntaxErrorMessage .value = err .message ;
104+ console .error (" info" in err ? err .info : err );
105+ return ` ${err } ` ;
106+ }
107+ });
108108
109109function run() {
110110 logs .value = [];
111- exec ({
111+ v . value . exec ({
112112 in : (q : string ) =>
113113 new Promise ((ok ) => {
114114 const res = window .prompt (q );
0 commit comments