@@ -15,17 +15,20 @@ import {
15
15
import { ref , onMounted , watch } from " vue" ;
16
16
import { basicCode } from " @/constant" ;
17
17
import { memberList } from " @/constant" ;
18
- import createMonaco , { PlMonaco } from " @pivot-lang/create-monaco" ;
18
+ // import createMonaco, { PlMonaco } from "@pivot-lang/create-monaco";
19
19
import CodeBlock from " @/components/codeBlock.vue" ;
20
20
import { cp } from " fs" ;
21
21
import " xterm/css/xterm.css" ;
22
22
import { Terminal } from " xterm" ;
23
23
24
24
const tabVal = ref (" hello world" );
25
25
const tabList = basicCode .map ((item ) => item .title );
26
- let monaco: PlMonaco ;
27
26
let code = ref (" " );
28
27
let runResult = ref (" " );
28
+ let initialized = ref (false );
29
+ let watchCallback = (val : string ) => {
30
+ console .log (' not initialized yet...' );
31
+ };
29
32
function gotoEmail() {
30
33
window .location .href = " mailto:[email protected] " ;
31
34
}
@@ -47,41 +50,47 @@ function handleOutput(re: string) {
47
50
}
48
51
49
52
onMounted (async () => {
50
- monaco = createMonaco (
51
- document .getElementById (" container" )! ,
52
- basicCode [0 ].code
53
- );
54
53
code .value = basicCode [0 ].code ;
55
- monaco .editor .onDidChangeModelContent (() => {
56
- code .value = monaco .editor .getModel ()! .getValue ();
54
+ import (" @pivot-lang/create-monaco" ).then (pl => {
55
+ let monaco = pl .default (
56
+ document .getElementById (" container" )! ,
57
+ basicCode [0 ].code
58
+ );
59
+ monaco .editor .onDidChangeModelContent (() => {
60
+ code .value = monaco .editor .getModel ()! .getValue ();
61
+ });
62
+ terminal .open (document .querySelector (" .code-block" ) as HTMLElement );
63
+ terminal .resize (44 , 17 );
64
+ watchCallback = (val ) => {
65
+ const code1 = basicCode .find ((item ) => item .title === val )?.code || " " ;
66
+ code .value = code1 ;
67
+ monaco .setContent (code1 );
68
+ };
69
+ initialized .value = true ;
57
70
});
58
- terminal .open (document .querySelector (" .code-block" ) as HTMLElement );
59
- terminal .resize (44 , 17 );
60
71
});
61
72
watch (
62
73
() => tabVal .value ,
63
74
(val ) => {
64
- const code1 = basicCode .find ((item ) => item .title === val )?.code || " " ;
65
- code .value = code1 ;
66
- monaco .setContent (code1 );
75
+ watchCallback (val );
67
76
}
68
77
);
69
78
</script >
70
79
71
80
<template >
72
81
<div class =" container" >
73
82
<Nav ></Nav >
74
- <FirstPage :monaco = " monaco " ></FirstPage >
83
+ <FirstPage ></FirstPage >
75
84
<div id =" code-show" >
76
85
<div class =" gradient-font title" >Enjoy coding pivot lang now!</div >
77
86
<div class =" detail-describe" >
78
87
With the help of Web Assembly technology, we are able to provide support
79
88
for some of the Pivot Lang syntax in the browser for you to experience.
80
89
</div >
81
- <div class =" code-now-container" >
90
+ <div v-show = " initialized " class =" code-now-container" >
82
91
<div class =" code-box" >
83
92
<TabList
84
- @updateVal =" (val) => (tabVal = val)"
93
+ @updateVal =" (val:string ) => (tabVal = val)"
85
94
@updateOutput =" handleOutput"
86
95
:tablist =" tabList"
87
96
:val =" tabVal"
@@ -96,6 +105,9 @@ watch(
96
105
<div class =" code-block" ></div >
97
106
</div >
98
107
</div >
108
+ <div v-show =" !initialized" class =" code-now-container" >
109
+ <div class =" spinner" ></div >
110
+ </div >
99
111
</div >
100
112
<div id =" advantage" >
101
113
<div class =" gradient-font title" >Immix Garbage Collector</div >
@@ -334,4 +346,18 @@ watch(
334
346
}
335
347
}
336
348
}
349
+ @keyframes spin {
350
+ 0% { transform : rotate (0deg ); }
351
+ 100% { transform : rotate (360deg ); }
352
+ }
353
+
354
+ .spinner {
355
+ border : 16px solid #f3f3f3 ; /* Light grey */
356
+ border-top : 16px solid #3498db ; /* Blue */
357
+ border-radius : 50% ;
358
+ width : 120px ;
359
+ height : 120px ;
360
+ animation : spin 2s linear infinite ;
361
+ margin : auto ;
362
+ }
337
363
</style >
0 commit comments