@zuccadev-labs/zuix-zui 0.1.0 → 0.2.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/AGENTS.md +96 -37
- package/CHANGELOG.md +215 -0
- package/README.md +73 -44
- package/THIRD_PARTY_NOTICES.md +71 -0
- package/dist/esm/components/actions/Button.d.ts +1 -1
- package/dist/esm/components/actions/Button.js +2 -2
- package/dist/esm/components/actions/Button.js.map +1 -1
- package/dist/esm/components/actions/IconButton.d.ts +1 -1
- package/dist/esm/components/actions/IconButton.js +2 -2
- package/dist/esm/components/actions/IconButton.js.map +1 -1
- package/dist/esm/components/actions/Link.d.ts +1 -1
- package/dist/esm/components/actions/Link.js +5 -3
- package/dist/esm/components/actions/Link.js.map +1 -1
- package/dist/esm/components/actions/SegmentedControl.d.ts +6 -3
- package/dist/esm/components/actions/SegmentedControl.js +29 -13
- package/dist/esm/components/actions/SegmentedControl.js.map +1 -1
- package/dist/esm/components/actions/Toggle.d.ts +5 -3
- package/dist/esm/components/actions/Toggle.js +8 -3
- package/dist/esm/components/actions/Toggle.js.map +1 -1
- package/dist/esm/components/carousel/Carousel.js +3 -8
- package/dist/esm/components/carousel/Carousel.js.map +1 -1
- package/dist/esm/components/carousel/engine.js +11 -10
- package/dist/esm/components/carousel/engine.js.map +1 -1
- package/dist/esm/components/carousel/lens.js +2 -2
- package/dist/esm/components/carousel/lens.js.map +1 -1
- package/dist/esm/components/carousel/lensRenderer.d.ts +6 -0
- package/dist/esm/components/carousel/lensRenderer.js +32 -4
- package/dist/esm/components/carousel/lensRenderer.js.map +1 -1
- package/dist/esm/components/carousel/useCarouselTrack.js +1 -0
- package/dist/esm/components/carousel/useCarouselTrack.js.map +1 -1
- package/dist/esm/components/content/Card.js.map +1 -1
- package/dist/esm/components/content/CodeBlock.js.map +1 -1
- package/dist/esm/components/content/Panel.js.map +1 -1
- package/dist/esm/components/data/Avatar.js +6 -1
- package/dist/esm/components/data/Avatar.js.map +1 -1
- package/dist/esm/components/data/AvatarGroup.js +1 -1
- package/dist/esm/components/data/AvatarGroup.js.map +1 -1
- package/dist/esm/components/data/Chip.js +1 -1
- package/dist/esm/components/data/Chip.js.map +1 -1
- package/dist/esm/components/data/DataTable.js +2 -17
- package/dist/esm/components/data/DataTable.js.map +1 -1
- package/dist/esm/components/data/Kbd.js +4 -1
- package/dist/esm/components/data/Kbd.js.map +1 -1
- package/dist/esm/components/data/Meter.js.map +1 -1
- package/dist/esm/components/data/Progress.js.map +1 -1
- package/dist/esm/components/data/Rating.d.ts +1 -1
- package/dist/esm/components/data/Rating.js +10 -6
- package/dist/esm/components/data/Rating.js.map +1 -1
- package/dist/esm/components/data/StatTile.js.map +1 -1
- package/dist/esm/components/data/Table.js.map +1 -1
- package/dist/esm/components/feedback/Alert.js.map +1 -1
- package/dist/esm/components/feedback/ErrorBoundary.js +1 -1
- package/dist/esm/components/feedback/ErrorBoundary.js.map +1 -1
- package/dist/esm/components/feedback/LoadingOverlay.js.map +1 -1
- package/dist/esm/components/feedback/Skeleton.js +1 -1
- package/dist/esm/components/feedback/Skeleton.js.map +1 -1
- package/dist/esm/components/feedback/Spinner.js +1 -1
- package/dist/esm/components/feedback/Spinner.js.map +1 -1
- package/dist/esm/components/forms/Calendar.d.ts +3 -8
- package/dist/esm/components/forms/Calendar.js +41 -44
- package/dist/esm/components/forms/Calendar.js.map +1 -1
- package/dist/esm/components/forms/Checkbox.d.ts +12 -4
- package/dist/esm/components/forms/Checkbox.js +17 -5
- package/dist/esm/components/forms/Checkbox.js.map +1 -1
- package/dist/esm/components/forms/Combobox.js +30 -26
- package/dist/esm/components/forms/Combobox.js.map +1 -1
- package/dist/esm/components/forms/DateInput.js +2 -7
- package/dist/esm/components/forms/DateInput.js.map +1 -1
- package/dist/esm/components/forms/DatePicker.js +54 -21
- package/dist/esm/components/forms/DatePicker.js.map +1 -1
- package/dist/esm/components/forms/Field.d.ts +6 -0
- package/dist/esm/components/forms/Field.js +11 -2
- package/dist/esm/components/forms/Field.js.map +1 -1
- package/dist/esm/components/forms/FileUpload.js +32 -13
- package/dist/esm/components/forms/FileUpload.js.map +1 -1
- package/dist/esm/components/forms/Input.js.map +1 -1
- package/dist/esm/components/forms/NativeSelect.js +1 -1
- package/dist/esm/components/forms/NativeSelect.js.map +1 -1
- package/dist/esm/components/forms/OTPInput.js +15 -4
- package/dist/esm/components/forms/OTPInput.js.map +1 -1
- package/dist/esm/components/forms/Radio.d.ts +5 -4
- package/dist/esm/components/forms/Radio.js +17 -3
- package/dist/esm/components/forms/Radio.js.map +1 -1
- package/dist/esm/components/forms/RadioGroup.d.ts +12 -5
- package/dist/esm/components/forms/RadioGroup.js +37 -6
- package/dist/esm/components/forms/RadioGroup.js.map +1 -1
- package/dist/esm/components/forms/SearchInput.js +2 -7
- package/dist/esm/components/forms/SearchInput.js.map +1 -1
- package/dist/esm/components/forms/Select.d.ts +5 -2
- package/dist/esm/components/forms/Select.js +131 -13
- package/dist/esm/components/forms/Select.js.map +1 -1
- package/dist/esm/components/forms/Slider.d.ts +23 -5
- package/dist/esm/components/forms/Slider.js +92 -5
- package/dist/esm/components/forms/Slider.js.map +1 -1
- package/dist/esm/components/forms/Switch.d.ts +10 -3
- package/dist/esm/components/forms/Switch.js +11 -4
- package/dist/esm/components/forms/Switch.js.map +1 -1
- package/dist/esm/components/forms/Textarea.d.ts +2 -2
- package/dist/esm/components/forms/Textarea.js +10 -3
- package/dist/esm/components/forms/Textarea.js.map +1 -1
- package/dist/esm/components/forms/index.d.ts +1 -1
- package/dist/esm/components/forms/index.js +1 -1
- package/dist/esm/components/forms/index.js.map +1 -1
- package/dist/esm/components/navigation/Accordion.d.ts +3 -2
- package/dist/esm/components/navigation/Accordion.js +57 -10
- package/dist/esm/components/navigation/Accordion.js.map +1 -1
- package/dist/esm/components/navigation/Breadcrumb.js +1 -1
- package/dist/esm/components/navigation/Breadcrumb.js.map +1 -1
- package/dist/esm/components/navigation/NavList.d.ts +4 -3
- package/dist/esm/components/navigation/NavList.js +10 -6
- package/dist/esm/components/navigation/NavList.js.map +1 -1
- package/dist/esm/components/navigation/Pagination.js +10 -19
- package/dist/esm/components/navigation/Pagination.js.map +1 -1
- package/dist/esm/components/navigation/Stepper.d.ts +1 -1
- package/dist/esm/components/navigation/Stepper.js +2 -2
- package/dist/esm/components/navigation/Stepper.js.map +1 -1
- package/dist/esm/components/navigation/Tabs.d.ts +4 -3
- package/dist/esm/components/navigation/Tabs.js +39 -5
- package/dist/esm/components/navigation/Tabs.js.map +1 -1
- package/dist/esm/components/navigation/Tree.d.ts +1 -1
- package/dist/esm/components/navigation/Tree.js +19 -3
- package/dist/esm/components/navigation/Tree.js.map +1 -1
- package/dist/esm/components/overlay/CommandPalette.js +34 -36
- package/dist/esm/components/overlay/CommandPalette.js.map +1 -1
- package/dist/esm/components/overlay/ConfirmDialog.d.ts +6 -2
- package/dist/esm/components/overlay/ConfirmDialog.js +23 -6
- package/dist/esm/components/overlay/ConfirmDialog.js.map +1 -1
- package/dist/esm/components/overlay/ContextMenu.d.ts +2 -1
- package/dist/esm/components/overlay/ContextMenu.js +50 -7
- package/dist/esm/components/overlay/ContextMenu.js.map +1 -1
- package/dist/esm/components/overlay/Drawer.d.ts +3 -2
- package/dist/esm/components/overlay/Drawer.js +11 -6
- package/dist/esm/components/overlay/Drawer.js.map +1 -1
- package/dist/esm/components/overlay/Menu.d.ts +3 -2
- package/dist/esm/components/overlay/Menu.js +27 -8
- package/dist/esm/components/overlay/Menu.js.map +1 -1
- package/dist/esm/components/overlay/Modal.d.ts +3 -2
- package/dist/esm/components/overlay/Modal.js +11 -10
- package/dist/esm/components/overlay/Modal.js.map +1 -1
- package/dist/esm/components/overlay/Popover.d.ts +20 -5
- package/dist/esm/components/overlay/Popover.js +53 -4
- package/dist/esm/components/overlay/Popover.js.map +1 -1
- package/dist/esm/components/overlay/Toast.d.ts +8 -4
- package/dist/esm/components/overlay/Toast.js +145 -50
- package/dist/esm/components/overlay/Toast.js.map +1 -1
- package/dist/esm/components/overlay/Tooltip.d.ts +2 -2
- package/dist/esm/components/overlay/Tooltip.js +64 -7
- package/dist/esm/components/overlay/Tooltip.js.map +1 -1
- package/dist/esm/components/overlay/internal.d.ts +18 -50
- package/dist/esm/components/overlay/internal.js +24 -48
- package/dist/esm/components/overlay/internal.js.map +1 -1
- package/dist/esm/core/accept.d.ts +5 -0
- package/dist/esm/core/accept.js +13 -0
- package/dist/esm/core/accept.js.map +1 -0
- package/dist/esm/core/compare.d.ts +5 -0
- package/dist/esm/core/compare.js +27 -0
- package/dist/esm/core/compare.js.map +1 -0
- package/dist/esm/core/date.d.ts +27 -0
- package/dist/esm/core/date.js +59 -0
- package/dist/esm/core/date.js.map +1 -0
- package/dist/esm/core/dir.d.ts +4 -0
- package/dist/esm/core/dir.js +10 -0
- package/dist/esm/core/dir.js.map +1 -0
- package/dist/esm/core/focus.d.ts +16 -0
- package/dist/esm/core/focus.js +50 -0
- package/dist/esm/core/focus.js.map +1 -0
- package/dist/esm/core/keys.d.ts +6 -0
- package/dist/esm/core/keys.js +14 -0
- package/dist/esm/core/keys.js.map +1 -0
- package/dist/esm/core/layers.d.ts +33 -0
- package/dist/esm/core/layers.js +75 -0
- package/dist/esm/core/layers.js.map +1 -0
- package/dist/esm/core/long-press.d.ts +13 -0
- package/dist/esm/core/long-press.js +33 -0
- package/dist/esm/core/long-press.js.map +1 -0
- package/dist/esm/core/menu-aim.d.ts +17 -0
- package/dist/esm/core/menu-aim.js +48 -0
- package/dist/esm/core/menu-aim.js.map +1 -0
- package/dist/esm/core/modal-host.d.ts +16 -0
- package/dist/esm/core/modal-host.js +59 -0
- package/dist/esm/core/modal-host.js.map +1 -0
- package/dist/esm/core/pagination.d.ts +6 -0
- package/dist/esm/core/pagination.js +32 -0
- package/dist/esm/core/pagination.js.map +1 -0
- package/dist/esm/core/place.d.ts +54 -0
- package/dist/esm/core/place.js +97 -0
- package/dist/esm/core/place.js.map +1 -0
- package/dist/esm/core/presence.d.ts +7 -0
- package/dist/esm/core/presence.js +43 -0
- package/dist/esm/core/presence.js.map +1 -0
- package/dist/esm/core/ref.d.ts +9 -0
- package/dist/esm/core/ref.js +25 -0
- package/dist/esm/core/ref.js.map +1 -0
- package/dist/esm/core/roving.d.ts +6 -0
- package/dist/esm/core/roving.js +27 -0
- package/dist/esm/core/roving.js.map +1 -0
- package/dist/esm/core/scroll-lock.d.ts +2 -0
- package/dist/esm/core/scroll-lock.js +33 -0
- package/dist/esm/core/scroll-lock.js.map +1 -0
- package/dist/esm/core/search.d.ts +4 -0
- package/dist/esm/core/search.js +20 -0
- package/dist/esm/core/search.js.map +1 -0
- package/dist/esm/core/slider.d.ts +20 -0
- package/dist/esm/core/slider.js +66 -0
- package/dist/esm/core/slider.js.map +1 -0
- package/dist/esm/core/swipe.d.ts +18 -0
- package/dist/esm/core/swipe.js +78 -0
- package/dist/esm/core/swipe.js.map +1 -0
- package/dist/esm/core/timer.d.ts +11 -0
- package/dist/esm/core/timer.js +38 -0
- package/dist/esm/core/timer.js.map +1 -0
- package/dist/esm/core/typeahead.d.ts +19 -0
- package/dist/esm/core/typeahead.js +33 -0
- package/dist/esm/core/typeahead.js.map +1 -0
- package/dist/esm/dom/carousel.d.ts +2 -1
- package/dist/esm/dom/carousel.js +18 -30
- package/dist/esm/dom/carousel.js.map +1 -1
- package/dist/esm/dom/collections.d.ts +2 -1
- package/dist/esm/dom/collections.js +67 -72
- package/dist/esm/dom/collections.js.map +1 -1
- package/dist/esm/dom/forms-calendar.d.ts +4 -5
- package/dist/esm/dom/forms-calendar.js +74 -72
- package/dist/esm/dom/forms-calendar.js.map +1 -1
- package/dist/esm/dom/forms-controls.d.ts +2 -1
- package/dist/esm/dom/forms-controls.js +84 -65
- package/dist/esm/dom/forms-controls.js.map +1 -1
- package/dist/esm/dom/forms-listbox.d.ts +2 -1
- package/dist/esm/dom/forms-listbox.js +66 -64
- package/dist/esm/dom/forms-listbox.js.map +1 -1
- package/dist/esm/dom/forms-popup.d.ts +3 -2
- package/dist/esm/dom/forms-popup.js +34 -44
- package/dist/esm/dom/forms-popup.js.map +1 -1
- package/dist/esm/dom/forms.d.ts +2 -1
- package/dist/esm/dom/forms.js +2 -2
- package/dist/esm/dom/forms.js.map +1 -1
- package/dist/esm/dom/index.d.ts +28 -10
- package/dist/esm/dom/index.js +500 -296
- package/dist/esm/dom/index.js.map +1 -1
- package/dist/esm/dom/shared.d.ts +22 -0
- package/dist/esm/dom/shared.js +45 -0
- package/dist/esm/dom/shared.js.map +1 -0
- package/dist/esm/primitives/dialog.d.ts +17 -0
- package/dist/esm/primitives/dialog.js +78 -0
- package/dist/esm/primitives/dialog.js.map +1 -0
- package/dist/esm/primitives/hooks.d.ts +15 -0
- package/dist/esm/primitives/hooks.js +65 -0
- package/dist/esm/primitives/hooks.js.map +1 -0
- package/dist/esm/primitives/menu.d.ts +26 -0
- package/dist/esm/primitives/menu.js +249 -0
- package/dist/esm/primitives/menu.js.map +1 -0
- package/dist/esm/primitives/native-input.d.ts +13 -0
- package/dist/esm/primitives/native-input.js +26 -0
- package/dist/esm/primitives/native-input.js.map +1 -0
- package/dist/esm/primitives/popup.d.ts +51 -0
- package/dist/esm/primitives/popup.js +137 -0
- package/dist/esm/primitives/popup.js.map +1 -0
- package/dist/esm/primitives/radio-context.d.ts +11 -0
- package/dist/esm/primitives/radio-context.js +5 -0
- package/dist/esm/primitives/radio-context.js.map +1 -0
- package/dist/esm/primitives/slot.d.ts +13 -0
- package/dist/esm/primitives/slot.js +39 -0
- package/dist/esm/primitives/slot.js.map +1 -0
- package/dist/esm/refs.d.ts +8 -0
- package/dist/esm/refs.js +32 -0
- package/dist/esm/refs.js.map +1 -0
- package/dist/styles/actions.css +22 -12
- package/dist/styles/base.css +216 -9
- package/dist/styles/carousel.css +132 -35
- package/dist/styles/content.css +13 -7
- package/dist/styles/data.css +61 -35
- package/dist/styles/feedback.css +17 -6
- package/dist/styles/forms.css +75 -20
- package/dist/styles/material.css +9 -4
- package/dist/styles/native.css +120 -23
- package/dist/styles/navigation.css +630 -154
- package/dist/styles/overlay.css +625 -188
- package/dist/zui.css +315 -150
- package/dist/zui.dom.carousel-gl.js +3 -3
- package/dist/zui.dom.js +1 -1
- package/html.json +19 -23
- package/manifest.json +121 -64
- package/package.json +9 -10
|
@@ -1,12 +1,69 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef } from "react";
|
|
4
4
|
import { cx } from "../../cx.js";
|
|
5
|
-
|
|
5
|
+
import { useControllable, usePresence } from "../../primitives/hooks.js";
|
|
6
|
+
import { Popup, Portal, rectOf } from "../../primitives/popup.js";
|
|
7
|
+
import { slot } from "../../primitives/slot.js";
|
|
8
|
+
// Margen para que el puntero cruce del disparador a la burbuja sin que se cierre.
|
|
9
|
+
const CLOSE_MS = 120;
|
|
10
|
+
export function Tooltip(props) {
|
|
6
11
|
// Sin contenido no hay burbuja: se devuelve el disparador tal cual.
|
|
7
|
-
if (content === null || content === undefined || content === "")
|
|
8
|
-
return children;
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
if (props.content === null || props.content === undefined || props.content === "")
|
|
13
|
+
return props.children;
|
|
14
|
+
return _jsx(Bubble, { ...props });
|
|
15
|
+
}
|
|
16
|
+
// WCAG 1.4.13: la burbuja se puede descartar sin mover el puntero (Escape), el puntero puede pasar a ella sin que se
|
|
17
|
+
// cierre y sigue visible mientras el puntero o el foco estén en el disparador o en la burbuja.
|
|
18
|
+
function Bubble({ content, children, side = "top", align = "center", delay = 300, open: openProp, defaultOpen, onOpenChange, className, }) {
|
|
19
|
+
const id = useId();
|
|
20
|
+
const [open, setOpen] = useControllable(openProp, defaultOpen ?? false, onOpenChange);
|
|
21
|
+
const trigger = useRef(null);
|
|
22
|
+
const tip = useRef(null);
|
|
23
|
+
const timer = useRef(undefined);
|
|
24
|
+
const present = usePresence(open, tip);
|
|
25
|
+
const schedule = (next, ms) => {
|
|
26
|
+
clearTimeout(timer.current);
|
|
27
|
+
if (ms <= 0)
|
|
28
|
+
setOpen(next);
|
|
29
|
+
else
|
|
30
|
+
timer.current = setTimeout(() => setOpen(next), ms);
|
|
31
|
+
};
|
|
32
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
33
|
+
// Escape cierra la burbuja sin mover el puntero ni el foco; no consume la tecla.
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!open)
|
|
36
|
+
return;
|
|
37
|
+
const onKey = (event) => {
|
|
38
|
+
if (event.key === "Escape")
|
|
39
|
+
schedule(false, 0);
|
|
40
|
+
};
|
|
41
|
+
document.addEventListener("keydown", onKey, true);
|
|
42
|
+
return () => document.removeEventListener("keydown", onKey, true);
|
|
43
|
+
});
|
|
44
|
+
const describedBy = children.props["aria-describedby"];
|
|
45
|
+
const host = slot(children, {
|
|
46
|
+
ref: trigger,
|
|
47
|
+
// Se añade a la descripción que el control ya tuviera (la ayuda de un Field), sin sustituirla.
|
|
48
|
+
"aria-describedby": present ? [describedBy, id].filter(Boolean).join(" ") : describedBy,
|
|
49
|
+
"data-state": open ? "open" : "closed",
|
|
50
|
+
onPointerEnter: (event) => {
|
|
51
|
+
if (event.pointerType !== "touch")
|
|
52
|
+
schedule(true, delay);
|
|
53
|
+
},
|
|
54
|
+
onPointerLeave: (event) => {
|
|
55
|
+
// Con el foco en el disparador la burbuja se queda: se cierra al perder el foco o con Escape.
|
|
56
|
+
if (open && event.currentTarget.matches(":focus-visible"))
|
|
57
|
+
return clearTimeout(timer.current);
|
|
58
|
+
schedule(false, open ? CLOSE_MS : 0);
|
|
59
|
+
},
|
|
60
|
+
onPointerDown: () => schedule(false, 0),
|
|
61
|
+
onFocus: (event) => {
|
|
62
|
+
if (event.currentTarget.matches(":focus-visible"))
|
|
63
|
+
schedule(true, 0);
|
|
64
|
+
},
|
|
65
|
+
onBlur: () => schedule(false, 0),
|
|
66
|
+
});
|
|
67
|
+
return (_jsxs(_Fragment, { children: [host, present ? (_jsx(Portal, { anchor: trigger, children: _jsx(Popup, { ref: tip, id: id, open: open, anchorRect: () => rectOf(trigger.current), watch: trigger, placement: align === "center" ? side : `${side}-${align}`, gap: 7, role: "tooltip", className: cx("z-liquid z-tooltip", className), onPointerEnter: () => clearTimeout(timer.current), onPointerLeave: () => schedule(false, CLOSE_MS), children: content }) })) : null] }));
|
|
11
68
|
}
|
|
12
69
|
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../src/components/overlay/Tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../src/components/overlay/Tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAyE,MAAM,OAAO,CAAC;AACxH,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAiB7C,kFAAkF;AAClF,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB,MAAM,UAAU,OAAO,CAAC,KAAmB;IACzC,oEAAoE;IACpE,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAC;IACzG,OAAO,KAAC,MAAM,OAAK,KAAK,GAAI,CAAC;AAC/B,CAAC;A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AAC,gBAAgB,CAAC;gBAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;KACjC,CAAC,CAAC;IAEH,OAAO,CACL,8BACG,IAAI,EACJ,OAAO,CAAC,CAAC,CAAC,CACT,KAAC,MAAM,IAAC,MAAM,EAAE,OAAO,YACrB,KAAC,KAAK,IACJ,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EACzC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,EACzD,GAAG,EAAE,CAAC,EACN,IAAI,EAAC,SAAS,EACd,SAAS,EAAE,EAAE,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAC9C,cAAc,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,EACjD,cAAc,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,YAE9C,OAAO,GACF,GACD,CACV,CAAC,CAAC,CAAC,IAAI,IACP,CACJ,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useId, useRef, type FocusEvent, type PointerEvent, type ReactElement, type ReactNode } from \"react\";\nimport { cx } from \"../../cx\";\nimport { useControllable, usePresence } from \"../../primitives/hooks\";\nimport { Popup, Portal, rectOf } from \"../../primitives/popup\";\nimport { slot } from \"../../primitives/slot\";\n\nexport interface TooltipProps {\n /** Texto o contenido de la burbuja. */\n content: ReactNode;\n /** Disparador: un único elemento enfocable. */\n children: ReactElement;\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n align?: \"start\" | \"center\" | \"end\";\n /** Retardo de apertura en ms. */\n delay?: number;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n className?: string;\n}\n\n// Margen para que el puntero cruce del disparador a la burbuja sin que se cierre.\nconst CLOSE_MS = 120;\n\nexport function Tooltip(props: TooltipProps) {\n // Sin contenido no hay burbuja: se devuelve el disparador tal cual.\n if (props.content === null || props.content === undefined || props.content === \"\") return props.children;\n return <Bubble {...props} />;\n}\n\n// WCAG 1.4.13: la burbuja se puede descartar sin mover el puntero (Escape), el puntero puede pasar a ella sin que se\n// cierre y sigue visible mientras el puntero o el foco estén en el disparador o en la burbuja.\nfunction Bubble({\n content,\n children,\n side = \"top\",\n align = \"center\",\n delay = 300,\n open: openProp,\n defaultOpen,\n onOpenChange,\n className,\n}: TooltipProps) {\n const id = useId();\n const [open, setOpen] = useControllable(openProp, defaultOpen ?? false, onOpenChange);\n const trigger = useRef<HTMLElement | null>(null);\n const tip = useRef<HTMLDivElement | null>(null);\n const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const present = usePresence(open, tip);\n\n const schedule = (next: boolean, ms: number) => {\n clearTimeout(timer.current);\n if (ms <= 0) setOpen(next);\n else timer.current = setTimeout(() => setOpen(next), ms);\n };\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape cierra la burbuja sin mover el puntero ni el foco; no consume la tecla.\n useEffect(() => {\n if (!open) return;\n const onKey = (event: globalThis.KeyboardEvent) => {\n if (event.key === \"Escape\") schedule(false, 0);\n };\n document.addEventListener(\"keydown\", onKey, true);\n return () => document.removeEventListener(\"keydown\", onKey, true);\n });\n\n const describedBy = (children.props as { \"aria-describedby\"?: string })[\"aria-describedby\"];\n const host = slot(children, {\n ref: trigger,\n // Se añade a la descripción que el control ya tuviera (la ayuda de un Field), sin sustituirla.\n \"aria-describedby\": present ? [describedBy, id].filter(Boolean).join(\" \") : describedBy,\n \"data-state\": open ? \"open\" : \"closed\",\n onPointerEnter: (event: PointerEvent) => {\n if (event.pointerType !== \"touch\") schedule(true, delay);\n },\n onPointerLeave: (event: PointerEvent) => {\n // Con el foco en el disparador la burbuja se queda: se cierra al perder el foco o con Escape.\n if (open && event.currentTarget.matches(\":focus-visible\")) return clearTimeout(timer.current);\n schedule(false, open ? CLOSE_MS : 0);\n },\n onPointerDown: () => schedule(false, 0),\n onFocus: (event: FocusEvent) => {\n if (event.currentTarget.matches(\":focus-visible\")) schedule(true, 0);\n },\n onBlur: () => schedule(false, 0),\n });\n\n return (\n <>\n {host}\n {present ? (\n <Portal anchor={trigger}>\n <Popup\n ref={tip}\n id={id}\n open={open}\n anchorRect={() => rectOf(trigger.current)}\n watch={trigger}\n placement={align === \"center\" ? side : `${side}-${align}`}\n gap={7}\n role=\"tooltip\"\n className={cx(\"z-liquid z-tooltip\", className)}\n onPointerEnter={() => clearTimeout(timer.current)}\n onPointerLeave={() => schedule(false, CLOSE_MS)}\n >\n {content}\n </Popup>\n </Portal>\n ) : null}\n </>\n );\n}\n"]}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { type ComponentProps, type
|
|
1
|
+
import { type ComponentProps, type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { type IconName } from "@zuccadev-labs/zuix-zicon/core";
|
|
3
|
-
/** Verdadero dentro de un Modal: los menús anidados suben de capa para no quedar detrás. */
|
|
4
|
-
export declare const ElevatedContext: import("react").Context<boolean>;
|
|
5
|
-
/**
|
|
6
|
-
* Devolución del foco para diálogos abiertos sin disparador (uso controlado). Radix solo devuelve el foco a su
|
|
7
|
-
* `Trigger`; sin él, al cerrar el foco se quedaba en `body`. Aquí se recuerda el elemento enfocado al abrir y se
|
|
8
|
-
* le devuelve el foco al cerrar. Con disparador no hace nada.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useReturnFocus(hasTrigger: boolean): {
|
|
11
|
-
onOpenAutoFocus: () => void;
|
|
12
|
-
onCloseAutoFocus: (event: Event) => void;
|
|
13
|
-
};
|
|
14
|
-
/** Un clic en el velo de un diálogo que no se cierra con él no debe llevarse el foco a `body`. */
|
|
15
|
-
export declare const keepFocus: (event: MouseEvent) => void;
|
|
16
3
|
export interface CloseButtonProps extends ComponentProps<"button"> {
|
|
17
4
|
label: string;
|
|
18
5
|
}
|
|
@@ -44,39 +31,20 @@ export type MenuEntry = {
|
|
|
44
31
|
type: "label";
|
|
45
32
|
label: ReactNode;
|
|
46
33
|
} | MenuItemEntry;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
SubTrigger: ComponentType<{
|
|
65
|
-
className?: string;
|
|
66
|
-
disabled?: boolean;
|
|
67
|
-
children?: ReactNode;
|
|
68
|
-
}>;
|
|
69
|
-
SubContent: ComponentType<{
|
|
70
|
-
className?: string;
|
|
71
|
-
children?: ReactNode;
|
|
72
|
-
}>;
|
|
73
|
-
Portal: ComponentType<{
|
|
74
|
-
children?: ReactNode;
|
|
75
|
-
}>;
|
|
76
|
-
}
|
|
77
|
-
export declare function MenuEntries({ kit, items, size, elevated }: {
|
|
78
|
-
kit: MenuKit;
|
|
79
|
-
items: MenuEntry[];
|
|
80
|
-
size: "md" | "lg";
|
|
81
|
-
elevated: boolean;
|
|
82
|
-
}): import("react").JSX.Element;
|
|
34
|
+
/**
|
|
35
|
+
* Estado abierto/cerrado de una capa con disparador opcional. Devuelve el disparador ya conectado (clic, ref y
|
|
36
|
+
* atributos ARIA) y su ref, a la que vuelve el foco al cerrar.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useDisclosure(options: {
|
|
39
|
+
open?: boolean;
|
|
40
|
+
defaultOpen?: boolean;
|
|
41
|
+
onOpenChange?: (open: boolean) => void;
|
|
42
|
+
trigger?: ReactElement;
|
|
43
|
+
popup?: "dialog" | "menu";
|
|
44
|
+
id?: string;
|
|
45
|
+
}): {
|
|
46
|
+
open: boolean;
|
|
47
|
+
setOpen: (next: boolean) => void;
|
|
48
|
+
trigger: ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null;
|
|
49
|
+
triggerRef: import("react").RefObject<HTMLElement | null>;
|
|
50
|
+
};
|
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
// Piezas internas del grupo overlay: botón de cierre, botón de acción
|
|
4
|
-
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Piezas internas del grupo overlay: botón de cierre, botón de acción, tipos de las entradas de menú y el estado
|
|
4
|
+
// abierto/cerrado con disparador que comparten los diálogos.
|
|
5
|
+
import { useRef } from "react";
|
|
5
6
|
import { Icon } from "@zuccadev-labs/zuix-zicon/core";
|
|
7
|
+
import { useControllable } from "../../primitives/hooks.js";
|
|
8
|
+
import { slot } from "../../primitives/slot.js";
|
|
6
9
|
import { cx } from "../../cx.js";
|
|
7
|
-
/** Verdadero dentro de un Modal: los menús anidados suben de capa para no quedar detrás. */
|
|
8
|
-
export const ElevatedContext = createContext(false);
|
|
9
|
-
/**
|
|
10
|
-
* Devolución del foco para diálogos abiertos sin disparador (uso controlado). Radix solo devuelve el foco a su
|
|
11
|
-
* `Trigger`; sin él, al cerrar el foco se quedaba en `body`. Aquí se recuerda el elemento enfocado al abrir y se
|
|
12
|
-
* le devuelve el foco al cerrar. Con disparador no hace nada.
|
|
13
|
-
*/
|
|
14
|
-
export function useReturnFocus(hasTrigger) {
|
|
15
|
-
const previous = useRef(null);
|
|
16
|
-
return {
|
|
17
|
-
onOpenAutoFocus: () => {
|
|
18
|
-
// En este momento el foco aún no ha entrado en el diálogo.
|
|
19
|
-
previous.current = document.activeElement instanceof HTMLElement && document.activeElement !== document.body ? document.activeElement : null;
|
|
20
|
-
},
|
|
21
|
-
onCloseAutoFocus: (event) => {
|
|
22
|
-
const target = previous.current;
|
|
23
|
-
previous.current = null;
|
|
24
|
-
if (hasTrigger || !target || !target.isConnected)
|
|
25
|
-
return;
|
|
26
|
-
event.preventDefault();
|
|
27
|
-
target.focus({ preventScroll: true });
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/** Un clic en el velo de un diálogo que no se cierra con él no debe llevarse el foco a `body`. */
|
|
32
|
-
export const keepFocus = (event) => event.preventDefault();
|
|
33
10
|
/** Botón de cierre local (el grupo no depende de `actions`). */
|
|
34
11
|
export function CloseButton({ label, className, ...rest }) {
|
|
35
12
|
return (_jsx("button", { type: "button", ...rest, className: cx("z-overlay-close", className), "aria-label": label, children: _jsx(Icon, { name: "x-mark", size: 16 }) }));
|
|
@@ -38,24 +15,23 @@ export function CloseButton({ label, className, ...rest }) {
|
|
|
38
15
|
export function DialogButton({ variant = "secondary", className, ...rest }) {
|
|
39
16
|
return _jsx("button", { type: "button", ...rest, className: cx("z-dialog-btn", className), "data-variant": variant });
|
|
40
17
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}) }));
|
|
18
|
+
/**
|
|
19
|
+
* Estado abierto/cerrado de una capa con disparador opcional. Devuelve el disparador ya conectado (clic, ref y
|
|
20
|
+
* atributos ARIA) y su ref, a la que vuelve el foco al cerrar.
|
|
21
|
+
*/
|
|
22
|
+
export function useDisclosure(options) {
|
|
23
|
+
const [open, setOpen] = useControllable(options.open, options.defaultOpen ?? false, options.onOpenChange);
|
|
24
|
+
const triggerRef = useRef(null);
|
|
25
|
+
const trigger = options.trigger
|
|
26
|
+
? slot(options.trigger, {
|
|
27
|
+
ref: triggerRef,
|
|
28
|
+
"aria-haspopup": options.popup ?? "dialog",
|
|
29
|
+
"aria-expanded": open,
|
|
30
|
+
"aria-controls": open ? options.id : undefined,
|
|
31
|
+
"data-state": open ? "open" : "closed",
|
|
32
|
+
onClick: () => setOpen(!open),
|
|
33
|
+
})
|
|
34
|
+
: null;
|
|
35
|
+
return { open, setOpen, trigger, triggerRef };
|
|
60
36
|
}
|
|
61
37
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../src/components/overlay/internal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../src/components/overlay/internal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,iHAAiH;AACjH,6DAA6D;AAC7D,OAAO,EAAE,MAAM,EAA0D,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,IAAI,EAAiB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAM9B,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,EAAoB;IACzE,OAAO,CACL,iBAAQ,IAAI,EAAC,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,iBAAiB,EAAE,SAAS,CAAC,gBAAc,KAAK,YAC5F,KAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,EAAE,GAAI,GACzB,CACV,CAAC;AACJ,CAAC;AAMD,kEAAkE;AAClE,MAAM,UAAU,YAAY,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAAqB;IAC3F,OAAO,iBAAQ,IAAI,EAAC,QAAQ,KAAK,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC,kBAAgB,OAAO,GAAI,CAAC;AAC7G,CAAC;AAoBD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAO7B;IACC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1G,MAAM,UAAU,GAAG,MAAM,CAAqB,IAAI,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO;QAC7B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACpB,GAAG,EAAE,UAAU;YACf,eAAe,EAAE,OAAO,CAAC,KAAK,IAAI,QAAQ;YAC1C,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;YAC9C,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;YACtC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;SAC9B,CAAC;QACJ,CAAC,CAAC,IAAI,CAAC;IACT,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAChD,CAAC","sourcesContent":["\"use client\";\n// Piezas internas del grupo overlay: botón de cierre, botón de acción, tipos de las entradas de menú y el estado\n// abierto/cerrado con disparador que comparten los diálogos.\nimport { useRef, type ComponentProps, type ReactElement, type ReactNode } from \"react\";\nimport { Icon, type IconName } from \"@zuccadev-labs/zuix-zicon/core\";\nimport { useControllable } from \"../../primitives/hooks\";\nimport { slot } from \"../../primitives/slot\";\nimport { cx } from \"../../cx\";\n\nexport interface CloseButtonProps extends ComponentProps<\"button\"> {\n label: string;\n}\n\n/** Botón de cierre local (el grupo no depende de `actions`). */\nexport function CloseButton({ label, className, ...rest }: CloseButtonProps) {\n return (\n <button type=\"button\" {...rest} className={cx(\"z-overlay-close\", className)} aria-label={label}>\n <Icon name=\"x-mark\" size={16} />\n </button>\n );\n}\n\nexport interface DialogButtonProps extends ComponentProps<\"button\"> {\n variant?: \"primary\" | \"secondary\" | \"danger\";\n}\n\n/** Botón de pie de diálogo; misma forma que el botón estándar. */\nexport function DialogButton({ variant = \"secondary\", className, ...rest }: DialogButtonProps) {\n return <button type=\"button\" {...rest} className={cx(\"z-dialog-btn\", className)} data-variant={variant} />;\n}\n\nexport interface MenuItemEntry {\n type?: \"item\";\n id: string;\n label: ReactNode;\n icon?: IconName;\n /** Atajo mostrado a la derecha, p. ej. \"Ctrl K\". */\n shortcut?: string;\n danger?: boolean;\n disabled?: boolean;\n /** No cierra el menú al elegir. */\n keepOpen?: boolean;\n onSelect?: () => void;\n /** Submenú. */\n items?: MenuEntry[];\n}\n\nexport type MenuEntry = { type: \"separator\" } | { type: \"label\"; label: ReactNode } | MenuItemEntry;\n\n/**\n * Estado abierto/cerrado de una capa con disparador opcional. Devuelve el disparador ya conectado (clic, ref y\n * atributos ARIA) y su ref, a la que vuelve el foco al cerrar.\n */\nexport function useDisclosure(options: {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n trigger?: ReactElement;\n popup?: \"dialog\" | \"menu\";\n id?: string;\n}) {\n const [open, setOpen] = useControllable(options.open, options.defaultOpen ?? false, options.onOpenChange);\n const triggerRef = useRef<HTMLElement | null>(null);\n const trigger = options.trigger\n ? slot(options.trigger, {\n ref: triggerRef,\n \"aria-haspopup\": options.popup ?? \"dialog\",\n \"aria-expanded\": open,\n \"aria-controls\": open ? options.id : undefined,\n \"data-state\": open ? \"open\" : \"closed\",\n onClick: () => setOpen(!open),\n })\n : null;\n return { open, setOpen, trigger, triggerRef };\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Comprueba un archivo contra una lista `accept` (extensiones, tipos MIME y comodines `tipo/*`). Vacía: todo vale. */
|
|
2
|
+
export function matchesAccept(file, accept) {
|
|
3
|
+
const rules = (accept ?? "")
|
|
4
|
+
.split(",")
|
|
5
|
+
.map((rule) => rule.trim().toLowerCase())
|
|
6
|
+
.filter(Boolean);
|
|
7
|
+
if (!rules.length)
|
|
8
|
+
return true;
|
|
9
|
+
const name = file.name.toLowerCase();
|
|
10
|
+
const type = file.type.toLowerCase();
|
|
11
|
+
return rules.some((rule) => rule.startsWith(".") ? name.endsWith(rule) : rule.endsWith("/*") ? type.startsWith(rule.slice(0, -1)) : type === rule);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=accept.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accept.js","sourceRoot":"","sources":["../../../src/core/accept.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,MAAM,UAAU,aAAa,CAAC,IAAoC,EAAE,MAAiC;IACnG,MAAM,KAAK,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;SACzB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;SACxC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACzB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CACtH,CAAC;AACJ,CAAC","sourcesContent":["/** Comprueba un archivo contra una lista `accept` (extensiones, tipos MIME y comodines `tipo/*`). Vacía: todo vale. */\nexport function matchesAccept(file: { name: string; type: string }, accept: string | null | undefined): boolean {\n const rules = (accept ?? \"\")\n .split(\",\")\n .map((rule) => rule.trim().toLowerCase())\n .filter(Boolean);\n if (!rules.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return rules.some((rule) =>\n rule.startsWith(\".\") ? name.endsWith(rule) : rule.endsWith(\"/*\") ? type.startsWith(rule.slice(0, -1)) : type === rule,\n );\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const isDate: (value: unknown) => value is Date;
|
|
2
|
+
/** Compara dos valores de celda en orden ascendente; el texto, sin distinguir mayúsculas y con números naturales. */
|
|
3
|
+
export declare function compare(a: unknown, b: unknown): number;
|
|
4
|
+
/** Número escrito en una celda («1.234», «$ 12», «-5»); `null` si el texto no contiene ninguna cifra o no es un número. */
|
|
5
|
+
export declare function parseNumber(raw: string): number | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Orden de celdas de tabla. Los vacíos (null, undefined, NaN, fecha inválida) van al final.
|
|
2
|
+
// `instanceof Date` falla con fechas creadas en otro realm (un iframe, un entorno de pruebas): se mira la etiqueta.
|
|
3
|
+
export const isDate = (value) => Object.prototype.toString.call(value) === "[object Date]";
|
|
4
|
+
const empty = (value) => value == null || (typeof value === "number" && Number.isNaN(value)) || (isDate(value) && Number.isNaN(value.getTime()));
|
|
5
|
+
/** Compara dos valores de celda en orden ascendente; el texto, sin distinguir mayúsculas y con números naturales. */
|
|
6
|
+
export function compare(a, b) {
|
|
7
|
+
const ea = empty(a);
|
|
8
|
+
const eb = empty(b);
|
|
9
|
+
if (ea || eb)
|
|
10
|
+
return ea === eb ? 0 : ea ? 1 : -1;
|
|
11
|
+
if (isDate(a) && isDate(b))
|
|
12
|
+
return a.getTime() - b.getTime();
|
|
13
|
+
if (typeof a === "number" && typeof b === "number")
|
|
14
|
+
return a - b;
|
|
15
|
+
if (typeof a === "boolean" && typeof b === "boolean")
|
|
16
|
+
return Number(a) - Number(b);
|
|
17
|
+
return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: "base" });
|
|
18
|
+
}
|
|
19
|
+
/** Número escrito en una celda («1.234», «$ 12», «-5»); `null` si el texto no contiene ninguna cifra o no es un número. */
|
|
20
|
+
export function parseNumber(raw) {
|
|
21
|
+
const cleaned = raw.replace(/[^\d.eE+-]/g, "");
|
|
22
|
+
if (!/\d/.test(cleaned))
|
|
23
|
+
return null;
|
|
24
|
+
const n = Number(cleaned);
|
|
25
|
+
return Number.isNaN(n) ? null : n;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/core/compare.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAE5F,oHAAoH;AACpH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,eAAe,CAAC;AAEnH,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE,CAC/B,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAE1H,qHAAqH;AACrH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,CAAC,CAAC;AACpC,CAAC","sourcesContent":["// Orden de celdas de tabla. Los vacíos (null, undefined, NaN, fecha inválida) van al final.\n\n// `instanceof Date` falla con fechas creadas en otro realm (un iframe, un entorno de pruebas): se mira la etiqueta.\nexport const isDate = (value: unknown): value is Date => Object.prototype.toString.call(value) === \"[object Date]\";\n\nconst empty = (value: unknown) =>\n value == null || (typeof value === \"number\" && Number.isNaN(value)) || (isDate(value) && Number.isNaN(value.getTime()));\n\n/** Compara dos valores de celda en orden ascendente; el texto, sin distinguir mayúsculas y con números naturales. */\nexport function compare(a: unknown, b: unknown): number {\n const ea = empty(a);\n const eb = empty(b);\n if (ea || eb) return ea === eb ? 0 : ea ? 1 : -1;\n if (isDate(a) && isDate(b)) return a.getTime() - b.getTime();\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n if (typeof a === \"boolean\" && typeof b === \"boolean\") return Number(a) - Number(b);\n return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: \"base\" });\n}\n\n/** Número escrito en una celda («1.234», «$ 12», «-5»); `null` si el texto no contiene ninguna cifra o no es un número. */\nexport function parseNumber(raw: string): number | null {\n const cleaned = raw.replace(/[^\\d.eE+-]/g, \"\");\n if (!/\\d/.test(cleaned)) return null;\n const n = Number(cleaned);\n return Number.isNaN(n) ? null : n;\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Rango de fechas ISO (`YYYY-MM-DD`). `to` es `null` mientras solo se ha elegido el inicio. */
|
|
2
|
+
export interface DateRange {
|
|
3
|
+
from: string | null;
|
|
4
|
+
to: string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare const DAY_MS = 86400000;
|
|
7
|
+
export declare const MONTH: RegExp;
|
|
8
|
+
export declare const pad: (n: number, width?: number) => string;
|
|
9
|
+
export declare const parse: (iso: string) => Date;
|
|
10
|
+
export declare const format: (date: Date) => string;
|
|
11
|
+
/** Verdadero si es una fecha ISO que existe (2026-02-30 no). */
|
|
12
|
+
export declare const valid: (iso: string | null | undefined) => iso is string;
|
|
13
|
+
export declare const addDays: (iso: string, days: number) => string;
|
|
14
|
+
export declare const monthOf: (iso: string) => string;
|
|
15
|
+
export declare const daysInMonth: (year: number, monthIndex: number) => number;
|
|
16
|
+
/** Suma meses conservando el día; si no existe (31 en un mes de 30), usa el último del mes. */
|
|
17
|
+
export declare function addMonths(iso: string, months: number): string;
|
|
18
|
+
/** Hoy en la zona horaria local, como fecha ISO. */
|
|
19
|
+
export declare function todayISO(): string;
|
|
20
|
+
/** El locale si el entorno lo admite; si no, `undefined` (el del entorno). */
|
|
21
|
+
export declare function safeLocale(locale: string | undefined): string | undefined;
|
|
22
|
+
/** Primer día de la semana según el locale (Intl.Locale.weekInfo), o lunes. 0 domingo … 6 sábado. */
|
|
23
|
+
export declare function localeWeekStart(locale?: string): number;
|
|
24
|
+
/** `desde/hasta` → rango; las fechas que no son válidas quedan en `null`. */
|
|
25
|
+
export declare function parseRange(raw: string | undefined | null): DateRange;
|
|
26
|
+
/** Rango → `desde/hasta` (el valor que envía un formulario); vacío sin inicio. */
|
|
27
|
+
export declare const rangeText: (range: DateRange | null | undefined) => string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Aritmética de fechas del calendario. Fechas ISO `YYYY-MM-DD`, cálculo en UTC para que el día no dependa de la
|
|
2
|
+
// zona horaria. Sin librerías.
|
|
3
|
+
export const DAY_MS = 86_400_000;
|
|
4
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
5
|
+
export const MONTH = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
6
|
+
export const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
7
|
+
/** Fecha UTC a medianoche. `Date.UTC` toma los años 0 a 99 como 1900 a 1999; `setUTCFullYear` no. */
|
|
8
|
+
function utc(year, monthIndex, day) {
|
|
9
|
+
const date = new Date(0);
|
|
10
|
+
date.setUTCFullYear(year, monthIndex, day);
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
export const parse = (iso) => utc(Number(iso.slice(0, 4)), Number(iso.slice(5, 7)) - 1, Number(iso.slice(8, 10)));
|
|
14
|
+
export const format = (date) => `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;
|
|
15
|
+
/** Verdadero si es una fecha ISO que existe (2026-02-30 no). */
|
|
16
|
+
export const valid = (iso) => typeof iso === "string" && ISO_DATE.test(iso) && format(parse(iso)) === iso;
|
|
17
|
+
export const addDays = (iso, days) => format(new Date(parse(iso).getTime() + days * DAY_MS));
|
|
18
|
+
export const monthOf = (iso) => iso.slice(0, 7);
|
|
19
|
+
export const daysInMonth = (year, monthIndex) => utc(year, monthIndex + 1, 0).getUTCDate();
|
|
20
|
+
/** Suma meses conservando el día; si no existe (31 en un mes de 30), usa el último del mes. */
|
|
21
|
+
export function addMonths(iso, months) {
|
|
22
|
+
const date = parse(iso);
|
|
23
|
+
const target = utc(date.getUTCFullYear(), date.getUTCMonth() + months, 1);
|
|
24
|
+
const day = Math.min(date.getUTCDate(), daysInMonth(target.getUTCFullYear(), target.getUTCMonth()));
|
|
25
|
+
return format(utc(target.getUTCFullYear(), target.getUTCMonth(), day));
|
|
26
|
+
}
|
|
27
|
+
/** Hoy en la zona horaria local, como fecha ISO. */
|
|
28
|
+
export function todayISO() {
|
|
29
|
+
const now = new Date();
|
|
30
|
+
return `${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
31
|
+
}
|
|
32
|
+
/** El locale si el entorno lo admite; si no, `undefined` (el del entorno). */
|
|
33
|
+
export function safeLocale(locale) {
|
|
34
|
+
try {
|
|
35
|
+
return locale ? Intl.DateTimeFormat.supportedLocalesOf(locale)[0] : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Primer día de la semana según el locale (Intl.Locale.weekInfo), o lunes. 0 domingo … 6 sábado. */
|
|
42
|
+
export function localeWeekStart(locale) {
|
|
43
|
+
try {
|
|
44
|
+
const resolved = new Intl.Locale(locale ?? new Intl.DateTimeFormat().resolvedOptions().locale);
|
|
45
|
+
const first = (resolved.getWeekInfo?.() ?? resolved.weekInfo)?.firstDay;
|
|
46
|
+
return typeof first === "number" ? first % 7 : 1;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** `desde/hasta` → rango; las fechas que no son válidas quedan en `null`. */
|
|
53
|
+
export function parseRange(raw) {
|
|
54
|
+
const [from, to] = (raw ?? "").split("/");
|
|
55
|
+
return { from: valid(from) ? from : null, to: valid(to) ? to : null };
|
|
56
|
+
}
|
|
57
|
+
/** Rango → `desde/hasta` (el valor que envía un formulario); vacío sin inicio. */
|
|
58
|
+
export const rangeText = (range) => (range?.from ? `${range.from}/${range.to ?? ""}` : "");
|
|
59
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/core/date.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,+BAA+B;AAQ/B,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC;AACjC,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,MAAM,CAAC,MAAM,KAAK,GAAG,yBAAyB,CAAC;AAE/C,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5E,qGAAqG;AACrG,SAAS,GAAG,CAAC,IAAY,EAAE,UAAkB,EAAE,GAAW;IACxD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,UA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eAAe,CAAC,MAAe;IAC7C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,CAG5F,CAAC;QACF,MAAM,KAAK,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACxE,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,GAA8B;IACvD,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACxE,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAmC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC","sourcesContent":["// Aritmética de fechas del calendario. Fechas ISO `YYYY-MM-DD`, cálculo en UTC para que el día no dependa de la\n// zona horaria. Sin librerías.\n\n/** Rango de fechas ISO (`YYYY-MM-DD`). `to` es `null` mientras solo se ha elegido el inicio. */\nexport interface DateRange {\n from: string | null;\n to: string | null;\n}\n\nexport const DAY_MS = 86_400_000;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\nexport const MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/;\n\nexport const pad = (n: number, width = 2) => String(n).padStart(width, \"0\");\n/** Fecha UTC a medianoche. `Date.UTC` toma los años 0 a 99 como 1900 a 1999; `setUTCFullYear` no. */\nfunction utc(year: number, monthIndex: number, day: number): Date {\n const date = new Date(0);\n date.setUTCFullYear(year, monthIndex, day);\n return date;\n}\nexport const parse = (iso: string) => utc(Number(iso.slice(0, 4)), Number(iso.slice(5, 7)) - 1, Number(iso.slice(8, 10)));\nexport const format = (date: Date) => `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;\n/** Verdadero si es una fecha ISO que existe (2026-02-30 no). */\nexport const valid = (iso: string | null | undefined): iso is string =>\n typeof iso === \"string\" && ISO_DATE.test(iso) && format(parse(iso)) === iso;\nexport const addDays = (iso: string, days: number) => format(new Date(parse(iso).getTime() + days * DAY_MS));\nexport const monthOf = (iso: string) => iso.slice(0, 7);\nexport const daysInMonth = (year: number, monthIndex: number) => utc(year, monthIndex + 1, 0).getUTCDate();\n\n/** Suma meses conservando el día; si no existe (31 en un mes de 30), usa el último del mes. */\nexport function addMonths(iso: string, months: number): string {\n const date = parse(iso);\n const target = utc(date.getUTCFullYear(), date.getUTCMonth() + months, 1);\n const day = Math.min(date.getUTCDate(), daysInMonth(target.getUTCFullYear(), target.getUTCMonth()));\n return format(utc(target.getUTCFullYear(), target.getUTCMonth(), day));\n}\n\n/** Hoy en la zona horaria local, como fecha ISO. */\nexport function todayISO(): string {\n const now = new Date();\n return `${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;\n}\n\n/** El locale si el entorno lo admite; si no, `undefined` (el del entorno). */\nexport function safeLocale(locale: string | undefined): string | undefined {\n try {\n return locale ? Intl.DateTimeFormat.supportedLocalesOf(locale)[0] : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Primer día de la semana según el locale (Intl.Locale.weekInfo), o lunes. 0 domingo … 6 sábado. */\nexport function localeWeekStart(locale?: string): number {\n try {\n const resolved = new Intl.Locale(locale ?? new Intl.DateTimeFormat().resolvedOptions().locale) as Intl.Locale & {\n getWeekInfo?: () => { firstDay?: number };\n weekInfo?: { firstDay?: number };\n };\n const first = (resolved.getWeekInfo?.() ?? resolved.weekInfo)?.firstDay;\n return typeof first === \"number\" ? first % 7 : 1;\n } catch {\n return 1;\n }\n}\n\n/** `desde/hasta` → rango; las fechas que no son válidas quedan en `null`. */\nexport function parseRange(raw: string | undefined | null): DateRange {\n const [from, to] = (raw ?? \"\").split(\"/\");\n return { from: valid(from) ? from : null, to: valid(to) ? to : null };\n}\n\n/** Rango → `desde/hasta` (el valor que envía un formulario); vacío sin inicio. */\nexport const rangeText = (range: DateRange | null | undefined) => (range?.from ? `${range.from}/${range.to ?? \"\"}` : \"\");\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Verdadero si el elemento se lee de derecha a izquierda. */
|
|
2
|
+
export declare const isRtl: (el: Element) => boolean;
|
|
3
|
+
/** Intercambia ArrowLeft y ArrowRight en RTL: la flecha que apunta hacia el final de la línea avanza. */
|
|
4
|
+
export declare function logicalKey(key: string, el: Element): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Dirección de lectura. Se lee del DOM (CSS `direction`), no de una prop: vale para React y para el modo DOM.
|
|
2
|
+
/** Verdadero si el elemento se lee de derecha a izquierda. */
|
|
3
|
+
export const isRtl = (el) => getComputedStyle(el).direction === "rtl";
|
|
4
|
+
/** Intercambia ArrowLeft y ArrowRight en RTL: la flecha que apunta hacia el final de la línea avanza. */
|
|
5
|
+
export function logicalKey(key, el) {
|
|
6
|
+
if ((key !== "ArrowLeft" && key !== "ArrowRight") || !isRtl(el))
|
|
7
|
+
return key;
|
|
8
|
+
return key === "ArrowLeft" ? "ArrowRight" : "ArrowLeft";
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir.js","sourceRoot":"","sources":["../../../src/core/dir.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAE9G,8DAA8D;AAC9D,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC;AAE/E,yGAAyG;AACzG,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,EAAW;IACjD,IAAI,CAAC,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAAE,OAAO,GAAG,CAAC;IAC5E,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;AAC1D,CAAC","sourcesContent":["// Dirección de lectura. Se lee del DOM (CSS `direction`), no de una prop: vale para React y para el modo DOM.\n\n/** Verdadero si el elemento se lee de derecha a izquierda. */\nexport const isRtl = (el: Element) => getComputedStyle(el).direction === \"rtl\";\n\n/** Intercambia ArrowLeft y ArrowRight en RTL: la flecha que apunta hacia el final de la línea avanza. */\nexport function logicalKey(key: string, el: Element): string {\n if ((key !== \"ArrowLeft\" && key !== \"ArrowRight\") || !isRtl(el)) return key;\n return key === \"ArrowLeft\" ? \"ArrowRight\" : \"ArrowLeft\";\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Elementos de `root` que reciben el foco con Tab, en orden del documento. */
|
|
2
|
+
export declare function tabbable(root: ParentNode): HTMLElement[];
|
|
3
|
+
/** Elemento con el foco, o null si está en `body` o no hay documento. */
|
|
4
|
+
export declare function activeElement(doc?: Document): HTMLElement | null;
|
|
5
|
+
/** Enfoca sin desplazar la página. Devuelve si el foco quedó en el elemento. */
|
|
6
|
+
export declare function focusQuiet(el: HTMLElement | null | undefined): boolean;
|
|
7
|
+
/** Lleva el foco dentro de `container`: `[autofocus]`, el primer tabulable o el propio contenedor. */
|
|
8
|
+
export declare function focusInto(container: HTMLElement): void;
|
|
9
|
+
/**
|
|
10
|
+
* Tab dentro de una capa no modal que retiene el foco: del último tabulable vuelve al primero y al revés.
|
|
11
|
+
* Devuelve true si movió el foco (el llamador hace `preventDefault`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function trapTab(container: HTMLElement, event: {
|
|
14
|
+
key: string;
|
|
15
|
+
shiftKey: boolean;
|
|
16
|
+
}): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Foco: elementos tabulables, entrada del foco en una capa, trampa de Tab y devolución al cerrar.
|
|
2
|
+
const TABBABLE = 'a[href], area[href], button, input:not([type="hidden"]), select, textarea, summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable="false"]), [tabindex]';
|
|
3
|
+
const visible = (el) => !el.closest("[hidden], [inert]") && (typeof el.checkVisibility === "function" ? el.checkVisibility() : el.getClientRects().length > 0);
|
|
4
|
+
/** Elementos de `root` que reciben el foco con Tab, en orden del documento. */
|
|
5
|
+
export function tabbable(root) {
|
|
6
|
+
return [...root.querySelectorAll(TABBABLE)].filter((el) => el.tabIndex >= 0 && !el.disabled && visible(el));
|
|
7
|
+
}
|
|
8
|
+
/** Elemento con el foco, o null si está en `body` o no hay documento. */
|
|
9
|
+
export function activeElement(doc = document) {
|
|
10
|
+
const active = doc.activeElement;
|
|
11
|
+
return active instanceof HTMLElement && active !== doc.body ? active : null;
|
|
12
|
+
}
|
|
13
|
+
/** Enfoca sin desplazar la página. Devuelve si el foco quedó en el elemento. */
|
|
14
|
+
export function focusQuiet(el) {
|
|
15
|
+
if (!el?.isConnected)
|
|
16
|
+
return false;
|
|
17
|
+
el.focus({ preventScroll: true });
|
|
18
|
+
return el.ownerDocument.activeElement === el;
|
|
19
|
+
}
|
|
20
|
+
/** Lleva el foco dentro de `container`: `[autofocus]`, el primer tabulable o el propio contenedor. */
|
|
21
|
+
export function focusInto(container) {
|
|
22
|
+
if (container.contains(container.ownerDocument.activeElement) && container.ownerDocument.activeElement !== container)
|
|
23
|
+
return;
|
|
24
|
+
const target = container.querySelector("[autofocus]") ?? tabbable(container)[0];
|
|
25
|
+
if (!focusQuiet(target)) {
|
|
26
|
+
if (!container.hasAttribute("tabindex"))
|
|
27
|
+
container.tabIndex = -1;
|
|
28
|
+
focusQuiet(container);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Tab dentro de una capa no modal que retiene el foco: del último tabulable vuelve al primero y al revés.
|
|
33
|
+
* Devuelve true si movió el foco (el llamador hace `preventDefault`).
|
|
34
|
+
*/
|
|
35
|
+
export function trapTab(container, event) {
|
|
36
|
+
if (event.key !== "Tab")
|
|
37
|
+
return false;
|
|
38
|
+
const list = tabbable(container);
|
|
39
|
+
const active = container.ownerDocument.activeElement;
|
|
40
|
+
if (!list.length)
|
|
41
|
+
return focusQuiet(container) || true;
|
|
42
|
+
const first = list[0];
|
|
43
|
+
const last = list[list.length - 1];
|
|
44
|
+
if (event.shiftKey && (active === first || active === container))
|
|
45
|
+
return focusQuiet(last) || true;
|
|
46
|
+
if (!event.shiftKey && active === last)
|
|
47
|
+
return focusQuiet(first) || true;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus.js","sourceRoot":"","sources":["../../../src/core/focus.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAElG,MAAM,QAAQ,GACZ,4LAA4L,CAAC;AAE/L,MAAM,OAAO,GAAG,CAAC,EAAe,EAAE,EAAE,CAClC,CAAC,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,eAAe,KAAK,UAAU,CAAC,CAA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,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QACjE,UAAU,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,SAAsB,EAAE,KAAyC;IACvF,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,SAAS,CAAC,aAAa,CAAC,aAAa,CAAC;IACrD,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;IACpC,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,SAAS,CAAC;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IAClG,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzE,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Foco: elementos tabulables, entrada del foco en una capa, trampa de Tab y devolución al cerrar.\n\nconst TABBABLE =\n 'a[href], area[href], button, input:not([type=\"hidden\"]), select, textarea, summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable=\"false\"]), [tabindex]';\n\nconst visible = (el: HTMLElement) =>\n !el.closest(\"[hidden], [inert]\") && (typeof el.checkVisibility === \"function\" ? el.checkVisibility() : el.getClientRects().length > 0);\n\n/** Elementos de `root` que reciben el foco con Tab, en orden del documento. */\nexport function tabbable(root: ParentNode): HTMLElement[] {\n return [...root.querySelectorAll<HTMLElement>(TABBABLE)].filter(\n (el) => el.tabIndex >= 0 && !(el as HTMLButtonElement).disabled && visible(el),\n );\n}\n\n/** Elemento con el foco, o null si está en `body` o no hay documento. */\nexport function activeElement(doc: Document = document): HTMLElement | null {\n const active = doc.activeElement;\n return active instanceof HTMLElement && active !== doc.body ? active : null;\n}\n\n/** Enfoca sin desplazar la página. Devuelve si el foco quedó en el elemento. */\nexport function focusQuiet(el: HTMLElement | null | undefined): boolean {\n if (!el?.isConnected) return false;\n el.focus({ preventScroll: true });\n return el.ownerDocument.activeElement === el;\n}\n\n/** Lleva el foco dentro de `container`: `[autofocus]`, el primer tabulable o el propio contenedor. */\nexport function focusInto(container: HTMLElement): void {\n if (container.contains(container.ownerDocument.activeElement) && container.ownerDocument.activeElement !== container) return;\n const target = container.querySelector<HTMLElement>(\"[autofocus]\") ?? tabbable(container)[0];\n if (!focusQuiet(target)) {\n if (!container.hasAttribute(\"tabindex\")) container.tabIndex = -1;\n focusQuiet(container);\n }\n}\n\n/**\n * Tab dentro de una capa no modal que retiene el foco: del último tabulable vuelve al primero y al revés.\n * Devuelve true si movió el foco (el llamador hace `preventDefault`).\n */\nexport function trapTab(container: HTMLElement, event: { key: string; shiftKey: boolean }): boolean {\n if (event.key !== \"Tab\") return false;\n const list = tabbable(container);\n const active = container.ownerDocument.activeElement;\n if (!list.length) return focusQuiet(container) || true;\n const first = list[0]!;\n const last = list[list.length - 1]!;\n if (event.shiftKey && (active === first || active === container)) return focusQuiet(last) || true;\n if (!event.shiftKey && active === last) return focusQuiet(first) || true;\n return false;\n}\n"]}
|