Skip to content

Commit 2f6f036

Browse files
committed
editor improves
1 parent 2e8edc6 commit 2f6f036

File tree

4 files changed

+83
-17
lines changed

4 files changed

+83
-17
lines changed

src/components/Editor.vue

+64-12
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,99 @@
11
<template>
22
<div class="editor">
3-
<div class="header">
4-
5-
</div>
3+
<spinner v-if="loading"/>
64
<iframe src="https://ide.wy-lang.org/embed?show-bars" ref="iframe"/>
75
</div>
86
</template>
97

108
<script>
9+
import Spinner from './Spinner.vue'
10+
1111
export default {
1212
name: 'Editor',
1313
props: {
1414
snippet: Object
1515
},
16+
data() {
17+
return {
18+
loading: true,
19+
}
20+
},
21+
components: {
22+
Spinner,
23+
},
1624
methods: {
17-
updateCode() {
25+
send(data){
26+
this.$refs.iframe.contentWindow.postMessage(data, '*')
27+
},
28+
initEditor() {
1829
this.$refs.iframe.onload = () => {
19-
this.$refs.iframe.contentWindow.postMessage({ action: 'config', field:'title', value: this.snippet.title }, '*')
20-
this.$refs.iframe.contentWindow.postMessage({ action: 'code', value: this.snippet.code }, '*')
21-
this.$refs.iframe.contentWindow.postMessage({ action: 'run' }, '*')
30+
this.send({
31+
action: 'custom',
32+
value: [{
33+
id: 'save',
34+
icon: 'content-save',
35+
}, {
36+
id: 'fullscreen',
37+
icon: 'fullscreen',
38+
align: 'right'
39+
}]
40+
})
41+
this.send({ action: 'config', field: 'title', value: this.snippet.title })
42+
this.send({ action: 'code', value: this.snippet.code })
43+
this.send({ action: 'run' })
44+
this.loading = false
45+
}
46+
},
47+
registerListener () {
48+
window.addEventListener('message', this.onListener)
49+
},
50+
unregisterListener(){
51+
window.removeEventListener('message', this.onListener)
52+
},
53+
onListener(e) {
54+
const { action, source, id } = e.data
55+
if (source !== 'wenyan-ide')
56+
return
57+
if (action === 'custom'){
58+
switch (id){
59+
case 'fullscreen':
60+
this.$emit('fullscreen', true)
61+
}
2262
}
2363
}
2464
},
25-
watch:{
65+
watch: {
2666
snippet() {
27-
this.updateCode()
67+
this.initEditor()
2868
}
2969
},
30-
mounted(){
31-
this.updateCode()
70+
mounted() {
71+
this.registerListener()
72+
this.initEditor()
73+
},
74+
destroyed() {
75+
this.unregisterListener()
3276
}
3377
}
3478
</script>
3579

3680
<style lang="stylus" scoped>
3781
.editor
3882
border 1px solid gainsboro
39-
border-radius 5px
4083
background white
84+
position relative
85+
height 100%
86+
width 100%
4187
4288
iframe
4389
border 0
4490
width 100%
4591
min-height 30rem
4692
height 100%
93+
94+
.spinner
95+
position absolute
96+
top 50%
97+
left 50%
98+
transform translate(-50%, -50%)
4799
</style>

src/components/Home.vue

+17-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
/>
1919
</div>
2020
<div class="modal" v-if="editing" @click='editing = null'>
21-
<div class="dialog">
22-
<editor :snippet="editing"></editor>
21+
<div class="dialog" :class="{fullscreen: editingFullscreen}">
22+
<editor
23+
:snippet="editing"
24+
@fullscreen="i=>editingFullscreen=i"
25+
></editor>
2326
</div>
2427
</div>
2528
<spinner v-show="loading"/>
@@ -47,7 +50,8 @@ export default {
4750
snippets: [],
4851
page: 0,
4952
totalPages: 9999,
50-
editing: null
53+
editing: null,
54+
editingFullscreen: false,
5155
}
5256
},
5357
computed: {
@@ -149,6 +153,16 @@ $max-width = 85rem
149153
top 5rem
150154
bottom 5rem
151155
right 5rem
156+
border-radius 5px
157+
overflow hidden
158+
159+
&.fullscreen
160+
left 0
161+
top 0
162+
bottom 0
163+
right 0
164+
height 100vh
165+
border-radius 0
152166
153167
.end-of-pages
154168
padding 2rem

src/components/SnippetPreview.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div class='right-aligned'>
99
<icon-button @click.native="openAndRun" icon="play"/>
10-
<icon-button @click.native="edit" icon="pencil"/>
10+
<icon-button @click.native="edit" icon="pencil" v-if="snippet.token === 'public'"/>
1111
<icon-button @click.native="fork" icon="source-fork"/>
1212
</div>
1313
</div>

src/components/Spinner.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div style="text-align:center">
2+
<div class="spinner" style="text-align:center">
33
<span class="lds-ring">
44
<div></div>
55
</span>

0 commit comments

Comments
 (0)