-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bicou/directus-extension-tiptap": minor | ||
--- | ||
|
||
emoji button and suggestions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<template> | ||
<div class="emoji-list"> | ||
<v-list dense> | ||
<v-list-item | ||
v-for="(item, index) in items" | ||
:key="index" | ||
clickable | ||
:active="index === selectedIndex" | ||
@click="selectItem(index)" | ||
> | ||
<v-list-item-icon> | ||
{{ item.emoji }} | ||
</v-list-item-icon> | ||
<v-list-item-content> :{{ item.name }}: </v-list-item-content> | ||
</v-list-item> | ||
</v-list> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
items: { | ||
type: Array, | ||
required: true, | ||
}, | ||
command: { | ||
type: Function, | ||
required: true, | ||
}, | ||
editor: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
selectedIndex: 0, | ||
}; | ||
}, | ||
watch: { | ||
items() { | ||
this.selectedIndex = 0; | ||
}, | ||
}, | ||
methods: { | ||
onKeyDown({ event }) { | ||
if (event.key === "ArrowUp") { | ||
this.upHandler(); | ||
return true; | ||
} | ||
if (event.key === "ArrowDown") { | ||
this.downHandler(); | ||
return true; | ||
} | ||
if (event.key === "Enter") { | ||
this.enterHandler(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
upHandler() { | ||
this.selectedIndex = (this.selectedIndex + this.items.length - 1) % this.items.length; | ||
}, | ||
downHandler() { | ||
this.selectedIndex = (this.selectedIndex + 1) % this.items.length; | ||
}, | ||
enterHandler() { | ||
this.selectItem(this.selectedIndex); | ||
}, | ||
selectItem(index) { | ||
const item = this.items[index]; | ||
if (item) { | ||
this.command({ name: item.name }); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss"> | ||
.emoji-list { | ||
max-height: 30vh; | ||
padding: 0 4px; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
background-color: var(--theme--popover--menu--background); | ||
border: none; | ||
border-radius: var(--theme--popover--menu--border-radius); | ||
box-shadow: var(--theme--popover--menu--box-shadow); | ||
transition-timing-function: var(--transition-out); | ||
transition-duration: var(--fast); | ||
transition-property: opacity, transform; | ||
contain: content; | ||
.v-list { | ||
--v-list-background-color: transparent; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { VueRenderer } from "@tiptap/vue-3"; | ||
import EmojiList from "../components/emoji-list.vue"; | ||
import type { SuggestionOptions } from "@tiptap/suggestion"; | ||
import type { EmojiItem } from "@tiptap-pro/extension-emoji"; | ||
import tippy, { type Instance as TippyInstance } from "tippy.js"; | ||
|
||
export const suggestion: Omit<SuggestionOptions, "editor"> = { | ||
items: ({ editor, query }) => { | ||
return editor.storage.emoji.emojis | ||
.filter(({ shortcodes, tags }: EmojiItem) => { | ||
return ( | ||
shortcodes.find((shortcode) => shortcode.startsWith(query.toLowerCase())) || | ||
tags.find((tag) => tag.startsWith(query.toLowerCase())) | ||
); | ||
}) | ||
.slice(0, 5); | ||
}, | ||
|
||
render: () => { | ||
let component: VueRenderer | null = null; | ||
let popup: TippyInstance | null = null; | ||
|
||
return { | ||
onStart: (props) => { | ||
component = new VueRenderer(EmojiList, { | ||
props, | ||
editor: props.editor, | ||
}); | ||
|
||
popup = tippy(document.body, { | ||
getReferenceClientRect: props.clientRect, | ||
appendTo: () => document.body, | ||
content: component.element, | ||
showOnCreate: true, | ||
interactive: true, | ||
trigger: "manual", | ||
placement: "bottom-start", | ||
}); | ||
}, | ||
|
||
onUpdate(props) { | ||
component?.updateProps(props); | ||
|
||
popup?.setProps({ | ||
getReferenceClientRect: props.clientRect, | ||
}); | ||
}, | ||
|
||
onKeyDown(props) { | ||
if (props.event.key === "Escape") { | ||
popup?.hide(); | ||
component?.destroy(); | ||
|
||
return true; | ||
} | ||
|
||
return component?.ref?.onKeyDown(props); | ||
}, | ||
|
||
onExit() { | ||
popup?.destroy(); | ||
component?.destroy(); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters