2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
import type Parchment from 'parchment';
|
2020-10-21 09:53:32 -07:00
|
|
|
import Quill from 'quill';
|
|
|
|
|
2020-11-06 12:11:18 -08:00
|
|
|
import { emojiToImage } from '../../components/emoji/lib';
|
2020-10-21 09:53:32 -07:00
|
|
|
|
|
|
|
const Embed: typeof Parchment.Embed = Quill.import('blots/embed');
|
|
|
|
|
2020-11-06 12:11:18 -08:00
|
|
|
// the DOM structure of this EmojiBlot should match the other emoji implementations:
|
|
|
|
// ts/components/conversation/Emojify.tsx
|
|
|
|
// ts/components/emoji/Emoji.tsx
|
|
|
|
|
2020-10-21 09:53:32 -07:00
|
|
|
export class EmojiBlot extends Embed {
|
2021-11-12 17:44:20 -06:00
|
|
|
static override blotName = 'emoji';
|
2020-10-21 09:53:32 -07:00
|
|
|
|
2021-11-12 17:44:20 -06:00
|
|
|
static override tagName = 'img';
|
2020-10-21 09:53:32 -07:00
|
|
|
|
2021-11-12 17:44:20 -06:00
|
|
|
static override className = 'emoji-blot';
|
2020-10-21 09:53:32 -07:00
|
|
|
|
2021-11-12 17:44:20 -06:00
|
|
|
static override create(emoji: string): Node {
|
2020-10-21 09:53:32 -07:00
|
|
|
const node = super.create(undefined) as HTMLElement;
|
|
|
|
node.dataset.emoji = emoji;
|
|
|
|
|
2020-11-06 12:11:18 -08:00
|
|
|
const image = emojiToImage(emoji);
|
|
|
|
|
|
|
|
node.setAttribute('src', image || '');
|
|
|
|
node.setAttribute('data-emoji', emoji);
|
|
|
|
node.setAttribute('title', emoji);
|
|
|
|
node.setAttribute('aria-label', emoji);
|
2020-10-21 09:53:32 -07:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2021-11-12 17:44:20 -06:00
|
|
|
static override value(node: HTMLElement): string | undefined {
|
2020-10-21 09:53:32 -07:00
|
|
|
return node.dataset.emoji;
|
|
|
|
}
|
|
|
|
}
|