Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
5ad42d1d
Unverified
Commit
5ad42d1d
authored
2 years ago
by
Andreas Nedbal
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(client): refactor scratchpad to use Composition API (#8565)
parent
8f32064f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/client/src/pages/scratchpad.vue
+75
-88
75 additions, 88 deletions
packages/client/src/pages/scratchpad.vue
with
75 additions
and
88 deletions
packages/client/src/pages/scratchpad.vue
+
75
−
88
View file @
5ad42d1d
...
...
@@ -6,20 +6,20 @@
</div>
<MkContainer
:foldable=
"true"
class=
"_gap"
>
<template
#header
>
{{
$
ts
.
output
}}
</
template
>
<template
#header
>
{{
i18n
.
ts
.
output
}}
</
template
>
<div
class=
"bepmlvbi"
>
<div
v-for=
"log in logs"
:key=
"log.id"
class=
"log"
:class=
"{ print: log.print }"
>
{{ log.text }}
</div>
</div>
</MkContainer>
<div
class=
"_gap"
>
{{
$
ts.scratchpadDescription }}
{{
i18n.
ts.scratchpadDescription }}
</div>
</div>
</template>
<
script
lang=
"ts"
>
import
{
define
Component
}
from
'
vue
'
;
<
script
lang=
"ts"
setup
>
import
{
define
Expose
,
ref
,
watch
}
from
'
vue
'
;
import
'
prismjs
'
;
import
{
highlight
,
languages
}
from
'
prismjs/components/prism-core
'
;
import
'
prismjs/components/prism-clike
'
;
...
...
@@ -27,103 +27,90 @@ import 'prismjs/components/prism-javascript';
import
'
prismjs/themes/prism-okaidia.css
'
;
import
{
PrismEditor
}
from
'
vue-prism-editor
'
;
import
'
vue-prism-editor/dist/prismeditor.min.css
'
;
import
{
AiScript
,
parse
,
utils
,
values
}
from
'
@syuilo/aiscript
'
;
import
{
AiScript
,
parse
,
utils
}
from
'
@syuilo/aiscript
'
;
import
MkContainer
from
'
@/components/ui/container.vue
'
;
import
MkButton
from
'
@/components/ui/button.vue
'
;
import
{
createAiScriptEnv
}
from
'
@/scripts/aiscript/api
'
;
import
*
as
os
from
'
@/os
'
;
import
*
as
symbols
from
'
@/symbols
'
;
import
{
$i
}
from
'
@/account
'
;
import
{
i18n
}
from
'
@/i18n
'
;
export
default
defineComponent
({
components
:
{
MkContainer
,
MkButton
,
PrismEditor
,
},
data
()
{
return
{
[
symbols
.
PAGE_INFO
]:
{
title
:
this
.
$ts
.
scratchpad
,
icon
:
'
fas fa-terminal
'
,
},
code
:
''
,
logs
:
[],
}
},
watch
:
{
code
()
{
localStorage
.
setItem
(
'
scratchpad
'
,
this
.
code
);
}
},
const
code
=
ref
(
''
);
const
logs
=
ref
<
any
[]
>
([]);
created
()
{
const
saved
=
localStorage
.
getItem
(
'
scratchpad
'
);
if
(
saved
)
{
this
.
code
=
saved
;
}
},
const
saved
=
localStorage
.
getItem
(
'
scratchpad
'
);
if
(
saved
)
{
code
.
value
=
saved
;
}
methods
:
{
async
run
()
{
this
.
logs
=
[];
const
aiscript
=
new
AiScript
(
createAiScriptEnv
({
storageKey
:
'
scratchpad
'
,
token
:
this
.
$i
?.
token
,
}),
{
in
:
(
q
)
=>
{
return
new
Promise
(
ok
=>
{
os
.
inputText
({
title
:
q
,
}).
then
(({
canceled
,
result
:
a
})
=>
{
ok
(
a
);
});
});
},
out
:
(
value
)
=>
{
this
.
logs
.
push
({
id
:
Math
.
random
(),
text
:
value
.
type
===
'
str
'
?
value
.
value
:
utils
.
valToString
(
value
),
print
:
true
});
},
log
:
(
type
,
params
)
=>
{
switch
(
type
)
{
case
'
end
'
:
this
.
logs
.
push
({
id
:
Math
.
random
(),
text
:
utils
.
valToString
(
params
.
val
,
true
),
print
:
false
});
break
;
default
:
break
;
}
}
});
watch
(
code
,
()
=>
{
localStorage
.
setItem
(
'
scratchpad
'
,
code
.
value
);
});
let
ast
;
try
{
ast
=
parse
(
this
.
code
);
}
catch
(
e
)
{
os
.
alert
({
type
:
'
error
'
,
text
:
'
Syntax error :(
'
});
return
;
}
try
{
await
aiscript
.
exec
(
ast
);
}
catch
(
e
)
{
os
.
alert
({
type
:
'
error
'
,
text
:
e
async
function
run
()
{
logs
.
value
=
[];
const
aiscript
=
new
AiScript
(
createAiScriptEnv
({
storageKey
:
'
scratchpad
'
,
token
:
$i
?.
token
,
}),
{
in
:
(
q
)
=>
{
return
new
Promise
(
ok
=>
{
os
.
inputText
({
title
:
q
,
}).
then
(({
canceled
,
result
:
a
})
=>
{
ok
(
a
);
});
}
}
);
},
highlighter
(
code
)
{
return
highlight
(
code
,
languages
.
js
,
'
javascript
'
);
out
:
(
value
)
=>
{
logs
.
value
.
push
({
id
:
Math
.
random
(),
text
:
value
.
type
===
'
str
'
?
value
.
value
:
utils
.
valToString
(
value
),
print
:
true
});
},
log
:
(
type
,
params
)
=>
{
switch
(
type
)
{
case
'
end
'
:
logs
.
value
.
push
({
id
:
Math
.
random
(),
text
:
utils
.
valToString
(
params
.
val
,
true
),
print
:
false
});
break
;
default
:
break
;
}
}
});
let
ast
;
try
{
ast
=
parse
(
code
.
value
);
}
catch
(
error
)
{
os
.
alert
({
type
:
'
error
'
,
text
:
'
Syntax error :(
'
});
return
;
}
try
{
await
aiscript
.
exec
(
ast
);
}
catch
(
error
:
any
)
{
os
.
alert
({
type
:
'
error
'
,
text
:
error
.
message
});
}
};
function
highlighter
(
code
)
{
return
highlight
(
code
,
languages
.
js
,
'
javascript
'
);
}
defineExpose
({
[
symbols
.
PAGE_INFO
]:
{
title
:
i18n
.
ts
.
scratchpad
,
icon
:
'
fas fa-terminal
'
,
},
});
</
script
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment