@m3ui-vue/m3ui-vue 0.8.7 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +13 -3
  2. package/dist/{MMenuItem-DmrsQrK7.js → MTextField-B0wGv1Mx.js} +374 -364
  3. package/dist/MTextField-B0wGv1Mx.js.map +1 -0
  4. package/dist/barcode.js +9 -11
  5. package/dist/barcode.js.map +1 -1
  6. package/dist/code-editor.js +2 -2
  7. package/dist/code-editor.js.map +1 -1
  8. package/dist/components/MCarousel.vue.d.ts +55 -36
  9. package/dist/components/MDialog.vue.d.ts +4 -2
  10. package/dist/components/MEmojiSelector.vue.d.ts +21 -5
  11. package/dist/components/MFabMenu.vue.d.ts +1 -1
  12. package/dist/components/MFlex.vue.d.ts +1 -1
  13. package/dist/components/MLightbox.vue.d.ts +15 -5
  14. package/dist/components/MScheduler.vue.d.ts +38 -1
  15. package/dist/components/MShape.vue.d.ts +1 -1
  16. package/dist/components/MSimpleCarousel.vue.d.ts +2 -2
  17. package/dist/components/MSlider.vue.d.ts +1 -1
  18. package/dist/components/MStack.vue.d.ts +1 -1
  19. package/dist/components/MToolbar.vue.d.ts +1 -1
  20. package/dist/components/MWindow.vue.d.ts +1 -1
  21. package/dist/composables/_carouselStrategy.d.ts +101 -0
  22. package/dist/composables/useLocale.d.ts +23 -0
  23. package/dist/data/emoji-names/emoji-names-de.d.ts +2 -0
  24. package/dist/data/emoji-names/emoji-names-en.d.ts +2 -0
  25. package/dist/data/emoji-names/emoji-names-es.d.ts +2 -0
  26. package/dist/data/emoji-names/emoji-names-fr.d.ts +2 -0
  27. package/dist/data/emoji-names/emoji-names-ja.d.ts +2 -0
  28. package/dist/data/emoji-names/emoji-names-ko.d.ts +2 -0
  29. package/dist/data/emoji-names/emoji-names-pt.d.ts +2 -0
  30. package/dist/data/emoji-names/emoji-names-zh.d.ts +2 -0
  31. package/dist/data/emojis.d.ts +7 -1
  32. package/dist/emoji-names-de-BphO5XpV.js +1877 -0
  33. package/dist/emoji-names-de-BphO5XpV.js.map +1 -0
  34. package/dist/emoji-names-en-9ZvMRvzi.js +1877 -0
  35. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -0
  36. package/dist/emoji-names-es-DvfWU3Pj.js +1877 -0
  37. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -0
  38. package/dist/emoji-names-fr-B-jhUlsP.js +1877 -0
  39. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -0
  40. package/dist/emoji-names-ja-l8cMFJo1.js +1877 -0
  41. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -0
  42. package/dist/emoji-names-ko-YP-o9G0c.js +1877 -0
  43. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -0
  44. package/dist/emoji-names-pt-DGj_Js4M.js +1877 -0
  45. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -0
  46. package/dist/emoji-names-zh-Dzecwtw_.js +1877 -0
  47. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -0
  48. package/dist/index.d.ts +2 -2
  49. package/dist/locales/index.js +168 -7
  50. package/dist/locales/index.js.map +1 -1
  51. package/dist/m3ui-vue.css +1 -1
  52. package/dist/m3ui.js +3926 -2430
  53. package/dist/m3ui.js.map +1 -1
  54. package/dist/plugin.d.ts +6 -0
  55. package/dist/rich-text-editor.js +9 -9
  56. package/dist/styles.css +1 -1
  57. package/dist/terminal.js +34 -27
  58. package/dist/terminal.js.map +1 -1
  59. package/dist/{useLocale-Bircp823.js → useLocale-CmI675Ab.js} +25 -2
  60. package/dist/useLocale-CmI675Ab.js.map +1 -0
  61. package/package.json +1 -1
  62. package/src/__tests__/MCarousel.test.ts +183 -21
  63. package/src/__tests__/MDialog.test.ts +18 -0
  64. package/src/__tests__/MEmojiSelector.test.ts +138 -0
  65. package/src/__tests__/MLightbox.test.ts +313 -5
  66. package/src/__tests__/MPagination.test.ts +37 -0
  67. package/src/__tests__/MPullToRefresh.test.ts +39 -0
  68. package/src/__tests__/MScheduler.test.ts +122 -0
  69. package/src/__tests__/MTerminal.test.ts +63 -0
  70. package/src/__tests__/attrsFallthrough.test.ts +65 -0
  71. package/src/__tests__/plugin.test.ts +28 -1
  72. package/src/components/MBarcode.vue +4 -2
  73. package/src/components/MBottomSheet.vue +1 -1
  74. package/src/components/MCarousel.vue +526 -200
  75. package/src/components/MCodeEditor.vue +3 -2
  76. package/src/components/MCommandPalette.vue +1 -1
  77. package/src/components/MContextMenu.vue +3 -1
  78. package/src/components/MDatePickerModal.vue +1 -1
  79. package/src/components/MDateRangePickerModal.vue +1 -1
  80. package/src/components/MDialog.vue +19 -6
  81. package/src/components/MEmojiSelector.vue +479 -78
  82. package/src/components/MFab.vue +3 -1
  83. package/src/components/MLightbox.vue +750 -268
  84. package/src/components/MLoadingOverlay.vue +6 -1
  85. package/src/components/MMenu.vue +3 -1
  86. package/src/components/MNavigationDrawer.vue +5 -1
  87. package/src/components/MNavigationRail.vue +8 -2
  88. package/src/components/MOverlay.vue +1 -0
  89. package/src/components/MPagination.vue +8 -5
  90. package/src/components/MPullToRefresh.vue +13 -1
  91. package/src/components/MScheduler.vue +282 -115
  92. package/src/components/MSideSheet.vue +1 -1
  93. package/src/components/MSplitButton.vue +3 -1
  94. package/src/components/MSpotlightSearch.vue +1 -1
  95. package/src/components/MTerminal.vue +22 -10
  96. package/src/components/MTimePickerModal.vue +1 -1
  97. package/src/components/MTooltip.vue +3 -0
  98. package/src/components/MTour.vue +2 -2
  99. package/src/composables/_carouselStrategy.ts +712 -0
  100. package/src/composables/useLocale.ts +48 -0
  101. package/src/data/emoji-names/emoji-names-de.ts +1875 -0
  102. package/src/data/emoji-names/emoji-names-en.ts +1875 -0
  103. package/src/data/emoji-names/emoji-names-es.ts +1875 -0
  104. package/src/data/emoji-names/emoji-names-fr.ts +1875 -0
  105. package/src/data/emoji-names/emoji-names-ja.ts +1875 -0
  106. package/src/data/emoji-names/emoji-names-ko.ts +1875 -0
  107. package/src/data/emoji-names/emoji-names-pt.ts +1875 -0
  108. package/src/data/emoji-names/emoji-names-zh.ts +1875 -0
  109. package/src/data/emojis.ts +29 -198
  110. package/src/index.ts +2 -2
  111. package/src/locales/de.ts +24 -0
  112. package/src/locales/es.ts +24 -0
  113. package/src/locales/fr.ts +24 -0
  114. package/src/locales/ja.ts +24 -0
  115. package/src/locales/ko.ts +24 -0
  116. package/src/locales/pt.ts +24 -0
  117. package/src/locales/zh.ts +24 -0
  118. package/src/plugin.ts +12 -1
  119. package/dist/MMenuItem-DmrsQrK7.js.map +0 -1
  120. package/dist/useLocale-Bircp823.js.map +0 -1
