platform/plugins/text-editor-resources/src/components/editor/actions.ts
Anton Alexeyev 14f5252d7f Add custom emojis presentation
Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
2025-05-02 22:02:54 +07:00

57 lines
1.4 KiB
TypeScript

import { getResource } from '@hcengineering/platform'
import { getClient } from '@hcengineering/presentation'
import { EmojiPopup, IconEmoji, showPopup } from '@hcengineering/ui'
import textEditor, { type RefAction } from '@hcengineering/text-editor'
import RiMention from '../icons/RIMention.svelte'
export const defaultRefActions: RefAction[] = [
{
label: textEditor.string.Mention,
icon: RiMention,
action: (_element, editorHandler) => {
editorHandler.insertText('@')
editorHandler.focus()
},
order: 3000
},
{
label: textEditor.string.Emoji,
icon: IconEmoji,
action: (element, editorHandler) => {
showPopup(
EmojiPopup,
{},
element,
(emoji) => {
if (emoji === null || emoji === undefined) {
return
}
editorHandler.insertEmoji(emoji.text, emoji.url)
editorHandler.focus()
},
() => {}
)
},
order: 4001
}
]
export async function getModelRefActions (): Promise<RefAction[]> {
const client = getClient()
const actions: RefAction[] = []
const items = await client.findAll(textEditor.class.RefInputActionItem, {})
for (const item of items) {
actions.push({
label: item.label,
icon: item.icon,
order: item.order ?? 10000,
action: await getResource(item.action)
})
}
return actions
}