@kapiuara/ui 0.4.0 → 0.6.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.
- package/README.md +54 -1
- package/dist/components/chat/KapiChatDivider.d.ts +15 -0
- package/dist/components/chat/KapiChatDivider.js +17 -0
- package/dist/components/chat/KapiChatList.d.ts +57 -0
- package/dist/components/chat/KapiChatList.js +71 -0
- package/dist/components/chat/KapiChatThread.d.ts +35 -0
- package/dist/components/chat/KapiChatThread.js +85 -0
- package/dist/components/chat/KapiComposer.d.ts +60 -0
- package/dist/components/chat/KapiComposer.js +89 -0
- package/dist/components/chat/KapiMessageBubble.d.ts +43 -0
- package/dist/components/chat/KapiMessageBubble.js +67 -0
- package/dist/components/chat/KapiTypingIndicator.d.ts +27 -0
- package/dist/components/chat/KapiTypingIndicator.js +34 -0
- package/dist/components/chat/chatLogic.d.ts +76 -0
- package/dist/components/chat/chatLogic.js +34 -0
- package/dist/components/chat/index.d.ts +14 -0
- package/dist/components/display/KapiCommentComposer.d.ts +4 -0
- package/dist/components/display/KapiCommentComposer.js +43 -46
- package/dist/components/display/commentLogic.d.ts +9 -2
- package/dist/components/display/commentLogic.js +1 -1
- package/dist/components/display/index.d.ts +1 -0
- package/dist/components/inputs/KapiFacetedSearch.d.ts +14 -1
- package/dist/components/inputs/KapiFacetedSearch.js +172 -110
- package/dist/components/inputs/KapiSelect.d.ts +7 -0
- package/dist/components/inputs/KapiSelect.js +233 -229
- package/dist/components/inputs/facetedSearchLogic.d.ts +12 -2
- package/dist/components/inputs/facetedSearchLogic.js +10 -7
- package/dist/components/layout/KapiPanelParts.js +9 -9
- package/dist/components/layout/KapiRail.js +8 -8
- package/dist/components/locale/labelRegistry.d.ts +10 -0
- package/dist/components/navigation/KapiContextPanel.js +86 -86
- package/dist/components/navigation/KapiPanelGroup.js +18 -18
- package/dist/components/navigation/KapiTabs.js +1 -1
- package/dist/components/navigation/MiniNavItem.js +1 -1
- package/dist/hooks/dateFormat.d.ts +7 -0
- package/dist/hooks/dateFormat.js +16 -2
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useSubmitDraft.d.ts +34 -0
- package/dist/hooks/useSubmitDraft.js +28 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +83 -76
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ niveles; `0` no es estable (el antialiasing varía entre corridas).
|
|
|
52
52
|
## Estructura
|
|
53
53
|
|
|
54
54
|
```
|
|
55
|
-
src/components/{inputs,overlays,data,feedback,navigation,layout}/ # un index.ts por tema
|
|
55
|
+
src/components/{inputs,overlays,data,feedback,navigation,layout,chat}/ # un index.ts por tema
|
|
56
56
|
src/hooks/ # mecánicas: drag-scroll, click derecho global, tema, media query
|
|
57
57
|
src/styles/ # kapi.css (componentes; importa los tokens de @kapiuara/tokens), shell.css, fonts.css
|
|
58
58
|
src/index.ts # barrel: re-exporta todo
|
|
@@ -478,6 +478,59 @@ el foco. Con acción y sin `duration`, el toast dura 6 s (`TOAST_ACTION_DURATION
|
|
|
478
478
|
kapiToast.success("Trámite creado", { action: { label: "Ver trámite", onClick: () => abrir(id) } });
|
|
479
479
|
```
|
|
480
480
|
|
|
481
|
+
## Chat
|
|
482
|
+
|
|
483
|
+
La familia de chat está en `src/components/chat/` y se importa del paquete como el resto. Son seis piezas
|
|
484
|
+
chicas que se componen; ninguna sabe de red, de usuarios ni de tu modelo de mensajes.
|
|
485
|
+
|
|
486
|
+
- `KapiMessageBubble`: una burbuja (entrante o saliente), con hora, estado de entrega, cita de respuesta y un
|
|
487
|
+
slot para adjuntos. Su `grouping` redondea las esquinas de una corrida del mismo autor.
|
|
488
|
+
- `KapiChatThread`: la zona que scrollea. Sigue al fondo cuando entra un mensaje, **no** mueve el scroll si el
|
|
489
|
+
usuario subió a leer (lo avisa con una píldora, `unseen`) y baja siempre al cambiar `followKey`.
|
|
490
|
+
- `KapiChatDivider`: el separador de día o de no leídos (`tone="unread"`).
|
|
491
|
+
- `KapiComposer`: el campo de escritura al pie. Textarea que crece, acciones a los lados (`leading`/`trailing`)
|
|
492
|
+
y botón de envío.
|
|
493
|
+
- `KapiChatList`: la lista de conversaciones (avatar, nombre, hora, preview y contador de no leídos). La app es
|
|
494
|
+
dueña de la conversación activa: `activeId` + `onSelect(id)`.
|
|
495
|
+
- `KapiTypingIndicator`: el aviso «Fulano está escribiendo…». `names` vacío no dibuja nada.
|
|
496
|
+
|
|
497
|
+
La lógica es pura y va aparte: `groupChatMessages` convierte los mensajes (en orden cronológico) en renglones
|
|
498
|
+
(`day`, `unread`, `message`) y decide la posición de cada burbuja dentro de su corrida; `formatDayLabel` pone
|
|
499
|
+
«hoy», «ayer» o el día de la semana al separador. El tipo de tu mensaje extiende `KapiChatMessage`
|
|
500
|
+
(`id`, `authorId`, `at`, `status?`) con lo que quieras.
|
|
501
|
+
|
|
502
|
+
```tsx
|
|
503
|
+
const entries = groupChatMessages(messages, { meId: "yo", firstUnreadId });
|
|
504
|
+
|
|
505
|
+
<KapiChatThread followKey={sent} unseen={unseen}>
|
|
506
|
+
{entries.map((e) =>
|
|
507
|
+
e.kind === "day" ? (
|
|
508
|
+
<KapiChatDivider key={e.key}>{formatDayLabel(e.at)}</KapiChatDivider>
|
|
509
|
+
) : e.kind === "unread" ? (
|
|
510
|
+
<KapiChatDivider key={e.key} tone="unread">{`${e.count} sin leer`}</KapiChatDivider>
|
|
511
|
+
) : (
|
|
512
|
+
<KapiMessageBubble key={e.key} outgoing={e.outgoing} grouping={e.grouping} time={hora(e.message.at)}>
|
|
513
|
+
{e.message.text}
|
|
514
|
+
</KapiMessageBubble>
|
|
515
|
+
)
|
|
516
|
+
)}
|
|
517
|
+
</KapiChatThread>
|
|
518
|
+
<KapiTypingIndicator names={escribiendo} />
|
|
519
|
+
<KapiComposer onSubmit={(texto) => enviar(texto)} />
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**El atajo de envío:** en `KapiComposer` Enter envía y Shift + Enter hace un salto de línea (`submitOn="enter"`,
|
|
523
|
+
el valor por defecto; `submitOn="modifier"` lo pasa a Ctrl/⌘ + Enter). `KapiCommentComposer` **no cambia**: sigue
|
|
524
|
+
enviando con Ctrl/⌘ + Enter y Enter solo agrega un salto de línea. Como con el resto, `onSubmit` puede devolver una
|
|
525
|
+
promesa: el campo queda ocupado y se vacía solo si resuelve.
|
|
526
|
+
|
|
527
|
+
`KapiTypingIndicator` es una región `aria-live="polite"`: un lector de pantalla anuncia quién escribe sin mover el
|
|
528
|
+
foco. Sus puntos son un loop que **no se congela** con movimiento reducido (parecería colgado): sigue vivo pero
|
|
529
|
+
lento, como el spinner. Textos en las claves `messageBubble`, `chatThread`, `composer`, `chatList` y
|
|
530
|
+
`typingIndicator`. Fuera de alcance, a propósito: virtualizar historiales largos, el transporte en tiempo real, el
|
|
531
|
+
picker de emojis, las notas de voz y el visor de media; son infraestructura de la app. Un ejemplo completo está en
|
|
532
|
+
el demo, en Pantallas · «Chat · mensajería».
|
|
533
|
+
|
|
481
534
|
## Campana de notificaciones
|
|
482
535
|
|
|
483
536
|
`KapiNotificationBell` (layout) es la campana de la barra superior: badge con las no leídas y un panel con la
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode, Ref } from "react";
|
|
2
|
+
import "./chat.css";
|
|
3
|
+
/** Qué separa un `KapiChatDivider`: un día del hilo o el corte de mensajes no leídos. */
|
|
4
|
+
export type KapiChatDividerTone = "day" | "unread";
|
|
5
|
+
/** Atributos nativos (`className`, `style`, `id`, `data-*`…) van al `<div>` del separador. */
|
|
6
|
+
export type KapiChatDividerProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
7
|
+
/** Qué separa: un día del hilo o el corte de mensajes no leídos. @default "day" */
|
|
8
|
+
tone?: KapiChatDividerTone | undefined;
|
|
9
|
+
/** Texto del separador (p. ej. la etiqueta de `formatDayLabel`). */
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** Ref al `<div>`. */
|
|
12
|
+
ref?: Ref<HTMLDivElement>;
|
|
13
|
+
};
|
|
14
|
+
/** Separador de un hilo de chat: una línea con el texto centrado en una cápsula (día o "no leídos"). */
|
|
15
|
+
export declare const KapiChatDivider: ({ tone, children, ref, className, ...rest }: KapiChatDividerProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { joinClasses as e } from "../rootProps.js";
|
|
3
|
+
/* empty css */
|
|
4
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/chat/KapiChatDivider.tsx
|
|
6
|
+
var n = ({ tone: n = "day", children: r, ref: i, className: a, ...o }) => /* @__PURE__ */ t("div", {
|
|
7
|
+
...o,
|
|
8
|
+
ref: i,
|
|
9
|
+
className: e("kapi-chatdiv", a),
|
|
10
|
+
"data-tone": n,
|
|
11
|
+
children: /* @__PURE__ */ t("span", {
|
|
12
|
+
className: "kapi-chatdiv__label",
|
|
13
|
+
children: r
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { n as KapiChatDivider };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode, Ref } from "react";
|
|
2
|
+
import type { KapiBadgeVariant } from "../display/KapiBadge";
|
|
3
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
4
|
+
import "./chat.css";
|
|
5
|
+
/** Textos de la lista de conversaciones. */
|
|
6
|
+
export type KapiChatListLabels = {
|
|
7
|
+
/** Nombre accesible de la lista. */
|
|
8
|
+
list: string;
|
|
9
|
+
/** Título del estado vacío. */
|
|
10
|
+
empty: string;
|
|
11
|
+
/** Texto accesible del contador, detrás del número (p. ej. "3 sin leer"). */
|
|
12
|
+
unread: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const DEFAULT_CHAT_LIST_LABELS: KapiChatListLabels;
|
|
15
|
+
/** Una conversación de la lista. */
|
|
16
|
+
export type KapiChatConversation<Id extends string = string> = {
|
|
17
|
+
/** Identificador estable; es lo que recibe `onSelect` y lo que compara `activeId`. */
|
|
18
|
+
id: Id;
|
|
19
|
+
/** Nombre que se muestra y del que salen las iniciales del avatar. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Último mensaje; se recorta a una línea con puntos suspensivos por CSS. */
|
|
22
|
+
preview?: ReactNode;
|
|
23
|
+
/** Hora (o fecha) ya formateada por el consumidor. */
|
|
24
|
+
time?: ReactNode;
|
|
25
|
+
/** Mensajes sin leer; 0 o ausente no dibuja el contador (tope visual "99+"). */
|
|
26
|
+
unread?: number | undefined;
|
|
27
|
+
/** Color del contador, como `KapiBadge`. @default "primary" */
|
|
28
|
+
unreadTone?: KapiBadgeVariant | undefined;
|
|
29
|
+
/** URL de la imagen del avatar; sin ella se dibujan las iniciales. */
|
|
30
|
+
avatarSrc?: string | undefined;
|
|
31
|
+
/** Pisa las iniciales calculadas desde `name`. */
|
|
32
|
+
initials?: string | undefined;
|
|
33
|
+
/** Deshabilita el ítem: no se puede elegir y no dispara `onSelect`. */
|
|
34
|
+
disabled?: boolean | undefined;
|
|
35
|
+
};
|
|
36
|
+
/** Atributos nativos (`className`, `style`, `id`, `data-*`…) van al contenedor de la lista. */
|
|
37
|
+
export type KapiChatListProps<Id extends string = string> = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onSelect"> & {
|
|
38
|
+
/** Las conversaciones, en el orden en que se dibujan. */
|
|
39
|
+
items: readonly KapiChatConversation<Id>[];
|
|
40
|
+
/** Id de la conversación abierta (resaltada y con `aria-current`); `null` o sin valor no marca ninguna. */
|
|
41
|
+
activeId?: NoInfer<Id> | null | undefined;
|
|
42
|
+
/** Se llama con el id al elegir una conversación; la app es dueña de `activeId`. */
|
|
43
|
+
onSelect?: ((id: Id) => void) | undefined;
|
|
44
|
+
/** Qué mostrar sin conversaciones; sin esto, un `KapiEmpty` con `labels.empty`. */
|
|
45
|
+
empty?: ReactNode;
|
|
46
|
+
/** Textos de la lista (clave `chatList`). */
|
|
47
|
+
labels?: KapiLabelsOverride<KapiChatListLabels> | undefined;
|
|
48
|
+
/** Ref al contenedor de la lista. */
|
|
49
|
+
ref?: Ref<HTMLDivElement>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Lista de conversaciones de dos líneas (nombre y hora arriba; preview y no leídos abajo) con avatar.
|
|
53
|
+
* Cada ítem es un `<button>` en el orden natural de tabulación, como los de `KapiPanelList`; el contador
|
|
54
|
+
* es `KapiNavBadge` y el avatar `KapiAvatar`. El nombre accesible del ítem sale de su contenido (nombre,
|
|
55
|
+
* hora, preview y "N sin leer"); el avatar va oculto para no repetir el nombre.
|
|
56
|
+
*/
|
|
57
|
+
export declare const KapiChatList: <Id extends string = string>({ items, activeId, onSelect, empty, labels, ref, className, ...rest }: KapiChatListProps<Id>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
+
import { joinClasses as t } from "../rootProps.js";
|
|
4
|
+
import { KapiAvatar as n } from "../display/KapiAvatar.js";
|
|
5
|
+
/* empty css */
|
|
6
|
+
import { KapiEmpty as r } from "../feedback/KapiEmpty.js";
|
|
7
|
+
import { KapiNavBadge as i } from "../navigation/KapiNavBadge.js";
|
|
8
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
9
|
+
//#region src/components/chat/KapiChatList.tsx
|
|
10
|
+
var s = {
|
|
11
|
+
list: "Conversaciones",
|
|
12
|
+
empty: "No hay conversaciones",
|
|
13
|
+
unread: "sin leer"
|
|
14
|
+
}, c = ({ items: c, activeId: l, onSelect: u, empty: d, labels: f, ref: p, className: m, ...h }) => {
|
|
15
|
+
let g = e("chatList", s, f);
|
|
16
|
+
return c.length === 0 ? /* @__PURE__ */ a("div", {
|
|
17
|
+
...h,
|
|
18
|
+
ref: p,
|
|
19
|
+
className: t("kapi-chatlist", m),
|
|
20
|
+
children: d === void 0 ? /* @__PURE__ */ a(r, { title: g.empty }) : d
|
|
21
|
+
}) : /* @__PURE__ */ a("div", {
|
|
22
|
+
"aria-label": g.list,
|
|
23
|
+
...h,
|
|
24
|
+
ref: p,
|
|
25
|
+
role: "group",
|
|
26
|
+
className: t("kapi-chatlist", m),
|
|
27
|
+
children: c.map((e) => {
|
|
28
|
+
let r = l != null && l === e.id, s = e.unread ?? 0;
|
|
29
|
+
return /* @__PURE__ */ o("button", {
|
|
30
|
+
type: "button",
|
|
31
|
+
className: t("kapi-chatlist__item", r && "kapi-chatlist__item--on"),
|
|
32
|
+
"aria-current": r ? "page" : void 0,
|
|
33
|
+
disabled: e.disabled,
|
|
34
|
+
onClick: () => u?.(e.id),
|
|
35
|
+
children: [/* @__PURE__ */ a("span", {
|
|
36
|
+
className: "kapi-chatlist__avatar",
|
|
37
|
+
"aria-hidden": "true",
|
|
38
|
+
children: /* @__PURE__ */ a(n, {
|
|
39
|
+
name: e.name,
|
|
40
|
+
...e.initials !== void 0 && { initials: e.initials },
|
|
41
|
+
...e.avatarSrc !== void 0 && { src: e.avatarSrc }
|
|
42
|
+
})
|
|
43
|
+
}), /* @__PURE__ */ o("span", {
|
|
44
|
+
className: "kapi-chatlist__main",
|
|
45
|
+
children: [/* @__PURE__ */ o("span", {
|
|
46
|
+
className: "kapi-chatlist__top",
|
|
47
|
+
children: [/* @__PURE__ */ a("span", {
|
|
48
|
+
className: "kapi-chatlist__name",
|
|
49
|
+
children: e.name
|
|
50
|
+
}), e.time != null && /* @__PURE__ */ a("span", {
|
|
51
|
+
className: "kapi-chatlist__time",
|
|
52
|
+
children: e.time
|
|
53
|
+
})]
|
|
54
|
+
}), /* @__PURE__ */ o("span", {
|
|
55
|
+
className: "kapi-chatlist__bottom",
|
|
56
|
+
children: [/* @__PURE__ */ a("span", {
|
|
57
|
+
className: "kapi-chatlist__preview",
|
|
58
|
+
children: e.preview
|
|
59
|
+
}), /* @__PURE__ */ a(i, {
|
|
60
|
+
value: s,
|
|
61
|
+
tone: e.unreadTone,
|
|
62
|
+
label: `${s} ${g.unread}`
|
|
63
|
+
})]
|
|
64
|
+
})]
|
|
65
|
+
})]
|
|
66
|
+
}, e.id);
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { s as DEFAULT_CHAT_LIST_LABELS, c as KapiChatList };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
3
|
+
import "./chat.css";
|
|
4
|
+
/** Textos de la píldora de mensajes nuevos. */
|
|
5
|
+
export type KapiChatThreadLabels = {
|
|
6
|
+
/** Texto de la píldora (el número de nuevos va aparte, en el badge). */
|
|
7
|
+
unseen: string;
|
|
8
|
+
/** Acción de la píldora: bajar al final del hilo. */
|
|
9
|
+
toBottom: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const DEFAULT_CHAT_THREAD_LABELS: KapiChatThreadLabels;
|
|
12
|
+
/**
|
|
13
|
+
* Atributos nativos (`className`, `style`, `id`, `data-*`…) van al contenedor; el contenido scrollea en
|
|
14
|
+
* una zona interior enfocable (`ref`).
|
|
15
|
+
*/
|
|
16
|
+
export type KapiChatThreadProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
17
|
+
/** Los renglones del hilo (burbujas y separadores), en orden. */
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/** Mensajes nuevos que el usuario todavía no vio; con el hilo despegado del fondo dibuja la píldora. @default 0 */
|
|
20
|
+
unseen?: number | undefined;
|
|
21
|
+
/** Cambiá este valor para bajar al fondo sí o sí (p. ej. al enviar un mensaje propio). */
|
|
22
|
+
followKey?: string | number | undefined;
|
|
23
|
+
/** Avisa cuando el usuario llega al fondo o se despega de él. */
|
|
24
|
+
onAtBottomChange?: ((atBottom: boolean) => void) | undefined;
|
|
25
|
+
/** Textos de la píldora de mensajes nuevos (clave `chatThread`). */
|
|
26
|
+
labels?: KapiLabelsOverride<KapiChatThreadLabels> | undefined;
|
|
27
|
+
/** Ref al elemento que scrollea. */
|
|
28
|
+
ref?: Ref<HTMLDivElement>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Hilo de chat que scrollea: sigue al fondo cuando entra contenido (salvo que el usuario haya subido a
|
|
32
|
+
* leer), baja siempre al cambiar `followKey` y muestra una píldora con los mensajes nuevos cuando está
|
|
33
|
+
* despegado del fondo. La detección de scroll es `useScrollEdges` (`edges.end === false` es "al fondo").
|
|
34
|
+
*/
|
|
35
|
+
export declare const KapiChatThread: ({ children, unseen, followKey, onAtBottomChange, labels, ref, className, ...rest }: KapiChatThreadProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { assignRef as e } from "../inputs/fieldLogic.js";
|
|
3
|
+
import { useLabels as t } from "../locale/KapiLocaleProvider.js";
|
|
4
|
+
import { joinClasses as n } from "../rootProps.js";
|
|
5
|
+
import { prefersReducedMotion as r } from "../../hooks/reducedMotion.js";
|
|
6
|
+
import { shouldFollowBottom as i } from "./chatLogic.js";
|
|
7
|
+
/* empty css */
|
|
8
|
+
import { KapiNavBadge as a } from "../navigation/KapiNavBadge.js";
|
|
9
|
+
import { useScrollEdges as o } from "../../hooks/useScrollEdges.js";
|
|
10
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
11
|
+
import { useCallback as l, useLayoutEffect as u, useRef as d } from "react";
|
|
12
|
+
//#region src/components/chat/KapiChatThread.tsx
|
|
13
|
+
var f = {
|
|
14
|
+
unseen: "Mensajes nuevos",
|
|
15
|
+
toBottom: "Ir al final del hilo"
|
|
16
|
+
}, p = ({ children: p, unseen: m = 0, followKey: h, onAtBottomChange: g, labels: _, ref: v, className: y, ...b }) => {
|
|
17
|
+
let x = t("chatThread", f, _), { ref: S, edges: C } = o({ axis: "y" }), w = d(null), T = !C.end, E = d(!0);
|
|
18
|
+
u(() => {
|
|
19
|
+
E.current = T;
|
|
20
|
+
}, [T]);
|
|
21
|
+
let D = l((t) => {
|
|
22
|
+
S.current = t, e(v, t);
|
|
23
|
+
}, [S, v]), O = l((e) => {
|
|
24
|
+
let t = S.current;
|
|
25
|
+
if (!t) return;
|
|
26
|
+
let n = e || r(t) ? "auto" : "smooth";
|
|
27
|
+
typeof t.scrollTo == "function" ? t.scrollTo({
|
|
28
|
+
top: t.scrollHeight,
|
|
29
|
+
behavior: n
|
|
30
|
+
}) : t.scrollTop = t.scrollHeight;
|
|
31
|
+
}, [S]);
|
|
32
|
+
u(() => {
|
|
33
|
+
O(!0);
|
|
34
|
+
}, [O]), u(() => {
|
|
35
|
+
let e = w.current;
|
|
36
|
+
if (!e || typeof ResizeObserver > "u") return;
|
|
37
|
+
let t = new ResizeObserver(() => {
|
|
38
|
+
i({
|
|
39
|
+
atBottom: E.current,
|
|
40
|
+
outgoing: !1
|
|
41
|
+
}) && O(!1);
|
|
42
|
+
});
|
|
43
|
+
return t.observe(e), () => t.disconnect();
|
|
44
|
+
}, [O]);
|
|
45
|
+
let k = d(h);
|
|
46
|
+
u(() => {
|
|
47
|
+
Object.is(k.current, h) || (k.current = h, i({
|
|
48
|
+
atBottom: E.current,
|
|
49
|
+
outgoing: !0
|
|
50
|
+
}) && O(!1));
|
|
51
|
+
}, [h, O]);
|
|
52
|
+
let A = d(!0);
|
|
53
|
+
u(() => {
|
|
54
|
+
A.current !== T && (A.current = T, g?.(T));
|
|
55
|
+
}, [T, g]);
|
|
56
|
+
let j = !T && m > 0;
|
|
57
|
+
return /* @__PURE__ */ c("div", {
|
|
58
|
+
...b,
|
|
59
|
+
className: n("kapi-chatthread", y),
|
|
60
|
+
children: [/* @__PURE__ */ s("div", {
|
|
61
|
+
ref: D,
|
|
62
|
+
className: "kapi-chatthread__scroll",
|
|
63
|
+
tabIndex: 0,
|
|
64
|
+
children: /* @__PURE__ */ s("div", {
|
|
65
|
+
ref: w,
|
|
66
|
+
className: "kapi-chatthread__content",
|
|
67
|
+
children: p
|
|
68
|
+
})
|
|
69
|
+
}), j && /* @__PURE__ */ c("button", {
|
|
70
|
+
type: "button",
|
|
71
|
+
className: "kapi-chatthread__pill",
|
|
72
|
+
"aria-label": `${x.unseen}: ${m}. ${x.toBottom}`,
|
|
73
|
+
onClick: () => O(!1),
|
|
74
|
+
children: [/* @__PURE__ */ s("span", {
|
|
75
|
+
"aria-hidden": "true",
|
|
76
|
+
children: x.unseen
|
|
77
|
+
}), /* @__PURE__ */ s(a, {
|
|
78
|
+
value: m,
|
|
79
|
+
announce: !1
|
|
80
|
+
})]
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { f as DEFAULT_CHAT_THREAD_LABELS, p as KapiChatThread };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode, type Ref, type TextareaHTMLAttributes } from "react";
|
|
2
|
+
import { type KapiSubmitShortcut } from "../display/commentLogic";
|
|
3
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
4
|
+
import "./chat.css";
|
|
5
|
+
export type KapiComposerLabels = {
|
|
6
|
+
/** Nombre accesible del textarea si no hay `KapiField`, `aria-label` ni `aria-labelledby`. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Placeholder del textarea (lo pisa la prop `placeholder`). */
|
|
9
|
+
placeholder: string;
|
|
10
|
+
/** Nombre accesible del botón de envío. */
|
|
11
|
+
send: string;
|
|
12
|
+
/** Pista del atajo de teclado, como descripción accesible del campo (no se dibuja). */
|
|
13
|
+
shortcut: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_COMPOSER_LABELS: KapiComposerLabels;
|
|
16
|
+
type OwnKeys = "value" | "defaultValue" | "onChange" | "onSubmit" | "children" | "className" | "style";
|
|
17
|
+
/**
|
|
18
|
+
* Los atributos nativos (`name`, `id`, `rows`, `maxLength`, `onBlur`, `aria-*`…) van al `<textarea>`;
|
|
19
|
+
* `className` y `style` van a la barra.
|
|
20
|
+
*/
|
|
21
|
+
export type KapiComposerProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, OwnKeys> & {
|
|
22
|
+
/** Texto (controlado). */
|
|
23
|
+
value?: string | undefined;
|
|
24
|
+
/** Texto inicial (no controlado). */
|
|
25
|
+
defaultValue?: string | undefined;
|
|
26
|
+
/** Cambio del texto, ya como string. */
|
|
27
|
+
onChange?: ((text: string) => void) | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Envío (botón o atajo) con el texto recortado. No controlado, el campo se vacía después; si devuelve una
|
|
30
|
+
* promesa, queda ocupado mientras corre y se vacía solo si resuelve (si rechaza, el borrador se conserva).
|
|
31
|
+
*/
|
|
32
|
+
onSubmit: (text: string) => void | PromiseLike<unknown>;
|
|
33
|
+
/** Tecla que envía: `"enter"` (Shift+Enter salta de línea) o `"modifier"` (Ctrl/Cmd+Enter). @default "enter" */
|
|
34
|
+
submitOn?: KapiSubmitShortcut | undefined;
|
|
35
|
+
/** Enviando: bloquea el envío y marca el botón `aria-busy`. */
|
|
36
|
+
loading?: boolean | undefined;
|
|
37
|
+
/** Marca el textarea `aria-invalid` (o lo toma del `KapiField`). */
|
|
38
|
+
invalid?: boolean | undefined;
|
|
39
|
+
/** Acciones antes del campo (adjuntar, emoji), alineadas al fondo de la barra. */
|
|
40
|
+
leading?: ReactNode;
|
|
41
|
+
/** Acciones después del campo y antes de Enviar, alineadas al fondo de la barra. */
|
|
42
|
+
trailing?: ReactNode;
|
|
43
|
+
/** Filas visibles antes de que el campo scrollee. @default 6 */
|
|
44
|
+
maxRows?: number | undefined;
|
|
45
|
+
/** Clase extra de la barra. */
|
|
46
|
+
className?: string | undefined;
|
|
47
|
+
/** Estilos en línea de la barra. */
|
|
48
|
+
style?: CSSProperties | undefined;
|
|
49
|
+
/** Textos fijos (clave `composer`). */
|
|
50
|
+
labels?: KapiLabelsOverride<KapiComposerLabels> | undefined;
|
|
51
|
+
/** Ref al `<textarea>`. */
|
|
52
|
+
ref?: Ref<HTMLTextAreaElement>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Campo de escritura de un chat: una barra al pie del hilo con un textarea que crece, acciones a los lados
|
|
56
|
+
* y un botón de envío. Enter envía y Shift+Enter hace salto de línea (`submitOn="modifier"` invierte el
|
|
57
|
+
* contrato: Ctrl/Cmd+Enter envía). Comparte la lógica de envío con `KapiCommentComposer`.
|
|
58
|
+
*/
|
|
59
|
+
export declare const KapiComposer: ({ value: valueProp, defaultValue, onChange, onSubmit, submitOn, loading, invalid, required, disabled, leading, trailing, maxRows, rows, className, style, labels, ref, placeholder, onKeyDown, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...rest }: KapiComposerProps) => import("react").JSX.Element;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { KapiIconButton as e } from "../inputs/KapiIconButton.js";
|
|
3
|
+
import { assignRef as t, joinIds as n } from "../inputs/fieldLogic.js";
|
|
4
|
+
import { useKapiField as r } from "../inputs/KapiField.js";
|
|
5
|
+
import { useLabels as i } from "../locale/KapiLocaleProvider.js";
|
|
6
|
+
import { joinClasses as a } from "../rootProps.js";
|
|
7
|
+
import { KapiTextarea as o } from "../inputs/KapiTextarea.js";
|
|
8
|
+
import { isSubmitShortcut as s } from "../display/commentLogic.js";
|
|
9
|
+
import { useSubmitDraft as c } from "../../hooks/useSubmitDraft.js";
|
|
10
|
+
/* empty css */
|
|
11
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
12
|
+
import { useId as d } from "react";
|
|
13
|
+
import { Send as f } from "lucide-react";
|
|
14
|
+
//#region src/components/chat/KapiComposer.tsx
|
|
15
|
+
var p = {
|
|
16
|
+
label: "Mensaje",
|
|
17
|
+
placeholder: "Escribe un mensaje…",
|
|
18
|
+
send: "Enviar",
|
|
19
|
+
shortcut: "Enter envía, Shift + Enter hace un salto de línea"
|
|
20
|
+
}, m = ({ value: m, defaultValue: h, onChange: g, onSubmit: _, submitOn: v = "enter", loading: y = !1, invalid: b, required: x, disabled: S, leading: C, trailing: w, maxRows: T = 6, rows: E = 1, className: D, style: O, labels: k, ref: A, placeholder: j, onKeyDown: M, "aria-label": N, "aria-labelledby": P, "aria-describedby": F, ...I }) => {
|
|
21
|
+
let L = i("composer", p, k), R = r(), z = d(), { text: B, setText: V, submit: H, busy: U, canSubmit: W, boxRef: G } = c({
|
|
22
|
+
value: m,
|
|
23
|
+
defaultValue: h,
|
|
24
|
+
onChange: g,
|
|
25
|
+
onSubmit: _,
|
|
26
|
+
disabled: S,
|
|
27
|
+
loading: y
|
|
28
|
+
}), K = (e) => {
|
|
29
|
+
M?.(e), !e.defaultPrevented && s({
|
|
30
|
+
key: e.key,
|
|
31
|
+
ctrlKey: e.ctrlKey,
|
|
32
|
+
metaKey: e.metaKey,
|
|
33
|
+
shiftKey: e.shiftKey,
|
|
34
|
+
isComposing: e.nativeEvent.isComposing
|
|
35
|
+
}, v) && (e.preventDefault(), H());
|
|
36
|
+
}, q = N !== void 0 || P !== void 0 || R !== null;
|
|
37
|
+
return /* @__PURE__ */ u("div", {
|
|
38
|
+
className: a("kapi-chatcomposer", D),
|
|
39
|
+
style: O,
|
|
40
|
+
children: [
|
|
41
|
+
C != null && /* @__PURE__ */ l("div", {
|
|
42
|
+
className: "kapi-chatcomposer__side",
|
|
43
|
+
children: C
|
|
44
|
+
}),
|
|
45
|
+
/* @__PURE__ */ l(o, {
|
|
46
|
+
...I,
|
|
47
|
+
ref: (e) => {
|
|
48
|
+
G.current = e, t(A, e);
|
|
49
|
+
},
|
|
50
|
+
className: "kapi-chatcomposer__input",
|
|
51
|
+
autosize: !0,
|
|
52
|
+
maxRows: T,
|
|
53
|
+
rows: E,
|
|
54
|
+
value: B,
|
|
55
|
+
disabled: S,
|
|
56
|
+
placeholder: j ?? L.placeholder,
|
|
57
|
+
"aria-label": q ? N : L.label,
|
|
58
|
+
"aria-labelledby": P,
|
|
59
|
+
"aria-describedby": n(F, z),
|
|
60
|
+
...x === void 0 ? {} : { required: x },
|
|
61
|
+
...b ? { status: "err" } : {},
|
|
62
|
+
onChange: (e) => V(e.target.value),
|
|
63
|
+
onKeyDown: K
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ l("span", {
|
|
66
|
+
id: z,
|
|
67
|
+
className: "kapi-sr-only",
|
|
68
|
+
children: L.shortcut
|
|
69
|
+
}),
|
|
70
|
+
w != null && /* @__PURE__ */ l("div", {
|
|
71
|
+
className: "kapi-chatcomposer__side",
|
|
72
|
+
children: w
|
|
73
|
+
}),
|
|
74
|
+
/* @__PURE__ */ l(e, {
|
|
75
|
+
className: "kapi-chatcomposer__send",
|
|
76
|
+
icon: /* @__PURE__ */ l(f, {
|
|
77
|
+
size: 18,
|
|
78
|
+
"aria-hidden": "true"
|
|
79
|
+
}),
|
|
80
|
+
"aria-label": L.send,
|
|
81
|
+
disabled: !W,
|
|
82
|
+
"aria-busy": U || void 0,
|
|
83
|
+
onClick: H
|
|
84
|
+
})
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
export { p as DEFAULT_COMPOSER_LABELS, m as KapiComposer };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode, Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
3
|
+
import type { KapiChatGrouping, KapiChatStatus } from "./chatLogic";
|
|
4
|
+
import "./chat.css";
|
|
5
|
+
/** Textos del estado de entrega (los lee el lector de pantalla junto al ícono). */
|
|
6
|
+
export type KapiMessageBubbleLabels = {
|
|
7
|
+
/** Estado `sending`: el mensaje todavía no salió. */
|
|
8
|
+
sending: string;
|
|
9
|
+
/** Estado `sent`: el servidor lo recibió. */
|
|
10
|
+
sent: string;
|
|
11
|
+
/** Estado `delivered`: llegó al dispositivo del destinatario. */
|
|
12
|
+
delivered: string;
|
|
13
|
+
/** Estado `read`: el destinatario lo leyó. */
|
|
14
|
+
read: string;
|
|
15
|
+
/** Estado `failed`: el envío falló. */
|
|
16
|
+
failed: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const DEFAULT_MESSAGE_BUBBLE_LABELS: KapiMessageBubbleLabels;
|
|
19
|
+
/** Atributos nativos (`className`, `style`, `id`, `data-*`…) van al `<div>` de la burbuja. */
|
|
20
|
+
export type KapiMessageBubbleProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "title"> & {
|
|
21
|
+
/** Mensaje propio: se alinea a la derecha, teñido, y muestra el estado de entrega. @default false */
|
|
22
|
+
outgoing?: boolean | undefined;
|
|
23
|
+
/** Posición dentro de una corrida del mismo autor; achica los radios del lado del autor. @default "single" */
|
|
24
|
+
grouping?: KapiChatGrouping | undefined;
|
|
25
|
+
/** Nombre del autor; sólo se dibuja en mensajes entrantes (típicamente el primero de la corrida). */
|
|
26
|
+
author?: ReactNode;
|
|
27
|
+
/** Hora ya formateada por el consumidor. */
|
|
28
|
+
time?: ReactNode;
|
|
29
|
+
/** Estado de entrega; sólo se dibuja si la burbuja es saliente. */
|
|
30
|
+
status?: KapiChatStatus | undefined;
|
|
31
|
+
/** Cita del mensaje al que responde, arriba del texto. */
|
|
32
|
+
reply?: ReactNode;
|
|
33
|
+
/** Adjunto o imagen, debajo del texto. */
|
|
34
|
+
media?: ReactNode;
|
|
35
|
+
/** Texto del mensaje (respeta los saltos de línea). */
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
/** Textos del estado de entrega. */
|
|
38
|
+
labels?: KapiLabelsOverride<KapiMessageBubbleLabels> | undefined;
|
|
39
|
+
/** Ref al `<div>` de la burbuja. */
|
|
40
|
+
ref?: Ref<HTMLDivElement>;
|
|
41
|
+
};
|
|
42
|
+
/** Burbuja de un mensaje de chat: entrante o saliente, agrupable en corridas, con hora, estado, cita y adjunto. */
|
|
43
|
+
export declare const KapiMessageBubble: ({ outgoing, grouping, author, time, status, reply, media, children, labels, ref, className, ...rest }: KapiMessageBubbleProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
3
|
+
import { joinClasses as t } from "../rootProps.js";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
6
|
+
import { Check as i, CheckCheck as a, Clock as o, TriangleAlert as s } from "lucide-react";
|
|
7
|
+
//#region src/components/chat/KapiMessageBubble.tsx
|
|
8
|
+
var c = {
|
|
9
|
+
sending: "Enviando",
|
|
10
|
+
sent: "Enviado",
|
|
11
|
+
delivered: "Entregado",
|
|
12
|
+
read: "Leído",
|
|
13
|
+
failed: "No se pudo enviar"
|
|
14
|
+
}, l = {
|
|
15
|
+
sending: o,
|
|
16
|
+
sent: i,
|
|
17
|
+
delivered: a,
|
|
18
|
+
read: a,
|
|
19
|
+
failed: s
|
|
20
|
+
}, u = (e) => e != null && e !== !1, d = ({ outgoing: i = !1, grouping: a = "single", author: o, time: s, status: d, reply: f, media: p, children: m, labels: h, ref: g, className: _, ...v }) => {
|
|
21
|
+
let y = e("messageBubble", c, h), b = i && d !== void 0 ? l[d] : null, x = u(s) || b !== null;
|
|
22
|
+
return /* @__PURE__ */ r("div", {
|
|
23
|
+
...v,
|
|
24
|
+
ref: g,
|
|
25
|
+
className: t("kapi-bubble", _),
|
|
26
|
+
"data-direction": i ? "out" : "in",
|
|
27
|
+
"data-grouping": a,
|
|
28
|
+
children: [
|
|
29
|
+
!i && u(o) && /* @__PURE__ */ n("span", {
|
|
30
|
+
className: "kapi-bubble__author",
|
|
31
|
+
children: o
|
|
32
|
+
}),
|
|
33
|
+
u(f) && /* @__PURE__ */ n("div", {
|
|
34
|
+
className: "kapi-bubble__reply",
|
|
35
|
+
children: f
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ n("div", {
|
|
38
|
+
className: "kapi-bubble__text",
|
|
39
|
+
children: m
|
|
40
|
+
}),
|
|
41
|
+
u(p) && /* @__PURE__ */ n("div", {
|
|
42
|
+
className: "kapi-bubble__media",
|
|
43
|
+
children: p
|
|
44
|
+
}),
|
|
45
|
+
x && /* @__PURE__ */ r("span", {
|
|
46
|
+
className: "kapi-bubble__meta",
|
|
47
|
+
children: [u(s) && /* @__PURE__ */ n("span", {
|
|
48
|
+
className: "kapi-bubble__time",
|
|
49
|
+
children: s
|
|
50
|
+
}), b !== null && d !== void 0 && /* @__PURE__ */ r("span", {
|
|
51
|
+
className: "kapi-bubble__status",
|
|
52
|
+
"data-status": d,
|
|
53
|
+
children: [/* @__PURE__ */ n(b, {
|
|
54
|
+
size: 14,
|
|
55
|
+
strokeWidth: 2,
|
|
56
|
+
"aria-hidden": "true"
|
|
57
|
+
}), /* @__PURE__ */ n("span", {
|
|
58
|
+
className: "kapi-sr-only",
|
|
59
|
+
children: y[d]
|
|
60
|
+
})]
|
|
61
|
+
})]
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { c as DEFAULT_MESSAGE_BUBBLE_LABELS, d as KapiMessageBubble };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HTMLAttributes, Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic";
|
|
3
|
+
import "./chat.css";
|
|
4
|
+
/** Textos del indicador de escritura. */
|
|
5
|
+
export type KapiTypingIndicatorLabels = {
|
|
6
|
+
/** Una persona escribiendo: `{name}` se reemplaza por el nombre. */
|
|
7
|
+
one: string;
|
|
8
|
+
/** Dos o más: `{count}` se reemplaza por la cantidad. */
|
|
9
|
+
many: string;
|
|
10
|
+
/** Sin nombres. */
|
|
11
|
+
someone: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const DEFAULT_TYPING_INDICATOR_LABELS: KapiTypingIndicatorLabels;
|
|
14
|
+
/** Los atributos nativos (`className`, `style`, `id`, `data-*`…) van al `<div>` raíz. */
|
|
15
|
+
export type KapiTypingIndicatorProps = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
16
|
+
/** Quiénes están escribiendo; vacío no dibuja nada. */
|
|
17
|
+
names?: readonly string[] | undefined;
|
|
18
|
+
/** Textos (clave `typingIndicator`). */
|
|
19
|
+
labels?: KapiLabelsOverride<KapiTypingIndicatorLabels> | undefined;
|
|
20
|
+
/** Ref al `<div>`. */
|
|
21
|
+
ref?: Ref<HTMLDivElement>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Aviso de "está escribiendo…": tres puntos que laten y el texto. El `<div>` es una región `aria-live`
|
|
25
|
+
* educada, así que un lector de pantalla lo anuncia sin mover el foco. Sin `names` no dibuja nada.
|
|
26
|
+
*/
|
|
27
|
+
export declare const KapiTypingIndicator: ({ names, labels, ref, className, ...rest }: KapiTypingIndicatorProps) => import("react").JSX.Element | null;
|