@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,32 @@
|
|
|
1
|
+
import { hotkeyTokens as e } from "./hotkeyLogic.js";
|
|
2
|
+
//#region src/hooks/hotkeyRegistry.ts
|
|
3
|
+
var t = /* @__PURE__ */ new Set(), n = [], r = {
|
|
4
|
+
subscribe(e) {
|
|
5
|
+
return t.add(e), () => void t.delete(e);
|
|
6
|
+
},
|
|
7
|
+
getSnapshot() {
|
|
8
|
+
return n;
|
|
9
|
+
},
|
|
10
|
+
register(e) {
|
|
11
|
+
n = [...n, e], t.forEach((e) => e());
|
|
12
|
+
let r = !0;
|
|
13
|
+
return () => {
|
|
14
|
+
if (!r) return;
|
|
15
|
+
r = !1;
|
|
16
|
+
let i = n.indexOf(e);
|
|
17
|
+
i >= 0 && (n = [...n.slice(0, i), ...n.slice(i + 1)]), t.forEach((e) => e());
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}, i = (e, t) => {
|
|
21
|
+
let n = [], r = /* @__PURE__ */ new Map();
|
|
22
|
+
for (let i of e) {
|
|
23
|
+
let e = i.group ?? t;
|
|
24
|
+
r.has(e) || (r.set(e, []), n.push(e)), r.get(e).push(i);
|
|
25
|
+
}
|
|
26
|
+
return n.map((e) => ({
|
|
27
|
+
group: e,
|
|
28
|
+
items: r.get(e)
|
|
29
|
+
}));
|
|
30
|
+
}, a = (t, n) => e(t).map((e) => e.toLowerCase()).filter(Boolean).map((e) => e === "mod" ? n ? "⌘" : "Ctrl" : e === "meta" || e === "cmd" ? n ? "⌘" : "Win" : e === "ctrl" ? "Ctrl" : e === "alt" ? n ? "⌥" : "Alt" : e === "shift" ? n ? "⇧" : "Shift" : e === "escape" || e === "esc" ? "Esc" : e === "arrowup" ? "↑" : e === "arrowdown" ? "↓" : e === "arrowleft" ? "←" : e === "arrowright" ? "→" : e === "enter" ? "Enter" : e === "space" ? "Espacio" : e.length === 1 ? e.toUpperCase() : e.charAt(0).toUpperCase() + e.slice(1));
|
|
31
|
+
//#endregion
|
|
32
|
+
export { i as groupHotkeys, a as hotkeyKeys, r as hotkeyRegistry };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -127,3 +127,13 @@ export { checkThemeContrast } from "./themeContrastLogic.js";
|
|
|
127
127
|
export type { KapiThemeContrastFailure, KapiThemeContrastOptions } from "./themeContrastLogic.js";
|
|
128
128
|
export { directionOf, logicalArrowKey } from "./directionLogic.js";
|
|
129
129
|
export type { KapiDir } from "./directionLogic.js";
|
|
130
|
+
export { useDisclosure } from "./useDisclosure.js";
|
|
131
|
+
export type { UseDisclosureHandlers, UseDisclosureOptions, UseDisclosureResult } from "./useDisclosure.js";
|
|
132
|
+
export { useDebouncedValue } from "./useDebouncedValue.js";
|
|
133
|
+
export type { UseDebouncedValueOptions, UseDebouncedValueResult } from "./useDebouncedValue.js";
|
|
134
|
+
export { useElementSize } from "./useElementSize.js";
|
|
135
|
+
export type { UseElementSizeResult } from "./useElementSize.js";
|
|
136
|
+
export { EMPTY_ELEMENT_SIZE, sameSize } from "./elementSizeLogic.js";
|
|
137
|
+
export type { KapiElementSize } from "./elementSizeLogic.js";
|
|
138
|
+
export { hotkeyRegistry, groupHotkeys, hotkeyKeys } from "./hotkeyRegistry.js";
|
|
139
|
+
export type { KapiHotkeyInfo } from "./hotkeyRegistry.js";
|
|
@@ -33,7 +33,7 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
33
33
|
bg: "#f4f2fb",
|
|
34
34
|
card: "#ffffff",
|
|
35
35
|
line: "#ece8f7",
|
|
36
|
-
primary: "#
|
|
36
|
+
primary: "#6c4fdf",
|
|
37
37
|
ink: "#342f4a",
|
|
38
38
|
success: "#137a44",
|
|
39
39
|
info: "#1b649f",
|
|
@@ -44,7 +44,7 @@ var a = /^\d+(\.\d+)?px$/, o = /^\d+(\.\d+)?(px|%)$/, s = {
|
|
|
44
44
|
bg: "#14121d",
|
|
45
45
|
card: "#1e1b2b",
|
|
46
46
|
line: "#322d45",
|
|
47
|
-
primary: "#
|
|
47
|
+
primary: "#967ff2",
|
|
48
48
|
ink: "#ece9f7",
|
|
49
49
|
success: "#4ec98a",
|
|
50
50
|
info: "#6bb6ef",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Opciones de `useDebouncedValue`. */
|
|
2
|
+
export type UseDebouncedValueOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Publica el primer cambio al toque y recién después empieza a esperar. Sirve para que una
|
|
5
|
+
* búsqueda reaccione al primer tecleo y no a los siguientes.
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
8
|
+
leading?: boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
/** Lo que devuelve `useDebouncedValue`: el valor demorado y la función que corta la espera. */
|
|
11
|
+
export type UseDebouncedValueResult<T> = readonly [T, () => void];
|
|
12
|
+
/**
|
|
13
|
+
* Demora un valor: devuelve el último que se mantuvo quieto `delay` milisegundos. Cada cambio
|
|
14
|
+
* reinicia la espera, así que tipear rápido publica **una** vez, la última.
|
|
15
|
+
*
|
|
16
|
+
* Para qué sirve: filtrar una tabla, buscar mientras se escribe, o cualquier efecto caro atado a un
|
|
17
|
+
* valor que cambia en cada tecla. El `KapiSelect` con `loadOptions`, el `KapiAutocomplete` y el
|
|
18
|
+
* `KapiFacetedSearch` **ya traen el suyo** (`useAsyncLoader`, que además cancela los pedidos que
|
|
19
|
+
* quedaron viejos): esto es para el estado del lado de la app, no para re-implementar aquello.
|
|
20
|
+
*
|
|
21
|
+
* Desmontar cancela la espera pendiente, así que no actualiza un componente que ya no está.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const [texto, setTexto] = useState("");
|
|
26
|
+
* const [buscado] = useDebouncedValue(texto, 300);
|
|
27
|
+
* const filas = useMemo(() => filtrar(datos, buscado), [datos, buscado]);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const useDebouncedValue: <T>(value: T, delay: number, { leading }?: UseDebouncedValueOptions) => UseDebouncedValueResult<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
|
|
3
|
+
//#region src/hooks/useDebouncedValue.ts
|
|
4
|
+
var i = (i, a, { leading: o = !1 } = {}) => {
|
|
5
|
+
let [s, c] = r(i), l = n(null), u = n(!1), d = e(() => {
|
|
6
|
+
l.current !== null && clearTimeout(l.current), l.current = null, u.current = !1;
|
|
7
|
+
}, []), f = n(!0);
|
|
8
|
+
return t(() => {
|
|
9
|
+
if (f.current) f.current = !1;
|
|
10
|
+
else return o && !u.current ? (u.current = !0, c(i), l.current = setTimeout(() => {
|
|
11
|
+
l.current = null, u.current = !1;
|
|
12
|
+
}, a), () => {
|
|
13
|
+
l.current !== null && clearTimeout(l.current), l.current = null;
|
|
14
|
+
}) : (l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => {
|
|
15
|
+
l.current = null, u.current = !1, c(i);
|
|
16
|
+
}, a), () => {
|
|
17
|
+
l.current !== null && clearTimeout(l.current), l.current = null;
|
|
18
|
+
});
|
|
19
|
+
}, [
|
|
20
|
+
i,
|
|
21
|
+
a,
|
|
22
|
+
o
|
|
23
|
+
]), t(() => d, [d]), [s, d];
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { i as useDebouncedValue };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Avisos opcionales de `useDisclosure`. */
|
|
2
|
+
export type UseDisclosureOptions = {
|
|
3
|
+
/** Se llama cuando pasa de cerrado a abierto (no cuando ya estaba abierto). */
|
|
4
|
+
onOpen?: (() => void) | undefined;
|
|
5
|
+
/** Se llama cuando pasa de abierto a cerrado (no cuando ya estaba cerrado). */
|
|
6
|
+
onClose?: (() => void) | undefined;
|
|
7
|
+
};
|
|
8
|
+
/** Las tres acciones de `useDisclosure`. La identidad es estable entre renders. */
|
|
9
|
+
export type UseDisclosureHandlers = {
|
|
10
|
+
/** Abre. Si ya estaba abierto no hace nada ni avisa. */
|
|
11
|
+
open: () => void;
|
|
12
|
+
/** Cierra. Si ya estaba cerrado no hace nada ni avisa. */
|
|
13
|
+
close: () => void;
|
|
14
|
+
/** Alterna, y avisa el callback del lado al que va. */
|
|
15
|
+
toggle: () => void;
|
|
16
|
+
};
|
|
17
|
+
/** Lo que devuelve `useDisclosure`: el estado y sus acciones. */
|
|
18
|
+
export type UseDisclosureResult = readonly [boolean, UseDisclosureHandlers];
|
|
19
|
+
/**
|
|
20
|
+
* Estado booleano de apertura con acciones estables, para lo que se abre y se cierra desde la app:
|
|
21
|
+
* un modal, un offcanvas, un panel, un menú.
|
|
22
|
+
*
|
|
23
|
+
* Es el patrón que ya escribe cada pantalla a mano (`const [open, setOpen] = useState(false)` más
|
|
24
|
+
* tres callbacks), con dos cosas que a mano se olvidan: los handlers **no cambian de identidad**
|
|
25
|
+
* entre renders —van como prop a componentes memoizados y como dependencia de efectos—, y
|
|
26
|
+
* `onOpen` / `onClose` avisan **sólo cuando el estado cambia de verdad**, así un consumidor que
|
|
27
|
+
* registra aperturas no cuenta de más.
|
|
28
|
+
*
|
|
29
|
+
* No reemplaza el contrato controlado de los componentes (`open` + `onClose`): esto es el estado
|
|
30
|
+
* del lado de la app que alimenta esas props.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const [abierto, { open, close }] = useDisclosure();
|
|
35
|
+
* <KapiButton onClick={open}>Ver</KapiButton>
|
|
36
|
+
* <KapiModal open={abierto} onClose={close} title="Detalle">…</KapiModal>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const useDisclosure: (initial?: boolean, { onOpen, onClose }?: UseDisclosureOptions) => UseDisclosureResult;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useMemo as t, useRef as n, useState as r } from "react";
|
|
3
|
+
//#region src/hooks/useDisclosure.ts
|
|
4
|
+
var i = (i = !1, { onOpen: a, onClose: o } = {}) => {
|
|
5
|
+
let [s, c] = r(i), l = n({
|
|
6
|
+
onOpen: a,
|
|
7
|
+
onClose: o
|
|
8
|
+
});
|
|
9
|
+
l.current = {
|
|
10
|
+
onOpen: a,
|
|
11
|
+
onClose: o
|
|
12
|
+
};
|
|
13
|
+
let u = n(s);
|
|
14
|
+
u.current = s;
|
|
15
|
+
let d = e((e) => {
|
|
16
|
+
u.current !== e && (u.current = e, e ? l.current.onOpen?.() : l.current.onClose?.());
|
|
17
|
+
}, []), f = e(() => {
|
|
18
|
+
d(!0), c(!0);
|
|
19
|
+
}, [d]), p = e(() => {
|
|
20
|
+
d(!1), c(!1);
|
|
21
|
+
}, [d]), m = e(() => {
|
|
22
|
+
d(!u.current), c((e) => !e);
|
|
23
|
+
}, [d]);
|
|
24
|
+
return [s, t(() => ({
|
|
25
|
+
open: f,
|
|
26
|
+
close: p,
|
|
27
|
+
toggle: m
|
|
28
|
+
}), [
|
|
29
|
+
f,
|
|
30
|
+
p,
|
|
31
|
+
m
|
|
32
|
+
])];
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { i as useDisclosure };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type KapiElementSize } from "./elementSizeLogic.js";
|
|
2
|
+
/** Lo que devuelve `useElementSize`: la ref que hay que colgar y el tamaño medido. */
|
|
3
|
+
export type UseElementSizeResult<T extends HTMLElement = HTMLElement> = KapiElementSize & {
|
|
4
|
+
/** Ref callback para el elemento a medir. */
|
|
5
|
+
ref: (node: T | null) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Mide un elemento y vuelve a medirlo cuando cambia de tamaño.
|
|
9
|
+
*
|
|
10
|
+
* Para qué sirve: decidir desde JS algo que el CSS no puede —cuántas columnas entran, si un texto
|
|
11
|
+
* necesita «ver más», el alto de una fila virtualizada— sin escuchar el `resize` de la ventana, que
|
|
12
|
+
* no se entera cuando el que cambia es un panel lateral y no la ventana.
|
|
13
|
+
*
|
|
14
|
+
* Tres cosas que a mano se olvidan y acá están: observa el elemento con `ResizeObserver` (no la
|
|
15
|
+
* ventana), **no vuelve a renderizar si el tamaño no cambió** —el observador también avisa cuando
|
|
16
|
+
* el elemento se movió— y desconecta al desmontar o al cambiar de elemento.
|
|
17
|
+
*
|
|
18
|
+
* Si `ResizeObserver` no existe (entornos sin DOM, SSR) mide una vez y se queda quieto, en vez de
|
|
19
|
+
* romper.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { ref, width } = useElementSize<HTMLDivElement>();
|
|
24
|
+
* return <div ref={ref}>{width > 600 ? <Tabla /> : <Tarjetas />}</div>;
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const useElementSize: <T extends HTMLElement = HTMLElement>() => UseElementSizeResult<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { EMPTY_ELEMENT_SIZE as e, sameSize as t } from "./elementSizeLogic.js";
|
|
3
|
+
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
+
//#region src/hooks/useElementSize.ts
|
|
5
|
+
var o = () => {
|
|
6
|
+
let [o, s] = a(e), c = i(null), l = n((e) => {
|
|
7
|
+
let { width: n, height: r } = e.getBoundingClientRect();
|
|
8
|
+
s((e) => t(e, {
|
|
9
|
+
width: n,
|
|
10
|
+
height: r
|
|
11
|
+
}) ? e : {
|
|
12
|
+
width: n,
|
|
13
|
+
height: r
|
|
14
|
+
});
|
|
15
|
+
}, []), u = n((e) => {
|
|
16
|
+
if (c.current?.disconnect(), c.current = null, !e || (l(e), typeof ResizeObserver > "u")) return;
|
|
17
|
+
let t = new ResizeObserver(() => l(e));
|
|
18
|
+
t.observe(e), c.current = t;
|
|
19
|
+
}, [l]);
|
|
20
|
+
return r(() => () => {
|
|
21
|
+
c.current?.disconnect(), c.current = null;
|
|
22
|
+
}, []), {
|
|
23
|
+
ref: u,
|
|
24
|
+
width: o.width,
|
|
25
|
+
height: o.height
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { o as useElementSize };
|
|
@@ -5,6 +5,14 @@ export type UseHotkeyOptions = {
|
|
|
5
5
|
preventDefault?: boolean | undefined;
|
|
6
6
|
/** Also fire while typing in inputs, textareas or contenteditable. Default true when the combo has a modifier, false otherwise. */
|
|
7
7
|
allowInInputs?: boolean | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* What the shortcut does. Pass it to list the shortcut in `KapiShortcutsHelp`; without it the
|
|
10
|
+
* shortcut still works but stays out of the help, because an entry with no description would be
|
|
11
|
+
* a key with no explanation.
|
|
12
|
+
*/
|
|
13
|
+
description?: string | undefined;
|
|
14
|
+
/** Heading the shortcut is listed under in the help ("Navegación", "Edición"). */
|
|
15
|
+
group?: string | undefined;
|
|
8
16
|
};
|
|
9
17
|
/**
|
|
10
18
|
* Global keyboard shortcut. `combo` is `+`-separated: modifiers `mod` (Ctrl or Cmd), `ctrl`, `meta`/`cmd`,
|
package/dist/hooks/useHotkey.js
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { matchesHotkey as e, parseHotkey as t } from "./hotkeyLogic.js";
|
|
3
|
-
import {
|
|
3
|
+
import { hotkeyRegistry as n } from "./hotkeyRegistry.js";
|
|
4
|
+
import { useEffect as r, useRef as i } from "react";
|
|
4
5
|
//#region src/hooks/useHotkey.ts
|
|
5
|
-
var
|
|
6
|
-
let { enabled:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}),
|
|
10
|
-
if (
|
|
11
|
-
|
|
6
|
+
var a = (a, o, s = {}) => {
|
|
7
|
+
let { enabled: c = !0, preventDefault: l = !0, allowInInputs: u, description: d, group: f } = s, p = i(o);
|
|
8
|
+
r(() => {
|
|
9
|
+
p.current = o;
|
|
10
|
+
}), r(() => {
|
|
11
|
+
if (c && d !== void 0) return n.register({
|
|
12
|
+
combo: a,
|
|
13
|
+
description: d,
|
|
14
|
+
...f === void 0 ? {} : { group: f }
|
|
15
|
+
});
|
|
16
|
+
}, [
|
|
17
|
+
a,
|
|
18
|
+
c,
|
|
19
|
+
d,
|
|
20
|
+
f
|
|
21
|
+
]), r(() => {
|
|
22
|
+
if (!c) return;
|
|
23
|
+
let n = t(a);
|
|
12
24
|
if (!n) return;
|
|
13
|
-
let r = n.mod || n.ctrl || n.meta || n.alt,
|
|
25
|
+
let r = n.mod || n.ctrl || n.meta || n.alt, i = u ?? r, o = (t) => {
|
|
14
26
|
if (!(t.defaultPrevented || t.isComposing || !e(t, n))) {
|
|
15
|
-
if (!
|
|
27
|
+
if (!i) {
|
|
16
28
|
let e = t.target;
|
|
17
29
|
if (e instanceof HTMLElement && (e.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName))) return;
|
|
18
30
|
}
|
|
19
|
-
|
|
31
|
+
l && t.preventDefault(), p.current(t);
|
|
20
32
|
}
|
|
21
33
|
};
|
|
22
34
|
return window.addEventListener("keydown", o), () => window.removeEventListener("keydown", o);
|
|
23
35
|
}, [
|
|
24
|
-
|
|
25
|
-
s,
|
|
36
|
+
a,
|
|
26
37
|
c,
|
|
27
|
-
l
|
|
38
|
+
l,
|
|
39
|
+
u
|
|
28
40
|
]);
|
|
29
41
|
};
|
|
30
42
|
//#endregion
|
|
31
|
-
export {
|
|
43
|
+
export { a as useHotkey };
|