Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
323 lines
12 KiB
TypeScript
323 lines
12 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useRef, useEffect, useCallback, KeyboardEvent, ChangeEvent } from 'react'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Emoji data
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface EmojiCategory {
|
|
label: string
|
|
icon: string
|
|
emojis: string[]
|
|
}
|
|
|
|
const EMOJI_CATEGORIES: EmojiCategory[] = [
|
|
{
|
|
label: 'Smileys',
|
|
icon: '๐',
|
|
emojis: [
|
|
'๐', '๐', '๐', '๐', '๐', '๐
', '๐คฃ', '๐',
|
|
'๐', '๐', '๐', '๐', '๐', '๐ฅฐ', '๐', '๐คฉ',
|
|
'๐', '๐', '๐', '๐', '๐ฅฒ', '๐', '๐', '๐',
|
|
'๐คช', '๐', '๐ค', '๐ค', '๐คญ', '๐ซข', '๐ซฃ', '๐คซ',
|
|
'๐ค', '๐ซ ', '๐ค', '๐คจ', '๐', '๐', '๐ถ', '๐ซฅ',
|
|
'๐', '๐', '๐', '๐ฌ', '๐คฅ', '๐', '๐', '๐ช',
|
|
'๐คค', '๐ด', '๐ท', '๐ค', '๐ค', '๐คข', '๐คง', '๐ฅต',
|
|
'๐ฅถ', '๐ฅด', '๐ต', '๐คฏ', '๐ค ', '๐ฅณ', '๐ฅธ', '๐',
|
|
],
|
|
},
|
|
{
|
|
label: 'People',
|
|
icon: '๐',
|
|
emojis: [
|
|
'๐', '๐ค', '๐', 'โ', '๐', '๐ซฑ', '๐ซฒ', '๐ซณ',
|
|
'๐ซด', '๐', '๐ค', '๐ค', 'โ', '๐ค', '๐ซฐ', '๐ค',
|
|
'๐ค', '๐ค', '๐', '๐', '๐', '๐', '๐', 'โ',
|
|
'๐ซต', '๐', '๐', 'โ', '๐', '๐ค', '๐ค', '๐',
|
|
'๐', '๐ซถ', '๐', '๐คฒ', '๐ค', '๐', 'โ', '๐
',
|
|
'๐คณ', '๐ช', '๐ฆพ', '๐ฆฟ', '๐ฆต', '๐ฆถ', '๐', '๐ฆป',
|
|
'๐', '๐ซ', '๐ซ', '๐ง ', '๐ฆท', '๐ฆด', '๐', '๐
',
|
|
'๐', '๐ง', '๐ฆ', '๐ง', '๐ฉ', '๐จ', '๐ง', '๐ฑ',
|
|
],
|
|
},
|
|
{
|
|
label: 'Nature',
|
|
icon: '๐ฟ',
|
|
emojis: [
|
|
'๐ฟ', '๐ฑ', '๐ฒ', '๐ณ', '๐ด', '๐ต', '๐', '๐',
|
|
'๐', '๐', '๐', '๐', '๐ชด', '๐พ', '๐บ', '๐ธ',
|
|
'๐ผ', '๐ป', '๐น', '๐ท', '๐ชท', '๐', '๐', '๐',
|
|
'๐ชธ', '๐', '๐ฅ', '๐', 'โ
', '๐ค', 'โ', '๐ฉ',
|
|
'๐ง', '๐จ', '๐ฌ', '๐', '๐ซ', '๐ฆ', '๐ฅ', 'โ',
|
|
'๐', '๐', '๐', '๐', '๐', '๐', 'โญ', '๐',
|
|
'โจ', 'โก', '๐', '๐', '๐', '๐ช', '๐ ', 'โ',
|
|
'๐ถ', '๐ฑ', '๐ญ', '๐น', '๐ฐ', '๐ฆ', '๐ป', '๐ผ',
|
|
],
|
|
},
|
|
{
|
|
label: 'Food',
|
|
icon: '๐',
|
|
emojis: [
|
|
'๐', '๐', '๐ฎ', '๐ฏ', '๐ฅ', '๐ง', '๐ฅ', '๐ณ',
|
|
'๐ฅ', '๐ฒ', '๐ซ', '๐ฅฃ', '๐ฅ', '๐ฟ', '๐ง', '๐ฑ',
|
|
'๐', '๐', '๐', '๐', '๐', '๐', '๐ ', '๐ข',
|
|
'๐ฃ', '๐ค', '๐ฅ', '๐ฅฎ', '๐ก', '๐ฅ', '๐ฅ ', '๐ฅก',
|
|
'๐ฆ', '๐ฆ', '๐ฆ', '๐ฆ', '๐ฆ', '๐ง', '๐จ', '๐ฉ',
|
|
'๐ช', '๐', '๐ฐ', '๐ง', '๐ฅง', '๐ซ', '๐ฌ', '๐ญ',
|
|
'โ', '๐ต', '๐ง', '๐ฅค', '๐ง', '๐บ', '๐ป', '๐ฅ',
|
|
'๐ท', '๐ฅ', '๐ธ', '๐น', '๐ง', '๐พ', '๐ฅ', '๐ด',
|
|
],
|
|
},
|
|
{
|
|
label: 'Travel',
|
|
icon: 'โ๏ธ',
|
|
emojis: [
|
|
'โ', '๐', '๐ธ', '๐', '๐บ', '๐', '๐', '๐',
|
|
'๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐ป',
|
|
'๐', '๐', '๐', '๐', '๐ต', '๐ด', '๐ฒ', '๐น',
|
|
'๐ผ', '๐จ', '๐ฅ', '๐ค', 'โฝ', '๐ข', 'โด', '๐ฅ',
|
|
'๐ค', 'โต', '๐ฃ', '๐ถ', '๐', '๐', '๐', '๐',
|
|
'โฐ', '๐', '๐ป', '๐', '๐ ', '๐ก', '๐ข', '๐ฃ',
|
|
'๐ค', '๐ฅ', '๐ฆ', '๐จ', '๐ฉ', '๐ช', '๐ซ', '๐ฌ',
|
|
'๐ญ', '๐', '๐', 'โช', '๐', '๐', '๐ผ', '๐ฝ',
|
|
],
|
|
},
|
|
{
|
|
label: 'Objects',
|
|
icon: '๐ก',
|
|
emojis: [
|
|
'๐ก', '๐ฆ', '๐ฏ', '๐ช', '๐', '๐', '๐ป', '๐ฅ',
|
|
'๐จ', 'โจ', '๐ฑ', '๐ฒ', '๐ฑ', '๐ฒ', 'โ', '๐',
|
|
'๐', '๐ ', '๐บ', '๐ป', '๐', '๐', '๐', '๐งญ',
|
|
'โฑ', 'โฒ', 'โฐ', '๐ฐ', '๐ก', '๐ญ', '๐ฌ', '๐งช',
|
|
'๐งซ', '๐งฌ', '๐ฉบ', '๐ฉป', '๐', '๐ฉน', '๐ฉผ', '๐ฉธ',
|
|
'๐ง', '๐ช', '๐จ', '๐ช', 'โ', '๐ ', '๐ก', 'โ',
|
|
'๐ก', '๐', '๐', '๐', '๐', '๐ช', '๐ช', '๐ช',
|
|
'๐ฆ', '๐ซ', '๐ฌ', '๐ญ', '๐ฎ', '๐ณ', 'โ', '๐',
|
|
],
|
|
},
|
|
]
|
|
|
|
const FREQUENT_KEY = 'gitgram:emoji:frequent'
|
|
const MAX_FREQUENT = 8
|
|
|
|
function loadFrequent(): string[] {
|
|
if (typeof window === 'undefined') return []
|
|
try {
|
|
const raw = localStorage.getItem(FREQUENT_KEY)
|
|
return raw ? (JSON.parse(raw) as string[]) : []
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
function saveFrequent(emoji: string, current: string[]): string[] {
|
|
const filtered = current.filter((e) => e !== emoji)
|
|
const updated = [emoji, ...filtered].slice(0, MAX_FREQUENT)
|
|
try {
|
|
localStorage.setItem(FREQUENT_KEY, JSON.stringify(updated))
|
|
} catch {
|
|
// Ignore storage errors
|
|
}
|
|
return updated
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Component
|
|
// ---------------------------------------------------------------------------
|
|
|
|
interface EmojiPickerProps {
|
|
onSelect: (emoji: string) => void
|
|
}
|
|
|
|
export default function EmojiPicker({ onSelect }: EmojiPickerProps) {
|
|
const [open, setOpen] = useState(false)
|
|
const [activeCategory, setActiveCategory] = useState(0)
|
|
const [search, setSearch] = useState('')
|
|
const [frequent, setFrequent] = useState<string[]>([])
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const searchRef = useRef<HTMLInputElement>(null)
|
|
|
|
// Load frequent emojis on open
|
|
useEffect(() => {
|
|
if (open) {
|
|
setFrequent(loadFrequent())
|
|
// Focus the search input after the popover opens
|
|
requestAnimationFrame(() => searchRef.current?.focus())
|
|
} else {
|
|
setSearch('')
|
|
setActiveCategory(0)
|
|
}
|
|
}, [open])
|
|
|
|
// Close on outside click
|
|
useEffect(() => {
|
|
if (!open) return
|
|
function handleClick(e: MouseEvent) {
|
|
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
|
|
setOpen(false)
|
|
}
|
|
}
|
|
document.addEventListener('mousedown', handleClick)
|
|
return () => document.removeEventListener('mousedown', handleClick)
|
|
}, [open])
|
|
|
|
// Close on Escape
|
|
useEffect(() => {
|
|
if (!open) return
|
|
function handleKey(e: globalThis.KeyboardEvent) {
|
|
if (e.key === 'Escape') setOpen(false)
|
|
}
|
|
document.addEventListener('keydown', handleKey)
|
|
return () => document.removeEventListener('keydown', handleKey)
|
|
}, [open])
|
|
|
|
const handleSelect = useCallback(
|
|
(emoji: string) => {
|
|
setFrequent((prev) => saveFrequent(emoji, prev))
|
|
onSelect(emoji)
|
|
setOpen(false)
|
|
},
|
|
[onSelect]
|
|
)
|
|
|
|
const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
setSearch(e.target.value)
|
|
}
|
|
|
|
// Filtered emojis when searching
|
|
const searchResults: string[] = search.trim()
|
|
? EMOJI_CATEGORIES.flatMap((cat) =>
|
|
cat.emojis.filter((emoji) =>
|
|
cat.label.toLowerCase().includes(search.toLowerCase()) || emoji.includes(search)
|
|
)
|
|
).slice(0, 40)
|
|
: []
|
|
|
|
const activeEmojis = search.trim()
|
|
? searchResults
|
|
: EMOJI_CATEGORIES[activeCategory]?.emojis ?? []
|
|
|
|
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
if (e.key === 'Escape') {
|
|
e.preventDefault()
|
|
setOpen(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div ref={containerRef} className="relative inline-block" onKeyDown={handleKeyDown}>
|
|
{/* Trigger button */}
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen((prev) => !prev)}
|
|
className="text-xl p-1.5 rounded-lg text-neutral-500 hover:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors"
|
|
aria-label="Open emoji picker"
|
|
aria-expanded={open}
|
|
aria-haspopup="dialog"
|
|
>
|
|
๐
|
|
</button>
|
|
|
|
{/* Popover */}
|
|
{open && (
|
|
<div
|
|
role="dialog"
|
|
aria-label="Emoji picker"
|
|
className="absolute bottom-full mb-2 right-0 w-72 bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded-xl shadow-xl z-50 flex flex-col"
|
|
>
|
|
{/* Search */}
|
|
<div className="p-2 border-b border-neutral-100 dark:border-neutral-800">
|
|
<input
|
|
ref={searchRef}
|
|
type="text"
|
|
value={search}
|
|
onChange={handleSearchChange}
|
|
placeholder="Search emojis..."
|
|
className="w-full px-3 py-1.5 text-sm bg-neutral-100 dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 placeholder-neutral-400 dark:placeholder-neutral-500 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
/>
|
|
</div>
|
|
|
|
{/* Frequently used */}
|
|
{!search.trim() && frequent.length > 0 && (
|
|
<div className="px-2 pt-2 pb-1">
|
|
<p className="text-[10px] font-semibold uppercase tracking-wide text-neutral-400 dark:text-neutral-500 mb-1 px-1">
|
|
Frequently used
|
|
</p>
|
|
<div className="grid grid-cols-8 gap-0.5">
|
|
{frequent.map((emoji) => (
|
|
<button
|
|
key={`freq-${emoji}`}
|
|
type="button"
|
|
onClick={() => handleSelect(emoji)}
|
|
className="text-xl p-1 rounded hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors"
|
|
aria-label={emoji}
|
|
>
|
|
{emoji}
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Category tabs โ hidden when searching */}
|
|
{!search.trim() && (
|
|
<div className="flex gap-0.5 px-2 py-1 border-b border-neutral-100 dark:border-neutral-800 overflow-x-auto scrollbar-none">
|
|
{EMOJI_CATEGORIES.map((cat, i) => (
|
|
<button
|
|
key={cat.label}
|
|
type="button"
|
|
onClick={() => setActiveCategory(i)}
|
|
title={cat.label}
|
|
className={`flex-shrink-0 text-base p-1.5 rounded-lg transition-colors ${
|
|
activeCategory === i
|
|
? 'bg-blue-50 dark:bg-blue-950 ring-1 ring-blue-400'
|
|
: 'hover:bg-neutral-100 dark:hover:bg-neutral-800'
|
|
}`}
|
|
aria-label={cat.label}
|
|
aria-pressed={activeCategory === i}
|
|
>
|
|
{cat.icon}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{/* Emoji grid */}
|
|
<div className="overflow-y-auto" style={{ maxHeight: '192px' }}>
|
|
{activeEmojis.length === 0 ? (
|
|
<p className="text-center text-sm text-neutral-400 dark:text-neutral-500 py-6">
|
|
No emojis found
|
|
</p>
|
|
) : (
|
|
<div className="grid grid-cols-8 gap-0.5 p-2">
|
|
{activeEmojis.map((emoji, idx) => (
|
|
<button
|
|
key={`${emoji}-${idx}`}
|
|
type="button"
|
|
onClick={() => handleSelect(emoji)}
|
|
className="text-xl p-1 rounded hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors"
|
|
aria-label={emoji}
|
|
>
|
|
{emoji}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Category label footer */}
|
|
{!search.trim() && (
|
|
<div className="px-3 py-1.5 border-t border-neutral-100 dark:border-neutral-800">
|
|
<p className="text-[10px] font-semibold uppercase tracking-wide text-neutral-400 dark:text-neutral-500">
|
|
{EMOJI_CATEGORIES[activeCategory]?.label}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|