2022-06-22 08:41:04 -07:00
|
|
|
import EmojiData from '@emoji-mart/data';
|
2022-01-10 14:17:52 -08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
2022-06-22 08:41:04 -07:00
|
|
|
import { Picker } from 'emoji-mart';
|
2020-03-27 13:59:38 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2022-06-22 08:41:04 -07:00
|
|
|
import React, { useRef, useEffect } from 'react';
|
2022-01-10 14:17:52 -08:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2020-03-27 13:59:38 -07:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import Overlay from 'react-overlays/lib/Overlay';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
import { IconButton } from 'soapbox/components/ui';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import { buildCustomEmojis } from '../../emoji/emoji';
|
2022-06-22 08:41:04 -07:00
|
|
|
// import { EmojiPicker as EmojiPickerAsync } from '../../ui/util/async-components';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
2021-06-30 02:33:42 -07:00
|
|
|
emoji_search: { id: 'emoji_button.search', defaultMessage: 'Search…' },
|
2022-03-21 11:09:01 -07:00
|
|
|
emoji_not_found: { id: 'emoji_button.not_found', defaultMessage: 'No emoji\'s found.' },
|
2020-03-27 13:59:38 -07:00
|
|
|
custom: { id: 'emoji_button.custom', defaultMessage: 'Custom' },
|
|
|
|
recent: { id: 'emoji_button.recent', defaultMessage: 'Frequently used' },
|
|
|
|
search_results: { id: 'emoji_button.search_results', defaultMessage: 'Search results' },
|
|
|
|
people: { id: 'emoji_button.people', defaultMessage: 'People' },
|
|
|
|
nature: { id: 'emoji_button.nature', defaultMessage: 'Nature' },
|
|
|
|
food: { id: 'emoji_button.food', defaultMessage: 'Food & Drink' },
|
|
|
|
activity: { id: 'emoji_button.activity', defaultMessage: 'Activity' },
|
|
|
|
travel: { id: 'emoji_button.travel', defaultMessage: 'Travel & Places' },
|
|
|
|
objects: { id: 'emoji_button.objects', defaultMessage: 'Objects' },
|
|
|
|
symbols: { id: 'emoji_button.symbols', defaultMessage: 'Symbols' },
|
|
|
|
flags: { id: 'emoji_button.flags', defaultMessage: 'Flags' },
|
|
|
|
});
|
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
function EmojiPicker({ customEmojis }) {
|
|
|
|
const ref = useRef();
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
useEffect(() => {
|
|
|
|
const emojis = buildCustomEmojis(customEmojis);
|
|
|
|
const input = { data: EmojiData, ref, custom: [{ emojis }] };
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
// console.log(input);
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
new Picker(input);
|
|
|
|
}, []);
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
return <div ref={ref} />;
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
2022-06-22 08:41:04 -07:00
|
|
|
// let EmojiPicker, Emoji; // load asynchronously
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
// const backgroundImageFn = () => require('emoji-datasource/img/twitter/sheets/32.png');
|
|
|
|
const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
// const categoriesSort = [
|
|
|
|
// 'recent',
|
|
|
|
// 'custom',
|
|
|
|
// 'people',
|
|
|
|
// 'nature',
|
|
|
|
// 'foods',
|
|
|
|
// 'activity',
|
|
|
|
// 'places',
|
|
|
|
// 'objects',
|
|
|
|
// 'symbols',
|
|
|
|
// 'flags',
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// class ModifierPickerMenu extends React.PureComponent {
|
|
|
|
//
|
|
|
|
// static propTypes = {
|
|
|
|
// active: PropTypes.bool,
|
|
|
|
// onSelect: PropTypes.func.isRequired,
|
|
|
|
// onClose: PropTypes.func.isRequired,
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// handleClick = e => {
|
|
|
|
// this.props.onSelect(e.currentTarget.getAttribute('data-index') * 1);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// componentDidUpdate(prevProps) {
|
|
|
|
// if (this.props.active) {
|
|
|
|
// this.attachListeners();
|
|
|
|
// } else {
|
|
|
|
// this.removeListeners();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// componentWillUnmount() {
|
|
|
|
// this.removeListeners();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// handleDocumentClick = e => {
|
|
|
|
// if (this.node && !this.node.contains(e.target)) {
|
|
|
|
// this.props.onClose();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// attachListeners() {
|
|
|
|
// document.addEventListener('click', this.handleDocumentClick, false);
|
|
|
|
// document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// removeListeners() {
|
|
|
|
// document.removeEventListener('click', this.handleDocumentClick, false);
|
|
|
|
// document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// setRef = c => {
|
|
|
|
// this.node = c;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// render() {
|
|
|
|
// const { active } = this.props;
|
|
|
|
//
|
|
|
|
// return (
|
|
|
|
// <div className='emoji-picker-dropdown__modifiers__menu' style={{ display: active ? 'block' : 'none' }} ref={this.setRef}>
|
|
|
|
// <button onClick={this.handleClick} data-index={1}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={1} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// <button onClick={this.handleClick} data-index={2}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={2} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// <button onClick={this.handleClick} data-index={3}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={3} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// <button onClick={this.handleClick} data-index={4}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={4} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// <button onClick={this.handleClick} data-index={5}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={5} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// <button onClick={this.handleClick} data-index={6}><Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={6} backgroundImageFn={backgroundImageFn} /></button>
|
|
|
|
// </div>
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
// class ModifierPicker extends React.PureComponent {
|
|
|
|
//
|
|
|
|
// static propTypes = {
|
|
|
|
// active: PropTypes.bool,
|
|
|
|
// modifier: PropTypes.number,
|
|
|
|
// onChange: PropTypes.func,
|
|
|
|
// onClose: PropTypes.func,
|
|
|
|
// onOpen: PropTypes.func,
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// handleClick = () => {
|
|
|
|
// if (this.props.active) {
|
|
|
|
// this.props.onClose();
|
|
|
|
// } else {
|
|
|
|
// this.props.onOpen();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// handleSelect = modifier => {
|
|
|
|
// this.props.onChange(modifier);
|
|
|
|
// this.props.onClose();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// render() {
|
|
|
|
// const { active, modifier } = this.props;
|
|
|
|
//
|
|
|
|
// return (
|
|
|
|
// <div className='emoji-picker-dropdown__modifiers'>
|
|
|
|
// <Emoji emoji='thumbsup' set='twitter' size={22} sheetSize={32} skin={modifier} onClick={this.handleClick} backgroundImageFn={backgroundImageFn} />
|
|
|
|
// <ModifierPickerMenu active={active} onSelect={this.handleSelect} onClose={this.props.onClose} />
|
|
|
|
// </div>
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
@injectIntl
|
|
|
|
class EmojiPickerMenu extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
custom_emojis: ImmutablePropTypes.list,
|
2022-06-22 08:41:04 -07:00
|
|
|
// frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string),
|
2020-03-27 13:59:38 -07:00
|
|
|
loading: PropTypes.bool,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onPick: PropTypes.func.isRequired,
|
|
|
|
style: PropTypes.object,
|
|
|
|
placement: PropTypes.string,
|
|
|
|
arrowOffsetLeft: PropTypes.string,
|
|
|
|
arrowOffsetTop: PropTypes.string,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2022-06-22 08:41:04 -07:00
|
|
|
// skinTone: PropTypes.number.isRequired,
|
2020-03-27 13:59:38 -07:00
|
|
|
onSkinTone: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
style: {},
|
|
|
|
loading: true,
|
|
|
|
frequentlyUsedEmojis: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
modifierOpen: false,
|
|
|
|
placement: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleDocumentClick = e => {
|
|
|
|
if (this.node && !this.node.contains(e.target)) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
componentDidMount() {
|
2020-03-27 13:59:38 -07:00
|
|
|
document.addEventListener('click', this.handleDocumentClick, false);
|
|
|
|
document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
componentWillUnmount() {
|
2020-03-27 13:59:38 -07:00
|
|
|
document.removeEventListener('click', this.handleDocumentClick, false);
|
|
|
|
document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
getI18n = () => {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return {
|
|
|
|
search: intl.formatMessage(messages.emoji_search),
|
|
|
|
notfound: intl.formatMessage(messages.emoji_not_found),
|
|
|
|
categories: {
|
|
|
|
search: intl.formatMessage(messages.search_results),
|
|
|
|
recent: intl.formatMessage(messages.recent),
|
|
|
|
people: intl.formatMessage(messages.people),
|
|
|
|
nature: intl.formatMessage(messages.nature),
|
|
|
|
foods: intl.formatMessage(messages.food),
|
|
|
|
activity: intl.formatMessage(messages.activity),
|
|
|
|
places: intl.formatMessage(messages.travel),
|
|
|
|
objects: intl.formatMessage(messages.objects),
|
|
|
|
symbols: intl.formatMessage(messages.symbols),
|
|
|
|
flags: intl.formatMessage(messages.flags),
|
|
|
|
custom: intl.formatMessage(messages.custom),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = emoji => {
|
|
|
|
if (!emoji.native) {
|
|
|
|
emoji.native = emoji.colons;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.props.onClose();
|
|
|
|
this.props.onPick(emoji);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierOpen = () => {
|
|
|
|
this.setState({ modifierOpen: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierClose = () => {
|
|
|
|
this.setState({ modifierOpen: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleModifierChange = modifier => {
|
|
|
|
this.props.onSkinTone(modifier);
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2022-06-22 08:41:04 -07:00
|
|
|
// const { loading, style, intl, custom_emojis, skinTone, frequentlyUsedEmojis } = this.props;
|
|
|
|
const { loading, style, custom_emojis } = this.props;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <div style={{ width: 299 }} />;
|
|
|
|
}
|
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
// const title = intl.formatMessage(messages.emoji);
|
2020-03-27 13:59:38 -07:00
|
|
|
const { modifierOpen } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames('emoji-picker-dropdown__menu', { selecting: modifierOpen })} style={style} ref={this.setRef}>
|
2022-06-22 08:41:04 -07:00
|
|
|
<EmojiPicker customEmojis={custom_emojis} />
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
|
|
|
);
|
2022-06-22 08:41:04 -07:00
|
|
|
|
|
|
|
// return (
|
|
|
|
// <div className={classNames('emoji-picker-dropdown__menu', { selecting: modifierOpen })} style={style} ref={this.setRef}>
|
|
|
|
// <EmojiPicker
|
|
|
|
// perLine={8}
|
|
|
|
// emojiSize={22}
|
|
|
|
// sheetSize={32}
|
|
|
|
// custom={buildCustomEmojis(custom_emojis)}
|
|
|
|
// color=''
|
|
|
|
// emoji=''
|
|
|
|
// set='twitter'
|
|
|
|
// title={title}
|
|
|
|
// i18n={this.getI18n()}
|
|
|
|
// onClick={this.handleClick}
|
|
|
|
// include={categoriesSort}
|
|
|
|
// recent={frequentlyUsedEmojis}
|
|
|
|
// skin={skinTone}
|
|
|
|
// showPreview={false}
|
|
|
|
// backgroundImageFn={backgroundImageFn}
|
|
|
|
// autoFocus
|
|
|
|
// emojiTooltip
|
|
|
|
// />
|
|
|
|
//
|
|
|
|
// <ModifierPicker
|
|
|
|
// active={modifierOpen}
|
|
|
|
// modifier={skinTone}
|
|
|
|
// onOpen={this.handleModifierOpen}
|
|
|
|
// onClose={this.handleModifierClose}
|
|
|
|
// onChange={this.handleModifierChange}
|
|
|
|
// />
|
|
|
|
// </div>
|
|
|
|
// );
|
2020-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default @injectIntl
|
|
|
|
class EmojiPickerDropdown extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
custom_emojis: ImmutablePropTypes.list,
|
|
|
|
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onPickEmoji: PropTypes.func.isRequired,
|
|
|
|
onSkinTone: PropTypes.func.isRequired,
|
|
|
|
skinTone: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
active: false,
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
setRef = (c) => {
|
|
|
|
this.dropdown = c;
|
|
|
|
}
|
|
|
|
|
2022-06-09 08:38:52 -07:00
|
|
|
onShowDropdown = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
this.setState({ active: true });
|
|
|
|
|
2022-06-22 08:41:04 -07:00
|
|
|
// if (!EmojiPicker) {
|
|
|
|
// this.setState({ loading: true });
|
|
|
|
//
|
|
|
|
// EmojiPickerAsync().then(EmojiMart => {
|
|
|
|
// EmojiPicker = EmojiMart.Picker;
|
|
|
|
// Emoji = EmojiMart.Emoji;
|
|
|
|
//
|
|
|
|
// this.setState({ loading: false });
|
|
|
|
// }).catch(() => {
|
|
|
|
// this.setState({ loading: false });
|
|
|
|
// });
|
|
|
|
// }
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-06-09 08:38:52 -07:00
|
|
|
const { top } = e.target.getBoundingClientRect();
|
2020-03-27 13:59:38 -07:00
|
|
|
this.setState({ placement: top * 2 < innerHeight ? 'bottom' : 'top' });
|
|
|
|
}
|
|
|
|
|
|
|
|
onHideDropdown = () => {
|
|
|
|
this.setState({ active: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onToggle = (e) => {
|
|
|
|
if (!this.state.loading && (!e.key || e.key === 'Enter')) {
|
|
|
|
if (this.state.active) {
|
|
|
|
this.onHideDropdown();
|
|
|
|
} else {
|
|
|
|
this.onShowDropdown(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleKeyDown = e => {
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
this.onHideDropdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTargetRef = c => {
|
|
|
|
this.target = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
findTarget = () => {
|
|
|
|
return this.target;
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:47:35 -07:00
|
|
|
render() {
|
2020-03-27 13:59:38 -07:00
|
|
|
const { intl, onPickEmoji, onSkinTone, skinTone, frequentlyUsedEmojis } = this.props;
|
|
|
|
const title = intl.formatMessage(messages.emoji);
|
|
|
|
const { active, loading, placement } = this.state;
|
|
|
|
|
|
|
|
return (
|
2022-03-21 11:09:01 -07:00
|
|
|
<div className='relative' onKeyDown={this.handleKeyDown}>
|
|
|
|
<IconButton
|
|
|
|
ref={this.setTargetRef}
|
|
|
|
className={classNames({
|
|
|
|
'text-gray-400 hover:text-gray-600': true,
|
|
|
|
'pulse-loading': active && loading,
|
|
|
|
})}
|
|
|
|
alt='😀'
|
|
|
|
src={require('@tabler/icons/icons/mood-happy.svg')}
|
|
|
|
title={title}
|
|
|
|
aria-label={title}
|
|
|
|
aria-expanded={active}
|
|
|
|
role='button'
|
|
|
|
onClick={this.onToggle}
|
|
|
|
onKeyDown={this.onToggle}
|
|
|
|
tabIndex={0}
|
|
|
|
/>
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
<Overlay show={active} placement={placement} target={this.findTarget}>
|
|
|
|
<EmojiPickerMenu
|
|
|
|
custom_emojis={this.props.custom_emojis}
|
|
|
|
loading={loading}
|
|
|
|
onClose={this.onHideDropdown}
|
|
|
|
onPick={onPickEmoji}
|
|
|
|
onSkinTone={onSkinTone}
|
|
|
|
skinTone={skinTone}
|
|
|
|
frequentlyUsedEmojis={frequentlyUsedEmojis}
|
|
|
|
/>
|
|
|
|
</Overlay>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|