Compare commits
2 Commits
copilot/fi
...
emojiLocal
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92d761bb8a | ||
|
|
9210386508 |
@@ -86,6 +86,7 @@
|
||||
"@napi-rs/system-ocr": "patch:@napi-rs/system-ocr@npm%3A1.0.2#~/.yarn/patches/@napi-rs-system-ocr-npm-1.0.2-59e7a78e8b.patch",
|
||||
"@paymoapp/electron-shutdown-handler": "^1.1.2",
|
||||
"@strongtz/win32-arm64-msvc": "^0.4.7",
|
||||
"emoji-picker-element-data": "^1.8.0",
|
||||
"express": "^5.1.0",
|
||||
"font-list": "^2.0.0",
|
||||
"graceful-fs": "^4.2.11",
|
||||
|
||||
@@ -1,33 +1,62 @@
|
||||
import 'emoji-picker-element'
|
||||
|
||||
import TwemojiCountryFlagsWoff2 from '@renderer/assets/fonts/country-flag-fonts/TwemojiCountryFlags.woff2?url'
|
||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||
import { polyfillCountryFlagEmojis } from 'country-flag-emoji-polyfill'
|
||||
import emojiData from 'emoji-picker-element-data/en/emojibase/data.json'
|
||||
import type { FC } from 'react'
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
interface EmojiPickerElement extends HTMLElement {
|
||||
dataSource: typeof emojiData
|
||||
}
|
||||
|
||||
interface EmojiClickEvent extends CustomEvent {
|
||||
detail: {
|
||||
unicode?: string
|
||||
emoji?: { unicode: string }
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onEmojiClick: (emoji: string) => void
|
||||
}
|
||||
|
||||
declare module 'react' {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
'emoji-picker': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { class?: string }, HTMLElement>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EmojiPicker: FC<Props> = ({ onEmojiClick }) => {
|
||||
const { theme } = useTheme()
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const ref = useRef<EmojiPickerElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
polyfillCountryFlagEmojis('Twemoji Mozilla', TwemojiCountryFlagsWoff2)
|
||||
}, [])
|
||||
|
||||
// 初始化 dataSource
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.dataSource = emojiData
|
||||
}
|
||||
}, [])
|
||||
|
||||
// 事件监听
|
||||
useEffect(() => {
|
||||
const refValue = ref.current
|
||||
|
||||
if (refValue) {
|
||||
const handleEmojiClick = (event: any) => {
|
||||
const handleEmojiClick = (event: Event) => {
|
||||
event.stopPropagation()
|
||||
onEmojiClick(event.detail.unicode || event.detail.emoji.unicode)
|
||||
const emojiEvent = event as EmojiClickEvent
|
||||
onEmojiClick(emojiEvent.detail.unicode || emojiEvent.detail.emoji?.unicode || '')
|
||||
}
|
||||
// 添加事件监听器
|
||||
refValue.addEventListener('emoji-click', handleEmojiClick)
|
||||
|
||||
// 清理事件监听器
|
||||
return () => {
|
||||
refValue.removeEventListener('emoji-click', handleEmojiClick)
|
||||
}
|
||||
@@ -35,7 +64,6 @@ const EmojiPicker: FC<Props> = ({ onEmojiClick }) => {
|
||||
return
|
||||
}, [onEmojiClick])
|
||||
|
||||
// @ts-ignore next-line
|
||||
return <emoji-picker ref={ref} class={theme === 'dark' ? 'dark' : 'light'} style={{ border: 'none' }} />
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'emoji-picker-element'
|
||||
|
||||
import { CloseCircleFilled } from '@ant-design/icons'
|
||||
import CodeEditor from '@renderer/components/CodeEditor'
|
||||
import EmojiPicker from '@renderer/components/EmojiPicker'
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'emoji-picker-element'
|
||||
|
||||
import { CheckOutlined, LoadingOutlined, RollbackOutlined, ThunderboltOutlined } from '@ant-design/icons'
|
||||
import { loggerService } from '@logger'
|
||||
import EmojiPicker from '@renderer/components/EmojiPicker'
|
||||
|
||||
@@ -10074,6 +10074,7 @@ __metadata:
|
||||
electron-window-state: "npm:^5.0.3"
|
||||
emittery: "npm:^1.0.3"
|
||||
emoji-picker-element: "npm:^1.22.1"
|
||||
emoji-picker-element-data: "npm:^1.8.0"
|
||||
epub: "patch:epub@npm%3A1.3.0#~/.yarn/patches/epub-npm-1.3.0-8325494ffe.patch"
|
||||
eslint: "npm:^9.22.0"
|
||||
eslint-plugin-import-zod: "npm:^1.2.0"
|
||||
@@ -13655,6 +13656,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"emoji-picker-element-data@npm:^1.8.0":
|
||||
version: 1.8.0
|
||||
resolution: "emoji-picker-element-data@npm:1.8.0"
|
||||
checksum: 10c0/c8976b636205a0cc90d2690859a1193add71a948dadf743962b47c338a4c3715768404d0ccbc02156608b44abf41f3e1d51756e06f1bbed9d164dd4cb1752103
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"emoji-picker-element@npm:^1.22.1":
|
||||
version: 1.26.3
|
||||
resolution: "emoji-picker-element@npm:1.26.3"
|
||||
|
||||
Reference in New Issue
Block a user