signal-desktop/ts/quill/emoji/matchers.ts
Sidney Keese 7af2284c6b
Composition area: Only paste HTML that originated in Signal
Co-authored-by: Chris Svenningsen <chris@carbonfive.com>
2020-11-11 17:01:45 -08:00

35 lines
993 B
TypeScript

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import Delta from 'quill-delta';
import { insertEmojiOps } from '../util';
export const matchEmojiImage = (node: Element): Delta => {
if (node.classList.contains('emoji')) {
const emoji = node.getAttribute('title');
return new Delta().insert({ emoji });
}
return new Delta();
};
export const matchEmojiBlot = (node: HTMLElement, delta: Delta): Delta => {
if (node.classList.contains('emoji-blot')) {
const { emoji } = node.dataset;
return new Delta().insert({ emoji });
}
return delta;
};
export const matchReactEmoji = (node: HTMLElement, delta: Delta): Delta => {
if (node.classList.contains('module-emoji')) {
const emoji = node.innerText.trim();
return new Delta().insert({ emoji });
}
return delta;
};
export const matchEmojiText = (node: Text): Delta => {
const nodeAsInsert = { insert: node.data };
return new Delta(insertEmojiOps([nodeAsInsert]));
};