mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
survive empty urls
This commit is contained in:
parent
1df3cb1ed1
commit
f47502ade1
@ -19,7 +19,7 @@ export default {
|
|||||||
arrow: true,
|
arrow: true,
|
||||||
arrowType: 'round',
|
arrowType: 'round',
|
||||||
content: content,
|
content: content,
|
||||||
// duration: [400, 200],
|
duration: [400, 200],
|
||||||
inertia: true,
|
inertia: true,
|
||||||
interactive: true,
|
interactive: true,
|
||||||
placement: 'top-start',
|
placement: 'top-start',
|
||||||
@ -27,9 +27,10 @@ export default {
|
|||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
trigger,
|
trigger,
|
||||||
onMount(instance) {
|
onMount(instance) {
|
||||||
instance.popper.querySelector('input').focus()
|
instance.popper.querySelector('input').focus({ preventScroll: true })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// we have to update tippy whenever the DOM is updated
|
// we have to update tippy whenever the DOM is updated
|
||||||
if (MutationObserver) {
|
if (MutationObserver) {
|
||||||
this.observer = new MutationObserver(() => {
|
this.observer = new MutationObserver(() => {
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
<link-input
|
<link-input
|
||||||
v-show="isLinkInputActive"
|
v-show="isLinkInputActive"
|
||||||
ref="linkInput"
|
ref="linkInput"
|
||||||
:linkUrl="linkUrl"
|
|
||||||
:editor-command="editor.commands.link"
|
:editor-command="editor.commands.link"
|
||||||
:toggle-link-input="toggleLinkInput"
|
:toggle-link-input="toggleLinkInput"
|
||||||
:set-link-url="setLinkUrl"
|
:set-link-url="setLinkUrl"
|
||||||
@ -60,7 +59,6 @@ export default {
|
|||||||
return {
|
return {
|
||||||
lastValueHash: null,
|
lastValueHash: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
linkUrl: null,
|
|
||||||
isLinkInputActive: false,
|
isLinkInputActive: false,
|
||||||
suggestionType: '',
|
suggestionType: '',
|
||||||
query: null,
|
query: null,
|
||||||
@ -251,26 +249,26 @@ export default {
|
|||||||
},
|
},
|
||||||
toggleLinkInput(attrs, element) {
|
toggleLinkInput(attrs, element) {
|
||||||
if (!this.isLinkInputActive && attrs && element) {
|
if (!this.isLinkInputActive && attrs && element) {
|
||||||
this.linkUrl = attrs.href
|
this.$refs.linkInput.linkUrl = attrs.href
|
||||||
this.isLinkInputActive = true
|
this.isLinkInputActive = true
|
||||||
this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkInput.$el, 'link')
|
this.$refs.contextMenu.displayContextMenu(element, this.$refs.linkInput.$el, 'link')
|
||||||
} else {
|
} else {
|
||||||
this.$refs.contextMenu.hideContextMenu()
|
this.$refs.contextMenu.hideContextMenu()
|
||||||
this.linkUrl = null
|
|
||||||
this.isLinkInputActive = false
|
this.isLinkInputActive = false
|
||||||
this.editor.focus()
|
this.editor.focus()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setLinkUrl(command, url) {
|
setLinkUrl(url) {
|
||||||
const links = linkify().match(url)
|
const normalizedLinks = url ? linkify().match(url) : null
|
||||||
if (links) {
|
const command = this.editor.commands.link
|
||||||
|
if (normalizedLinks) {
|
||||||
// add valid link
|
// add valid link
|
||||||
command({
|
command({
|
||||||
href: links.pop().url,
|
href: normalizedLinks.pop().url,
|
||||||
})
|
})
|
||||||
this.toggleLinkInput()
|
this.toggleLinkInput()
|
||||||
this.editor.focus()
|
this.editor.focus()
|
||||||
} else if (!url) {
|
} else {
|
||||||
// remove link
|
// remove link
|
||||||
command({ href: null })
|
command({ href: null })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,11 @@
|
|||||||
<ds-input
|
<ds-input
|
||||||
id="linkInputId"
|
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="toggleLinkInput()"
|
@blur.native.capture="toggleLinkInput()"
|
||||||
@keydown.native.esc.prevent="toggleLinkInput()"
|
@keydown.native.esc.prevent="toggleLinkInput()"
|
||||||
@keydown.native.enter.prevent="setLinkUrl(editorCommand, linkUrl)"
|
@keydown.native.enter.prevent="enterLink()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -16,10 +15,19 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
linkUrl: String,
|
|
||||||
editorCommand: Function,
|
|
||||||
toggleLinkInput: Function,
|
toggleLinkInput: Function,
|
||||||
setLinkUrl: Function,
|
setLinkUrl: Function,
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
linkUrl: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
enterLink() {
|
||||||
|
this.setLinkUrl(this.linkUrl)
|
||||||
|
this.linkUrl = null
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user