mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
get link input to work
This commit is contained in:
parent
62e34bf5b0
commit
1df3cb1ed1
@ -7,21 +7,28 @@ export default {
|
|||||||
node: Object,
|
node: Object,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
displayContextMenu(target, content, trigger) {
|
displayContextMenu(target, content, type) {
|
||||||
|
const trigger = type === 'link' ? 'click' : 'mouseenter'
|
||||||
|
const showOnInit = type !== 'link'
|
||||||
|
|
||||||
if (this.menu) {
|
if (this.menu) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menu = tippy(target, {
|
this.menu = tippy(target, {
|
||||||
content: content,
|
|
||||||
trigger: trigger || 'mouseenter',
|
|
||||||
interactive: true,
|
|
||||||
theme: 'dark',
|
|
||||||
placement: 'top-start',
|
|
||||||
inertia: true,
|
|
||||||
duration: [400, 200],
|
|
||||||
showOnInit: true,
|
|
||||||
arrow: true,
|
arrow: true,
|
||||||
arrowType: 'round',
|
arrowType: 'round',
|
||||||
|
content: content,
|
||||||
|
// duration: [400, 200],
|
||||||
|
inertia: true,
|
||||||
|
interactive: true,
|
||||||
|
placement: 'top-start',
|
||||||
|
showOnInit,
|
||||||
|
theme: 'dark',
|
||||||
|
trigger,
|
||||||
|
onMount(instance) {
|
||||||
|
instance.popper.querySelector('input').focus()
|
||||||
|
},
|
||||||
})
|
})
|
||||||
// we have to update tippy whenever the DOM is updated
|
// we have to update tippy whenever the DOM is updated
|
||||||
if (MutationObserver) {
|
if (MutationObserver) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="editor">
|
<div class="editor">
|
||||||
<menu-bar :editor="editor" :showLinkMenu="showLinkMenu" />
|
<menu-bar :editor="editor" :toggleLinkInput="toggleLinkInput" />
|
||||||
<editor-content ref="editor" :editor="editor" />
|
<editor-content ref="editor" :editor="editor" />
|
||||||
<context-menu ref="contextMenu" />
|
<context-menu ref="contextMenu" />
|
||||||
<suggestion-list
|
<suggestion-list
|
||||||
@ -11,7 +11,14 @@
|
|||||||
:query="query"
|
:query="query"
|
||||||
:select-item="selectItem"
|
:select-item="selectItem"
|
||||||
/>
|
/>
|
||||||
<link-input v-show="linkMenuIsActive" ref="linkMenu" :editorCommand="editor.commands.link" />
|
<link-input
|
||||||
|
v-show="isLinkInputActive"
|
||||||
|
ref="linkInput"
|
||||||
|
:linkUrl="linkUrl"
|
||||||
|
:editor-command="editor.commands.link"
|
||||||
|
:toggle-link-input="toggleLinkInput"
|
||||||
|
:set-link-url="setLinkUrl"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -54,7 +61,7 @@ export default {
|
|||||||
lastValueHash: null,
|
lastValueHash: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
linkUrl: null,
|
linkUrl: null,
|
||||||
linkMenuIsActive: false,
|
isLinkInputActive: false,
|
||||||
suggestionType: '',
|
suggestionType: '',
|
||||||
query: null,
|
query: null,
|
||||||
suggestionRange: null,
|
suggestionRange: null,
|
||||||
@ -242,23 +249,17 @@ export default {
|
|||||||
this.$emit('input', content)
|
this.$emit('input', content)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showLinkMenu(attrs, element) {
|
toggleLinkInput(attrs, element) {
|
||||||
|
if (!this.isLinkInputActive && attrs && element) {
|
||||||
this.linkUrl = attrs.href
|
this.linkUrl = attrs.href
|
||||||
this.linkMenuIsActive = true
|
this.isLinkInputActive = true
|
||||||
this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkMenu.$el, 'click')
|
this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkInput.$el, 'link')
|
||||||
this.$nextTick(() => {
|
} else {
|
||||||
try {
|
|
||||||
const input = this.$refs.linkMenu.$el.querySelector('input')
|
|
||||||
input.focus()
|
|
||||||
input.select()
|
|
||||||
} catch (err) {}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
hideLinkMenu() {
|
|
||||||
this.$refs.contextMenu.hideContextMenu()
|
this.$refs.contextMenu.hideContextMenu()
|
||||||
this.linkUrl = null
|
this.linkUrl = null
|
||||||
this.linkMenuIsActive = false
|
this.isLinkInputActive = false
|
||||||
this.editor.focus()
|
this.editor.focus()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setLinkUrl(command, url) {
|
setLinkUrl(command, url) {
|
||||||
const links = linkify().match(url)
|
const links = linkify().match(url)
|
||||||
@ -267,7 +268,7 @@ export default {
|
|||||||
command({
|
command({
|
||||||
href: links.pop().url,
|
href: links.pop().url,
|
||||||
})
|
})
|
||||||
this.hideLinkMenu()
|
this.toggleLinkInput()
|
||||||
this.editor.focus()
|
this.editor.focus()
|
||||||
} else if (!url) {
|
} else if (!url) {
|
||||||
// remove link
|
// remove link
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<ds-input
|
<ds-input
|
||||||
|
id="linkInputId"
|
||||||
v-model="linkUrl"
|
v-model="linkUrl"
|
||||||
|
autofocus
|
||||||
class="editor-menu-link-input"
|
class="editor-menu-link-input"
|
||||||
placeholder="https://"
|
placeholder="https://"
|
||||||
@blur.native.capture="hideLinkMenu()"
|
@blur.native.capture="toggleLinkInput()"
|
||||||
@keydown.native.esc.prevent="hideLinkMenu()"
|
@keydown.native.esc.prevent="toggleLinkInput()"
|
||||||
@keydown.native.enter.prevent="setLinkUrl(editorCommand, linkUrl)"
|
@keydown.native.enter.prevent="setLinkUrl(editorCommand, linkUrl)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -13,11 +15,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: ['hideLinkMenu', 'setLinkUrl', 'editorCommand'],
|
props: {
|
||||||
data() {
|
linkUrl: String,
|
||||||
return {
|
editorCommand: Function,
|
||||||
linkUrl: null,
|
toggleLinkInput: Function,
|
||||||
}
|
setLinkUrl: Function,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
<menu-bar-button
|
<menu-bar-button
|
||||||
ref="linkButton"
|
ref="linkButton"
|
||||||
:isActive="isActive.link()"
|
:isActive="isActive.link()"
|
||||||
:onClick="event => showLinkMenu(getMarkAttrs('link'), event.currentTarget)"
|
:onClick="event => toggleLinkInput(getMarkAttrs('link'), event.currentTarget)"
|
||||||
icon="link"
|
icon="link"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ export default {
|
|||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
editor: Object,
|
editor: Object,
|
||||||
showLinkMenu: Function,
|
toggleLinkInput: Function,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ds-button size="small" :ghost="!isActive" @click="onClick" :icon="icon">
|
<ds-button size="small" :ghost="!isActive" @click.prevent="onClick" :icon="icon">
|
||||||
<span v-if="label">{{ label }}</span>
|
<span v-if="label">{{ label }}</span>
|
||||||
</ds-button>
|
</ds-button>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user