Skip to content

Commit 8ae34ee

Browse files
committed
feat: add snippets header, fragments (basic)
1 parent bfd86ba commit 8ae34ee

File tree

5 files changed

+151
-5
lines changed

5 files changed

+151
-5
lines changed

src/renderer/assets/scss/variables.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
--sidebar-width: 180px;
33
--snippets-list-width: 220px;
44
--snippets-view-header-height: 60px;
5+
--snippets-view-header-top-height: 30px;
56
--snippets-view-header-full-height: calc(var(--snippets-view-header-height) + var(--snippets-tags-height));
67
--snippets-view-footer-height: 30px;
7-
--snippet-tab-header-height: 40px;
8+
--snippet-header-fragment-height: 25px;
89
--snippet-tab-height: 30px;
9-
--title-bar-height: 20px;
10+
--title-bar-height: 15px;
1011
--menu-header: 80px;
1112

1213
--spacing-unit: 4px;

src/renderer/components/editor/TheEditor.vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div class="editor">
2+
<div
3+
class="editor"
4+
:class="{ 'with-fragments': fragments }"
5+
>
36
<div
47
ref="editorRef"
58
class="main"
@@ -38,6 +41,7 @@ import { languages, oldLanguageMap } from './languages'
3841
interface Props {
3942
lang: Language
4043
theme: string
44+
fragments: boolean
4145
modelValue: string
4246
}
4347
@@ -48,7 +52,8 @@ interface Emits {
4852
4953
const props = withDefaults(defineProps<Props>(), {
5054
lang: 'typescript',
51-
theme: 'google'
55+
theme: 'google',
56+
fragments: false
5257
})
5358
5459
const emit = defineEmits<Emits>()
@@ -133,8 +138,21 @@ watch(
133138

134139
<style lang="scss" scoped>
135140
.editor {
141+
padding-top: 4px;
142+
&.with-fragments {
143+
.main {
144+
height: calc(
145+
100vh - var(--title-bar-height) - var(--snippets-view-header-top-height) -
146+
var(--snippets-view-footer-height) -
147+
var(--snippet-header-fragment-height)
148+
);
149+
}
150+
}
136151
.main {
137-
height: calc(100vh - var(--title-bar-height) - 30px);
152+
height: calc(
153+
100vh - var(--title-bar-height) - var(--snippets-view-header-top-height) -
154+
var(--snippets-view-footer-height)
155+
);
138156
}
139157
.footer {
140158
height: 30px;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<div class="fragments">
3+
<div
4+
v-for="(i, index) in snippetStore.fragmentLabels"
5+
:key="index"
6+
class="item"
7+
:class="{ 'is-active': index == snippetStore.fragment }"
8+
@click="onClickFragment(index)"
9+
>
10+
{{ i }}
11+
</div>
12+
</div>
13+
</template>
14+
15+
<script setup lang="ts">
16+
import { useSnippetStore } from '@/store/snippets'
17+
18+
const snippetStore = useSnippetStore()
19+
20+
const onClickFragment = (index: number) => {
21+
snippetStore.fragment = index
22+
}
23+
</script>
24+
25+
<style lang="scss" scoped>
26+
.fragments {
27+
display: flex;
28+
align-items: center;
29+
height: var(--snippet-header-fragment-height);
30+
.item {
31+
padding: 0 var(--spacing-xs);
32+
display: flex;
33+
align-items: center;
34+
height: var(--snippet-header-fragment-height);
35+
width: 1000%;
36+
border-top: 1px solid var(--color-border);
37+
border-bottom: 1px solid var(--color-border);
38+
&.is-active {
39+
background-color: var(--color-contrast-lower);
40+
}
41+
}
42+
}
43+
</style>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<div class="header">
3+
<div class="top">
4+
<div class="name">
5+
{{ snippetStore.snippet?.name }}
6+
</div>
7+
<div class="action">
8+
<AppActionButton>
9+
<UniconsArrow />
10+
</AppActionButton>
11+
<AppActionButton>
12+
<UniconsPlus />
13+
</AppActionButton>
14+
</div>
15+
</div>
16+
<div class="bottom">
17+
<SnippetFragments v-if="snippetStore.isFragmentsShow" />
18+
</div>
19+
</div>
20+
</template>
21+
22+
<script setup lang="ts">
23+
import { useSnippetStore } from '@/store/snippets'
24+
25+
const snippetStore = useSnippetStore()
26+
</script>
27+
28+
<style lang="scss" scoped>
29+
.header {
30+
.top {
31+
padding: 0 var(--spacing-xs);
32+
display: flex;
33+
justify-content: space-between;
34+
align-items: center;
35+
height: var(--snippets-view-header-top-height);
36+
}
37+
.name {
38+
font-size: 16px;
39+
}
40+
.action {
41+
display: flex;
42+
}
43+
}
44+
</style>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<div class="snippets-view">
3+
<SnippetHeader />
4+
<TheEditor
5+
v-model="snippet"
6+
v-model:lang="lang"
7+
:fragments="snippetStore.isFragmentsShow"
8+
/>
9+
</div>
10+
</template>
11+
12+
<script setup lang="ts">
13+
import { useSnippetStore } from '@/store/snippets'
14+
import { computed } from 'vue'
15+
16+
const snippetStore = useSnippetStore()
17+
18+
const snippet = computed({
19+
get: () => snippetStore.currentContent || '',
20+
set: v => {
21+
if (!v) return
22+
if (snippetStore.currentContent !== v) {
23+
snippetStore.patchCurrentSnippetContentByKey('value', v)
24+
}
25+
}
26+
})
27+
28+
const lang = computed({
29+
get: () => snippetStore.currentLanguage || 'plain_text',
30+
set: v => {
31+
snippetStore.patchCurrentSnippetContentByKey('language', v)
32+
}
33+
})
34+
</script>
35+
36+
<style lang="scss" scoped>
37+
.snippets-view {
38+
padding-top: var(--title-bar-height);
39+
}
40+
</style>

0 commit comments

Comments
 (0)