mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-10 17:30:51 +00:00
Remove redundant skin tone code
Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
parent
752638f448
commit
e19aec5abd
@ -6,7 +6,6 @@
|
|||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { getEmbeddedLabel } from '@hcengineering/platform'
|
import { getEmbeddedLabel } from '@hcengineering/platform'
|
||||||
import { tooltip, capitalizeFirstLetter, type EmojiWithGroup, type LabelAndProps } from '../../'
|
import { tooltip, capitalizeFirstLetter, type EmojiWithGroup, type LabelAndProps } from '../../'
|
||||||
import { getEmoji } from '.'
|
|
||||||
import { type Emoji } from 'emojibase'
|
import { type Emoji } from 'emojibase'
|
||||||
|
|
||||||
export let emoji: EmojiWithGroup
|
export let emoji: EmojiWithGroup
|
||||||
@ -18,14 +17,13 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
const getSkinsCount = (e: Emoji | EmojiWithGroup): number | undefined => {
|
const getSkinsCount = (e: EmojiWithGroup): number | undefined => {
|
||||||
return Array.isArray(e.skins) ? e.skins.length : undefined
|
return Array.isArray(e.skins) ? e.skins.length : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
let displayedEmoji: Emoji | EmojiWithGroup
|
let displayedEmoji: Emoji | EmojiWithGroup
|
||||||
$: _emoji = (getSkinsCount(emoji) ?? 0) > 0 ? emoji : getEmoji(emoji.hexcode)?.parent ?? emoji
|
$: skinIndex = emoji?.skins?.findIndex((skin) => skin.tone === skinTone) ?? -1
|
||||||
$: skinIndex = _emoji?.skins?.findIndex((skin) => skin.tone === skinTone) ?? -1
|
$: displayedEmoji = skinTone > 0 && Array.isArray(emoji.skins) && skinIndex > -1 ? emoji.skins[skinIndex] : emoji
|
||||||
$: displayedEmoji = skinTone > 0 && Array.isArray(_emoji.skins) && skinIndex > -1 ? _emoji.skins[skinIndex] : _emoji
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if emoji}
|
{#if emoji}
|
||||||
@ -34,9 +32,9 @@
|
|||||||
class="hulyPopupEmoji-button"
|
class="hulyPopupEmoji-button"
|
||||||
class:preview
|
class:preview
|
||||||
class:selected
|
class:selected
|
||||||
class:skins={_emoji?.skins !== undefined && _emoji.skins.length === 5}
|
class:skins={emoji?.skins !== undefined && emoji.skins.length === 5}
|
||||||
class:constructor={_emoji?.skins !== undefined && _emoji.skins.length > 5}
|
class:constructor={emoji?.skins !== undefined && emoji.skins.length > 5}
|
||||||
data-skins={getSkinsCount(_emoji)}
|
data-skins={getSkinsCount(emoji)}
|
||||||
{disabled}
|
{disabled}
|
||||||
on:touchstart
|
on:touchstart
|
||||||
on:contextmenu
|
on:contextmenu
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// Licensed under the Eclipse Public License v2.0 (SPDX: EPL-2.0).
|
// Licensed under the Eclipse Public License v2.0 (SPDX: EPL-2.0).
|
||||||
//
|
//
|
||||||
import { createEventDispatcher, onMount, onDestroy } from 'svelte'
|
import { createEventDispatcher, onMount, onDestroy } from 'svelte'
|
||||||
import type { Emoji } from 'emojibase'
|
|
||||||
import {
|
import {
|
||||||
Scroller,
|
Scroller,
|
||||||
SearchInput,
|
SearchInput,
|
||||||
@ -13,18 +12,16 @@
|
|||||||
showPopup,
|
showPopup,
|
||||||
eventToHTMLElement,
|
eventToHTMLElement,
|
||||||
ButtonBase,
|
ButtonBase,
|
||||||
closeTooltip
|
closeTooltip, getSkinnedEmoji
|
||||||
} from '../../'
|
} from '../../'
|
||||||
import plugin from '../../plugin'
|
import plugin from '../../plugin'
|
||||||
import {
|
import {
|
||||||
searchEmoji,
|
searchEmoji,
|
||||||
emojiStore,
|
emojiStore,
|
||||||
generateSkinToneEmojis,
|
|
||||||
emojiCategories,
|
emojiCategories,
|
||||||
getFrequentlyEmojis,
|
getFrequentlyEmojis,
|
||||||
addFrequentlyEmojis,
|
addFrequentlyEmojis,
|
||||||
removeFrequentlyEmojis,
|
removeFrequentlyEmojis,
|
||||||
getEmoji,
|
|
||||||
getSkinTone,
|
getSkinTone,
|
||||||
setSkinTone
|
setSkinTone
|
||||||
} from '.'
|
} from '.'
|
||||||
@ -100,25 +97,23 @@
|
|||||||
if (selectedCategory !== undefined) currentCategory = selectedCategory
|
if (selectedCategory !== undefined) currentCategory = selectedCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendEmoji = (emoji: Emoji | EmojiWithGroup): void => {
|
const sendEmoji = (emoji: EmojiWithGroup): void => {
|
||||||
selected = emoji.emoji
|
selected = emoji.emoji
|
||||||
addFrequentlyEmojis(emoji.hexcode)
|
addFrequentlyEmojis(emoji)
|
||||||
dispatch('close', {
|
dispatch('close', {
|
||||||
emoji: emoji.emoji,
|
emoji: emoji.emoji,
|
||||||
codes: emoji.hexcode.split('-').map((hc) => parseInt(hc, 16))
|
codes: emoji.hexcode.split('-').map((hc) => parseInt(hc, 16))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedEmoji = (event: CustomEvent<{ detail: EmojiWithGroup }>): void => {
|
const selectedEmoji = (event: CustomEvent<EmojiWithGroup>): void => {
|
||||||
if (event.detail === undefined || typeof event.detail !== 'object') return
|
if (event.detail === undefined || typeof event.detail !== 'object') return
|
||||||
const detail = event.detail as unknown as EmojiWithGroup
|
sendEmoji(event.detail)
|
||||||
sendEmoji(detail)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openContextMenu (event: TouchEvent | MouseEvent, _emoji: EmojiWithGroup, remove: boolean): void {
|
function openContextMenu (event: TouchEvent | MouseEvent, _emoji: EmojiWithGroup, remove: boolean): void {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const temp = getEmoji(_emoji.hexcode)
|
const emoji = _emoji
|
||||||
const emoji = temp?.parent ?? temp?.emoji
|
|
||||||
if (emoji === undefined) return
|
if (emoji === undefined) return
|
||||||
|
|
||||||
clearTimer()
|
clearTimer()
|
||||||
@ -127,9 +122,9 @@
|
|||||||
ActionsPopup,
|
ActionsPopup,
|
||||||
{ emoji, remove },
|
{ emoji, remove },
|
||||||
eventToHTMLElement(event),
|
eventToHTMLElement(event),
|
||||||
(result: 'remove' | Emoji | EmojiWithGroup) => {
|
(result: 'remove' | EmojiWithGroup) => {
|
||||||
if (result === 'remove') {
|
if (result === 'remove') {
|
||||||
removeFrequentlyEmojis(emoji.hexcode)
|
removeFrequentlyEmojis(emoji)
|
||||||
const index = emojisCat.findIndex((ec) => ec.id === 'frequently-used')
|
const index = emojisCat.findIndex((ec) => ec.id === 'frequently-used')
|
||||||
if (index > -1) emojisCat[index].emojis = getFrequentlyEmojis()
|
if (index > -1) emojisCat[index].emojis = getFrequentlyEmojis()
|
||||||
emojisCat = emojisCat.filter(
|
emojisCat = emojisCat.filter(
|
||||||
@ -171,7 +166,7 @@
|
|||||||
|
|
||||||
const showSkinMenu = (event: MouseEvent): void => {
|
const showSkinMenu = (event: MouseEvent): void => {
|
||||||
shownSTM = true
|
shownSTM = true
|
||||||
showPopup(SkinTonePopup, { emoji: 0x1f590, selected: skinTone }, eventToHTMLElement(event), (result) => {
|
showPopup(SkinTonePopup, { emoji: getSkinnedEmoji(':hand:'), selected: skinTone }, eventToHTMLElement(event), (result) => {
|
||||||
if (typeof result === 'number') {
|
if (typeof result === 'number') {
|
||||||
skinTone = result
|
skinTone = result
|
||||||
setSkinTone(skinTone)
|
setSkinTone(skinTone)
|
||||||
@ -270,7 +265,7 @@
|
|||||||
tooltip={{ label: plugin.string.DefaultSkinTone }}
|
tooltip={{ label: plugin.string.DefaultSkinTone }}
|
||||||
on:click={showSkinMenu}
|
on:click={showSkinMenu}
|
||||||
>
|
>
|
||||||
<span style:font-size={'1.5rem'}>{generateSkinToneEmojis(0x1f590)[skinTone]}</span>
|
<span style:font-size={'1.5rem'}>{getSkinnedEmoji(':hand:', skinTone)?.emoji}</span>
|
||||||
</ButtonBase>
|
</ButtonBase>
|
||||||
</div>
|
</div>
|
||||||
<Scroller
|
<Scroller
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import type { Emoji } from 'emojibase'
|
import type { Emoji } from 'emojibase'
|
||||||
import { Label, closeTooltip, ModernCheckbox } from '../../'
|
import { Label, closeTooltip, ModernCheckbox } from '../../'
|
||||||
import { generateSkinToneEmojis, skinTones, getEmojiCode } from '.'
|
import { skinTones } from '.'
|
||||||
import type { EmojiWithGroup } from '.'
|
import type { EmojiWithGroup } from '.'
|
||||||
|
|
||||||
export let emoji: number | number[] | string | Emoji | EmojiWithGroup
|
export let emoji: EmojiWithGroup
|
||||||
export let selected: number
|
export let selected: number
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
closeTooltip()
|
closeTooltip()
|
||||||
|
|
||||||
const skins: string[] = generateSkinToneEmojis(getEmojiCode(emoji))
|
const skins: Emoji[] = emoji.skins !== undefined ? [emoji, ...emoji.skins] : []
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="hulyPopup-container noPadding">
|
<div class="hulyPopup-container noPadding">
|
||||||
@ -31,7 +31,7 @@
|
|||||||
dispatch('close', index)
|
dispatch('close', index)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span style:font-size={'1.5rem'}>{skin}</span>
|
<span style:font-size={'1.5rem'}>{skin.emoji}</span>
|
||||||
{#if label}<span class="hulyPopup-row__label"><Label {label} /></span>{/if}
|
{#if label}<span class="hulyPopup-row__label"><Label {label} /></span>{/if}
|
||||||
{#if disabled}<span class="hulyPopup-row__keys"><ModernCheckbox checked disabled /></span>{/if}
|
{#if disabled}<span class="hulyPopup-row__keys"><ModernCheckbox checked disabled /></span>{/if}
|
||||||
</button>
|
</button>
|
||||||
|
@ -4,16 +4,16 @@
|
|||||||
// Licensed under the Eclipse Public License v2.0 (SPDX: EPL-2.0).
|
// Licensed under the Eclipse Public License v2.0 (SPDX: EPL-2.0).
|
||||||
//
|
//
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import type { Emoji } from 'emojibase'
|
import { type EmojiWithGroup } from '.'
|
||||||
import { generateSkinToneEmojis, getEmojiCode, type EmojiWithGroup } from '.'
|
|
||||||
import { ButtonBase, closeTooltip } from '../..'
|
import { ButtonBase, closeTooltip } from '../..'
|
||||||
|
import { Emoji } from 'emojibase'
|
||||||
|
|
||||||
export let emoji: number | number[] | string | Emoji | EmojiWithGroup
|
export let emoji: EmojiWithGroup
|
||||||
export let selected: number
|
export let selected: number
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
const skins: string[] = generateSkinToneEmojis(getEmojiCode(emoji))
|
const skins: Emoji[] = emoji.skins ?? []
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex-row-center flex-gap-1">
|
<div class="flex-row-center flex-gap-1">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
closeTooltip()
|
closeTooltip()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span style:font-size={'1.5rem'}>{skin}</span>
|
<span style:font-size={'1.5rem'}>{skin.emoji}</span>
|
||||||
</ButtonBase>
|
</ButtonBase>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,11 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
import { writable, derived } from 'svelte/store'
|
import { writable, derived } from 'svelte/store'
|
||||||
import type { Emoji } from 'emojibase'
|
|
||||||
import type { EmojiWithGroup } from '.'
|
import type { EmojiWithGroup } from '.'
|
||||||
|
|
||||||
export const emojiStore = writable<EmojiWithGroup[]>([])
|
export const emojiStore = writable<EmojiWithGroup[]>([])
|
||||||
export const emojiComponents = writable<Emoji[]>([])
|
|
||||||
export const searchEmoji = writable<string>('')
|
export const searchEmoji = writable<string>('')
|
||||||
|
|
||||||
export const resultEmojis = derived([emojiStore, searchEmoji], ([emojis, search]) => {
|
export const resultEmojis = derived([emojiStore, searchEmoji], ([emojis, search]) => {
|
||||||
@ -29,16 +27,3 @@ export const resultEmojis = derived([emojiStore, searchEmoji], ([emojis, search]
|
|||||||
)
|
)
|
||||||
: emojis
|
: emojis
|
||||||
})
|
})
|
||||||
|
|
||||||
export const groupsResultEmojis = derived(resultEmojis, (result) => {
|
|
||||||
const keys = new Set(result.map((res) => res?.key ?? ''))
|
|
||||||
const groups: string[] = keys?.size > 0 ? [...keys] : ['']
|
|
||||||
return {
|
|
||||||
emojis: new Map<string, EmojiWithGroup[]>(
|
|
||||||
groups.map((group) => {
|
|
||||||
return [group, result.filter((res) => res.key === group)]
|
|
||||||
})
|
|
||||||
),
|
|
||||||
groups
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
@ -17,7 +17,13 @@ import type { AnySvelteComponent } from '../..'
|
|||||||
import type { Emoji } from 'emojibase'
|
import type { Emoji } from 'emojibase'
|
||||||
|
|
||||||
export type EmojiWithGroup = Emoji & { key: string }
|
export type EmojiWithGroup = Emoji & { key: string }
|
||||||
export type Emojis = Emoji | EmojiWithGroup
|
|
||||||
|
export interface CustomEmoji {
|
||||||
|
shortcode: string
|
||||||
|
label: string
|
||||||
|
url: string
|
||||||
|
tags?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface EmojiCategory {
|
export interface EmojiCategory {
|
||||||
id: string
|
id: string
|
||||||
|
@ -13,15 +13,15 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
import type { Emoji, Locale } from 'emojibase'
|
||||||
import { fetchEmojis, fetchMessages } from 'emojibase'
|
import { fetchEmojis, fetchMessages } from 'emojibase'
|
||||||
import EMOJI_REGEX from 'emojibase-regex'
|
import EMOJI_REGEX from 'emojibase-regex'
|
||||||
import EMOTICON_REGEX from 'emojibase-regex/emoticon'
|
import EMOTICON_REGEX from 'emojibase-regex/emoticon'
|
||||||
import SHORTCODE_REGEX from 'emojibase-regex/shortcode'
|
import SHORTCODE_REGEX from 'emojibase-regex/shortcode'
|
||||||
import type { Emoji, Locale } from 'emojibase'
|
|
||||||
import { getCurrentAccount } from '@hcengineering/core'
|
import { getCurrentAccount } from '@hcengineering/core'
|
||||||
import { deviceOptionsStore as deviceInfo } from '../..'
|
import { deviceOptionsStore as deviceInfo } from '../..'
|
||||||
import { emojiStore, emojiComponents, emojiCategories, skinTonesCodes } from '.'
|
import type { EmojiWithGroup } from '.'
|
||||||
import type { EmojiWithGroup, EmojiHierarchy } from '.'
|
import { emojiCategories, emojiStore } from '.'
|
||||||
|
|
||||||
export const emojiRegex = EMOJI_REGEX
|
export const emojiRegex = EMOJI_REGEX
|
||||||
export const emojiGlobalRegex = new RegExp(EMOJI_REGEX.source, EMOJI_REGEX.flags + 'g')
|
export const emojiGlobalRegex = new RegExp(EMOJI_REGEX.source, EMOJI_REGEX.flags + 'g')
|
||||||
@ -32,12 +32,9 @@ export const emoticonGlobalRegex = new RegExp(`(?<!\\S)${EMOTICON_REGEX.source}(
|
|||||||
export const shortcodeRegex = new RegExp(`(?:^|\\s)(${SHORTCODE_REGEX.source})$`)
|
export const shortcodeRegex = new RegExp(`(?:^|\\s)(${SHORTCODE_REGEX.source})$`)
|
||||||
export const shortcodeGlobalRegex = new RegExp(`(?<!\\S)${SHORTCODE_REGEX.source}(?!\\S)`, SHORTCODE_REGEX.flags + 'g')
|
export const shortcodeGlobalRegex = new RegExp(`(?<!\\S)${SHORTCODE_REGEX.source}(?!\\S)`, SHORTCODE_REGEX.flags + 'g')
|
||||||
|
|
||||||
let availableEmojis: Emoji[]
|
let availableEmojis: EmojiWithGroup[]
|
||||||
|
|
||||||
export async function loadEmojis (lang?: string): Promise<{
|
export async function loadEmojis (lang?: string): Promise<EmojiWithGroup[]> {
|
||||||
emojis: EmojiWithGroup[]
|
|
||||||
components: Emoji[]
|
|
||||||
}> {
|
|
||||||
const local = lang ?? get(deviceInfo).language ?? 'en'
|
const local = lang ?? get(deviceInfo).language ?? 'en'
|
||||||
const englishEmojis =
|
const englishEmojis =
|
||||||
local === 'en'
|
local === 'en'
|
||||||
@ -64,27 +61,32 @@ export async function loadEmojis (lang?: string): Promise<{
|
|||||||
})
|
})
|
||||||
: (englishEmojis as Emoji[])
|
: (englishEmojis as Emoji[])
|
||||||
|
|
||||||
return {
|
return emojis
|
||||||
emojis: emojis
|
.filter((e) => e.group !== 2 && e.group !== undefined)
|
||||||
.filter((e) => e.group !== 2 && e.group !== undefined)
|
.map((e) => {
|
||||||
.map((e) => {
|
return { ...e, key: categories.get(groupKeys.get(e?.group ?? 0) ?? '') ?? '' }
|
||||||
return { ...e, key: categories.get(groupKeys.get(e?.group ?? 0) ?? '') ?? '' }
|
})
|
||||||
}),
|
|
||||||
components: emojis.filter((e) => e.group === 2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateEmojis (lang?: string): Promise<void> {
|
export async function updateEmojis (lang?: string): Promise<void> {
|
||||||
const { emojis, components } = await loadEmojis(lang)
|
const emojis = await loadEmojis(lang)
|
||||||
availableEmojis = emojis
|
availableEmojis = emojis
|
||||||
emojiStore.set(emojis)
|
emojiStore.set(emojis)
|
||||||
emojiComponents.set(components)
|
}
|
||||||
|
|
||||||
|
export function getSkinnedEmoji (shortcode: string | undefined, skinTone?: number): Emoji | undefined {
|
||||||
|
if (shortcode === undefined) return undefined
|
||||||
|
const shortcodeSlice = shortcode.slice(1, -1)
|
||||||
|
const matchEmoji = availableEmojis.find((e) => e.shortcodes?.includes(shortcodeSlice))
|
||||||
|
if (skinTone === undefined || matchEmoji === undefined) return matchEmoji
|
||||||
|
if (skinTone === 0) return matchEmoji
|
||||||
|
return matchEmoji.skins === undefined ? undefined : matchEmoji.skins[skinTone - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getEmojiForShortCode (shortcode: string | undefined): string | undefined {
|
export function getEmojiForShortCode (shortcode: string | undefined): string | undefined {
|
||||||
shortcode = shortcode?.slice(1, -1)
|
|
||||||
if (shortcode === undefined) return undefined
|
if (shortcode === undefined) return undefined
|
||||||
const result = availableEmojis.find(e => e.shortcodes?.includes(shortcode))
|
const shortcodeSlice = shortcode.slice(1, -1)
|
||||||
|
const result = availableEmojis.find(e => e.shortcodes?.includes(shortcodeSlice))
|
||||||
return result === undefined ? undefined : result.emoji
|
return result === undefined ? undefined : result.emoji
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +101,8 @@ function getEmojisLocalStorageKey (suffix: string = 'frequently'): string {
|
|||||||
return `emojis.${suffix}.${me.uuid}`
|
return `emojis.${suffix}.${me.uuid}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeFrequentlyEmojis = (_hexcode: string): void => {
|
export const removeFrequentlyEmojis = (emoji: EmojiWithGroup): void => {
|
||||||
const emoji = getEmoji(_hexcode)
|
const hexcode = emoji.hexcode
|
||||||
const hexcode = emoji?.parent?.hexcode ?? emoji?.emoji.hexcode
|
|
||||||
if (hexcode === undefined) return
|
if (hexcode === undefined) return
|
||||||
|
|
||||||
const frequentlyEmojisKey = getEmojisLocalStorageKey()
|
const frequentlyEmojisKey = getEmojisLocalStorageKey()
|
||||||
@ -116,10 +117,9 @@ export const removeFrequentlyEmojis = (_hexcode: string): void => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const addFrequentlyEmojis = (_hexcode: string): void => {
|
export const addFrequentlyEmojis = (emoji: EmojiWithGroup): void => {
|
||||||
const emoji = getEmoji(_hexcode)
|
if (emoji === undefined) return
|
||||||
const hexcode = emoji?.parent?.hexcode ?? emoji?.emoji.hexcode
|
const hexcode = emoji.hexcode
|
||||||
if (hexcode === undefined) return
|
|
||||||
|
|
||||||
const frequentlyEmojisKey = getEmojisLocalStorageKey()
|
const frequentlyEmojisKey = getEmojisLocalStorageKey()
|
||||||
const frequentlyEmojis = window.localStorage.getItem(frequentlyEmojisKey)
|
const frequentlyEmojis = window.localStorage.getItem(frequentlyEmojisKey)
|
||||||
@ -146,18 +146,8 @@ export const getFrequentlyEmojis = (): EmojiWithGroup[] | undefined => {
|
|||||||
try {
|
try {
|
||||||
const parsedEmojis = JSON.parse(frequentlyEmojis)
|
const parsedEmojis = JSON.parse(frequentlyEmojis)
|
||||||
if (!Array.isArray(parsedEmojis)) return undefined
|
if (!Array.isArray(parsedEmojis)) return undefined
|
||||||
|
const emojis = get(emojiStore)
|
||||||
const res: EmojiWithGroup[] = []
|
return emojis.filter(e => parsedEmojis.find(pe => pe.hexcode === e.hexcode) !== undefined)
|
||||||
|
|
||||||
for (const val of parsedEmojis) {
|
|
||||||
const map = getEmoji(val.hexcode)
|
|
||||||
const emoji = map?.parent ?? map?.emoji
|
|
||||||
if (emoji !== undefined) {
|
|
||||||
res.push(emoji)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return undefined
|
return undefined
|
||||||
@ -180,31 +170,3 @@ export const getSkinTone = (): number => {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const generateSkinToneEmojis = (baseEmoji: number | number[]): string[] => {
|
|
||||||
const isArray = Array.isArray(baseEmoji)
|
|
||||||
return [
|
|
||||||
String.fromCodePoint(...(isArray ? baseEmoji : [baseEmoji])),
|
|
||||||
...skinTonesCodes.map((skinTone) => {
|
|
||||||
return String.fromCodePoint(...(isArray ? baseEmoji : [baseEmoji]), skinTone)
|
|
||||||
})
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getEmojiMap = (): Map<string, EmojiHierarchy> | undefined => {
|
|
||||||
const result = new Map<string, EmojiHierarchy>()
|
|
||||||
const emojis = get(emojiStore)
|
|
||||||
|
|
||||||
emojis.forEach((emoji) => {
|
|
||||||
result.set(emoji.hexcode, { emoji })
|
|
||||||
emoji.skins?.forEach((skin) => result.set(skin.hexcode, { emoji: { ...skin, key: emoji.key }, parent: emoji }))
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
export const getEmoji = (hexcode: string): EmojiHierarchy | undefined => {
|
|
||||||
return getEmojiMap()?.get(hexcode)
|
|
||||||
}
|
|
||||||
export const getEmojiCode = (e: number | number[] | string | Emoji | EmojiWithGroup): number | number[] => {
|
|
||||||
return typeof e === 'number' || Array.isArray(e)
|
|
||||||
? e
|
|
||||||
: (typeof e === 'object' ? e.hexcode : e).split('-').map((h) => parseInt(h, 16))
|
|
||||||
}
|
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
getEventPositionElement,
|
getEventPositionElement,
|
||||||
showPopup,
|
showPopup,
|
||||||
type Location,
|
type Location,
|
||||||
type Emojis
|
type EmojiWithGroup
|
||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import { type AttributeModel } from '@hcengineering/view'
|
import { type AttributeModel } from '@hcengineering/view'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
@ -61,7 +61,7 @@ export async function addReactionAction (
|
|||||||
|
|
||||||
closePopup()
|
closePopup()
|
||||||
|
|
||||||
showPopup(EmojiPopup, {}, element, (emoji: Emojis) => {
|
showPopup(EmojiPopup, {}, element, (emoji: EmojiWithGroup) => {
|
||||||
if (emoji?.emoji !== undefined) void updateDocReactions(reactions, message, emoji.emoji)
|
if (emoji?.emoji !== undefined) void updateDocReactions(reactions, message, emoji.emoji)
|
||||||
params?.onClose?.()
|
params?.onClose?.()
|
||||||
})
|
})
|
||||||
|
@ -34,7 +34,7 @@ function handleEmoji (
|
|||||||
if (!isValidEmojiPosition($from)) {
|
if (!isValidEmojiPosition($from)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const emoji = getEmojiFunction(match[0])
|
const emoji = getEmojiFunction(match.pop())
|
||||||
if (emoji === undefined) return
|
if (emoji === undefined) return
|
||||||
commands.insertContentAt(range, [
|
commands.insertContentAt(range, [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user