Skip to content

Commit 78a4475

Browse files
committed
feat(vue-playground): add style for editor
1 parent 227d1a9 commit 78a4475

File tree

6 files changed

+137
-77
lines changed

6 files changed

+137
-77
lines changed

packages/doc-site/.vuepress/plugins/vuepress-plugin-demo/client/playground/components/preview.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {Preview, PreviewProxy} from '../../core/'
2121
import {CLEAR_CONSOLE_INJECT_KEY, STORE_INJECT_KEY} from '../constants'
2222
2323
const store = inject(STORE_INJECT_KEY)!
24-
const clearConsole = computed(() => unref(inject(CLEAR_CONSOLE_INJECT_KEY)))
24+
const _clearConsole = inject(CLEAR_CONSOLE_INJECT_KEY)!
25+
const clearConsole = computed(() => unref(_clearConsole))
2526
const container = ref<HTMLElement>()
2627
const runtimeError = ref()
2728
const runtimeWarning = ref()

packages/vue-playground/src/playground/components/editor.vue

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {debounce, File} from '../../core'
1010
import {STORE_INJECT_KEY} from '../constants'
1111
import {useMonaco} from '../hooks/useMonaco'
1212
import {EditorExpose, PlaygroundLifeCycle} from '../utils/types-helper'
13-
import FileManageBar from './file-manage-bar.vue'
13+
import FileManagerBar from './file-manager-bar.vue'
1414
import Message from './message.vue'
1515
1616
const props = defineProps({
@@ -58,19 +58,36 @@ onChange(handleChange)
5858
</script>
5959

6060
<template>
61-
<div>
62-
<FileManageBar />
63-
<div class="editor-container">
64-
<div ref="editorEl" style="width: 100%; height: 600px"></div>
61+
<div class="vue-playground-editor">
62+
<FileManagerBar />
63+
<div class="vue-playground-editor-container">
64+
<div ref="editorEl" class="vue-playground-editor-monaco"></div>
6565
<Message :err="store.state.errors[0]" />
6666
</div>
6767
</div>
6868
</template>
6969

7070
<style scoped>
71-
.editor-container {
71+
.vue-playground-editor {
7272
position: relative;
73-
height: calc(100% - var(--header-height));
73+
flex: 1;
74+
width: 100%;
75+
height: 50%;
76+
min-height: 320px;
77+
border-top: 1px solid #e5e7eb;
78+
}
79+
80+
.vue-playground-editor-container {
81+
position: absolute;
82+
top: 40px;
83+
flex: 1;
84+
width: 100%;
85+
height: calc(100% - 40px);
7486
overflow: hidden;
7587
}
88+
.vue-playground-editor-monaco {
89+
top: 0;
90+
width: 100%;
91+
height: 100%;
92+
}
7693
</style>

packages/vue-playground/src/playground/components/file-manage-bar.vue renamed to packages/vue-playground/src/playground/components/file-manager-bar.vue

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ function doneAddFile() {
4545
pendingFilename.value = DEFAULT_FILE_NAME
4646
}
4747
48-
const fileSel = ref(null)
48+
const fileManagerBarRef = ref(null)
4949
function horizontalScroll(e: WheelEvent) {
5050
e.preventDefault()
51-
const el = fileSel.value! as HTMLElement
51+
const el = fileManagerBarRef.value! as HTMLElement
5252
const direction = Math.abs(e.deltaX) >= Math.abs(e.deltaY) ? e.deltaX : e.deltaY
5353
const distance = 30 * (direction > 0 ? 1 : -1)
5454
el.scrollTo({
@@ -58,23 +58,30 @@ function horizontalScroll(e: WheelEvent) {
5858
</script>
5959

6060
<template>
61-
<div ref="fileSel" class="file-selector" :class="{'has-import-map': showImportMap}" @wheel="horizontalScroll">
61+
<div
62+
ref="fileManagerBarRef"
63+
class="vue-playground-file-manager-bar"
64+
:class="{'vue-playground-file-manager-bar-has-import-map': showImportMap}"
65+
@wheel="horizontalScroll"
66+
>
6267
<div
6368
v-for="(fileName, i) in fileNames"
6469
:key="i"
65-
class="file"
66-
:class="{active: store.state.activeFile.filename === fileName}"
70+
class="vue-playground-file-manager-bar-file"
71+
:class="{'vue-playground-file-manager-bar-file-active': store.state.activeFile.filename === fileName}"
6772
@click="store.setActive(fileName)"
6873
>
69-
<span class="label">{{ fileName === importMapFile ? 'Import Map' : fileName }}</span>
70-
<span v-if="i > 0" class="remove" @click.stop="store.deleteFile(fileName)">
71-
<svg class="icon" width="12" height="12" viewBox="0 0 24 24">
74+
<span class="vue-playground-file-manager-bar-file-filename">{{
75+
fileName === importMapFile ? 'Import Map' : fileName
76+
}}</span>
77+
<span v-if="i > 0" class="vue-playground-file-manager-bar-file-remove" @click.stop="store.deleteFile(fileName)">
78+
<svg class="vue-playground-file-manager-bar-file-remove-icon" width="12" height="12" viewBox="0 0 24 24">
7279
<line stroke="#999" x1="18" y1="6" x2="6" y2="18"></line>
7380
<line stroke="#999" x1="6" y1="6" x2="18" y2="18"></line>
7481
</svg>
7582
</span>
7683
</div>
77-
<div v-if="pending" class="file pending">
84+
<div v-if="pending" class="vue-playground-file-manager-bar-pending">
7885
<input
7986
v-model="pendingFilename"
8087
spellcheck="false"
@@ -84,112 +91,141 @@ function horizontalScroll(e: WheelEvent) {
8491
@vnodeMounted="focus"
8592
/>
8693
</div>
87-
<button class="add" @click="startAddFile">+</button>
8894

89-
<div v-if="showImportMap" class="import-map-wrapper">
95+
<div class="vue-playground-file-manager-bar-create-btn" @click="startAddFile">+</div>
96+
97+
<div v-if="showImportMap" class="vue-playground-file-manager-bar-import-map-wrapper">
9098
<div
91-
class="file import-map"
99+
class="vue-playground-file-manager-bar-import-map"
92100
:class="{active: store.state.activeFile.filename === importMapFile}"
93101
@click="store.setActive(importMapFile)"
94102
>
95-
<span class="label">Import Map</span>
103+
<span class="vue-playground-file-manager-bar-import-map-name">Import Map</span>
96104
</div>
97105
</div>
98106
</div>
99107
</template>
100108

101109
<style scoped>
102-
.file-selector {
110+
.vue-playground-file-manager-bar {
103111
position: relative;
104112
box-sizing: border-box;
105113
display: flex;
106-
height: var(--header-height);
114+
flex-shrink: 0;
115+
width: 100%;
116+
height: 40px;
107117
overflow-x: auto;
108118
overflow-y: hidden;
109119
white-space: nowrap;
110-
background-color: var(--bg);
111-
border-bottom: 1px solid var(--border);
120+
background-color: #fff;
121+
border-bottom: 1px solid #e5e7eb;
112122
}
113123
114-
.file-selector::-webkit-scrollbar {
124+
.vue-playground-file-manager-bar::-webkit-scrollbar {
115125
height: 1px;
116126
}
117127
118-
.file-selector::-webkit-scrollbar-track {
119-
background-color: var(--border);
128+
.vue-playground-file-manager-bar::-webkit-scrollbar-track {
129+
background-color: #e5e7eb;
120130
}
121131
122-
.file-selector::-webkit-scrollbar-thumb {
123-
background-color: var(--color-branding);
132+
.vue-playground-file-manager-bar::-webkit-scrollbar-thumb {
133+
background-color: #584984;
124134
}
125135
126-
.file-selector.has-import-map .add {
136+
.vue-playground-file-manager-bar-has-import-map .vue-playground-file-manager-bar-create-btn {
127137
margin-right: 10px;
128138
}
129139
130-
.file {
140+
.vue-playground-file-manager-bar-file {
131141
box-sizing: border-box;
132-
display: inline-block;
133-
font-family: var(--font-code);
134-
font-size: 13px;
135-
color: var(--text-light);
142+
display: flex;
143+
align-items: center;
144+
justify-content: center;
145+
padding: 0 8px;
146+
margin: 2px 2px 0;
147+
font-size: 12px;
148+
font-weight: 600;
149+
color: #94a3b8;
136150
cursor: pointer;
151+
user-select: none;
152+
border-bottom: 3px solid transparent;
137153
}
138-
.file.active {
139-
color: var(--color-branding);
154+
155+
.vue-playground-file-manager-bar-file-active {
156+
color: #584984;
140157
cursor: text;
141-
border-bottom: 3px solid var(--color-branding);
158+
border-bottom: 3px solid #584984;
142159
}
143-
.file span {
144-
display: inline-block;
160+
161+
.vue-playground-file-manager-bar-file span {
162+
display: flex;
145163
padding: 8px 10px 6px;
146164
line-height: 20px;
147165
}
148-
.file.pending input {
166+
167+
.vue-playground-file-manager-bar-file-remove {
168+
display: flex;
169+
padding-left: 0;
170+
line-height: 12px;
171+
vertical-align: middle;
172+
cursor: pointer;
173+
}
174+
175+
.vue-playground-file-manager-bar-file-remove-icon {
176+
margin-top: -1px;
177+
}
178+
179+
.vue-playground-file-manager-bar-pending {
180+
display: flex;
181+
align-items: center;
182+
justify-content: center;
183+
}
184+
185+
.vue-playground-file-manager-bar-pending input {
149186
width: 90px;
150187
height: 30px;
151188
padding: 0 0 0 10px;
152189
margin-top: 2px;
153190
margin-left: 6px;
154-
font-family: var(--font-code);
155191
font-size: 12px;
156192
line-height: 30px;
157-
border: 1px solid var(--border);
193+
color: #584984;
194+
border: 1px solid #584984;
158195
border-radius: 4px;
159196
outline: none;
160197
}
161-
.file .remove {
162-
display: inline-block;
163-
padding-left: 0;
164-
line-height: 12px;
165-
vertical-align: middle;
166-
cursor: pointer;
167-
}
168-
.add {
169-
position: relative;
170-
top: -1px;
198+
199+
.vue-playground-file-manager-bar-create-btn {
200+
display: flex;
201+
align-items: center;
202+
justify-content: center;
171203
margin-left: 6px;
172-
font-family: var(--font-code);
173204
font-size: 18px;
174-
color: #999;
175-
vertical-align: middle;
176-
}
177-
.add:hover {
178-
color: var(--color-branding);
205+
color: #94a3b8;
206+
cursor: pointer;
179207
}
180-
.icon {
181-
margin-top: -1px;
208+
209+
.vue-playground-file-manager-bar-create-btn:hover {
210+
color: #584984;
182211
}
183-
.import-map-wrapper {
212+
213+
.vue-playground-file-manager-bar-import-map-wrapper {
184214
position: sticky;
185215
top: 0;
186216
right: 0;
187-
padding-left: 30px;
217+
display: flex;
218+
align-items: center;
219+
justify-content: center;
220+
padding: 0 15px;
188221
margin-left: auto;
222+
font-size: 12px;
223+
color: #94a3b8;
224+
cursor: pointer;
189225
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 25%);
190-
background-color: var(--bg);
191226
}
192-
.dark .import-map-wrapper {
227+
228+
.vue-playground-dark .vue-playground-file-manager-bar-import-map-wrapper {
193229
background: linear-gradient(90deg, rgba(26, 26, 26, 0) 0%, rgba(26, 26, 26, 1) 25%);
194230
}
195231
</style>

packages/vue-playground/src/playground/components/preview.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {CLEAR_CONSOLE_INJECT_KEY, STORE_INJECT_KEY} from '../constants'
2222
import {PreviewExpose} from '../utils/types-helper'
2323
2424
const store = inject(STORE_INJECT_KEY)!
25-
const clearConsole = computed(() => unref(inject(CLEAR_CONSOLE_INJECT_KEY)))
25+
const _clearConsole = inject(CLEAR_CONSOLE_INJECT_KEY, false)
26+
const clearConsole = computed(() => unref(_clearConsole))
2627
const container = ref<HTMLElement>()
2728
const runtimeError = ref()
2829
const runtimeWarning = ref()

packages/vue-playground/src/playground/playground.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ defineExpose({
3838
} as PlaygroundExpose)
3939
</script>
4040
<template>
41-
<div>
41+
<div class="vue-playground">
4242
vue playground
43-
<preview></preview>
44-
<editor ref="editorRef" :life-cycle="options.lifeCycle"></editor>
43+
<Preview></Preview>
44+
<Editor ref="EditorRef" :life-cycle="options.lifeCycle"></Editor>
4545
</div>
4646
</template>
47-
<style lang="scss" scoped></style>
47+
<style scoped>
48+
.vue-playground {
49+
position: relative;
50+
display: flex;
51+
flex-direction: column;
52+
overflow: hidden;
53+
background-color: #fff;
54+
border: 1px solid #e5e7eb;
55+
border-radius: 8px;
56+
}
57+
</style>

packages/vuepress-plugin-sandbox/src/enhanceAppFile.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ import {defineClientAppEnhance} from '@vuepress/client'
33
import {ConcreteComponent, DefineComponent, h, resolveComponent} from 'vue'
44
import * as base64 from 'js-base64'
55
import {SANDBOX_COMPONENT_NAME} from './constants'
6-
import css from '../node_modules/vue-playground/dist/style.css'
6+
import 'vue-playground/dist/style.css'
77

88
export default defineClientAppEnhance(async ({app}) => {
99
let Playground: DefineComponent<{}, {}, any> | undefined
1010

1111
if (!__VUEPRESS_SSR__) {
12-
// add playground styles to global
13-
const styleEl = document.createElement('style')
14-
styleEl.innerHTML = css
15-
document.head.appendChild(styleEl)
16-
1712
// load playground
1813
const VuePlayground = await import('vue-playground')
1914
Playground = VuePlayground.Playground

0 commit comments

Comments
 (0)