@kapiuara/ui 0.17.0 → 0.19.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 +259 -9
- package/dist/components/data/KapiDataTable.d.ts +12 -2
- package/dist/components/data/KapiDataTable.js +78 -76
- package/dist/components/data/KapiScatterChart.d.ts +56 -0
- package/dist/components/data/KapiScatterChart.js +90 -0
- package/dist/components/data/KapiTable.d.ts +2 -2
- package/dist/components/data/KapiTable.js +229 -227
- package/dist/components/data/chartFrame.d.ts +20 -2
- package/dist/components/data/chartFrame.js +33 -24
- package/dist/components/data/index.d.ts +5 -1
- package/dist/components/data/scatterLogic.d.ts +56 -0
- package/dist/components/data/scatterLogic.js +43 -0
- package/dist/components/data/tableTypes.d.ts +37 -0
- package/dist/components/data/useRowKeyWarning.d.ts +9 -3
- package/dist/components/data/useRowKeyWarning.js +7 -7
- package/dist/components/data/useTableSelection.d.ts +3 -2
- package/dist/components/data/useTableSelection.js +3 -3
- package/dist/components/display/KapiAvatarGroup.d.ts +14 -2
- package/dist/components/display/KapiAvatarGroup.js +25 -23
- package/dist/components/display/KapiTimeline.d.ts +14 -0
- package/dist/components/display/KapiTimeline.js +28 -21
- package/dist/components/display/avatarGroupSlots.d.ts +6 -0
- package/dist/components/display/avatarGroupSlots.js +9 -0
- package/dist/components/display/index.d.ts +1 -1
- package/dist/components/feedback/KapiAlert.d.ts +6 -1
- package/dist/components/feedback/KapiAlert.js +45 -44
- package/dist/components/feedback/KapiCountdown.d.ts +12 -1
- package/dist/components/feedback/KapiCountdown.js +34 -31
- package/dist/components/feedback/KapiEmpty.d.ts +6 -1
- package/dist/components/feedback/KapiEmpty.js +20 -18
- package/dist/components/feedback/KapiProgress.js +1 -1
- package/dist/components/feedback/KapiSpinner.d.ts +48 -0
- package/dist/components/feedback/KapiSpinner.js +27 -0
- package/dist/components/feedback/KapiToastContainer.js +1 -1
- package/dist/components/feedback/KapiTour.js +1 -1
- package/dist/components/feedback/alertSlots.d.ts +9 -0
- package/dist/components/feedback/alertSlots.js +12 -0
- package/dist/components/feedback/countdownSlots.d.ts +6 -0
- package/dist/components/feedback/countdownSlots.js +9 -0
- package/dist/components/feedback/emptySlots.d.ts +8 -0
- package/dist/components/feedback/emptySlots.js +11 -0
- package/dist/components/feedback/index.d.ts +5 -3
- package/dist/components/inputs/KapiFileUpload.d.ts +14 -1
- package/dist/components/inputs/KapiFileUpload.js +80 -67
- package/dist/components/inputs/formBridgeLogic.d.ts +104 -0
- package/dist/components/inputs/formBridgeLogic.js +25 -0
- package/dist/components/inputs/index.d.ts +2 -0
- package/dist/components/locale/labelRegistry.d.ts +8 -0
- package/dist/components/navigation/KapiSteps.d.ts +26 -5
- package/dist/components/navigation/KapiSteps.js +55 -43
- package/dist/components/overlays/KapiImageViewer.d.ts +63 -0
- package/dist/components/overlays/KapiImageViewer.js +106 -0
- package/dist/components/overlays/KapiShortcutsHelp.d.ts +53 -0
- package/dist/components/overlays/KapiShortcutsHelp.js +55 -0
- package/dist/components/overlays/KapiTooltip.d.ts +49 -10
- package/dist/components/overlays/KapiTooltip.js +110 -58
- package/dist/components/overlays/KapiViewport.d.ts +63 -0
- package/dist/components/overlays/KapiViewport.js +195 -0
- package/dist/components/overlays/index.d.ts +8 -0
- package/dist/components/overlays/shortcutsHelpSlots.d.ts +9 -0
- package/dist/components/overlays/shortcutsHelpSlots.js +12 -0
- package/dist/components/overlays/viewportLogic.d.ts +73 -0
- package/dist/components/overlays/viewportLogic.js +54 -0
- package/dist/components/slotCatalog.d.ts +33 -0
- package/dist/components/slotCatalog.js +30 -20
- package/dist/css/base.css +1 -1
- package/dist/css/components/data/KapiScatterChart.css +1 -0
- package/dist/css/components/display/display.css +1 -1
- package/dist/css/components/inputs/KapiFileUpload.css +1 -1
- package/dist/css/components/navigation/KapiSteps.css +1 -1
- package/dist/css/components/overlays/KapiViewport.css +1 -0
- package/dist/css/components/overlays/overlays.css +1 -1
- package/dist/hooks/elementSizeLogic.d.ts +15 -0
- package/dist/hooks/elementSizeLogic.js +7 -0
- package/dist/hooks/hotkeyLogic.d.ts +9 -0
- package/dist/hooks/hotkeyLogic.js +16 -15
- package/dist/hooks/hotkeyRegistry.d.ts +44 -0
- package/dist/hooks/hotkeyRegistry.js +32 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/themeDeriveLogic.js +2 -2
- package/dist/hooks/useDebouncedValue.d.ts +30 -0
- package/dist/hooks/useDebouncedValue.js +26 -0
- package/dist/hooks/useDisclosure.d.ts +39 -0
- package/dist/hooks/useDisclosure.js +35 -0
- package/dist/hooks/useElementSize.d.ts +27 -0
- package/dist/hooks/useElementSize.js +29 -0
- package/dist/hooks/useHotkey.d.ts +8 -0
- package/dist/hooks/useHotkey.js +27 -15
- package/dist/index.js +201 -188
- package/dist/kapi.css +1 -1
- package/dist/kapi.layered.css +1 -1
- package/dist/logic.d.ts +4 -0
- package/dist/logic.js +33 -29
- package/package.json +2 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "#kapi-css/components/overlays/KapiViewport.css";
|
|
3
|
+
import { joinClasses as e } from "../rootProps.js";
|
|
4
|
+
import { useLabels as t } from "../locale/KapiLocaleProvider.js";
|
|
5
|
+
import { KapiIconButton as n } from "../inputs/KapiIconButton.js";
|
|
6
|
+
import { useControllableState as r } from "../../hooks/useControllableState.js";
|
|
7
|
+
import { useDismiss as i } from "../../hooks/useDismiss.js";
|
|
8
|
+
/* empty css */
|
|
9
|
+
import { KapiViewport as a } from "./KapiViewport.js";
|
|
10
|
+
import { useCallback as o, useId as s, useRef as c, useState as l } from "react";
|
|
11
|
+
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
12
|
+
import { ChevronLeft as p, ChevronRight as m, X as h } from "lucide-react";
|
|
13
|
+
//#region src/components/overlays/KapiImageViewer.tsx
|
|
14
|
+
var g = {
|
|
15
|
+
close: "Cerrar el visor",
|
|
16
|
+
previous: "Imagen anterior",
|
|
17
|
+
next: "Imagen siguiente",
|
|
18
|
+
counter: "{i} de {n}"
|
|
19
|
+
}, _ = ({ ref: _, open: v, onClose: y, images: b, index: x, defaultIndex: S = 0, onIndexChange: C, className: w, style: T, id: E, labels: D }) => {
|
|
20
|
+
let O = t("imageViewer", g, D), k = c(null), A = s(), [j, M] = r(x, S, C), [N, P] = l(null), F = b.length, I = F === 0 ? 0 : Math.min(Math.max(j, 0), F - 1), L = b[I], R = o((e) => {
|
|
21
|
+
F !== 0 && M((I + e + F) % F);
|
|
22
|
+
}, [
|
|
23
|
+
I,
|
|
24
|
+
F,
|
|
25
|
+
M
|
|
26
|
+
]), z = c(L?.src);
|
|
27
|
+
if (z.current !== L?.src && (z.current = L?.src, P(null)), i(v, {
|
|
28
|
+
zones: [k],
|
|
29
|
+
onDismiss: (e) => y(e)
|
|
30
|
+
}), !v || !L) return null;
|
|
31
|
+
let B = L.width ?? N?.width ?? 0, V = L.height ?? N?.height ?? 0, H = O.counter.replace("{i}", String(I + 1)).replace("{n}", String(F));
|
|
32
|
+
return /* @__PURE__ */ f("div", {
|
|
33
|
+
ref: (e) => {
|
|
34
|
+
k.current = e, typeof _ == "function" ? _(e) : _ && (_.current = e);
|
|
35
|
+
},
|
|
36
|
+
id: E,
|
|
37
|
+
className: e("kapi-imgviewer", w),
|
|
38
|
+
style: T,
|
|
39
|
+
role: "dialog",
|
|
40
|
+
"aria-modal": "true",
|
|
41
|
+
"aria-labelledby": A,
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ f("div", {
|
|
44
|
+
className: "kapi-imgviewer__bar",
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ d("span", {
|
|
47
|
+
id: A,
|
|
48
|
+
className: "kapi-imgviewer__title",
|
|
49
|
+
children: L.alt
|
|
50
|
+
}),
|
|
51
|
+
F > 1 && /* @__PURE__ */ d("span", {
|
|
52
|
+
className: "kapi-imgviewer__count",
|
|
53
|
+
children: H
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ d(n, {
|
|
56
|
+
"aria-label": O.close,
|
|
57
|
+
icon: /* @__PURE__ */ d(h, {
|
|
58
|
+
size: 18,
|
|
59
|
+
strokeWidth: 2.2
|
|
60
|
+
}),
|
|
61
|
+
onClick: () => y("close-button")
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
}),
|
|
65
|
+
/* @__PURE__ */ d(a, {
|
|
66
|
+
className: "kapi-imgviewer__stage",
|
|
67
|
+
contentWidth: B,
|
|
68
|
+
contentHeight: V,
|
|
69
|
+
hideFullscreen: !0,
|
|
70
|
+
children: /* @__PURE__ */ d("img", {
|
|
71
|
+
className: "kapi-imgviewer__img",
|
|
72
|
+
src: L.src,
|
|
73
|
+
alt: L.alt,
|
|
74
|
+
draggable: !1,
|
|
75
|
+
onLoad: (e) => P({
|
|
76
|
+
width: e.currentTarget.naturalWidth,
|
|
77
|
+
height: e.currentTarget.naturalHeight
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}, L.src),
|
|
81
|
+
F > 1 && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d(n, {
|
|
82
|
+
className: "kapi-imgviewer__prev",
|
|
83
|
+
"aria-label": O.previous,
|
|
84
|
+
icon: /* @__PURE__ */ d(p, {
|
|
85
|
+
size: 20,
|
|
86
|
+
strokeWidth: 2.2
|
|
87
|
+
}),
|
|
88
|
+
onClick: () => R(-1)
|
|
89
|
+
}), /* @__PURE__ */ d(n, {
|
|
90
|
+
className: "kapi-imgviewer__next",
|
|
91
|
+
"aria-label": O.next,
|
|
92
|
+
icon: /* @__PURE__ */ d(m, {
|
|
93
|
+
size: 20,
|
|
94
|
+
strokeWidth: 2.2
|
|
95
|
+
}),
|
|
96
|
+
onClick: () => R(1)
|
|
97
|
+
})] }),
|
|
98
|
+
L.caption != null && /* @__PURE__ */ d("div", {
|
|
99
|
+
className: "kapi-imgviewer__caption",
|
|
100
|
+
children: L.caption
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { g as DEFAULT_IMAGE_VIEWER_LABELS, _ as KapiImageViewer };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { KapiCloseReason } from "../closeReason.js";
|
|
3
|
+
import type { KapiLabelsOverride } from "../labelsLogic.js";
|
|
4
|
+
import type { KapiClassNames } from "../slotCatalog.js";
|
|
5
|
+
/** Partes de `KapiShortcutsHelp` que acepta `classNames` (`group`, `groupTitle`, `list`, `row`, `keys`, `description`). */
|
|
6
|
+
export type KapiShortcutsHelpClassNames = KapiClassNames<"shortcutsHelp">;
|
|
7
|
+
/** Textos de `KapiShortcutsHelp`. */
|
|
8
|
+
export type KapiShortcutsHelpLabels = {
|
|
9
|
+
/** Título del diálogo. */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Encabezado de los atajos que no declararon grupo. */
|
|
12
|
+
general: string;
|
|
13
|
+
/** Qué se ve cuando no hay ningún atajo con descripción. */
|
|
14
|
+
empty: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const DEFAULT_SHORTCUTS_HELP_LABELS: KapiShortcutsHelpLabels;
|
|
17
|
+
/** `className`/`style`/`id` van al diálogo. */
|
|
18
|
+
export type KapiShortcutsHelpProps = {
|
|
19
|
+
/** Ref al `<div>` del diálogo. */
|
|
20
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
21
|
+
/** Abre el diálogo. */
|
|
22
|
+
open: boolean;
|
|
23
|
+
/** Se llama al cerrar (Escape, fondo, X). */
|
|
24
|
+
onClose: (reason: KapiCloseReason) => void;
|
|
25
|
+
/** Título propio. Sin él, el del locale. */
|
|
26
|
+
title?: ReactNode | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Fuerza el dibujo de las teclas al estilo de macOS (`⌘`, `⌥`, `⇧`). Sin la prop se deduce de la
|
|
29
|
+
* plataforma, que es lo que corresponde: el mismo `"mod+k"` se escribe distinto en cada una.
|
|
30
|
+
*/
|
|
31
|
+
mac?: boolean | undefined;
|
|
32
|
+
/** Clase del diálogo. */
|
|
33
|
+
className?: string | undefined;
|
|
34
|
+
/** Estilo del diálogo. */
|
|
35
|
+
style?: CSSProperties | undefined;
|
|
36
|
+
/** `id` del diálogo. */
|
|
37
|
+
id?: string | undefined;
|
|
38
|
+
/** Clases por parte (`group`, `groupTitle`, `list`, `row`, `keys`, `description`). Se suman a las propias. */
|
|
39
|
+
classNames?: KapiShortcutsHelpClassNames | undefined;
|
|
40
|
+
/** Textos fijos. */
|
|
41
|
+
labels?: KapiLabelsOverride<KapiShortcutsHelpLabels> | undefined;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* La ayuda «?» que lista los atajos que registró `useHotkey`.
|
|
45
|
+
*
|
|
46
|
+
* Sólo aparecen los que pasaron `description`: un atajo sin explicación sería una tecla suelta en
|
|
47
|
+
* una lista, que no ayuda a nadie. La lista se arma sola y **sigue al estado**: un atajo que está
|
|
48
|
+
* apagado (`enabled: false`) no se lista, porque prometería una tecla que no hace nada.
|
|
49
|
+
*
|
|
50
|
+
* El diálogo no registra ningún atajo propio para abrirse: quién abre la ayuda lo decide la app,
|
|
51
|
+
* normalmente con `useHotkey("?", …)`, y así la ayuda no se mete en el teclado de nadie.
|
|
52
|
+
*/
|
|
53
|
+
export declare const KapiShortcutsHelp: ({ ref, open, onClose, title, mac, className, style, id, classNames, labels }: KapiShortcutsHelpProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "#kapi-css/components/overlays/overlays.css";
|
|
3
|
+
import { useLabels as e } from "../locale/KapiLocaleProvider.js";
|
|
4
|
+
import { slot as t } from "../slotsLogic.js";
|
|
5
|
+
/* empty css */
|
|
6
|
+
import { KapiModal as n } from "./KapiModal.js";
|
|
7
|
+
import { groupHotkeys as r, hotkeyKeys as i, hotkeyRegistry as a } from "../../hooks/hotkeyRegistry.js";
|
|
8
|
+
import { SHORTCUTS_HELP_SLOTS as o } from "./shortcutsHelpSlots.js";
|
|
9
|
+
import { useSyncExternalStore as s } from "react";
|
|
10
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
11
|
+
//#region src/components/overlays/KapiShortcutsHelp.tsx
|
|
12
|
+
var u = {
|
|
13
|
+
title: "Atajos de teclado",
|
|
14
|
+
general: "General",
|
|
15
|
+
empty: "No hay atajos disponibles en esta pantalla."
|
|
16
|
+
}, d = () => typeof navigator < "u" && /mac/i.test(navigator.platform || navigator.userAgent), f = ({ ref: f, open: p, onClose: m, title: h, mac: g, className: _, style: v, id: y, classNames: b, labels: x }) => {
|
|
17
|
+
let S = e("shortcutsHelp", u, x), C = s(a.subscribe, a.getSnapshot, a.getSnapshot), w = r(C, S.general), T = g ?? d();
|
|
18
|
+
return /* @__PURE__ */ c(n, {
|
|
19
|
+
open: p,
|
|
20
|
+
onClose: m,
|
|
21
|
+
title: h === void 0 ? S.title : h,
|
|
22
|
+
size: "sm",
|
|
23
|
+
...f === void 0 ? {} : { ref: f },
|
|
24
|
+
..._ === void 0 ? {} : { className: _ },
|
|
25
|
+
...v === void 0 ? {} : { style: v },
|
|
26
|
+
...y === void 0 ? {} : { id: y },
|
|
27
|
+
children: w.length === 0 ? /* @__PURE__ */ c("p", {
|
|
28
|
+
className: "kapi-muted",
|
|
29
|
+
children: S.empty
|
|
30
|
+
}) : w.map(({ group: e, items: n }) => /* @__PURE__ */ l("section", {
|
|
31
|
+
...t(o, "group", b),
|
|
32
|
+
children: [/* @__PURE__ */ c("h3", {
|
|
33
|
+
...t(o, "groupTitle", b),
|
|
34
|
+
children: e
|
|
35
|
+
}), /* @__PURE__ */ c("dl", {
|
|
36
|
+
...t(o, "list", b),
|
|
37
|
+
children: n.map((e, n) => /* @__PURE__ */ l("div", {
|
|
38
|
+
...t(o, "row", b),
|
|
39
|
+
children: [/* @__PURE__ */ c("dt", {
|
|
40
|
+
...t(o, "keys", b),
|
|
41
|
+
children: i(e.combo, T).map((e, t) => /* @__PURE__ */ c("kbd", {
|
|
42
|
+
className: "kapi-kbd",
|
|
43
|
+
children: e
|
|
44
|
+
}, t))
|
|
45
|
+
}), /* @__PURE__ */ c("dd", {
|
|
46
|
+
...t(o, "description", b),
|
|
47
|
+
children: e.description
|
|
48
|
+
})]
|
|
49
|
+
}, `${e.combo}-${n}`))
|
|
50
|
+
})]
|
|
51
|
+
}, e))
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { u as DEFAULT_SHORTCUTS_HELP_LABELS, f as KapiShortcutsHelp };
|
|
@@ -8,25 +8,61 @@ type TooltipPhysicalSide = "right" | "left" | "top" | "bottom";
|
|
|
8
8
|
* sigue la dirección del texto: `end` es la derecha en LTR y la izquierda en RTL).
|
|
9
9
|
*/
|
|
10
10
|
export type KapiTooltipSide = TooltipPhysicalSide | "start" | "end";
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
label:
|
|
15
|
-
/** Disparador: el elemento que muestra el tooltip al pasar el mouse o enfocarlo. */
|
|
16
|
-
children: ReactNode;
|
|
11
|
+
/** Lo común a las dos formas de usarlo (envolviendo al disparador o apuntándolo por id). */
|
|
12
|
+
type KapiTooltipBase = KapiRootProps<HTMLSpanElement> & {
|
|
13
|
+
/** Contenido del tooltip. Puede ser texto o nodos (`<strong>`, varias partes). */
|
|
14
|
+
label: ReactNode;
|
|
17
15
|
/** Lado preferido: se respeta si entra; si no, va al opuesto. @default "end" */
|
|
18
16
|
prefer?: KapiTooltipSide | undefined;
|
|
17
|
+
/** Apagado: no se abre y no describe al disparador (no deja un `aria-describedby` a una burbuja que no se ve). */
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
/** Deja que el texto corte en varias líneas (tope 280px). Sin esto va en una sola, que es lo que conviene a un ícono. */
|
|
20
|
+
multiline?: boolean | undefined;
|
|
21
|
+
/** Milisegundos de espera antes de abrir con el mouse. Salir antes cancela. El foco de teclado NO espera. @default 0 */
|
|
22
|
+
openDelay?: number | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Abre y cierra desde afuera. Con la prop definida el estado es del consumidor: el hover y el foco
|
|
25
|
+
* dejan de abrirlo y cerrarlo. Sin ella, lo maneja el componente.
|
|
26
|
+
*/
|
|
27
|
+
opened?: boolean | undefined;
|
|
19
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* `className`/`style`/`id` van al envoltorio `<span class="kapi-tip">`.
|
|
31
|
+
*
|
|
32
|
+
* Dos formas, y el tipo obliga a elegir una: **envolviendo** al disparador (`children`) o
|
|
33
|
+
* **apuntándolo por id** (`target`), que no agrega ningún nodo alrededor.
|
|
34
|
+
*/
|
|
35
|
+
export type KapiTooltipProps = (KapiTooltipBase & {
|
|
36
|
+
/** Disparador: el elemento que muestra el tooltip al pasar el mouse o enfocarlo. */
|
|
37
|
+
children: ReactNode;
|
|
38
|
+
/** No aplica envolviendo al disparador. */
|
|
39
|
+
target?: undefined;
|
|
40
|
+
}) | (KapiTooltipBase & {
|
|
41
|
+
/**
|
|
42
|
+
* `id` del elemento que dispara el tooltip. El componente no lo envuelve: le cuelga los
|
|
43
|
+
* eventos y le pone `aria-describedby`, así el layout del disparador no cambia. Es la forma
|
|
44
|
+
* que necesita `UncontrolledTooltip target={id}` al migrar.
|
|
45
|
+
*/
|
|
46
|
+
target: string;
|
|
47
|
+
/** No aplica apuntando por id: el disparador es el elemento del `target`. */
|
|
48
|
+
children?: undefined;
|
|
49
|
+
});
|
|
20
50
|
/** Lado físico de `side` para la dirección del texto: `start`/`end` se resuelven; el resto pasa tal cual. */
|
|
21
51
|
export declare const physicalTooltipSide: (side: KapiTooltipSide, dir: KapiDir) => TooltipPhysicalSide;
|
|
22
|
-
/**
|
|
23
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Ancho estimado de la burbuja (sin medirla), con tope.
|
|
54
|
+
*
|
|
55
|
+
* Un `label` que no es texto no se puede medir contando caracteres, así que se asume el tope: el
|
|
56
|
+
* efecto es que el lado se da vuelta un poco antes de lo necesario, que es el error barato. Al
|
|
57
|
+
* revés —asumir angosto— la burbuja se saldría de la ventana.
|
|
58
|
+
*/
|
|
59
|
+
export declare const estimateTooltipWidth: (label: ReactNode) => number;
|
|
24
60
|
/**
|
|
25
61
|
* Lado final del tooltip (auto-flip) con el motor `placePopover`: se respeta el lado pedido salvo que
|
|
26
62
|
* la burbuja (tamaño estimado) no entre; entonces va al opuesto. Pura: recibe el rect del disparador y
|
|
27
63
|
* el viewport (sin `bottom`/`left` se toman `top`/`right`; sin alto de viewport, abajo siempre entra).
|
|
28
64
|
*/
|
|
29
|
-
export declare const resolveTooltipSide: (prefer: TooltipPhysicalSide, rect: Pick<DOMRect, "top" | "right"> & Partial<Pick<DOMRect, "bottom" | "left">>, label:
|
|
65
|
+
export declare const resolveTooltipSide: (prefer: TooltipPhysicalSide, rect: Pick<DOMRect, "top" | "right"> & Partial<Pick<DOMRect, "bottom" | "left">>, label: ReactNode, viewportWidth: number, viewportHeight?: number) => TooltipPhysicalSide;
|
|
30
66
|
/**
|
|
31
67
|
* Punto de la burbuja en coordenadas de viewport según el lado (la burbuja es `position: fixed`, así no la
|
|
32
68
|
* recorta un contenedor con overflow, como el panel plegado o la zona que scrollea del rail). El CSS la
|
|
@@ -43,6 +79,9 @@ export declare const tooltipDescribedBy: (existing: unknown, tipId: string) => s
|
|
|
43
79
|
* Tooltip para íconos sueltos. Se muestra con hover y con foco de teclado (`:focus-visible`), se
|
|
44
80
|
* descarta con Escape (WCAG 1.4.13) y el disparador lo referencia por `aria-describedby`. Al abrir mide
|
|
45
81
|
* el disparador y abre del lado con espacio.
|
|
82
|
+
*
|
|
83
|
+
* Dos formas: **envolviendo** al disparador (`children`) o **apuntándolo por id** (`target`), que no
|
|
84
|
+
* agrega ningún nodo alrededor y es la que necesita la migración de `UncontrolledTooltip`.
|
|
46
85
|
*/
|
|
47
|
-
export declare const KapiTooltip: ({ label, children, prefer, className, style, id, ref: refProp }: KapiTooltipProps) => import("react").JSX.Element;
|
|
86
|
+
export declare const KapiTooltip: ({ label, children, target, prefer, disabled, multiline, openDelay, opened, className, style, id, ref: refProp }: KapiTooltipProps) => import("react").JSX.Element;
|
|
48
87
|
export {};
|
|
@@ -10,10 +10,10 @@ import { onViewportChange as o } from "../../hooks/rafThrottle.js";
|
|
|
10
10
|
import { placementViewport as s } from "../../hooks/viewportInsetLogic.js";
|
|
11
11
|
import { resolveDirection as c } from "../../hooks/directionLogic.js";
|
|
12
12
|
/* empty css */
|
|
13
|
-
import { cloneElement as l, isValidElement as
|
|
14
|
-
import { jsx as
|
|
13
|
+
import { cloneElement as l, isValidElement as ee, useEffect as u, useId as te, useLayoutEffect as d, useRef as f, useState as p } from "react";
|
|
14
|
+
import { jsx as m, jsxs as ne } from "react/jsx-runtime";
|
|
15
15
|
//#region src/components/overlays/KapiTooltip.tsx
|
|
16
|
-
var
|
|
16
|
+
var h = 280, g = 7, _ = 28, v = 12, y = 44, b = (e, t) => e === "end" ? t === "rtl" ? "left" : "right" : e === "start" ? t === "rtl" ? "right" : "left" : e, x = (e) => typeof e == "string" || typeof e == "number" ? Math.min(h, String(e).length * g + _) : h, S = (e, t, n, r, i = Infinity) => {
|
|
17
17
|
let o = t.bottom ?? t.top, s = t.left ?? t.right, c = {
|
|
18
18
|
top: t.top,
|
|
19
19
|
bottom: o,
|
|
@@ -23,23 +23,23 @@ var v = 280, y = 7, b = 28, x = 12, S = 44, C = (e, t) => e === "end" ? t === "r
|
|
|
23
23
|
height: o - t.top
|
|
24
24
|
}, l = e === "top" || e === "bottom";
|
|
25
25
|
return a(c, {
|
|
26
|
-
width:
|
|
27
|
-
height:
|
|
26
|
+
width: x(n),
|
|
27
|
+
height: y
|
|
28
28
|
}, {
|
|
29
29
|
width: r,
|
|
30
30
|
height: i
|
|
31
31
|
}, {
|
|
32
32
|
side: e,
|
|
33
|
-
offset: l ? 0 :
|
|
33
|
+
offset: l ? 0 : v,
|
|
34
34
|
flip: "if-overflow",
|
|
35
35
|
shift: !1
|
|
36
36
|
}).side;
|
|
37
|
-
},
|
|
37
|
+
}, C = 10, w = 8, T = {
|
|
38
38
|
align: "center",
|
|
39
39
|
flip: !1,
|
|
40
40
|
shift: !1,
|
|
41
41
|
mainMin: -Infinity
|
|
42
|
-
},
|
|
42
|
+
}, E = (e, t) => {
|
|
43
43
|
let n = e === "top" || e === "bottom", { top: r, left: i } = a({
|
|
44
44
|
top: t.top,
|
|
45
45
|
bottom: t.bottom,
|
|
@@ -54,75 +54,127 @@ var v = 280, y = 7, b = 28, x = 12, S = 44, C = (e, t) => e === "end" ? t === "r
|
|
|
54
54
|
width: Infinity,
|
|
55
55
|
height: Infinity
|
|
56
56
|
}, {
|
|
57
|
-
...
|
|
57
|
+
...T,
|
|
58
58
|
side: e,
|
|
59
|
-
offset: n ?
|
|
59
|
+
offset: n ? w : C
|
|
60
60
|
});
|
|
61
61
|
return {
|
|
62
62
|
x: i,
|
|
63
63
|
y: r
|
|
64
64
|
};
|
|
65
|
-
},
|
|
65
|
+
}, D = (e, t) => {
|
|
66
66
|
try {
|
|
67
67
|
return e.matches(t);
|
|
68
68
|
} catch {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
-
},
|
|
72
|
-
let
|
|
71
|
+
}, O = (e, t) => i(typeof e == "string" ? e : void 0, t), k = ({ label: i, children: a, target: h, prefer: g = "end", disabled: _, multiline: v, openDelay: y = 0, opened: x, className: C, style: w, id: T, ref: k }) => {
|
|
72
|
+
let A = te(), j = f(null), M = t(j, k), N = n(), [P, re] = p(() => b(g, c(null, N))), [F, I] = p(!1), [ie, L] = p(!1), R = f(!1), z = x !== void 0, B = _ ? !1 : x ?? ie, V = f({
|
|
73
73
|
hover: !1,
|
|
74
74
|
focus: !1
|
|
75
|
-
}),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
}), H = f(null), U = () => {
|
|
76
|
+
H.current !== null && clearTimeout(H.current), H.current = null;
|
|
77
|
+
}, W = f(null), ae = () => W.current ?? j.current, G = () => {
|
|
78
|
+
let e = ae(), t = j.current;
|
|
79
|
+
if (!e || !t) return;
|
|
80
|
+
let n = e.getBoundingClientRect(), r = s(e), a = S(b(g, c(e, N)), n, i, r.width, r.height), { x: o, y: l } = E(a, n);
|
|
81
|
+
t.style.setProperty("--kapi-tip-x", `${Math.round(o)}px`), t.style.setProperty("--kapi-tip-y", `${Math.round(l)}px`), re(a);
|
|
82
|
+
}, K = f(G);
|
|
83
|
+
d(() => {
|
|
84
|
+
K.current = G;
|
|
83
85
|
});
|
|
84
|
-
let
|
|
85
|
-
let t =
|
|
86
|
+
let q = f(null), J = f(!1), Y = (e) => {
|
|
87
|
+
let t = q.current;
|
|
86
88
|
if (!t || typeof t.showPopover != "function") return;
|
|
87
|
-
let n =
|
|
88
|
-
e && !n && t.showPopover(), !e && n && t.hidePopover(),
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
89
|
+
let n = D(t, ":popover-open") ?? J.current;
|
|
90
|
+
e && !n && t.showPopover(), !e && n && t.hidePopover(), J.current = e;
|
|
91
|
+
}, X = () => {
|
|
92
|
+
I(!1), L(!0), K.current(), Y(!0);
|
|
93
|
+
}, Z = (e) => {
|
|
94
|
+
_ || z || (V.current[e] = !0, e === "focus" || y <= 0 ? (U(), X()) : (U(), H.current = setTimeout(() => {
|
|
95
|
+
H.current = null, (V.current.hover || V.current.focus) && X();
|
|
96
|
+
}, y)));
|
|
97
|
+
}, Q = (e) => {
|
|
98
|
+
_ || z || (V.current[e] = !1, !(V.current.hover || V.current.focus) && (U(), I(!1), L(!1), Y(!1)));
|
|
93
99
|
};
|
|
94
100
|
d(() => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
|
|
101
|
+
z && (B ? (R.current || I(!1), G(), Y(!0)) : Y(!1), R.current = B);
|
|
102
|
+
}, [
|
|
103
|
+
z,
|
|
104
|
+
B,
|
|
105
|
+
i,
|
|
106
|
+
g
|
|
107
|
+
]), u(() => {
|
|
108
|
+
_ && (U(), V.current.hover = !1, V.current.focus = !1, L(!1), Y(!1));
|
|
109
|
+
}, [_]), u(() => U, []), u(() => {
|
|
110
|
+
if (!B) return;
|
|
111
|
+
let e = r(j.current);
|
|
112
|
+
return o(() => K.current(), e ? { target: e } : {});
|
|
113
|
+
}, [B]);
|
|
114
|
+
let oe = () => I(!0), se = (e) => {
|
|
115
|
+
e.key === "Escape" && !F && oe();
|
|
116
|
+
};
|
|
117
|
+
u(() => {
|
|
118
|
+
if (h === void 0) return;
|
|
119
|
+
let e = (j.current?.ownerDocument ?? (typeof document > "u" ? null : document))?.getElementById(h) ?? null;
|
|
120
|
+
if (W.current = e, !e || _) return;
|
|
121
|
+
let t = e.getAttribute("aria-describedby"), n = O(t, A);
|
|
122
|
+
n !== void 0 && e.setAttribute("aria-describedby", n);
|
|
123
|
+
let r = () => Z("hover"), i = () => Q("hover"), a = () => {
|
|
124
|
+
(D(e, ":focus-visible") ?? !0) && Z("focus");
|
|
125
|
+
}, o = () => Q("focus"), s = (e) => {
|
|
126
|
+
e.key === "Escape" && oe();
|
|
127
|
+
};
|
|
128
|
+
return e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", i), e.addEventListener("focus", a), e.addEventListener("blur", o), e.addEventListener("keydown", s), () => {
|
|
129
|
+
e.removeEventListener("mouseenter", r), e.removeEventListener("mouseleave", i), e.removeEventListener("focus", a), e.removeEventListener("blur", o), e.removeEventListener("keydown", s), t === null ? e.removeAttribute("aria-describedby") : e.setAttribute("aria-describedby", t), W.current = null, V.current = {
|
|
130
|
+
hover: !1,
|
|
131
|
+
focus: !1
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
}, [
|
|
135
|
+
h,
|
|
136
|
+
A,
|
|
137
|
+
_,
|
|
138
|
+
y,
|
|
139
|
+
z
|
|
140
|
+
]);
|
|
141
|
+
let ce = /* @__PURE__ */ m("span", {
|
|
142
|
+
ref: q,
|
|
143
|
+
className: e("kapi-tip__bubble", v && "kapi-tip__bubble--multiline"),
|
|
144
|
+
role: "tooltip",
|
|
145
|
+
id: A,
|
|
146
|
+
popover: "manual",
|
|
147
|
+
children: i
|
|
148
|
+
});
|
|
149
|
+
if (h !== void 0) return /* @__PURE__ */ m("span", {
|
|
150
|
+
id: T,
|
|
151
|
+
className: e("kapi-tip", C),
|
|
152
|
+
style: w,
|
|
153
|
+
ref: M,
|
|
154
|
+
"data-side": P,
|
|
155
|
+
"data-open": B && !F ? "" : void 0,
|
|
156
|
+
"data-dismissed": F || void 0,
|
|
157
|
+
children: ce
|
|
158
|
+
});
|
|
159
|
+
let $ = ee(a) ? a : null, le = $ && !_ ? l($, { "aria-describedby": O($.props["aria-describedby"], A) }) : a;
|
|
160
|
+
return /* @__PURE__ */ ne("span", {
|
|
161
|
+
id: T,
|
|
162
|
+
className: e("kapi-tip", C),
|
|
163
|
+
style: w,
|
|
164
|
+
ref: M,
|
|
165
|
+
"data-side": P,
|
|
166
|
+
"data-open": B && !F ? "" : void 0,
|
|
167
|
+
"data-dismissed": F || void 0,
|
|
168
|
+
"aria-describedby": $ || _ ? void 0 : A,
|
|
169
|
+
onMouseEnter: () => Z("hover"),
|
|
111
170
|
onFocus: (e) => {
|
|
112
|
-
(
|
|
171
|
+
(D(e.target, ":focus-visible") ?? !0) && Z("focus");
|
|
113
172
|
},
|
|
114
|
-
onMouseLeave: () =>
|
|
115
|
-
onBlur: () =>
|
|
116
|
-
onKeyDown:
|
|
117
|
-
children: [
|
|
118
|
-
ref: V,
|
|
119
|
-
className: "kapi-tip__bubble",
|
|
120
|
-
role: "tooltip",
|
|
121
|
-
id: w,
|
|
122
|
-
popover: "manual",
|
|
123
|
-
children: i
|
|
124
|
-
})]
|
|
173
|
+
onMouseLeave: () => Q("hover"),
|
|
174
|
+
onBlur: () => Q("focus"),
|
|
175
|
+
onKeyDown: se,
|
|
176
|
+
children: [le, ce]
|
|
125
177
|
});
|
|
126
178
|
};
|
|
127
179
|
//#endregion
|
|
128
|
-
export {
|
|
180
|
+
export { k as KapiTooltip, x as estimateTooltipWidth, b as physicalTooltipSide, S as resolveTooltipSide, E as tooltipAnchor, O as tooltipDescribedBy };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { KapiLabelsOverride } from "../labelsLogic.js";
|
|
3
|
+
import { type KapiViewportState } from "./viewportLogic.js";
|
|
4
|
+
export type { KapiViewportState };
|
|
5
|
+
/** Textos de `KapiViewport`. */
|
|
6
|
+
export type KapiViewportLabels = {
|
|
7
|
+
/** Botón de acercar. */
|
|
8
|
+
zoomIn: string;
|
|
9
|
+
/** Botón de alejar. */
|
|
10
|
+
zoomOut: string;
|
|
11
|
+
/** Botón de ajustar a la pantalla. */
|
|
12
|
+
fit: string;
|
|
13
|
+
/** Botón de pantalla completa. */
|
|
14
|
+
fullscreen: string;
|
|
15
|
+
/** Botón de salir de pantalla completa. */
|
|
16
|
+
exitFullscreen: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const DEFAULT_VIEWPORT_LABELS: KapiViewportLabels;
|
|
19
|
+
/** Atributos nativos (`id`, `style`, `data-*`…) van al marco. */
|
|
20
|
+
export type KapiViewportProps = Omit<HTMLAttributes<HTMLDivElement>, "children" | "onScroll"> & {
|
|
21
|
+
/** Ref al `<div>` del marco. */
|
|
22
|
+
ref?: Ref<HTMLDivElement> | undefined;
|
|
23
|
+
/** Lo que se mira: una imagen, un SVG, un plano. */
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
/** Ancho natural del contenido, en píxeles. De acá sale el ajuste y el acotado del arrastre. */
|
|
26
|
+
contentWidth: number;
|
|
27
|
+
/** Alto natural del contenido. */
|
|
28
|
+
contentHeight: number;
|
|
29
|
+
/** Escala mínima. @default 0.25 */
|
|
30
|
+
minScale?: number | undefined;
|
|
31
|
+
/** Escala máxima. @default 8 */
|
|
32
|
+
maxScale?: number | undefined;
|
|
33
|
+
/** Cuánto cambia la escala por paso de rueda o por botón. Los dos usan el mismo. @default 0.25 */
|
|
34
|
+
scaleStep?: number | undefined;
|
|
35
|
+
/** Estado controlado (escala y desplazamiento). */
|
|
36
|
+
state?: KapiViewportState | undefined;
|
|
37
|
+
/** Estado inicial. Sin él, el contenido arranca ajustado al marco. */
|
|
38
|
+
defaultState?: KapiViewportState | undefined;
|
|
39
|
+
/** Avisa cada cambio de escala o de posición. */
|
|
40
|
+
onStateChange?: ((state: KapiViewportState) => void) | undefined;
|
|
41
|
+
/** Oculta la barra de botones (acercar, alejar, ajustar, pantalla completa). */
|
|
42
|
+
hideControls?: boolean | undefined;
|
|
43
|
+
/** Saca el botón de pantalla completa sin sacar los demás. */
|
|
44
|
+
hideFullscreen?: boolean | undefined;
|
|
45
|
+
/** Textos fijos de los botones. */
|
|
46
|
+
labels?: KapiLabelsOverride<KapiViewportLabels> | undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Marco con zoom y arrastre: rueda, doble clic, pellizco, arrastre, ajustar y pantalla completa.
|
|
50
|
+
*
|
|
51
|
+
* Toda la matemática vive en `viewportLogic.ts`, pura y testeada; acá sólo se escuchan eventos. Dos
|
|
52
|
+
* decisiones que no se ven en el código:
|
|
53
|
+
*
|
|
54
|
+
* - **La rueda usa el mismo motor de pasos que los botones** (`nextWheelZoom`), no un factor
|
|
55
|
+
* continuo propio: si no, un gesto de trackpad y tres clics en `+` dejarían escalas distintas y
|
|
56
|
+
* el `Ajustar` volvería a un lugar que no coincide con ninguna.
|
|
57
|
+
* - **Acercar deja quieto el punto bajo el cursor.** Sin eso el contenido crece desde el centro y
|
|
58
|
+
* lo que la persona estaba mirando se le va de la pantalla.
|
|
59
|
+
*
|
|
60
|
+
* El contenido más chico que el marco **no se arrastra**: queda centrado, para que una imagen chica
|
|
61
|
+
* no se pueda sacar de la vista.
|
|
62
|
+
*/
|
|
63
|
+
export declare const KapiViewport: ({ children, contentWidth, contentHeight, minScale, maxScale, scaleStep, state, defaultState, onStateChange, hideControls, hideFullscreen, labels, className, ref, ...rest }: KapiViewportProps) => import("react").JSX.Element;
|