Skip to content

Commit 0290c1f

Browse files
committed
feat: Further QEditor work
1 parent a06f961 commit 0290c1f

File tree

10 files changed

+94
-49
lines changed

10 files changed

+94
-49
lines changed

dev/components/form/editor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:toolbar="[
77
['bold', 'italic', 'strike', 'underline', 'subscript', 'superscript'],
88
['token', 'hr', 'link', 'custom_btn'],
9+
['print', 'fullscreen'],
910
[
1011
{
1112
label: 'Formatting',
@@ -46,7 +47,6 @@
4647
options: ['left', 'center', 'right', 'justify']
4748
}
4849
],
49-
['print'],
5050
['undo', 'redo'],
5151
[{
5252
label: 'Dropdown Test',

src/components/carousel/QCarousel.vue

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
</template>
5050

5151
<script>
52-
import Platform from '../../features/platform'
5352
import TouchPan from '../../directives/touch-pan'
5453
import { cssTransform } from '../../utils/dom'
5554
import { between, normalizeToInterval } from '../../utils/format'
5655
import { start, stop } from '../../utils/animate'
5756
import { getEventKey } from '../../utils/event'
5857
import CarouselMixin from './carousel-mixin'
5958
import { QIcon } from '../icon'
59+
import FullscreenMixin from '../../utils/fullscreen-mixin'
6060
6161
export default {
6262
name: 'q-carousel',
@@ -66,7 +66,7 @@ export default {
6666
directives: {
6767
TouchPan
6868
},
69-
mixins: [CarouselMixin],
69+
mixins: [CarouselMixin, FullscreenMixin],
7070
data () {
7171
return {
7272
position: 0,
@@ -217,44 +217,6 @@ export default {
217217
}
218218
})
219219
},
220-
toggleFullscreen () {
221-
if (this.inFullscreen) {
222-
if (!Platform.has.popstate) {
223-
this.__setFullscreen(false)
224-
}
225-
else {
226-
window.history.go(-1)
227-
}
228-
return
229-
}
230-
231-
this.__setFullscreen(true)
232-
if (Platform.has.popstate) {
233-
window.history.pushState({}, '')
234-
window.addEventListener('popstate', this.__popState)
235-
}
236-
},
237-
__setFullscreen (state) {
238-
if (this.inFullscreen === state) {
239-
return
240-
}
241-
242-
if (state) {
243-
this.container.replaceChild(this.fillerNode, this.$el)
244-
document.body.appendChild(this.$el)
245-
this.inFullscreen = true
246-
return
247-
}
248-
249-
this.inFullscreen = false
250-
this.container.replaceChild(this.$el, this.fillerNode)
251-
},
252-
__popState () {
253-
if (this.inFullscreen) {
254-
this.__setFullscreen(false)
255-
}
256-
window.removeEventListener('popstate', this.__popState)
257-
},
258220
stopAnimation () {
259221
stop(this.animUid)
260222
this.animationInProgress = false
@@ -298,8 +260,6 @@ export default {
298260
},
299261
mounted () {
300262
this.$nextTick(() => {
301-
this.fillerNode = document.createElement('span')
302-
this.container = this.$el.parentNode
303263
this.slidesNumber = this.__getSlidesNumber()
304264
this.__planAutoPlay()
305265
if (this.handleArrowKeys) {

src/components/editor/QEditor.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { getToolbar, getFonts } from './editor-utils'
33
import { buttons } from './editor-definitions'
44
import { Caret } from './editor-caret'
55
import extend from '../../utils/extend'
6+
import FullscreenMixin from '../../utils/fullscreen-mixin'
67

78
export default {
89
name: 'q-editor',
10+
mixins: [FullscreenMixin],
911
props: {
1012
value: {
1113
type: String,
@@ -17,6 +19,8 @@ export default {
1719
type: String,
1820
default: '10rem'
1921
},
22+
maxHeight: String,
23+
height: String,
2024
color: String,
2125
toggleColor: {
2226
type: String,
@@ -26,6 +30,10 @@ export default {
2630
type: String,
2731
default: 'grey-4'
2832
},
33+
contentColor: {
34+
type: String,
35+
default: 'white'
36+
},
2937
flat: Boolean,
3038
outline: Boolean,
3139
push: Boolean,
@@ -179,7 +187,7 @@ export default {
179187
},
180188
mounted () {
181189
this.$nextTick(() => {
182-
this.caret = new Caret(this.$refs.content)
190+
this.caret = new Caret(this.$refs.content, this)
183191
this.$refs.content.innerHTML = this.value
184192
this.$nextTick(this.refreshToolbar)
185193
})
@@ -189,8 +197,13 @@ export default {
189197
'div',
190198
{
191199
staticClass: 'q-editor',
200+
style: {
201+
height: this.inFullscreen ? '100vh' : null
202+
},
192203
'class': {
193-
disabled: this.disable
204+
disabled: this.disable,
205+
fullscreen: this.inFullscreen,
206+
column: this.inFullscreen
194207
}
195208
},
196209
[
@@ -208,8 +221,14 @@ export default {
208221
'div',
209222
{
210223
ref: 'content',
211-
staticClass: 'q-editor-content',
212-
style: { minHeight: this.minHeight },
224+
staticClass: `q-editor-content bg-${this.contentColor}`,
225+
style: this.inFullscreen
226+
? {}
227+
: { minHeight: this.minHeight, height: this.height, maxHeight: this.maxHeight },
228+
class: {
229+
col: this.inFullscreen,
230+
'overflow-auto': this.inFullscreen
231+
},
213232
attrs: { contenteditable: this.editable },
214233
on: {
215234
input: this.onInput,

src/components/editor/editor-caret.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ function isChildOf (el, parent) {
3434
}
3535

3636
export class Caret {
37-
constructor (el) {
37+
constructor (el, vm) {
3838
this.el = el
39+
this.vm = vm
3940
}
4041

4142
get selection () {
@@ -139,6 +140,8 @@ export class Caret {
139140
case 'fontName':
140141
const res = document.queryCommandValue(cmd)
141142
return res === `"${param}"` || res === param
143+
case 'fullscreen':
144+
return this.vm.inFullscreen
142145
default:
143146
const state = document.queryCommandState(cmd)
144147
return param ? state === param : state
@@ -232,6 +235,11 @@ export class Caret {
232235
})
233236
return
234237
}
238+
else if (cmd === 'fullscreen') {
239+
this.vm.toggleFullscreen()
240+
done()
241+
return
242+
}
235243

236244
document.execCommand(cmd, false, param)
237245
done()

src/components/editor/editor-definitions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ export const buttons = {
99
subscript: {cmd: 'subscript', icon: 'vertical_align_bottom', tip: 'Subscript', htmlTip: 'x<subscript>2</subscript>'},
1010
superscript: {cmd: 'superscript', icon: 'vertical_align_top', tip: 'Superscript', htmlTip: 'x<superscript>2</superscript>'},
1111
link: {cmd: 'link', icon: 'link', tip: 'Hyperlink', key: 76},
12+
fullscreen: {cmd: 'fullscreen', icon: 'fullscreen', tip: 'Toggle Fullscreen', key: 70},
1213

1314
quote: {cmd: 'formatBlock', param: 'BLOCKQUOTE', icon: 'format_quote', tip: 'Quote', key: 81},
1415
left: {cmd: 'justifyLeft', icon: 'format_align_left', tip: 'Left align'},
1516
center: {cmd: 'justifyCenter', icon: 'format_align_center', tip: 'Center align'},
1617
right: {cmd: 'justifyRight', icon: 'format_align_right', tip: 'Right align'},
1718
justify: {cmd: 'justifyFull', icon: 'format_align_justify', tip: 'Justify align'},
1819

19-
print: {type: 'no-state', cmd: 'print', icon: 'print', tip: 'Print'},
20+
print: {type: 'no-state', cmd: 'print', icon: 'print', tip: 'Print', key: 80},
2021
outdent: {type: 'no-state', disable: vm => vm.caret && !vm.caret.can('outdent'), cmd: 'outdent', icon: 'format_indent_decrease', tip: 'Decrease indentation'},
2122
indent: {type: 'no-state', disable: vm => vm.caret && !vm.caret.can('indent'), cmd: 'indent', icon: 'format_indent_increase', tip: 'Increase indentation'},
2223
removeFormat: {type: 'no-state', cmd: 'removeFormat', icon: 'format_clear', tip: 'Remove formatting'},

src/components/editor/editor.ios.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.q-editor-content
77
outline 0
88
padding $editor-content-padding
9+
min-height $editor-content-min-height
910

1011
hr
1112
border 0

src/components/editor/editor.mat.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.q-editor-content
77
outline 0
88
padding $editor-content-padding
9+
min-height $editor-content-min-height
910

1011
hr
1112
border 0

src/css/variables.ios.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ $dot-position-right ?= 10px
114114
$editor-border-color ?= #ccc
115115
$editor-border ?= 1px solid $editor-border-color
116116
$editor-content-padding ?= 10px
117+
$editor-content-min-height ?= 10em
117118
$editor-toolbar-padding ?= 5px
118119
$editor-hr-color ?= #ccc
119120
$editor-button-gutter ?= 5px

src/css/variables.mat.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ $dot-position-right ?= 10px
111111
$editor-border-color ?= #ccc
112112
$editor-border ?= 1px solid $editor-border-color
113113
$editor-content-padding ?= 10px
114+
$editor-content-min-height ?= 10em
114115
$editor-toolbar-padding ?= 5px
115116
$editor-hr-color ?= #ccc
116117
$editor-button-gutter ?= 5px

src/utils/fullscreen-mixin.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Platform from '../features/platform'
2+
3+
export default {
4+
data () {
5+
return {
6+
inFullscreen: false
7+
}
8+
},
9+
created () {
10+
this.fillerNode = document.createElement('span')
11+
},
12+
methods: {
13+
toggleFullscreen () {
14+
if (this.inFullscreen) {
15+
if (!Platform.has.popstate) {
16+
this.__setFullscreen(false)
17+
}
18+
else {
19+
window.history.go(-1)
20+
}
21+
return
22+
}
23+
24+
this.__setFullscreen(true)
25+
if (Platform.has.popstate) {
26+
window.history.pushState({}, '')
27+
window.addEventListener('popstate', this.__popState)
28+
}
29+
},
30+
__setFullscreen (state) {
31+
if (this.inFullscreen === state) {
32+
return
33+
}
34+
35+
if (state) {
36+
this.container = this.$el.parentNode
37+
this.container.replaceChild(this.fillerNode, this.$el)
38+
document.body.appendChild(this.$el)
39+
this.inFullscreen = true
40+
return
41+
}
42+
43+
this.inFullscreen = false
44+
this.container.replaceChild(this.$el, this.fillerNode)
45+
},
46+
__popState () {
47+
if (this.inFullscreen) {
48+
this.__setFullscreen(false)
49+
}
50+
window.removeEventListener('popstate', this.__popState)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)