@@ -1,126 +1,527 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed } from 'vue'
2
+ /*
3
+ * Emoji picker. M3 has no emoji component; the reference is Google's own androidx
4
+ * EmojiPickerView (a category bar with Recent first, a grid with headers, skin-tone variants on
5
+ * long press) plus Gboard's search.
6
+ *
7
+ * Data: src/data/emojis.ts (Unicode emoji-test, generated) ships with the component; names and
8
+ * keywords (CLDR, one file per language in src/data/emoji-names/) load on demand, for the app's
9
+ * language plus English while searching.
10
+ */
11
+ import { computed, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'
3
12
  import MIcon from './MIcon.vue'
4
- import MTextField from './MTextField.vue'
5
- import { emojiCategories, type EmojiCategory } from '../data/emojis'
13
+ import { useLocale, type M3Locale } from '../composables/useLocale'
14
+ import { emojiCategories, toneableEmojis, withSkinTone, type EmojiCategory } from '../data/emojis'
6
15
 
7
16
  const props = withDefaults(
8
17
  defineProps<{
9
18
  /** Which categories to show (ids). All if empty. */
10
19
  categories?: string[]
11
- /** Show search bar */
20
+ /** Show the search field. */
12
21
  search?: boolean
13
- /** Number of recent columns */
22
+ /** Fixed number of columns. By default as many as fit. */
14
23
  columns?: number
15
- /** Emoji render size in px */
24
+ /** Emoji size in px. */
16
25
  emojiSize?: number
26
+ /** Remember picked emoji and show them first (stored in localStorage). */
27
+ recent?: boolean
28
+ /** How many recent emoji to keep. */
29
+ recentLimit?: number
30
+ /** Offer skin tones (long press, right click or Shift+Enter on an emoji, or the footer button). */
31
+ skinTones?: boolean
32
+ /** Show the hovered or focused emoji with its name at the bottom. */
33
+ preview?: boolean
34
+ /** Height of the scrolling grid. */
35
+ height?: string
17
36
  }>(),
18
- { search: true, columns: 8, emojiSize: 28 },
37
+ { search: true, emojiSize: 28, recent: true, recentLimit: 24, skinTones: true, preview: true, height: '320px' },
19
38
  )
20
39
 
21
40
  const emit = defineEmits<{
22
41
  select: [emoji: string]
23
42
  }>()
24
43
 
25
- const query = ref('')
26
- const activeCategory = ref<string | null>(null)
27
- const scrollContainer = ref<HTMLElement | null>(null)
28
- const categoryRefs = ref<Record<string, HTMLElement>>({})
44
+ const t = useLocale()
45
+
46
+ // ── Names (lazy, per language) ────────────────────────────────────────────────────────────────
47
+
48
+ type Names = Record<string, string>
49
+ const loaders: Record<string, () => Promise<{ default: Names }>> = {
50
+ en: () => import('../data/emoji-names/emoji-names-en'),
51
+ es: () => import('../data/emoji-names/emoji-names-es'),
52
+ fr: () => import('../data/emoji-names/emoji-names-fr'),
53
+ pt: () => import('../data/emoji-names/emoji-names-pt'),
54
+ de: () => import('../data/emoji-names/emoji-names-de'),
55
+ ja: () => import('../data/emoji-names/emoji-names-ja'),
56
+ zh: () => import('../data/emoji-names/emoji-names-zh'),
57
+ ko: () => import('../data/emoji-names/emoji-names-ko'),
58
+ }
59
+ const lang = computed(() => {
60
+ const code = (t.lang || 'en').slice(0, 2).toLowerCase()
61
+ return code in loaders ? code : 'en'
62
+ })
63
+ const names = shallowRef<Names | null>(null)
64
+ const englishNames = shallowRef<Names | null>(null)
65
+
66
+ async function load(code: string) {
67
+ return (await loaders[code]!()).default
68
+ }
69
+ watch(lang, async (code) => {
70
+ names.value = await load(code)
71
+ if (code === 'en') englishNames.value = names.value
72
+ }, { immediate: true })
73
+
74
+ /** The emoji's name in the app's language (its first entry). */
75
+ function nameOf(emoji: string) {
76
+ const entry = names.value?.[emoji]
77
+ if (!entry) return ''
78
+ const name = entry.slice(0, entry.indexOf('|') === -1 ? undefined : entry.indexOf('|'))
79
+ return name.charAt(0).toUpperCase() + name.slice(1)
80
+ }
81
+
82
+ // ── Recent and skin tone (per viewer, localStorage) ───────────────────────────────────────────
83
+
84
+ const RECENT_KEY = 'm3-emoji-recent'
85
+ const TONE_KEY = 'm3-emoji-tone'
86
+ function read<T>(key: string, fallback: T): T {
87
+ try {
88
+ const v = localStorage.getItem(key)
89
+ return v === null ? fallback : (JSON.parse(v) as T)
90
+ } catch {
91
+ return fallback
92
+ }
93
+ }
94
+ function store(key: string, value: unknown) {
95
+ try { localStorage.setItem(key, JSON.stringify(value)) } catch { /* storage blocked */ }
96
+ }
97
+ const recents = ref<string[]>(read<string[]>(RECENT_KEY, []))
98
+ const tone = ref<number>(read<number>(TONE_KEY, 0))
29
99
 
30
- const visibleCategories = computed<EmojiCategory[]>(() => {
31
- if (props.categories?.length) {
32
- return emojiCategories.filter((c) => props.categories!.includes(c.id))
100
+ const show = (emoji: string) => (props.skinTones ? withSkinTone(emoji, tone.value) : emoji)
101
+ /** Toned variant → its base emoji, for names and the tone row (recent emoji are stored toned). */
102
+ const toneBase = new Map<string, string>()
103
+ for (const e of toneableEmojis) for (let i = 1; i <= 5; i++) toneBase.set(withSkinTone(e, i), e)
104
+ const baseOf = (emoji: string) => toneBase.get(emoji) ?? emoji
105
+
106
+ function pick(emoji: string) {
107
+ emit('select', emoji)
108
+ if (props.recent) {
109
+ recents.value = [emoji, ...recents.value.filter((e) => e !== emoji)].slice(0, props.recentLimit)
110
+ store(RECENT_KEY, recents.value)
33
111
  }
34
- return emojiCategories
112
+ }
113
+
114
+ // ── Sections ──────────────────────────────────────────────────────────────────────────────────
115
+
116
+ const categoryLabel: Record<string, keyof M3Locale> = {
117
+ smileys: 'emojiCategorySmileys', gestures: 'emojiCategoryGestures', people: 'emojiCategoryPeople',
118
+ animals: 'emojiCategoryAnimals', nature: 'emojiCategoryNature', food: 'emojiCategoryFood',
119
+ activities: 'emojiCategoryActivities', travel: 'emojiCategoryTravel', objects: 'emojiCategoryObjects',
120
+ symbols: 'emojiCategorySymbols', flags: 'emojiCategoryFlags',
121
+ }
122
+ const labelOf = (c: EmojiCategory) => (categoryLabel[c.id] ? String(t[categoryLabel[c.id]!]) : c.label)
123
+
124
+ const visibleCategories = computed<EmojiCategory[]>(() =>
125
+ props.categories?.length ? emojiCategories.filter((c) => props.categories!.includes(c.id)) : emojiCategories,
126
+ )
127
+
128
+ interface Section { id: string; label: string; icon: string; emojis: string[] }
129
+
130
+ const query = ref('')
131
+ const normalize = (s: string) => s.toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g, '')
132
+
133
+ watch(query, (q) => {
134
+ // Searching also matches English names, which people often type regardless of the UI language.
135
+ if (q && !englishNames.value) load('en').then((n) => (englishNames.value = n))
136
+ })
137
+
138
+ const searchIndex = computed(() => {
139
+ const local = names.value
140
+ const english = englishNames.value
141
+ if (!local && !english) return []
142
+ return visibleCategories.value.flatMap((c) =>
143
+ c.emojis.map((emoji) => ({
144
+ emoji,
145
+ name: normalize((local?.[emoji] ?? '').split('|')[0] ?? ''),
146
+ text: normalize(`${local?.[emoji] ?? ''}|${english && english !== local ? english[emoji] ?? '' : ''}`),
147
+ })),
148
+ )
35
149
  })
36
150
 
37
- const filteredCategories = computed(() => {
38
- if (!query.value) return visibleCategories.value
39
- const q = query.value.toLowerCase()
40
- return visibleCategories.value
41
- .map((cat) => ({
42
- ...cat,
43
- emojis: cat.id.includes(q) || cat.label.toLowerCase().includes(q)
44
- ? cat.emojis
45
- : [],
46
- }))
47
- .filter((cat) => cat.emojis.length > 0)
151
+ const results = computed(() => {
152
+ const q = normalize(query.value.trim())
153
+ if (!q) return []
154
+ const tokens = q.split(/\s+/)
155
+ return searchIndex.value
156
+ .filter((it) => tokens.every((tok) => it.text.includes(tok)))
157
+ .map((it) => ({ emoji: it.emoji, rank: it.name.startsWith(q) ? 0 : it.text.split('|').some((w) => w.startsWith(tokens[0]!)) ? 1 : 2 }))
158
+ .sort((a, b) => a.rank - b.rank)
159
+ .map((it) => it.emoji)
160
+ })
161
+
162
+ const sections = computed<Section[]>(() => {
163
+ if (query.value.trim()) return [{ id: 'results', label: t.emojiSearch, icon: 'search', emojis: results.value }]
164
+ const list: Section[] = visibleCategories.value.map((c) => ({ id: c.id, label: labelOf(c), icon: c.icon, emojis: c.emojis }))
165
+ if (props.recent && recents.value.length) list.unshift({ id: 'recent', label: t.emojiRecent, icon: 'schedule', emojis: recents.value })
166
+ return list
167
+ })
168
+
169
+ // ── Scrolling and the category bar ────────────────────────────────────────────────────────────
170
+
171
+ const gridEl = ref<HTMLElement | null>(null)
172
+ const activeSection = ref<string | null>(null)
173
+ let scrollFrame = 0
174
+
175
+ function onScroll() {
176
+ if (scrollFrame) return
177
+ scrollFrame = requestAnimationFrame(() => {
178
+ scrollFrame = 0
179
+ const grid = gridEl.value
180
+ if (!grid) return
181
+ let current = sections.value[0]?.id ?? null
182
+ for (const el of grid.querySelectorAll<HTMLElement>('[data-emoji-section]')) {
183
+ if (el.offsetTop - grid.scrollTop <= 8) current = el.dataset.emojiSection!
184
+ }
185
+ activeSection.value = current
186
+ })
187
+ }
188
+
189
+ function scrollToSection(id: string) {
190
+ const grid = gridEl.value
191
+ const el = grid?.querySelector<HTMLElement>(`[data-emoji-section="${id}"]`)
192
+ if (!grid || !el) return
193
+ activeSection.value = id
194
+ // scrollTo on the grid only: scrollIntoView() would scroll the page around it too.
195
+ grid.scrollTo({ top: el.offsetTop, behavior: 'smooth' })
196
+ }
197
+
198
+ watch(sections, () => nextTick(onScroll))
199
+
200
+ const gridColumns = computed(() =>
201
+ props.columns
202
+ ? `repeat(${props.columns}, minmax(0, 1fr))`
203
+ : `repeat(auto-fill, minmax(${props.emojiSize + 12}px, 1fr))`,
204
+ )
205
+
206
+ // ── Preview ───────────────────────────────────────────────────────────────────────────────────
207
+
208
+ const previewed = ref<string | null>(null)
209
+
210
+ // ── Keyboard (roving focus over the grid) ─────────────────────────────────────────────────────
211
+
212
+ const focusKey = ref<string | null>(null)
213
+ const keyOf = (section: string, emoji: string) => `${section}:${emoji}`
214
+ const firstKey = computed(() => {
215
+ const s = sections.value.find((x) => x.emojis.length)
216
+ return s ? keyOf(s.id, s.emojis[0]!) : null
48
217
  })
218
+ const rovingKey = computed(() => focusKey.value ?? firstKey.value)
219
+ watch(sections, () => (focusKey.value = null))
220
+
221
+ function buttons() {
222
+ return Array.from(gridEl.value?.querySelectorAll<HTMLElement>('[data-emoji]') ?? [])
223
+ }
49
224
 
50
- function scrollToCategory(id: string) {
51
- activeCategory.value = id
52
- const el = categoryRefs.value[id]
53
- if (el && scrollContainer.value) {
54
- el.scrollIntoView({ behavior: 'smooth', block: 'start' })
225
+ /** Keeps a focused emoji in view below the sticky header, scrolling the grid only. */
226
+ function keepVisible(el: HTMLElement) {
227
+ const grid = gridEl.value
228
+ if (!grid) return
229
+ const g = grid.getBoundingClientRect()
230
+ const r = el.getBoundingClientRect()
231
+ const header = 32
232
+ if (r.top < g.top + header) grid.scrollTop -= g.top + header - r.top
233
+ else if (r.bottom > g.bottom) grid.scrollTop += r.bottom - g.bottom
234
+ }
235
+
236
+ function focusButton(el: HTMLElement | undefined) {
237
+ if (!el) return
238
+ focusKey.value = el.dataset.key!
239
+ el.focus({ preventScroll: true })
240
+ keepVisible(el)
241
+ }
242
+
243
+ function onGridKeydown(e: KeyboardEvent) {
244
+ const list = buttons()
245
+ const i = list.indexOf(document.activeElement as HTMLElement)
246
+ if (i === -1) return
247
+ const cur = list[i]!
248
+ const rect = cur.getBoundingClientRect()
249
+ const sameColumnIn = (rows: HTMLElement[]) =>
250
+ rows.reduce<HTMLElement | undefined>((best, el) => {
251
+ const d = Math.abs(el.getBoundingClientRect().left - rect.left)
252
+ return !best || d < Math.abs(best.getBoundingClientRect().left - rect.left) ? el : best
253
+ }, undefined)
254
+ const rowOf = (from: HTMLElement[], top: number) => from.filter((el) => Math.abs(el.getBoundingClientRect().top - top) < 2)
255
+
256
+ if (e.key === 'ArrowRight') focusButton(list[i + 1])
257
+ else if (e.key === 'ArrowLeft') focusButton(list[i - 1])
258
+ else if (e.key === 'ArrowDown') {
259
+ const next = list.slice(i + 1).find((el) => el.getBoundingClientRect().top > rect.top + 2)
260
+ if (next) focusButton(sameColumnIn(rowOf(list.slice(i + 1), next.getBoundingClientRect().top)))
261
+ } else if (e.key === 'ArrowUp') {
262
+ const prev = [...list.slice(0, i)].reverse().find((el) => el.getBoundingClientRect().top < rect.top - 2)
263
+ if (prev) focusButton(sameColumnIn(rowOf(list.slice(0, i), prev.getBoundingClientRect().top)))
264
+ else searchEl.value?.focus()
265
+ } else if (e.key === 'Home') focusButton(list[0])
266
+ else if (e.key === 'End') focusButton(list[list.length - 1])
267
+ else if ((e.key === 'Enter' && e.shiftKey) || e.key === 'ContextMenu') {
268
+ const emoji = cur.dataset.emoji!
269
+ if (props.skinTones && toneableEmojis.has(baseOf(emoji))) openTones(baseOf(emoji), cur)
270
+ } else return
271
+ e.preventDefault()
272
+ }
273
+
274
+ const searchEl = ref<HTMLInputElement | null>(null)
275
+ function onSearchKeydown(e: KeyboardEvent) {
276
+ if (e.key === 'ArrowDown') {
277
+ e.preventDefault()
278
+ focusButton(buttons()[0])
279
+ } else if (e.key === 'Enter') {
280
+ const first = results.value[0]
281
+ if (first) pick(show(first))
282
+ } else if (e.key === 'Escape' && query.value) {
283
+ e.stopPropagation()
284
+ query.value = ''
55
285
  }
56
286
  }
57
287
 
58
- function selectEmoji(emoji: string) {
59
- emit('select', emoji)
288
+ // ── Skin tones ────────────────────────────────────────────────────────────────────────────────
289
+
290
+ const rootEl = ref<HTMLElement | null>(null)
291
+ const tonePicker = ref<{ emoji: string | null; x: number; y: number; below: boolean } | null>(null)
292
+ const toneLabels = computed(() => t.emojiSkinTones.split('|'))
293
+
294
+ /** Opens the tone row above `anchor`, for `emoji` (null: the default tone for every emoji). */
295
+ function openTones(emoji: string | null, anchor: HTMLElement) {
296
+ const root = rootEl.value
297
+ if (!root) return
298
+ const r = root.getBoundingClientRect()
299
+ const a = anchor.getBoundingClientRect()
300
+ const below = a.top - r.top < 56
301
+ tonePicker.value = { emoji, x: a.left - r.left + a.width / 2, y: below ? a.bottom - r.top + 4 : a.top - r.top - 4, below }
302
+ nextTick(() => rootEl.value?.querySelector<HTMLElement>('[data-tone-option][aria-checked="true"]')?.focus())
303
+ }
304
+
305
+ function chooseTone(i: number) {
306
+ const picker = tonePicker.value
307
+ tone.value = i
308
+ store(TONE_KEY, i)
309
+ tonePicker.value = null
310
+ if (picker?.emoji) pick(withSkinTone(picker.emoji, i))
311
+ }
312
+
313
+ function onToneKeydown(e: KeyboardEvent) {
314
+ const opts = Array.from(rootEl.value?.querySelectorAll<HTMLElement>('[data-tone-option]') ?? [])
315
+ const i = opts.indexOf(document.activeElement as HTMLElement)
316
+ if (e.key === 'ArrowRight') opts[Math.min(i + 1, opts.length - 1)]?.focus()
317
+ else if (e.key === 'ArrowLeft') opts[Math.max(i - 1, 0)]?.focus()
318
+ else if (e.key === 'Escape') {
319
+ e.stopPropagation()
320
+ tonePicker.value = null
321
+ } else return
322
+ e.preventDefault()
60
323
  }
61
324
 
62
- function setCategoryRef(id: string, el: any) {
63
- if (el) categoryRefs.value[id] = el as HTMLElement
325
+ function onDocPointerDown(e: PointerEvent) {
326
+ if (tonePicker.value && !(e.target as Element).closest('[data-tone-picker]')) tonePicker.value = null
327
+ }
328
+
329
+ // Long press (touch) opens the tones; the click that ends it doesn't also pick the emoji.
330
+ let pressTimer: ReturnType<typeof setTimeout> | null = null
331
+ let pressStart = { x: 0, y: 0 }
332
+ let suppressClick = false
333
+
334
+ function onEmojiPointerDown(e: PointerEvent, base: string) {
335
+ if (!props.skinTones || !toneableEmojis.has(base) || e.pointerType === 'mouse') return
336
+ const target = e.currentTarget as HTMLElement
337
+ pressStart = { x: e.clientX, y: e.clientY }
338
+ pressTimer = setTimeout(() => {
339
+ pressTimer = null
340
+ suppressClick = true
341
+ openTones(base, target)
342
+ }, 450)
343
+ }
344
+ function onEmojiPointerMove(e: PointerEvent) {
345
+ if (pressTimer && Math.hypot(e.clientX - pressStart.x, e.clientY - pressStart.y) > 8) cancelPress()
346
+ }
347
+ function cancelPress() {
348
+ if (pressTimer) clearTimeout(pressTimer)
349
+ pressTimer = null
64
350
  }
351
+ function onEmojiClick(emoji: string) {
352
+ if (suppressClick) {
353
+ suppressClick = false
354
+ return
355
+ }
356
+ pick(emoji)
357
+ }
358
+ function onEmojiContextMenu(e: MouseEvent, base: string) {
359
+ if (!props.skinTones || !toneableEmojis.has(base)) return
360
+ e.preventDefault()
361
+ openTones(base, e.currentTarget as HTMLElement)
362
+ }
363
+
364
+ onMounted(() => {
365
+ document.addEventListener('pointerdown', onDocPointerDown)
366
+ onScroll()
367
+ })
368
+ onBeforeUnmount(() => {
369
+ document.removeEventListener('pointerdown', onDocPointerDown)
370
+ cancelPress()
371
+ if (scrollFrame) cancelAnimationFrame(scrollFrame)
372
+ })
373
+
374
+ defineExpose({ focus: () => (searchEl.value ?? buttons()[0])?.focus() })
65
375
  </script>
66
376
 
67
377
  <template>
68
- <div class="flex w-full flex-col overflow-hidden rounded-xl border border-outline-variant bg-surface-container">
378
+ <div ref="rootEl" class="relative flex w-full flex-col overflow-hidden rounded-xl bg-surface-container-high">
69
379
  <!-- Search -->
70
- <div v-if="search" class="px-3 pt-3">
71
- <MTextField
72
- v-model="query"
73
- label="Search"
74
- leading-icon="search"
75
- variant="outlined"
76
- />
380
+ <!-- Its own bottom space: while searching the category bar is gone, and the results' sticky
381
+ header would otherwise cover the field's focus outline -->
382
+ <div v-if="search" class="px-3 pt-3 pb-1.5">
383
+ <label class="flex h-12 items-center gap-2 rounded-full bg-surface-container-highest px-4 focus-within:outline-2 focus-within:outline-secondary">
384
+ <MIcon name="search" :size="20" class="shrink-0 text-on-surface-variant" />
385
+ <input
386
+ ref="searchEl"
387
+ v-model="query"
388
+ type="text"
389
+ :placeholder="t.emojiSearch"
390
+ :aria-label="t.emojiSearch"
391
+ class="min-w-0 flex-1 bg-transparent text-body-large text-on-surface outline-none placeholder:text-on-surface-variant"
392
+ @keydown="onSearchKeydown"
393
+ />
394
+ <button
395
+ v-if="query"
396
+ type="button"
397
+ class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full text-on-surface-variant hover:bg-on-surface/8"
398
+ :aria-label="t.clearSearch"
399
+ @click="query = ''; searchEl?.focus()"
400
+ >
401
+ <MIcon name="close" :size="18" />
402
+ </button>
403
+ </label>
77
404
  </div>
78
405
 
79
- <!-- Category tabs -->
80
- <div class="flex gap-0.5 overflow-x-auto border-b border-outline-variant px-2 py-1.5">
406
+ <!-- Category bar -->
407
+ <div v-if="!query.trim()" class="flex gap-0.5 overflow-x-auto px-2 pb-1" :class="search ? 'pt-0.5' : 'pt-2'" style="scrollbar-width: none" role="tablist">
81
408
  <button
82
- v-for="cat in visibleCategories"
83
- :key="cat.id"
409
+ v-for="s in sections"
410
+ :key="s.id"
84
411
  type="button"
85
- :title="cat.label"
86
- class="flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full transition-colors duration-100"
87
- :class="activeCategory === cat.id
88
- ? 'bg-secondary-container text-on-secondary-container'
89
- : 'text-on-surface-variant hover:bg-on-surface/8'"
90
- @click="scrollToCategory(cat.id)"
412
+ role="tab"
413
+ :aria-selected="activeSection === s.id"
414
+ :aria-label="s.label"
415
+ :title="s.label"
416
+ class="flex h-9 min-w-9 flex-1 shrink-0 cursor-pointer items-center justify-center rounded-full transition-colors duration-150"
417
+ :class="activeSection === s.id ? 'bg-secondary-container text-on-secondary-container' : 'text-on-surface-variant hover:bg-on-surface/8'"
418
+ @click="scrollToSection(s.id)"
91
419
  >
92
- <MIcon :name="cat.icon" :size="20" />
420
+ <MIcon :name="s.icon" :size="20" />
93
421
  </button>
94
422
  </div>
95
423
 
96
- <!-- Emoji grid -->
97
- <div ref="scrollContainer" class="overflow-y-auto overflow-x-hidden px-2" style="max-height: 320px">
98
- <template v-for="cat in filteredCategories" :key="cat.id">
99
- <div :ref="(el) => setCategoryRef(cat.id, el)">
100
- <p class="sticky -top-px z-10 -mx-2 bg-surface-container px-3 py-1.5 text-label-medium text-on-surface-variant">
101
- {{ cat.label }}
102
- </p>
103
- <div class="grid gap-0.5" :style="{ gridTemplateColumns: `repeat(${columns}, 1fr)` }">
104
- <button
105
- v-for="emoji in cat.emojis"
106
- :key="emoji"
107
- type="button"
108
- class="flex cursor-pointer items-center justify-center rounded-lg p-1 transition-transform duration-75 hover:scale-115 hover:bg-on-surface/8 active:scale-95"
109
- :style="{ fontSize: `${emojiSize}px`, height: `${emojiSize + 10}px` }"
110
- @click="selectEmoji(emoji)"
111
- >
112
- {{ emoji }}
113
- </button>
114
- </div>
424
+ <!-- Grid -->
425
+ <div
426
+ ref="gridEl"
427
+ class="relative overflow-x-hidden overflow-y-auto px-2 pb-2"
428
+ :style="{ height }"
429
+ @scroll.passive="onScroll"
430
+ @keydown="onGridKeydown"
431
+ >
432
+ <section
433
+ v-for="s in sections"
434
+ :key="s.id"
435
+ :data-emoji-section="s.id"
436
+ role="group"
437
+ :aria-label="s.label"
438
+ >
439
+ <h3 class="sticky top-0 z-10 -mx-2 bg-surface-container-high px-3 py-1.5 text-label-medium text-on-surface-variant">{{ s.label }}</h3>
440
+ <div class="grid gap-0.5" :style="{ gridTemplateColumns: gridColumns }">
441
+ <button
442
+ v-for="emoji in s.emojis"
443
+ :key="emoji"
444
+ type="button"
445
+ :data-emoji="show(emoji)"
446
+ :data-key="keyOf(s.id, emoji)"
447
+ :tabindex="rovingKey === keyOf(s.id, emoji) ? 0 : -1"
448
+ :aria-label="nameOf(baseOf(emoji)) || emoji"
449
+ class="relative flex cursor-pointer items-center justify-center rounded-lg leading-none transition-transform duration-75 select-none hover:bg-on-surface/8 focus-visible:outline-2 focus-visible:outline-secondary active:scale-90"
450
+ :style="{ fontSize: `${emojiSize}px`, height: `${emojiSize + 12}px` }"
451
+ @click="onEmojiClick(show(emoji))"
452
+ @contextmenu="onEmojiContextMenu($event, baseOf(emoji))"
453
+ @pointerdown="onEmojiPointerDown($event, baseOf(emoji))"
454
+ @pointermove="onEmojiPointerMove"
455
+ @pointerup="cancelPress"
456
+ @pointercancel="cancelPress"
457
+ @pointerleave="cancelPress"
458
+ @mouseenter="previewed = show(emoji)"
459
+ @focus="previewed = show(emoji)"
460
+ >
461
+ {{ s.id === 'recent' ? emoji : show(emoji) }}
462
+ <!-- Takes a skin tone: a small corner mark, like Android's picker -->
463
+ <span
464
+ v-if="skinTones && s.id !== 'recent' && toneableEmojis.has(emoji)"
465
+ aria-hidden="true"
466
+ class="absolute right-1 bottom-1 h-1.5 w-1.5 bg-on-surface-variant/50 [clip-path:polygon(100%_0,100%_100%,0_100%)]"
467
+ />
468
+ </button>
115
469
  </div>
470
+ </section>
471
+
472
+ <p v-if="query.trim() && !results.length" class="py-10 text-center text-body-medium text-on-surface-variant">
473
+ {{ names || englishNames ? t.emojiNoResults : '…' }}
474
+ </p>
475
+ </div>
476
+
477
+ <!-- Preview and default skin tone -->
478
+ <div v-if="preview || skinTones" class="flex h-14 items-center gap-3 border-t border-outline-variant/60 px-4">
479
+ <template v-if="preview && previewed">
480
+ <span class="text-[32px] leading-none" aria-hidden="true">{{ previewed }}</span>
481
+ <span class="min-w-0 flex-1 truncate text-body-medium text-on-surface">{{ nameOf(baseOf(previewed)) }}</span>
116
482
  </template>
483
+ <span v-else class="flex-1" />
484
+ <button
485
+ v-if="skinTones"
486
+ type="button"
487
+ class="flex h-10 w-10 shrink-0 cursor-pointer items-center justify-center rounded-full text-[22px] leading-none hover:bg-on-surface/8"
488
+ :aria-label="`${t.emojiSkinTone}: ${toneLabels[tone] ?? ''}`"
489
+ :title="t.emojiSkinTone"
490
+ @click="openTones(null, $event.currentTarget as HTMLElement)"
491
+ >
492
+ {{ withSkinTone('✋', tone) }}
493
+ </button>
494
+ </div>
117
495
 
118
- <p
119
- v-if="query && filteredCategories.length === 0"
120
- class="py-8 text-center text-body-medium text-on-surface-variant"
496
+ <!-- Skin tone row -->
497
+ <div
498
+ v-if="tonePicker"
499
+ data-tone-picker
500
+ role="radiogroup"
501
+ :aria-label="t.emojiSkinTone"
502
+ class="absolute z-30 flex gap-0.5 rounded-full bg-surface-container-highest p-1 shadow-elevation-2"
503
+ :style="{
504
+ left: `clamp(4px, ${tonePicker.x}px - ${(emojiSize + 12) * 3}px, calc(100% - ${(emojiSize + 12) * 6 + 12}px))`,
505
+ top: `${tonePicker.y}px`,
506
+ transform: tonePicker.below ? undefined : 'translateY(-100%)',
507
+ }"
508
+ @keydown="onToneKeydown"
509
+ >
510
+ <button
511
+ v-for="(label, i) in toneLabels"
512
+ :key="i"
513
+ type="button"
514
+ role="radio"
515
+ data-tone-option
516
+ :aria-checked="tone === i"
517
+ :aria-label="label"
518
+ class="flex cursor-pointer items-center justify-center rounded-full leading-none hover:bg-on-surface/8 focus-visible:outline-2 focus-visible:outline-secondary"
519
+ :class="tone === i ? 'bg-secondary-container' : ''"
520
+ :style="{ fontSize: `${emojiSize}px`, width: `${emojiSize + 12}px`, height: `${emojiSize + 12}px` }"
521
+ @click="chooseTone(i)"
121
522
  >
122
- No results
123
- </p>
523
+ {{ withSkinTone(tonePicker.emoji ?? '✋', i) }}
524
+ </button>
124
525
  </div>
125
526
  </div>
126
527
  </template>
@@ -9,6 +9,8 @@ export interface SpeedDialItem {
9
9
  onClick?: () => void
10
10
  }
11
11
 
12
+ defineOptions({ inheritAttrs: false })
13
+
12
14
  const props = withDefaults(
13
15
  defineProps<{
14
16
  icon: string
@@ -275,7 +277,7 @@ onUnmounted(() => {
275
277
  </script>
276
278
 
277
279
  <template>
278
- <div ref="fabEl" class="relative inline-flex items-center justify-center">
280
+ <div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center">
279
281
  <component
280
282
  :is="fabTag"
281
283
  :to="to || undefined"