-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ReplInput.vue
75 lines (66 loc) · 1.67 KB
/
ReplInput.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<template>
<InputHeader />
<div class="modules" ref="modulesReference">
<ReplModule
v-for="(module, i) in modulesStore.modules"
:key="i"
:module="module"
:editable-header="i > 0"
editable
show-header
@remove="removeModule(i)"
/>
</div>
<button class="repl-button new-module" @click="createModule">
<span class="repl-icon-plus"></span>
add module
</button>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useModules } from '../stores/modules';
import InputHeader from './InputHeader.vue';
import ReplModule from './ReplModule.vue';
const modulesStore = useModules();
let uid = 1;
const modulesReference = ref<HTMLElement | null>(null);
const removeModule = (index: number) => modulesStore.modules.splice(index, 1);
function createModule() {
modulesStore.modules.push({
code: '',
isEntry: false,
name: `module_${uid++}.js`
});
setTimeout(() => {
const inputs = modulesReference.value?.querySelectorAll('input');
if (inputs) {
const input = inputs[inputs.length - 1];
input.focus();
}
});
}
</script>
<style scoped>
.new-module {
display: block;
width: 100%;
color: var(--vp-button-alt-text);
border: 1px solid var(--vp-button-alt-border);
background-color: var(--vp-button-alt-bg);
border-radius: 20px;
padding: 0;
margin-bottom: 0;
line-height: 38px;
transition: all 0.2s;
}
.new-module:hover {
color: var(--vp-button-alt-hover-text);
border-color: var(--vp-button-alt-hover-border);
background-color: var(--vp-button-alt-hover-bg);
}
.new-module:active {
color: var(--vp-button-alt-active-text);
border-color: var(--vp-button-alt-active-border);
background-color: var(--vp-button-alt-active-bg);
}
</style>