Skip to content

Commit 86c885a

Browse files
committed
Add fullscreen and preview hide
1 parent 8379007 commit 86c885a

File tree

7 files changed

+164
-75
lines changed

7 files changed

+164
-75
lines changed

src/components/DefaultConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function set (obj, config) {
1414

1515
export let defaultConfig = {
1616
height: '500px',
17+
previewDisplay: 'normal',
18+
fullscreen: false,
1719
parsers: [
1820
KatexParser
1921
],

src/components/InputArea.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export default {
5757
}
5858
5959
this.$emit('finish')
60-
}
60+
},
61+
height: function (newHeight) {
62+
this.editor.setSize('100%', newHeight)
63+
}
6164
},
6265
data: function () {
6366
return {
Lines changed: 119 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,158 @@
11
<template>
2-
<div id="luogu-markdown-editor" class="editor-container">
2+
<div id="luogu-markdown-editor" class="editor-container" :class="{'fullscreen': this.config.fullscreen}">
33
<div id="editor-toolbar" class="editor-toolbar">
4-
<toolbar @change="insert" @click="clickToolbar" :toolbarConfig="editorConfig.toolbarConfig"></toolbar>
4+
<toolbar @change="insert" @click="clickToolbar" @input="handleToolbarOperation"
5+
:toolbarConfig="editorConfig.toolbarConfig" ref="toolbar"></toolbar>
56
</div>
67
<div id="editor-area">
7-
<div id="editor-input-area" class="editor-area input-area">
8+
<div id="editor-input-area" class="input-area" :class="{
9+
'editor-area': this.config.previewDisplay === 'normal',
10+
'editor-area-full': this.config.previewDisplay === 'hide'
11+
}">
812
<input-area v-model="code"
13+
ref="inputArea"
914
@input="updateCode"
1015
@finish="insertCode = null"
11-
:height="editorConfig.height"
16+
:height="editorHeight"
1217
:insertCode="insertCode"
1318
:editorOption="editorConfig.editorOption"></input-area>
1419
</div>
15-
<div id="editor-preview-area" class="editor-area preview-area" >
16-
<preview-area v-model="code" :height="editorConfig.height" :parsers="editorConfig.parsers"></preview-area>
20+
<div id="editor-preview-area" class="editor-area preview-area" :class="{
21+
'editor-area': this.config.previewDisplay === 'normal',
22+
'editor-area-hide': this.config.previewDisplay === 'hide'
23+
}">
24+
<preview-area v-model="code" :height="editorHeight"
25+
:parsers="editorConfig.parsers" ref="previewArea"></preview-area>
1726
</div>
1827
</div>
1928
<div id="editor-dialog">
20-
<editor-dialog v-if="showDialog" :request="dialogRequest" @finish="dialogFinish" @close="closeDialog"></editor-dialog>
29+
<editor-dialog v-if="showDialog" :request="dialogRequest" @finish="dialogFinish"
30+
@close="closeDialog" ref="dialog"></editor-dialog>
2131
</div>
2232
</div>
2333
</template>
2434

