Stackedit/src/components/Layout.vue

197 lines
6.6 KiB
Vue
Raw Normal View History

2017-07-23 18:42:08 +00:00
<template>
2017-11-26 20:58:24 +00:00
<div class="layout" :class="{'layout--revision': revisionContent}">
2017-10-02 00:34:48 +00:00
<div class="layout__panel flex flex--row" :class="{'flex--end': styles.showSideBar}">
2017-11-15 08:12:56 +00:00
<div class="layout__panel layout__panel--explorer" v-show="styles.showExplorer" :aria-hidden="!styles.showExplorer" :style="{width: styles.layoutOverflow ? '100%' : constants.explorerWidth + 'px'}">
2017-07-28 20:04:12 +00:00
<explorer></explorer>
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel flex flex--column" :style="{width: styles.innerWidth + 'px'}">
<div class="layout__panel layout__panel--navigation-bar" v-show="styles.showNavigationBar" :style="{height: constants.navigationBarHeight + 'px'}">
2017-07-28 20:04:12 +00:00
<navigation-bar></navigation-bar>
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel flex flex--row" :style="{height: styles.innerHeight + 'px'}">
<div class="layout__panel layout__panel--editor" v-show="styles.showEditor" :style="{width: (styles.editorWidth + styles.editorGutterWidth) + 'px', fontSize: styles.fontSize + 'px'}">
<div class="gutter" :style="{left: styles.editorGutterLeft + 'px'}">
<div class="gutter__background" v-if="styles.editorGutterWidth" :style="{width: styles.editorGutterWidth + 'px'}"></div>
</div>
2017-07-28 20:04:12 +00:00
<editor></editor>
2017-11-15 08:12:56 +00:00
<div class="gutter" :style="{left: styles.editorGutterLeft + 'px'}">
<sticky-comment v-if="styles.editorGutterWidth && stickyComment === 'top'"></sticky-comment>
<current-discussion v-if="styles.editorGutterWidth"></current-discussion>
</div>
<div class="layout__panel layout__panel--find-replace" v-if="showFindReplace">
<find-replace></find-replace>
</div>
2017-07-28 20:04:12 +00:00
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel layout__panel--button-bar" v-show="styles.showEditor" :style="{width: constants.buttonBarWidth + 'px'}">
2017-07-23 18:42:08 +00:00
<button-bar></button-bar>
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel layout__panel--preview" v-show="styles.showPreview" :style="{width: (styles.previewWidth + styles.previewGutterWidth) + 'px', fontSize: styles.fontSize + 'px'}">
<div class="gutter" :style="{left: styles.previewGutterLeft + 'px'}">
<div class="gutter__background" v-if="styles.previewGutterWidth" :style="{width: styles.previewGutterWidth + 'px'}"></div>
</div>
2017-07-23 18:42:08 +00:00
<preview></preview>
2017-11-15 08:12:56 +00:00
<div class="gutter" :style="{left: styles.previewGutterLeft + 'px'}">
<sticky-comment v-if="styles.previewGutterWidth && stickyComment === 'top'"></sticky-comment>
<current-discussion v-if="styles.previewGutterWidth"></current-discussion>
</div>
2017-07-23 18:42:08 +00:00
</div>
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel layout__panel--status-bar" v-show="styles.showStatusBar" :style="{height: constants.statusBarHeight + 'px'}">
2017-07-28 20:04:12 +00:00
<status-bar></status-bar>
2017-07-23 18:42:08 +00:00
</div>
</div>
2017-11-15 08:12:56 +00:00
<div class="layout__panel layout__panel--side-bar" v-show="styles.showSideBar" :style="{width: styles.layoutOverflow ? '100%' : constants.sideBarWidth + 'px'}">
2017-07-28 20:04:12 +00:00
<side-bar></side-bar>
2017-07-23 18:42:08 +00:00
</div>
</div>
</div>
</template>
<script>
2017-11-15 08:12:56 +00:00
import { mapState, mapGetters, mapActions } from 'vuex';
2017-07-23 18:42:08 +00:00
import NavigationBar from './NavigationBar';
import ButtonBar from './ButtonBar';
import StatusBar from './StatusBar';
2017-07-28 20:04:12 +00:00
import Explorer from './Explorer';
import SideBar from './SideBar';
2017-07-23 18:42:08 +00:00
import Editor from './Editor';
import Preview from './Preview';
2017-11-15 08:12:56 +00:00
import StickyComment from './gutters/StickyComment';
import CurrentDiscussion from './gutters/CurrentDiscussion';
import FindReplace from './FindReplace';
2017-07-23 18:42:08 +00:00
import editorSvc from '../services/editorSvc';
export default {
components: {
NavigationBar,
ButtonBar,
StatusBar,
2017-07-28 20:04:12 +00:00
Explorer,
SideBar,
2017-07-23 18:42:08 +00:00
Editor,
Preview,
2017-11-15 08:12:56 +00:00
StickyComment,
CurrentDiscussion,
FindReplace,
2017-07-23 18:42:08 +00:00
},
2017-07-31 09:04:01 +00:00
computed: {
2017-11-26 20:58:24 +00:00
...mapState('content', [
'revisionContent',
]),
2017-11-15 08:12:56 +00:00
...mapState('discussion', [
'stickyComment',
]),
2017-07-31 09:04:01 +00:00
...mapGetters('layout', [
2017-08-06 00:58:39 +00:00
'constants',
2017-07-31 09:04:01 +00:00
'styles',
]),
showFindReplace() {
return !!this.$store.state.findReplace.type;
},
2017-07-31 09:04:01 +00:00
},
2017-07-23 18:42:08 +00:00
methods: {
2017-11-05 20:54:12 +00:00
...mapActions('layout', [
2017-07-31 09:04:01 +00:00
'updateBodySize',
2017-07-23 18:42:08 +00:00
]),
saveSelection: () => editorSvc.saveSelection(true),
},
created() {
2017-07-31 09:04:01 +00:00
this.updateBodySize();
window.addEventListener('resize', this.updateBodySize);
2017-07-23 18:42:08 +00:00
window.addEventListener('keyup', this.saveSelection);
window.addEventListener('mouseup', this.saveSelection);
window.addEventListener('focusin', this.saveSelection);
2017-07-23 18:42:08 +00:00
window.addEventListener('contextmenu', this.saveSelection);
},
mounted() {
const editorElt = this.$el.querySelector('.editor__inner');
const previewElt = this.$el.querySelector('.preview__inner-2');
2017-07-23 18:42:08 +00:00
const tocElt = this.$el.querySelector('.toc__inner');
editorSvc.init(editorElt, previewElt, tocElt);
// Focus on the editor every time reader mode is disabled
this.$watch(() => this.styles.showEditor,
showEditor => showEditor && editorSvc.clEditor.focus());
2017-07-23 18:42:08 +00:00
},
destroyed() {
window.removeEventListener('resize', this.updateStyle);
2017-08-06 00:58:39 +00:00
window.removeEventListener('keyup', this.saveSelection);
window.removeEventListener('mouseup', this.saveSelection);
window.removeEventListener('focusin', this.saveSelection);
2017-08-06 00:58:39 +00:00
window.removeEventListener('contextmenu', this.saveSelection);
2017-07-23 18:42:08 +00:00
},
};
</script>
<style lang="scss">
@import 'common/variables.scss';
2017-07-28 20:04:12 +00:00
.layout {
2017-07-23 18:42:08 +00:00
position: absolute;
width: 100%;
height: 100%;
}
2017-07-28 20:04:12 +00:00
.layout__panel {
position: relative;
width: 100%;
height: 100%;
flex: none;
overflow: hidden;
2017-07-23 18:42:08 +00:00
}
2017-07-28 20:04:12 +00:00
.layout__panel--navigation-bar {
2017-12-17 15:08:52 +00:00
background-color: $navbar-bg;
2017-07-23 18:42:08 +00:00
}
.layout__panel--status-bar {
background-color: #007acc;
}
2017-11-15 08:12:56 +00:00
$editor-background: #fff;
2017-07-28 20:04:12 +00:00
.layout__panel--editor {
2017-11-15 08:12:56 +00:00
background-color: $editor-background;
.gutter__background,
.comment-list__current-discussion,
.sticky-comment,
.current-discussion {
background-color: mix(#000, $editor-background, 6.7%);
border-color: $editor-background;
}
}
$preview-background: #f3f3f3;
.layout__panel--preview,
.layout__panel--button-bar {
background-color: $preview-background;
2017-07-23 18:42:08 +00:00
}
2017-08-06 00:58:39 +00:00
.layout__panel--preview {
2017-11-15 08:12:56 +00:00
.gutter__background,
.comment-list__current-discussion,
.sticky-comment,
.current-discussion {
background-color: mix(#000, $preview-background, 6.7%);
border-color: $preview-background;
}
2017-08-06 00:58:39 +00:00
}
2017-08-04 08:20:50 +00:00
.layout__panel--explorer,
.layout__panel--side-bar {
2017-07-31 09:04:01 +00:00
background-color: #dadada;
2017-07-28 07:40:24 +00:00
}
.layout__panel--find-replace {
background-color: #e6e6e6;
position: absolute;
left: 0;
bottom: 0;
width: 300px;
height: auto;
border-top-right-radius: $border-radius-base;
}
2017-07-23 18:42:08 +00:00
</style>