Skip to content

Commit 3b21c70

Browse files
committed
preview mode
1 parent 9657a23 commit 3b21c70

File tree

5 files changed

+192
-10
lines changed

5 files changed

+192
-10
lines changed

package-lock.json

Lines changed: 32 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"@babel/polyfill": "^7.4.4",
1616
"easymde": "^2.6.0",
17+
"markdown-it": "^8.4.2",
1718
"nextcloud-axios": "^0.1.3",
1819
"nextcloud-vue": "^0.11.3",
1920
"vue": "^2.6.10",

src/components/EditorEasyMDE.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export default {
9696
9797
.markdown-editor {
9898
min-height: 100%;
99-
padding: 1em;
10099
}
101100
102101
.CodeMirror {

src/components/EditorMarkdownIt.vue

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<template>
2+
<div class="note-preview" v-html="html" />
3+
</template>
4+
<script>
5+
6+
import MarkdownIt from 'markdown-it'
7+
8+
export default {
9+
name: 'ThePreview',
10+
11+
props: {
12+
value: {
13+
type: String,
14+
required: true,
15+
},
16+
},
17+
18+
data: function() {
19+
return {
20+
html: '',
21+
md: new MarkdownIt({
22+
linkify: true,
23+
}),
24+
}
25+
},
26+
27+
watch: {
28+
value: 'onUpdate',
29+
},
30+
31+
created() {
32+
this.onUpdate()
33+
},
34+
35+
methods: {
36+
onUpdate() {
37+
this.html = this.md.render(this.value)
38+
},
39+
},
40+
41+
}
42+
</script>
43+
<style lang="scss">
44+
.note-preview {
45+
padding: 1em;
46+
line-height: 1.5em;
47+
48+
& h1, & h2, & h3, & h4, & h5, & h6 {
49+
padding: 0;
50+
margin-top: 2ex;
51+
margin-bottom: 1ex;
52+
font-weight: bold;
53+
color: inherit;
54+
}
55+
56+
& h1 {
57+
font-size: 165%;
58+
}
59+
60+
& h2 {
61+
font-size: 140%;
62+
}
63+
64+
& h3 {
65+
font-size: 120%;
66+
}
67+
68+
& h4 {
69+
font-size: 110%;
70+
}
71+
72+
& p, & pre, & ul, & ol {
73+
margin: 2ex 0;
74+
}
75+
76+
& ul {
77+
list-style: initial;
78+
}
79+
80+
& ul, & ol {
81+
margin-left: 3ex;
82+
}
83+
84+
& li > p, & li > ul, & li > ol {
85+
margin-top: 0.5ex;
86+
margin-bottom: 0.5ex;
87+
}
88+
89+
& em {
90+
font-style: italic;
91+
color: inherit;
92+
}
93+
94+
& a {
95+
color: var(--color-primary);
96+
}
97+
98+
& pre, & code {
99+
background: var(--color-background-dark);
100+
font-size: 90%;
101+
padding: 0.2ex 0.5ex;
102+
}
103+
104+
& pre code {
105+
font-size: inherit;
106+
padding: 0;
107+
}
108+
109+
& blockquote {
110+
font-style: italic;
111+
border-left: 4px solid var(--color-border);
112+
padding-left: 2ex;
113+
color: var(--color-text-light)
114+
}
115+
}
116+
</style>

src/components/Note.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
<template>
2-
<AppContent :class="{ loading: loading || isManualSave, 'icon-error': !loading && (!note || note.error) }">
2+
<AppContent :class="{ loading: loading || isManualSave, 'icon-error': !loading && (!note || note.error), 'sidebar-open': sidebarOpen }">
33
<div v-if="!loading && note && !note.error" id="note-container"
44
class="note-container" :class="{ fullscreen: fullscreen }"
55
>
66
<div class="note-editor">
77
<div v-show="!note.content" class="placeholder">
88
{{ t('notes', 'Write …') }}
99
</div>
10-
<TheEditor :value="note.content" @input="onEdit" />
10+
<ThePreview v-if="preview" :value="note.content" />
11+
<TheEditor v-else :value="note.content" @input="onEdit" />
1112
</div>
1213
<span class="action-buttons">
1314
<button v-show="note.saveError"
1415
v-tooltip="t('notes', 'Save failed. Click to retry.')"
1516
class="icon-error-color"
1617
@click="onManualSave"
1718
/>
18-
<button v-show="!fullscreen"
19+
<button v-show="actionsOpen && !fullscreen"
1920
v-tooltip="t('notes', 'Toggle sidebar')"
2021
class="icon-details"
2122
@click="onToggleSidebar"
2223
/>
23-
<button
24+
<button v-show="actionsOpen"
25+
v-tooltip="t('notes', 'Toggle preview')"
26+
class="icon-toggle"
27+
:class="{ active: preview }"
28+
@click="onTogglePreview"
29+
/>
30+
<button v-show="actionsOpen"
2431
v-tooltip="t('notes', 'Toggle fullscreen mode')"
2532
class="icon-fullscreen"
33+
:class="{ active: fullscreen }"
2634
@click="onToggleDistractionFree"
2735
/>
36+
<button
37+
v-tooltip="t('notes', 'Toggle action menu')"
38+
class="icon-more"
39+
:class="{ active: actionsOpen }"
40+
@click="onToggleActions"
41+
/>
2842
</span>
2943
</div>
3044
</AppContent>
@@ -36,6 +50,7 @@ import {
3650
Tooltip,
3751
} from 'nextcloud-vue'
3852
import TheEditor from './EditorEasyMDE'
53+
import ThePreview from './EditorMarkdownIt'
3954
import NotesService from '../NotesService'
4055
import store from '../store'
4156
@@ -45,6 +60,7 @@ export default {
4560
components: {
4661
AppContent,
4762
TheEditor,
63+
ThePreview,
4864
},
4965
5066
directives: {
@@ -62,6 +78,8 @@ export default {
6278
return {
6379
loading: false,
6480
fullscreen: false,
81+
preview: false,
82+
actionsOpen: false,
6583
}
6684
},
6785
@@ -75,6 +93,9 @@ export default {
7593
isManualSave() {
7694
return store.state.isManualSave
7795
},
96+
sidebarOpen() {
97+
return store.state.sidebarOpen
98+
},
7899
},
79100
80101
watch: {
@@ -101,6 +122,7 @@ export default {
101122
store.commit('setSidebarOpen', false)
102123
this.onUpdateTitle(this.title)
103124
this.loading = true
125+
this.preview = false
104126
NotesService.fetchNote(this.noteId)
105127
.then((note) => {
106128
if (note.errorMessage) {
@@ -124,6 +146,11 @@ export default {
124146
}
125147
},
126148
149+
onTogglePreview() {
150+
this.preview = !this.preview
151+
this.actionsOpen = false
152+
},
153+
127154
onDetectFullscreen() {
128155
this.fullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen
129156
},
@@ -156,10 +183,16 @@ export default {
156183
} else {
157184
launchIntoFullscreen(document.getElementById('note-container'))
158185
}
186+
this.actionsOpen = false
159187
},
160188
161189
onToggleSidebar() {
162190
store.commit('setSidebarOpen', !store.state.sidebarOpen)
191+
this.actionsOpen = false
192+
},
193+
194+
onToggleActions() {
195+
this.actionsOpen = !this.actionsOpen
163196
},
164197
165198
onEdit(newContent) {
@@ -201,6 +234,7 @@ export default {
201234
.note-editor {
202235
max-width: 47em;
203236
font-size: 16px;
237+
padding: 0 1em;
204238
}
205239
206240
/* center editor on large screens */
@@ -210,6 +244,11 @@ export default {
210244
}
211245
.note-container {
212246
padding-right: 250px;
247+
transition-duration: var(--animation-quick);
248+
transition-property: padding-right;
249+
}
250+
.sidebar-open .note-container {
251+
padding-right: 0px;
213252
}
214253
}
215254

0 commit comments

Comments
 (0)