Skip to content

Commit b2fc835

Browse files
committed
Responsive edit area and toolbar
1 parent 37274f4 commit b2fc835

File tree

6 files changed

+76
-29
lines changed

6 files changed

+76
-29
lines changed

src/components/DefaultConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import KatexParser from '@luogu-dev/markdown-it-katex'
22
import 'katex/dist/katex.css'
33
import HighlightjsParser from './plugins/HighlightjsParser'
44
import 'highlight.js/styles/tomorrow.css'
5-
import { defaultBtns, getBtns } from './toolbar-button/toolbarBtn'
5+
import { defaultBtns, defaultSimpleBtns, getBtns } from './toolbar-button/toolbarBtn'
66
import _ from 'lodash'
77

88
function mixin (dest, src) {
@@ -24,6 +24,8 @@ export const defaultConfig = {
2424
HighlightjsParser
2525
],
2626
toolbarConfig: defaultBtns,
27+
bigScreenToolbarConfig: defaultBtns,
28+
smallScreenToolbarConfig: defaultSimpleBtns,
2729
editorOption: {
2830
mode: 'gfm',
2931
lineNumbers: true,

src/components/Dialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<form class="mp-dialog-body" @submit.prevent="finish">
1313
<div class="mp-dialog-form">
14-
<div class="mp-dialog-field" v-for="field in request.body">
14+
<div class="mp-dialog-field" v-for="field in request.body" :key="field.name">
1515
<component :is="field.type || field.component" :request-field="field" v-model="responseData[field.name]"></component>
1616
</div>
1717
</div>

src/components/MarkdownPalettes.vue

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="mp-editor-container" :class="{'mp-full-screen': this.fullScreen}">
3-
<div class="mp-editor-toolbar">
4-
<ul class="mp-editor-menu" v-if="toolbarConfig.length > 0">
5-
<li v-for="(item, index) in toolbarConfig" :class="{'mp-divider':item.name === '|'}" :key="item.name + index">
3+
<div class="mp-editor-toolbar" v-if="toolbarBtns.length">
4+
<ul class="mp-editor-menu">
5+
<li v-for="(item, index) in toolbarBtns" :class="{'mp-divider':item.name === '|'}" :key="item.name + index">
66
<span v-if="item.name === '|'">|</span>
77
<a v-else :title="t(ensureValue(item.title))" @click="toolbarAction(item)" unselectable="on">
88
<i :class="['fa', ensureValue(item.icon)]" unselectable="on">{{ ensureValue(item.content) }}</i>
@@ -13,13 +13,15 @@
1313
<div class="mp-editor-ground">
1414
<div class="mp-editor-zone mp-input-zone" :class="{
1515
'mp-editor-zone': previewDisplay === 'normal',
16-
'mp-editor-zone-full': previewDisplay === 'hide'
16+
'mp-editor-zone-full': previewDisplay === 'hide',
17+
'mp-editor-zone-hide': previewDisplay === 'full'
1718
}">
1819
<div class="mp-input-area" ref="inputArea"></div>
1920
</div>
2021
<div class="mp-editor-zone mp-preview-zone" :class="{
2122
'mp-editor-zone': previewDisplay === 'normal',
22-
'mp-editor-zone-hide': previewDisplay === 'hide'
23+
'mp-editor-zone-hide': previewDisplay === 'hide',
24+
'mp-editor-zone-full': previewDisplay === 'full'
2325
}">
2426
<div class="mp-preview-area" ref="previewArea" @scroll="previewAreaScroll">
2527
<div class="mp-preview-content" ref="previewContent" v-html="previewContent"></div>
@@ -34,6 +36,29 @@
3436
</template>
3537

