@traky-app/ui 1.5.0 → 1.6.1
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.
- package/package.json +1 -1
- package/registry/traky/json/internal-chat-mention.json +17 -0
- package/registry/traky/json/internal-chat-panel.json +31 -0
- package/registry/traky/json/option-combobox.json +22 -0
- package/registry/traky/registry.json +30 -0
- package/registry/traky/ui/internal-chat-mention.ts +202 -0
- package/registry/traky/ui/internal-chat-panel.tsx +1115 -0
- package/registry/traky/ui/option-combobox.tsx +307 -0
- package/src/ui/internal-chat-mention.ts +202 -0
- package/src/ui/internal-chat-panel.tsx +1115 -0
- package/src/ui/option-combobox.tsx +307 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useState, type ComponentType } from "react"
|
|
4
|
+
import { IconCheck, IconSelector } from "@tabler/icons-react"
|
|
5
|
+
import { Button } from "@/components/ui/button"
|
|
6
|
+
import {
|
|
7
|
+
Command,
|
|
8
|
+
CommandEmpty,
|
|
9
|
+
CommandGroup,
|
|
10
|
+
CommandInput,
|
|
11
|
+
CommandItem,
|
|
12
|
+
CommandList,
|
|
13
|
+
} from "@/components/ui/command"
|
|
14
|
+
import {
|
|
15
|
+
Popover,
|
|
16
|
+
PopoverContent,
|
|
17
|
+
PopoverTrigger,
|
|
18
|
+
} from "@/components/ui/popover"
|
|
19
|
+
import { cn, commandFilterAccentInsensitive } from "@/lib/utils"
|
|
20
|
+
|
|
21
|
+
export type OptionComboboxOption = {
|
|
22
|
+
value: string
|
|
23
|
+
label: string
|
|
24
|
+
icon?: ComponentType<{ className?: string; stroke?: number }>
|
|
25
|
+
iconClassName?: string
|
|
26
|
+
/** Pastilla de color, por ejemplo una etiqueta. */
|
|
27
|
+
color?: string
|
|
28
|
+
/** Sangría para una opción hija. */
|
|
29
|
+
indented?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function OptionGlyph({
|
|
33
|
+
icon: Icon,
|
|
34
|
+
className,
|
|
35
|
+
}: {
|
|
36
|
+
icon?: OptionComboboxOption["icon"]
|
|
37
|
+
className?: string
|
|
38
|
+
}) {
|
|
39
|
+
if (!Icon) return null
|
|
40
|
+
return <Icon className={cn("size-4 shrink-0", className)} stroke={1.75} />
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function OptionFace({ option }: { option: OptionComboboxOption }) {
|
|
44
|
+
if (option.color) {
|
|
45
|
+
return (
|
|
46
|
+
<span
|
|
47
|
+
className="inline-flex max-w-full items-center truncate rounded-full border px-2 py-0.5 text-xs font-medium"
|
|
48
|
+
style={{
|
|
49
|
+
color: option.color,
|
|
50
|
+
borderColor: option.color,
|
|
51
|
+
backgroundColor: `${option.color}1A`,
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
{option.label}
|
|
55
|
+
</span>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
return (
|
|
59
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
60
|
+
<OptionGlyph icon={option.icon} className={option.iconClassName} />
|
|
61
|
+
<span className="truncate">{option.label}</span>
|
|
62
|
+
</span>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function OptionCombobox({
|
|
67
|
+
value = "",
|
|
68
|
+
options,
|
|
69
|
+
onChange,
|
|
70
|
+
placeholder = "Seleccionar…",
|
|
71
|
+
searchPlaceholder = "Buscar…",
|
|
72
|
+
emptyLabel = "No se encontraron resultados.",
|
|
73
|
+
groupHeading,
|
|
74
|
+
allowEmpty = false,
|
|
75
|
+
emptyValueLabel,
|
|
76
|
+
emptyValueIcon,
|
|
77
|
+
clearLabel,
|
|
78
|
+
clearOption,
|
|
79
|
+
allOption,
|
|
80
|
+
groups,
|
|
81
|
+
multiple = false,
|
|
82
|
+
values = [],
|
|
83
|
+
onValuesChange,
|
|
84
|
+
className,
|
|
85
|
+
disabled = false,
|
|
86
|
+
modal = false,
|
|
87
|
+
title,
|
|
88
|
+
}: {
|
|
89
|
+
value?: string
|
|
90
|
+
options: OptionComboboxOption[]
|
|
91
|
+
onChange?: (value: string) => void
|
|
92
|
+
/** Varias opciones a la vez. El menú no se cierra al marcar. */
|
|
93
|
+
multiple?: boolean
|
|
94
|
+
values?: string[]
|
|
95
|
+
onValuesChange?: (values: string[]) => void
|
|
96
|
+
placeholder?: string
|
|
97
|
+
searchPlaceholder?: string
|
|
98
|
+
emptyLabel?: string
|
|
99
|
+
groupHeading?: string
|
|
100
|
+
/** Si es true, la primera fila deja el valor vacío y no pertenece a `options`. */
|
|
101
|
+
allowEmpty?: boolean
|
|
102
|
+
/** Texto de esa fila vacía. Si no se indica, usa `placeholder`. */
|
|
103
|
+
emptyValueLabel?: string
|
|
104
|
+
emptyValueIcon?: OptionComboboxOption["icon"]
|
|
105
|
+
/** Opción para vaciar el valor. El botón sigue mostrando `placeholder`. */
|
|
106
|
+
clearLabel?: string
|
|
107
|
+
/** Opción para vaciar el valor, visible también en el botón. */
|
|
108
|
+
clearOption?: OptionComboboxOption
|
|
109
|
+
/** Opción extra al inicio. Si no hay valor, el botón la muestra. */
|
|
110
|
+
allOption?: OptionComboboxOption
|
|
111
|
+
/** Varios grupos, por ejemplo persona y empresa. */
|
|
112
|
+
groups?: { heading?: string; options: OptionComboboxOption[] }[]
|
|
113
|
+
className?: string
|
|
114
|
+
disabled?: boolean
|
|
115
|
+
modal?: boolean
|
|
116
|
+
title?: string
|
|
117
|
+
}) {
|
|
118
|
+
const [open, setOpen] = useState(false)
|
|
119
|
+
const blankLabel = emptyValueLabel || placeholder
|
|
120
|
+
const realOptions = allowEmpty
|
|
121
|
+
? options.filter((option) => option.value !== "")
|
|
122
|
+
: options
|
|
123
|
+
const grouped = (groups ?? []).filter((group) => group.options.length > 0)
|
|
124
|
+
const catalog = grouped.length
|
|
125
|
+
? grouped.flatMap((group) => group.options)
|
|
126
|
+
: realOptions
|
|
127
|
+
const listOptions = allOption ? [allOption, ...catalog] : catalog
|
|
128
|
+
const emptyChoice: OptionComboboxOption = {
|
|
129
|
+
value: "",
|
|
130
|
+
label: blankLabel,
|
|
131
|
+
icon: emptyValueIcon,
|
|
132
|
+
}
|
|
133
|
+
const selected = allowEmpty && value === ""
|
|
134
|
+
? emptyChoice
|
|
135
|
+
: clearOption && value === ""
|
|
136
|
+
? clearOption
|
|
137
|
+
: listOptions.find((option) => option.value === value)
|
|
138
|
+
?? (!value ? allOption : undefined)
|
|
139
|
+
const selectedMany = multiple
|
|
140
|
+
? values.flatMap((id) => {
|
|
141
|
+
const option = listOptions.find((item) => item.value === id)
|
|
142
|
+
return option ? [option] : []
|
|
143
|
+
})
|
|
144
|
+
: []
|
|
145
|
+
|
|
146
|
+
const chosen = (optionValue: string) =>
|
|
147
|
+
multiple ? values.includes(optionValue) : value === optionValue
|
|
148
|
+
|
|
149
|
+
const choose = (next: string) => {
|
|
150
|
+
if (multiple) {
|
|
151
|
+
onValuesChange?.(
|
|
152
|
+
values.includes(next)
|
|
153
|
+
? values.filter((item) => item !== next)
|
|
154
|
+
: [...values, next],
|
|
155
|
+
)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
onChange?.(next)
|
|
159
|
+
setOpen(false)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<Popover
|
|
164
|
+
open={open}
|
|
165
|
+
onOpenChange={disabled ? undefined : setOpen}
|
|
166
|
+
modal={modal}
|
|
167
|
+
>
|
|
168
|
+
<PopoverTrigger asChild>
|
|
169
|
+
<Button
|
|
170
|
+
type="button"
|
|
171
|
+
variant="outline"
|
|
172
|
+
role="combobox"
|
|
173
|
+
aria-expanded={open}
|
|
174
|
+
disabled={disabled}
|
|
175
|
+
title={title}
|
|
176
|
+
className={cn(
|
|
177
|
+
"w-full justify-between font-normal",
|
|
178
|
+
multiple && "h-auto py-2",
|
|
179
|
+
className,
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{multiple ? (
|
|
183
|
+
<span className="flex min-w-0 flex-1 flex-wrap items-center gap-1.5">
|
|
184
|
+
{selectedMany.length ? (
|
|
185
|
+
selectedMany.map((option) => (
|
|
186
|
+
<OptionFace key={option.value} option={option} />
|
|
187
|
+
))
|
|
188
|
+
) : (
|
|
189
|
+
<span className="truncate text-muted-foreground">
|
|
190
|
+
{placeholder}
|
|
191
|
+
</span>
|
|
192
|
+
)}
|
|
193
|
+
</span>
|
|
194
|
+
) : selected ? (
|
|
195
|
+
<OptionFace option={selected} />
|
|
196
|
+
) : (
|
|
197
|
+
<span className="truncate text-muted-foreground">{placeholder}</span>
|
|
198
|
+
)}
|
|
199
|
+
<IconSelector className="size-4 shrink-0 opacity-50" />
|
|
200
|
+
</Button>
|
|
201
|
+
</PopoverTrigger>
|
|
202
|
+
{disabled ? null : (
|
|
203
|
+
<PopoverContent
|
|
204
|
+
align="start"
|
|
205
|
+
className="z-[60] w-[var(--radix-popover-trigger-width)] min-w-56 p-0"
|
|
206
|
+
>
|
|
207
|
+
<Command filter={commandFilterAccentInsensitive}>
|
|
208
|
+
<CommandInput placeholder={searchPlaceholder} />
|
|
209
|
+
<CommandList>
|
|
210
|
+
<CommandEmpty>{emptyLabel}</CommandEmpty>
|
|
211
|
+
{grouped.length ? (
|
|
212
|
+
grouped.map((group) => (
|
|
213
|
+
<CommandGroup
|
|
214
|
+
key={group.heading ?? group.options[0]?.value}
|
|
215
|
+
heading={group.heading}
|
|
216
|
+
>
|
|
217
|
+
{group.options.map((option) => (
|
|
218
|
+
<CommandItem
|
|
219
|
+
key={option.value || option.label}
|
|
220
|
+
value={`${option.label} ${option.value}`}
|
|
221
|
+
className={option.indented ? "pl-6" : undefined}
|
|
222
|
+
onSelect={() => choose(option.value)}
|
|
223
|
+
>
|
|
224
|
+
<OptionFace option={option} />
|
|
225
|
+
<IconCheck
|
|
226
|
+
className={cn(
|
|
227
|
+
"ml-auto size-4",
|
|
228
|
+
chosen(option.value) ? "opacity-100" : "opacity-0",
|
|
229
|
+
)}
|
|
230
|
+
/>
|
|
231
|
+
</CommandItem>
|
|
232
|
+
))}
|
|
233
|
+
</CommandGroup>
|
|
234
|
+
))
|
|
235
|
+
) : (
|
|
236
|
+
<CommandGroup heading={groupHeading}>
|
|
237
|
+
{allowEmpty ? (
|
|
238
|
+
<CommandItem
|
|
239
|
+
value={`__empty__ ${blankLabel}`}
|
|
240
|
+
onSelect={() => choose("")}
|
|
241
|
+
>
|
|
242
|
+
<OptionGlyph icon={emptyValueIcon} />
|
|
243
|
+
{blankLabel}
|
|
244
|
+
<IconCheck
|
|
245
|
+
className={cn(
|
|
246
|
+
"ml-auto size-4",
|
|
247
|
+
value ? "opacity-0" : "opacity-100",
|
|
248
|
+
)}
|
|
249
|
+
/>
|
|
250
|
+
</CommandItem>
|
|
251
|
+
) : null}
|
|
252
|
+
{clearOption ? (
|
|
253
|
+
<CommandItem
|
|
254
|
+
value={`__clear__ ${clearOption.label}`}
|
|
255
|
+
onSelect={() => choose("")}
|
|
256
|
+
>
|
|
257
|
+
<OptionGlyph
|
|
258
|
+
icon={clearOption.icon}
|
|
259
|
+
className={clearOption.iconClassName}
|
|
260
|
+
/>
|
|
261
|
+
{clearOption.label}
|
|
262
|
+
<IconCheck
|
|
263
|
+
className={cn(
|
|
264
|
+
"ml-auto size-4",
|
|
265
|
+
value ? "opacity-0" : "opacity-100",
|
|
266
|
+
)}
|
|
267
|
+
/>
|
|
268
|
+
</CommandItem>
|
|
269
|
+
) : clearLabel ? (
|
|
270
|
+
<CommandItem
|
|
271
|
+
value={`__clear__ ${clearLabel}`}
|
|
272
|
+
onSelect={() => choose("")}
|
|
273
|
+
>
|
|
274
|
+
{clearLabel}
|
|
275
|
+
<IconCheck
|
|
276
|
+
className={cn(
|
|
277
|
+
"ml-auto size-4",
|
|
278
|
+
value ? "opacity-0" : "opacity-100",
|
|
279
|
+
)}
|
|
280
|
+
/>
|
|
281
|
+
</CommandItem>
|
|
282
|
+
) : null}
|
|
283
|
+
{listOptions.map((option) => (
|
|
284
|
+
<CommandItem
|
|
285
|
+
key={option.value || option.label}
|
|
286
|
+
value={`${option.label} ${option.value}`}
|
|
287
|
+
className={option.indented ? "pl-6" : undefined}
|
|
288
|
+
onSelect={() => choose(option.value)}
|
|
289
|
+
>
|
|
290
|
+
<OptionFace option={option} />
|
|
291
|
+
<IconCheck
|
|
292
|
+
className={cn(
|
|
293
|
+
"ml-auto size-4",
|
|
294
|
+
chosen(option.value) ? "opacity-100" : "opacity-0",
|
|
295
|
+
)}
|
|
296
|
+
/>
|
|
297
|
+
</CommandItem>
|
|
298
|
+
))}
|
|
299
|
+
</CommandGroup>
|
|
300
|
+
)}
|
|
301
|
+
</CommandList>
|
|
302
|
+
</Command>
|
|
303
|
+
</PopoverContent>
|
|
304
|
+
)}
|
|
305
|
+
</Popover>
|
|
306
|
+
)
|
|
307
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { Icon } from "@tabler/icons-react";
|
|
2
|
+
|
|
3
|
+
export type InternalChatMentionKind = "guide" | "package";
|
|
4
|
+
|
|
5
|
+
export type InternalChatMentionItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: InternalChatMentionKind;
|
|
8
|
+
label: string;
|
|
9
|
+
subtitle: string;
|
|
10
|
+
insertLabel: string;
|
|
11
|
+
icon: Icon;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type InternalChatMentionCategoryMeta = {
|
|
15
|
+
label: string;
|
|
16
|
+
hint: string;
|
|
17
|
+
keywords: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type InternalChatMentionListEntry =
|
|
21
|
+
| {
|
|
22
|
+
type: "category";
|
|
23
|
+
kind: InternalChatMentionKind;
|
|
24
|
+
label: string;
|
|
25
|
+
hint: string;
|
|
26
|
+
icon: Icon;
|
|
27
|
+
}
|
|
28
|
+
| { type: "item"; data: InternalChatMentionItem };
|
|
29
|
+
|
|
30
|
+
export const DEFAULT_MENTION_KIND_ORDER: InternalChatMentionKind[] = [
|
|
31
|
+
"guide",
|
|
32
|
+
"package",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_MENTION_KIND_LABEL: Record<
|
|
36
|
+
InternalChatMentionKind,
|
|
37
|
+
string
|
|
38
|
+
> = {
|
|
39
|
+
guide: "Guías",
|
|
40
|
+
package: "Paquetes",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type InternalChatMentionConfig = {
|
|
44
|
+
kindOrder: InternalChatMentionKind[];
|
|
45
|
+
categoryMeta: Record<
|
|
46
|
+
InternalChatMentionKind,
|
|
47
|
+
InternalChatMentionCategoryMeta
|
|
48
|
+
>;
|
|
49
|
+
kindIcons: Record<InternalChatMentionKind, Icon>;
|
|
50
|
+
kindAliases?: Record<string, InternalChatMentionKind>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function resolveKindAlias(
|
|
54
|
+
raw: string,
|
|
55
|
+
config: InternalChatMentionConfig,
|
|
56
|
+
): InternalChatMentionKind | null {
|
|
57
|
+
const s = raw.trim().toLowerCase();
|
|
58
|
+
if (!s) return null;
|
|
59
|
+
|
|
60
|
+
const aliases: Record<string, InternalChatMentionKind> = {
|
|
61
|
+
guide: "guide",
|
|
62
|
+
guía: "guide",
|
|
63
|
+
guia: "guide",
|
|
64
|
+
paquete: "package",
|
|
65
|
+
paquetes: "package",
|
|
66
|
+
package: "package",
|
|
67
|
+
...config.kindAliases,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const direct = aliases[s];
|
|
71
|
+
if (direct) return direct;
|
|
72
|
+
|
|
73
|
+
for (const kind of config.kindOrder) {
|
|
74
|
+
const meta = config.categoryMeta[kind];
|
|
75
|
+
if (kind === s) return kind;
|
|
76
|
+
if (meta.label.toLowerCase() === s) return kind;
|
|
77
|
+
if (meta.keywords.some((k) => k === s)) return kind;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function parseMentionSegment(
|
|
84
|
+
query: string,
|
|
85
|
+
config: InternalChatMentionConfig,
|
|
86
|
+
):
|
|
87
|
+
| { phase: "category"; filter: string }
|
|
88
|
+
| { phase: "item"; kind: InternalChatMentionKind; filter: string } {
|
|
89
|
+
const colon = query.indexOf(":");
|
|
90
|
+
if (colon === -1) {
|
|
91
|
+
return { phase: "category", filter: query };
|
|
92
|
+
}
|
|
93
|
+
const head = query.slice(0, colon).trim().toLowerCase();
|
|
94
|
+
const tail = query.slice(colon + 1);
|
|
95
|
+
if (head === "") {
|
|
96
|
+
return { phase: "category", filter: query.replace(":", "") };
|
|
97
|
+
}
|
|
98
|
+
const kind = resolveKindAlias(head, config);
|
|
99
|
+
if (!kind) {
|
|
100
|
+
return { phase: "category", filter: query };
|
|
101
|
+
}
|
|
102
|
+
return { phase: "item", kind, filter: tail };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function parseSlashMention(
|
|
106
|
+
draft: string,
|
|
107
|
+
cursor: number,
|
|
108
|
+
): { start: number; query: string } | null {
|
|
109
|
+
const before = draft.slice(0, cursor);
|
|
110
|
+
const lastSlash = before.lastIndexOf("/");
|
|
111
|
+
if (lastSlash === -1) return null;
|
|
112
|
+
const charBefore = lastSlash === 0 ? " " : draft[lastSlash - 1];
|
|
113
|
+
if (charBefore !== " " && charBefore !== "\n" && lastSlash !== 0) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const afterSlash = before.slice(lastSlash + 1);
|
|
117
|
+
if (afterSlash.includes("\n")) return null;
|
|
118
|
+
return { start: lastSlash, query: afterSlash };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function filterCategoryEntries(
|
|
122
|
+
filterText: string,
|
|
123
|
+
config: InternalChatMentionConfig,
|
|
124
|
+
): InternalChatMentionListEntry[] {
|
|
125
|
+
const q = filterText.trim().toLowerCase();
|
|
126
|
+
const rows: InternalChatMentionListEntry[] = config.kindOrder.map((kind) => ({
|
|
127
|
+
type: "category",
|
|
128
|
+
kind,
|
|
129
|
+
label: config.categoryMeta[kind].label,
|
|
130
|
+
hint: config.categoryMeta[kind].hint,
|
|
131
|
+
icon: config.kindIcons[kind],
|
|
132
|
+
}));
|
|
133
|
+
if (!q) return rows;
|
|
134
|
+
const byAlias = resolveKindAlias(q, config);
|
|
135
|
+
return rows.filter((row) => {
|
|
136
|
+
if (row.type !== "category") return false;
|
|
137
|
+
if (byAlias && row.kind === byAlias) return true;
|
|
138
|
+
return (
|
|
139
|
+
row.label.toLowerCase().includes(q) ||
|
|
140
|
+
row.hint.toLowerCase().includes(q) ||
|
|
141
|
+
config.categoryMeta[row.kind].keywords.some(
|
|
142
|
+
(k) => k.includes(q) || q.includes(k),
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function filterItemsByKind(
|
|
149
|
+
kind: InternalChatMentionKind,
|
|
150
|
+
filterText: string,
|
|
151
|
+
catalog: InternalChatMentionItem[],
|
|
152
|
+
): InternalChatMentionListEntry[] {
|
|
153
|
+
const q = filterText.trim().toLowerCase();
|
|
154
|
+
let items = catalog.filter((i) => i.kind === kind);
|
|
155
|
+
if (q) {
|
|
156
|
+
items = items.filter(
|
|
157
|
+
(item) =>
|
|
158
|
+
item.label.toLowerCase().includes(q) ||
|
|
159
|
+
item.subtitle.toLowerCase().includes(q) ||
|
|
160
|
+
item.insertLabel.toLowerCase().includes(q),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return items.map((data) => ({ type: "item", data }));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function buildMentionList(
|
|
167
|
+
query: string,
|
|
168
|
+
guideItems: InternalChatMentionItem[],
|
|
169
|
+
packageItems: InternalChatMentionItem[],
|
|
170
|
+
config: InternalChatMentionConfig,
|
|
171
|
+
): InternalChatMentionListEntry[] {
|
|
172
|
+
const seg = parseMentionSegment(query, config);
|
|
173
|
+
if (seg.phase === "category") {
|
|
174
|
+
return filterCategoryEntries(seg.filter, config);
|
|
175
|
+
}
|
|
176
|
+
const pool = seg.kind === "guide" ? guideItems : packageItems;
|
|
177
|
+
return filterItemsByKind(seg.kind, seg.filter, pool);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function roomInitialLetter(name: string): string {
|
|
181
|
+
const t = name.trim();
|
|
182
|
+
if (!t) return "?";
|
|
183
|
+
const ch = [...t][0];
|
|
184
|
+
return ch && /\p{L}/u.test(ch) ? ch.toUpperCase() : "?";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function initialsFromDisplayName(name: string): string {
|
|
188
|
+
const t = name.trim();
|
|
189
|
+
if (!t) return "?";
|
|
190
|
+
const parts = t.split(/\s+/).filter(Boolean);
|
|
191
|
+
if (parts.length === 0) return "?";
|
|
192
|
+
if (parts.length === 1) return parts[0]!.slice(0, 2).toUpperCase();
|
|
193
|
+
return `${parts[0]![0]!}${parts[parts.length - 1]![0]!}`.toUpperCase();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function formatMessageTime(iso: string, locale = "es"): string {
|
|
197
|
+
return new Intl.DateTimeFormat(locale, {
|
|
198
|
+
hour: "2-digit",
|
|
199
|
+
minute: "2-digit",
|
|
200
|
+
hour12: false,
|
|
201
|
+
}).format(new Date(iso));
|
|
202
|
+
}
|