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 >
0 commit comments