3638
<style scoped lang="stylus">
39+
.mp-editor-zone
40+
height: 100%
41+
.mp-input-zone
42+
box-sizing: border-box
43+
width: 100%
44+
height: 100%
45+
.mp-preview-zone
46+
display: none
47+
48+
.mp-editor-zone-full
49+
display: block
50+
box-sizing: border-box
51+
width: 100%
52+
border: none !important
53+
.mp-editor-zone-hide
54+
display: none !important
55+
@media only screen and (min-width: 768px)
56+
.mp-editor-zone
57+
display block
58+
box-sizing: border-box
59+
width: 50%
60+
float: left
61+
3762
.mp-editor-container
3863
position:relative
3964
height: 100%
@@ -59,18 +84,6 @@
5984
bottom: 0
6085
overflow: hidden
6186
border-top: 1px solid #ddd
62-
63-
.mp-editor-zone
64-
box-sizing: border-box
65-
width: 50%
66-
height: 100%
67-
float: left
68-
.mp-editor-zone-full
69-
box-sizing: border-box
70-
width: 100%
71-
.mp-editor-zone-hide
72-
display: none
73-
7487
.mp-preview-zone
7588
border-left: 1px solid #ddd
7689
padding-bottom: 2px
@@ -129,6 +142,7 @@
129142
.mp-editor-menu>li>a
130143
outline: 0
131144
color: #666
145+
cursor pointer
132146
display: inline-block
133147
min-width: 24px
134148
font-size: 16px
@@ -198,7 +212,16 @@ export default {
198212
}
199213
},
200214
computed: {
201-
contentParser () { return contentParserFactory([...this.parsers, InjectLnParser]) }
215+
contentParser () {
216+
return contentParserFactory([...this.parsers, InjectLnParser])
217+
},
218+
toolbarBtns () {
219+
if (window.screen.width > 768) {
220+
return this.config.bigScreenToolbarConfig
221+
} else {
222+
return this.config.smallScreenToolbarConfig
223+
}
224+
}
202225
},
203226
methods: {
204227
setCode (code) {

src/components/ToolbarMixin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export default {
1919
toolbarHandleEventLegacy (event) {
2020
if (event === 'hide') {
2121
if (this.previewDisplay === 'normal') {
22-
this.previewDisplay = 'hide'
22+
if (window.screen.width > 768) {
23+
this.previewDisplay = 'hide'
24+
} else {
25+
this.previewDisplay = 'full'
26+
}
2327
} else {
2428
this.previewDisplay = 'normal'
2529
}

src/components/toolbar-button/btn-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function header (level) {
1+
export default function headerFactory (level) {
22
return {
33
name: 'h' + level,
44
icon: 'icon-blold',

src/components/toolbar-button/toolbarBtn.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Divider from './divider'
55
import BtnImg from './btn-img'
66
import BtnLink from './btn-link'
77
import BtnTable from './btn-table'
8-
import BtnsHeader from './btn-header'
8+
import BtnsHeaderFactory from './btn-header'
99
import BtnUl from './btn-ul'
1010
import BtnOl from './btn-ol'
1111
import BtnHr from './btn-hr'
@@ -21,12 +21,12 @@ export const defaultBtns = [
2121
BtnItalic,
2222
BtnHr,
2323
Divider,
24-
BtnsHeader(1),
25-
BtnsHeader(2),
26-
BtnsHeader(3),
27-
BtnsHeader(4),
28-
BtnsHeader(5),
29-
BtnsHeader(6),
24+
BtnsHeaderFactory(1),
25+
BtnsHeaderFactory(2),
26+
BtnsHeaderFactory(3),
27+
BtnsHeaderFactory(4),
28+
BtnsHeaderFactory(5),
29+
BtnsHeaderFactory(6),
3030
Divider,
3131
BtnUl,
3232
BtnOl,
@@ -43,6 +43,24 @@ export const defaultBtns = [
4343
BtnInfo
4444
]
4545

46+
export const defaultSimpleBtns = [
47+
BtnBold,
48+
BtnStrikeThrough,
49+
BtnItalic,
50+
BtnHr,
51+
BtnsHeaderFactory(1),
52+
BtnsHeaderFactory(2),
53+
BtnsHeaderFactory(3),
54+
BtnUl,
55+
BtnOl,
56+
BtnImg,
57+
BtnLink,
58+
BtnTable,
59+
BtnHide,
60+
BtnFullscreen,
61+
BtnInfo
62+
]
63+
4664
function getDefaultBtnsMap () {
4765
const btnsMap = {}
4866
defaultBtns.forEach(function (btn) {

0 commit comments

Comments
 (0)