File tree Expand file tree Collapse file tree 2 files changed +25
-15
lines changed
Expand file tree Collapse file tree 2 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -33,25 +33,26 @@ import SIconImport from "@/ui/icons/import.vue";
3333import { useProfile } from " @/consts" ;
3434const profile = useProfile ();
3535
36- import { onMounted , ref } from " vue" ;
36+ import { ref } from " vue" ;
3737import JSON5 from " json5" ;
3838import base64 from " base-64" ;
3939import utf8 from " utf8" ;
4040import type { FunctionPlotDatum } from " function-plot" ;
4141import { toInternalDatum } from " @/consts" ;
42- onMounted (() => {
43- const rawCode = window .location .search .match (/ \? code=(. + )$ / )?.[1 ];
44- if (rawCode )
45- try {
46- const code = utf8 .decode (base64 .decode (decodeURIComponent (rawCode )));
47- const data = toInternalDatum (
48- (JSON5 .parse (code ).data as FunctionPlotDatum []) ?? []
49- );
50- profile .data = toInternalDatum (<FunctionPlotDatum []>data );
51- console .log (code );
52- console .log (data );
53- } catch (e ) {}
54- });
42+
43+ const rawCode = window ?.location .search .match (/ \? code=(. + )$ / )?.[1 ];
44+ if (rawCode )
45+ try {
46+ const code = utf8 .decode (base64 .decode (decodeURIComponent (rawCode )));
47+ const data = toInternalDatum (
48+ (JSON5 .parse (code ).data as FunctionPlotDatum []) ?? []
49+ );
50+ profile .data = toInternalDatum (<FunctionPlotDatum []>data );
51+ console .log (code );
52+ console .log (data );
53+ } catch (e ) {
54+ if (e instanceof Error ) console .error (e );
55+ }
5556
5657const importStr = ref (" " );
5758import { Snackbar } from " sober" ;
Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ const { t } = useI18n();
3232import SIconCopy from " @/ui/icons/copy.vue" ;
3333
3434import JSON5 from " json5" ;
35+ import base64 from " base-64" ;
36+ import utf8 from " utf8" ;
37+
3538import prettier from " prettier/standalone" ;
3639import prettierPluginBabel from " prettier/plugins/babel" ;
3740import prettierPluginEstree from " prettier/plugins/estree" ;
@@ -43,8 +46,14 @@ const formatted = ref("");
4346watch (
4447 profile ,
4548 () => {
49+ const code = JSON5 .stringify ({ data: profile .getOriginalCopy (true ) });
50+ const url =
51+ window .location .href .match (/ https? :\/\/ [^ /] + \/ / ) +
52+ " ?code=" +
53+ encodeURIComponent (base64 .encode (utf8 .encode (code )).replace (/ =+ $ / , " " ));
54+ window .history .replaceState (null , " " , url );
4655 prettier
47- .format (JSON5 . stringify ({ data: profile . getOriginalCopy ( true ) }) , {
56+ .format (code , {
4857 parser: " json5" ,
4958 printWidth: 40 ,
5059 plugins: [prettierPluginBabel , prettierPluginEstree ],
You can’t perform that action at this time.
0 commit comments