Skip to content

Commit

Permalink
use vue-richtext helper functions to call the link picker
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 26, 2023
1 parent 014c0b2 commit 6db89bf
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/components/Suggestion/LinkPicker/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,38 @@
import createSuggestions from '../suggestions.js'
import LinkPickerList from './LinkPickerList.vue'

import { getProviders, sortProviders, getLinkWithPicker } from '@nextcloud/vue-richtext'

export default () => createSuggestions({
listComponent: LinkPickerList,
command: ({ editor, range, props }) => {
editor
.chain()
.focus()
.insertContentAt(range, props.label + ' ')
.run()
getLinkWithPicker(props.provider)
.then(link => {
editor
.chain()
.focus()
.insertContentAt(range, link)
.run()
})
.catch(error => {
console.error('Link picker promise rejected:', error)
})
},
items: ({ query }) => {
return [
{
label: 'Hello',
icon: '',
},
{
label: 'Hello2',
icon: '',
},
]
const providers = getProviders()
const escapedQuery = query.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
const regexp = new RegExp(escapedQuery, 'i')
const sortedProviders = sortProviders(providers)
return sortedProviders
.filter(p => {
return p.title.match(regexp)
})
.map(p => {
return {
label: p.title,
icon: p.icon_url,
provider: p,
}
})
},
})

0 comments on commit 6db89bf

Please sign in to comment.