mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
parent
5f5b3eac25
commit
3656c16b61
@ -9,6 +9,12 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
focused: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
editor: {
|
editor: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
@ -19,6 +25,16 @@ export default {
|
|||||||
editor,
|
editor,
|
||||||
element: this.$el,
|
element: this.$el,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
this.focused = editor.focused
|
||||||
|
|
||||||
|
editor.on('focus', () => {
|
||||||
|
this.focused = true
|
||||||
|
})
|
||||||
|
|
||||||
|
editor.on('menubar:focusUpdate', focused => {
|
||||||
|
this.focused = focused
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -31,7 +47,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.$scopedSlots.default({
|
return this.$scopedSlots.default({
|
||||||
focused: this.editor.view.focused,
|
focused: this.focused,
|
||||||
focus: this.editor.focus,
|
focus: this.editor.focus,
|
||||||
commands: this.editor.commands,
|
commands: this.editor.commands,
|
||||||
isActive: this.editor.isActive,
|
isActive: this.editor.isActive,
|
||||||
|
@ -11,18 +11,25 @@ class Menu {
|
|||||||
},
|
},
|
||||||
...options,
|
...options,
|
||||||
}
|
}
|
||||||
|
this.preventHide = false
|
||||||
this.editorView = editorView
|
this.editorView = editorView
|
||||||
this.isActive = false
|
this.isActive = false
|
||||||
this.top = 0
|
this.top = 0
|
||||||
|
|
||||||
// the mousedown event is fired before blur so we can prevent it
|
// the mousedown event is fired before blur so we can prevent it
|
||||||
this.options.element.addEventListener('mousedown', this.handleClick)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
|
this.options.element.addEventListener('mousedown', this.mousedownHandler)
|
||||||
|
|
||||||
this.options.editor.on('focus', ({ view }) => {
|
this.options.editor.on('focus', ({ view }) => {
|
||||||
this.update(view)
|
this.update(view)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.options.editor.on('blur', ({ event }) => {
|
this.options.editor.on('blur', ({ event }) => {
|
||||||
|
if (this.preventHide) {
|
||||||
|
this.preventHide = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.hide(event)
|
this.hide(event)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -38,8 +45,8 @@ class Menu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(event) {
|
handleClick() {
|
||||||
event.preventDefault()
|
this.preventHide = true
|
||||||
}
|
}
|
||||||
|
|
||||||
update(view, lastState) {
|
update(view, lastState) {
|
||||||
@ -103,7 +110,7 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.options.element.removeEventListener('mousedown', this.handleClick)
|
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
||||||
|
|
||||||
if (this.resizeObserver) {
|
if (this.resizeObserver) {
|
||||||
this.resizeObserver.unobserve(this.editorView.dom)
|
this.resizeObserver.unobserve(this.editorView.dom)
|
||||||
|
@ -4,17 +4,28 @@ class Menu {
|
|||||||
|
|
||||||
constructor({ options }) {
|
constructor({ options }) {
|
||||||
this.options = options
|
this.options = options
|
||||||
|
this.preventHide = false
|
||||||
|
|
||||||
// the mousedown event is fired before blur so we can prevent it
|
// the mousedown event is fired before blur so we can prevent it
|
||||||
this.options.element.addEventListener('mousedown', this.handleClick)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
|
this.options.element.addEventListener('mousedown', this.mousedownHandler)
|
||||||
|
|
||||||
|
this.options.editor.on('blur', () => {
|
||||||
|
if (this.preventHide) {
|
||||||
|
this.preventHide = false
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(event) {
|
this.options.editor.emit('menubar:focusUpdate', false)
|
||||||
event.preventDefault()
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClick() {
|
||||||
|
this.preventHide = true
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.options.element.removeEventListener('mousedown', this.handleClick)
|
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,21 +67,28 @@ class Menu {
|
|||||||
this.left = 0
|
this.left = 0
|
||||||
this.bottom = 0
|
this.bottom = 0
|
||||||
this.top = 0
|
this.top = 0
|
||||||
|
this.preventHide = false
|
||||||
|
|
||||||
// the mousedown event is fired before blur so we can prevent it
|
// the mousedown event is fired before blur so we can prevent it
|
||||||
this.options.element.addEventListener('mousedown', this.handleClick)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
|
this.options.element.addEventListener('mousedown', this.mousedownHandler)
|
||||||
|
|
||||||
this.options.editor.on('focus', ({ view }) => {
|
this.options.editor.on('focus', ({ view }) => {
|
||||||
this.update(view)
|
this.update(view)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.options.editor.on('blur', ({ event }) => {
|
this.options.editor.on('blur', ({ event }) => {
|
||||||
|
if (this.preventHide) {
|
||||||
|
this.preventHide = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.hide(event)
|
this.hide(event)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(event) {
|
handleClick() {
|
||||||
event.preventDefault()
|
this.preventHide = true
|
||||||
}
|
}
|
||||||
|
|
||||||
update(view, lastState) {
|
update(view, lastState) {
|
||||||
@ -146,6 +153,7 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide(event) {
|
hide(event) {
|
||||||
|
console.log('hide', { event })
|
||||||
if (event
|
if (event
|
||||||
&& event.relatedTarget
|
&& event.relatedTarget
|
||||||
&& this.options.element.parentNode.contains(event.relatedTarget)
|
&& this.options.element.parentNode.contains(event.relatedTarget)
|
||||||
@ -158,7 +166,7 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.options.element.removeEventListener('mousedown', this.handleClick)
|
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user