2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-21 16:53:32 +00:00
|
|
|
import Delta from 'quill-delta';
|
2020-11-12 01:01:45 +00:00
|
|
|
import { insertEmojiOps } from '../util';
|
2020-10-21 16:53:32 +00:00
|
|
|
|
2023-05-10 00:40:19 +00:00
|
|
|
export const matchEmojiImage = (node: Element, delta: Delta): Delta => {
|
|
|
|
if (
|
|
|
|
(node.classList.contains('emoji') ||
|
|
|
|
node.classList.contains('module-emoji__image--16px')) &&
|
|
|
|
!node.classList.contains('emoji--invisible')
|
|
|
|
) {
|
|
|
|
const emoji = node.getAttribute('aria-label');
|
2020-11-03 01:19:52 +00:00
|
|
|
return new Delta().insert({ emoji });
|
|
|
|
}
|
2023-05-10 00:40:19 +00:00
|
|
|
return delta;
|
2020-11-03 01:19:52 +00:00
|
|
|
};
|
|
|
|
|
2020-10-21 16:53:32 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-11-12 01:01:45 +00:00
|
|
|
export const matchEmojiText = (node: Text): Delta => {
|
2023-05-11 19:48:34 +00:00
|
|
|
if (node.data.replace(/(\n|\r\n)/g, '') === '') {
|
|
|
|
return new Delta();
|
|
|
|
}
|
|
|
|
|
2020-11-12 01:01:45 +00:00
|
|
|
const nodeAsInsert = { insert: node.data };
|
|
|
|
|
|
|
|
return new Delta(insertEmojiOps([nodeAsInsert]));
|
|
|
|
};
|