Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-02-19 18:58:56 +06:00 committed by GitHub
parent af315fd25a
commit b49762fe03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 6 deletions

View File

@ -311,7 +311,8 @@ function hashCode (str: string): number {
* @public * @public
*/ */
export function getColorNumberByText (str: string): number { export function getColorNumberByText (str: string): number {
return hashCode(str) const hash = hashCode(str)
return Math.abs(hash) % Math.min(darkPalette.length, whitePalette.length)
} }
/** /**

View File

@ -16,6 +16,7 @@
import { tooltip } from '../tooltips' import { tooltip } from '../tooltips'
import { AnySvelteComponent, emojiSP } from '../types' import { AnySvelteComponent, emojiSP } from '../types'
import plugin from '../plugin' import plugin from '../plugin'
import { fromCodePoint } from '../utils'
export let embedded = false export let embedded = false
export let selected: string | undefined export let selected: string | undefined
@ -108,7 +109,7 @@
function getEmojis (startCode: number, endCode: number, postfix?: number[]): Array<string | undefined> { function getEmojis (startCode: number, endCode: number, postfix?: number[]): Array<string | undefined> {
return [...Array(endCode - startCode + 1).keys()].map((v) => { return [...Array(endCode - startCode + 1).keys()].map((v) => {
const str = postfix ? String.fromCodePoint(v + startCode, ...postfix) : String.fromCodePoint(v + startCode) const str = postfix ? fromCodePoint(v + startCode, ...postfix) : fromCodePoint(v + startCode)
if ([...str.matchAll(regex)].length > 0) return str if ([...str.matchAll(regex)].length > 0) return str
return undefined return undefined
}) })

View File

@ -14,13 +14,14 @@
--> -->
<script lang="ts"> <script lang="ts">
import { IconSize } from '../types' import { IconSize } from '../types'
import { fromCodePoint } from '../utils'
export let icon: number export let icon: number
export let size: IconSize export let size: IconSize
let value: string = '' let value: string = ''
$: try { $: try {
value = String.fromCodePoint(icon) value = fromCodePoint(icon)
} catch (err) {} } catch (err) {}
</script> </script>

View File

@ -245,6 +245,10 @@ export function formatKey (key: string): string[][] {
return result return result
} }
export function fromCodePoint (...vals: number[]): string {
return String.fromCodePoint(...vals.map((p) => Math.abs(p) % 0x10ffff))
}
/** /**
* @public * @public
*/ */

View File

@ -31,6 +31,7 @@
ModernEditbox, ModernEditbox,
TextArea, TextArea,
closePopup, closePopup,
fromCodePoint,
getPlatformColorDef, getPlatformColorDef,
showPopup, showPopup,
themeStore themeStore
@ -421,7 +422,7 @@
{:else} {:else}
<EmojiPopup <EmojiPopup
embedded embedded
selected={String.fromCodePoint(color ?? 0)} selected={fromCodePoint(color ?? 0)}
on:close={(evt) => { on:close={(evt) => {
color = evt.detail.codePointAt(0) color = evt.detail.codePointAt(0)
icon = iconWithEmoji icon = iconWithEmoji

View File

@ -14,7 +14,15 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Asset, Metadata } from '@hcengineering/platform' import { Asset, Metadata } from '@hcengineering/platform'
import { Button, EmojiPopup, TabsControl, getPlatformColor, getPlatformColorDef, themeStore } from '@hcengineering/ui' import {
Button,
EmojiPopup,
TabsControl,
fromCodePoint,
getPlatformColor,
getPlatformColorDef,
themeStore
} from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import view from '../plugin' import view from '../plugin'
import ColorsPopup from './ColorsPopup.svelte' import ColorsPopup from './ColorsPopup.svelte'
@ -75,7 +83,7 @@
{:else} {:else}
<EmojiPopup <EmojiPopup
embedded embedded
selected={String.fromCodePoint(color ?? 0)} selected={fromCodePoint(color ?? 0)}
on:close={(evt) => { on:close={(evt) => {
dispatch('close', { icon: iconWithEmoji, color: evt.detail.codePointAt(0) }) dispatch('close', { icon: iconWithEmoji, color: evt.detail.codePointAt(0) })
}} }}