2535
<style>
2636
.editor-area {
27-
width: 49%;
37+
box-sizing: border-box;
38+
width: 50%;
2839
float: left;
2940
border-bottom: 1px solid #ddd;
3041
border-top: 1px solid #ddd;
3142
}
43+
44+
.editor-area-full {
45+
box-sizing: border-box;
46+
width: 100%;
47+
border: 1px solid #ddd;
48+
}
49+
50+
.editor-area-hide {
51+
display: none;
52+
}
53+
3254
.input-area {
3355
border-right: 1px solid #ddd;
3456
border-left: 1px solid #ddd;
3557
}
58+
3659
.preview-area {
3760
border-right: 1px solid #ddd;
3861
}
39-
.editor-toolbar {
40-
width: 98%;
41-
padding-right: 1px;
42-
min-height: 35px;
43-
border-right: 1px solid #ddd;
44-
border-left: 1px solid #ddd;
45-
border-top: 1px solid #ddd;
4662
63+
.fullscreen {
64+
position: fixed;
65+
z-index: 9997;
66+
top: 0;
67+
left: 0;
68+
height: 100%;
69+
width: 100%;
4770
}
4871
</style>
4972

5073
<script>
51-
import InputArea from './InputArea.vue'
52-
import PreviewArea from './PreviewArea.vue'
53-
import Toolbar from './Toolbar.vue'
54-
import EditorDialog from './Dialog.vue'
74+
import InputArea from './InputArea.vue'
75+
import PreviewArea from './PreviewArea.vue'
76+
import Toolbar from './Toolbar.vue'
77+
import EditorDialog from './Dialog.vue'
5578
56-
import { defaultConfig, getConfig } from './DefaultConfig'
79+
import {defaultConfig, getConfig} from './DefaultConfig'
5780
58-
export default {
59-
name: 'luogu-markdown-editor',
60-
props: {
61-
value: {
62-
type: String
63-
},
64-
config: {
65-
type: Object,
66-
default: function () {
67-
return defaultConfig
68-
}
69-
}
70-
},
71-
data () {
72-
return {
73-
code: '',
74-
showDialog: false,
75-
dialogRequest: {},
76-
insertCode: null,
77-
editorConfig: getConfig(this.config)
78-
}
79-
},
80-
mounted () {
81-
this.code = this.value
82-
},
83-
components: {
84-
InputArea,
85-
PreviewArea,
86-
Toolbar,
87-
EditorDialog
88-
},
89-
methods: {
90-
updateCode (code) {
91-
this.$emit('input', code)
92-
},
93-
insert (code) {
94-
if (code !== null) { this.insertCode = code }
95-
},
96-
closeDialog () {
97-
this.showDialog = false
98-
},
99-
dialogFinish (request) {
100-
this.insert(request.callback(request.data))
101-
this.closeDialog()
102-
},
103-
clickToolbar (request) {
104-
if (this.showDialog) { return }
105-
this.dialogRequest = request
106-
this.showDialog = true
81+
export default {
82+
name: 'luogu-markdown-editor',
83+
props: {
84+
value: {
85+
type: String
86+
},
87+
config: {
88+
type: Object,
89+
default: function () {
90+
return defaultConfig
91+
}
92+
}
93+
},
94+
data() {
95+
let config = getConfig(this.config)
96+
return {
97+
code: '',
98+
showDialog: false,
99+
dialogRequest: {},
100+
insertCode: null,
101+
editorConfig: config,
102+
editorHeight: config.height
103+
}
104+
},
105+
mounted() {
106+
this.code = this.value
107+
},
108+
components: {
109+
InputArea,
110+
PreviewArea,
111+
Toolbar,
112+
EditorDialog
113+
},
114+
methods: {
115+
updateCode(code) {
116+
this.$emit('input', code)
117+
},
118+
insert(code) {
119+
if (code !== null) {
120+
this.insertCode = code
121+
}
122+
},
123+
closeDialog() {
124+
this.showDialog = false
125+
},
126+
dialogFinish(request) {
127+
this.insert(request.callback(request.data))
128+
this.closeDialog()
129+
},
130+
clickToolbar(request) {
131+
if (this.showDialog) {
132+
return
133+
}
134+
this.dialogRequest = request
135+
this.showDialog = true
136+
},
137+
handleToolbarOperation(operation) {
138+
if (operation === 'hide') {
139+
if (this.config.previewDisplay === 'normal')
140+
this.config.previewDisplay = 'hide'
141+
else
142+
this.config.previewDisplay = 'normal'
143+
}
144+
if (operation === 'fullscreen') {
145+
if(!this.config.fullscreen) {
146+
this.config.fullscreen = true
147+
this.editorHeight = (screen.height - this.$refs.toolbar.$el.clientHeight).toString() + 'px'
148+
console.log(this.editorHeight)
149+
150+
} else {
151+
this.config.fullscreen = false
152+
this.editorHeight = this.editorConfig.height
153+
}
154+
}
155+
}
156+
}
107157
}
108-
}
109-
}
110158
</script>

src/components/Toolbar.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
</template>
1313

1414
<style>
15+
16+
#toolbar {
17+
box-sizing: border-box;
18+
width: 100%;
19+
padding-right: 1px;
20+
min-height: 35px;
21+
border-right: 1px solid #ddd;
22+
border-left: 1px solid #ddd;
23+
border-top: 1px solid #ddd;
24+
}
25+
1526
#editor-menu>li>a {
1627
outline: 0;
1728
color: #666;
@@ -98,9 +109,13 @@ export default {
98109
this.$emit('click', request)
99110
},
100111
handleAction (action) {
101-
if (action.insert) {
112+
if(action.event) {
113+
this.$emit('input', action.event)
114+
}
115+
else if (action.insert) {
102116
this.insertCode(action.insert)
103-
} else if (action.request) {
117+
}
118+
else if (action.request) {
104119
this.requestData(action.request)
105120
}
106121
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
name: 'fullscreen',
3+
icon: 'fa-arrows-alt',
4+
title: '全屏',
5+
action: {
6+
event: 'fullscreen'
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
name: 'hide',
3+
icon: 'fa-eye',
4+
title: '隐藏',
5+
action: {
6+
event: 'hide'
7+
}
8+
}

src/components/toolbar-button/toolbarBtn.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import BtnUl from './btn-ul'
1010
import BtnOl from './btn-ol'
1111
import BtnHr from './btn-hr'
1212
import BtnCode from './btn-code'
13+
import BtnHide from './btn-hide'
14+
import BtnFullscreen from './btn-fullscreen'
1315

1416
export let defaultBtns = [
1517
BtnBold,
@@ -30,7 +32,10 @@ export let defaultBtns = [
3032
BtnImg,
3133
BtnLink,
3234
BtnCode,
33-
BtnTable
35+
BtnTable,
36+
Divider,
37+
BtnHide,
38+
BtnFullscreen
3439
]
3540

3641
function getDefaultBtnsMap () {

0 commit comments

Comments
 (0)