@sincpro/web-ui 2.15.0 → 2.17.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.
Files changed (40) hide show
  1. package/README.md +36 -1
  2. package/dist/components/index.d.ts +1 -0
  3. package/dist/components/index.js +1 -0
  4. package/dist/components/media/Carousel.d.ts +34 -0
  5. package/dist/components/media/Carousel.js +148 -0
  6. package/dist/components/media/OnScroll.d.ts +27 -0
  7. package/dist/components/media/OnScroll.js +18 -0
  8. package/dist/components/media/Ribbon.d.ts +39 -0
  9. package/dist/components/media/Ribbon.js +74 -0
  10. package/dist/components/media/Rise.d.ts +31 -0
  11. package/dist/components/media/Rise.js +27 -0
  12. package/dist/components/media/Stories.d.ts +71 -0
  13. package/dist/components/media/Stories.js +174 -0
  14. package/dist/components/media/index.d.ts +5 -0
  15. package/dist/components/media/index.js +9 -0
  16. package/dist/components/media/motion.d.ts +7 -0
  17. package/dist/components/media/motion.js +17 -0
  18. package/dist/components/navigation/PortalNav.d.ts +49 -0
  19. package/dist/components/navigation/PortalNav.js +40 -0
  20. package/dist/components/navigation/index.d.ts +1 -0
  21. package/dist/components/navigation/index.js +3 -0
  22. package/dist/components/preview/FilePreview.d.ts +5 -3
  23. package/dist/components/preview/FilePreview.js +39 -3
  24. package/dist/components/preview/index.d.ts +1 -1
  25. package/dist/components/preview/index.js +1 -1
  26. package/dist/components/preview/previewKind.d.ts +12 -2
  27. package/dist/components/preview/previewKind.js +44 -2
  28. package/dist/components/shell/Notifications.d.ts +64 -0
  29. package/dist/components/shell/Notifications.js +84 -0
  30. package/dist/components/shell/index.d.ts +1 -0
  31. package/dist/components/shell/index.js +3 -0
  32. package/dist/foundations/copy.es.js +35 -0
  33. package/dist/foundations/uiCopy.d.ts +58 -0
  34. package/dist/foundations/uiCopy.js +42 -1
  35. package/dist/primitives/choice/CheckField.d.ts +26 -0
  36. package/dist/primitives/choice/CheckField.js +45 -0
  37. package/dist/primitives/choice/index.d.ts +1 -0
  38. package/dist/primitives/choice/index.js +2 -0
  39. package/dist/tokens.css +182 -0
  40. package/package.json +1 -1
@@ -0,0 +1,174 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
4
+ import { SurfaceProvider } from "../../foundations/surface.js";
5
+ import { ButtonLink, IconButton } from "../../primitives/button/Button.js";
6
+ import { Avatar } from "../../primitives/value/Avatar.js";
7
+ import { formatRelative } from "../../primitives/value/format.js";
8
+ import { ChevronLeft, ChevronRight, ExternalLink, Pause, Play, X } from "lucide-react";
9
+ import { useEffect, useRef, useState } from "react";
10
+ import { Dialog, Modal, ModalOverlay } from "react-aria-components";
11
+ const IMAGE_MS = 5000;
12
+ /* A finger that travels this far down meant «close», not «next». */
13
+ const SWIPE_CLOSE = 80;
14
+ /* Pressed longer than this is «hold to pause», not a tap that moves. */
15
+ const HOLD_MS = 250;
16
+ /**
17
+ * A person's avatar with the ring that says there is something new.
18
+ *
19
+ * Context: unseen is not only a colour — the ring is thicker and the word is in the
20
+ * button's name («Ana, nuevo»), so it reads the same without colour vision.
21
+ */
22
+ export function StoryRing({ name, avatar, seen = false, onPress, showName = true, }) {
23
+ const copy = useUiCopy();
24
+ return (_jsxs("button", { type: "button", "data-ui": "story-ring", "data-seen": seen ? "" : undefined, onClick: onPress, ...(showName ? {} : { "aria-label": fillCopy(copy.stories.open, { name }) }), className: "group/ring flex w-16 shrink-0 flex-col items-center gap-1 rounded-control focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary", children: [_jsx("span", { "aria-hidden": true, className: `flex rounded-pill ${seen ? "bg-line-strong p-px" : "bg-linear-to-tr from-accent to-primary p-0.5"}`, children: _jsx("span", { className: "flex rounded-pill bg-canvas p-0.5", children: _jsx(Avatar, { name: name, size: "xl", ...(avatar === undefined ? {} : { src: avatar }) }) }) }), showName ? (_jsx("span", { className: `w-full truncate text-center text-micro ${seen ? "text-muted" : "font-medium text-ink"}`, children: name })) : null, _jsxs("span", { className: "sr-only", children: [", ", seen ? copy.stories.seen : copy.stories.unseen] })] }));
25
+ }
26
+ /** The row of rings, scrolling sideways — the top of a portal's home. */
27
+ export function StoryBar({ people, onOpen }) {
28
+ const copy = useUiCopy();
29
+ return (_jsx("ul", { "data-ui": "story-bar", "aria-label": copy.stories.label, className: "scroll-quiet flex gap-3 py-1", children: people.map((person, at) => (_jsx("li", { children: _jsx(StoryRing, { name: person.name, ...(person.avatar === undefined ? {} : { avatar: person.avatar }), seen: person.seen === true, onPress: () => onOpen(at) }) }, person.id))) }));
30
+ }
31
+ /**
32
+ * One person's stories at full screen, then the next person's.
33
+ *
34
+ * Context: the gestures of the apps people already know — a tap on the left half goes back,
35
+ * on the right goes on, holding pauses, a swipe down closes — and each one has a key and a
36
+ * button too: the arrows, Space, Escape, the ✕ and the pause button, so it is not a
37
+ * touchscreen-only toy. The progress is a segment per item; the time runs only while the
38
+ * item is really there (a video's own clock, an image's timer), and stops while paused or
39
+ * while the tab is hidden.
40
+ */
41
+ export function StoryViewer({ people, open, personIndex, onPersonChange, onClose, onSeen, now, }) {
42
+ const copy = useUiCopy();
43
+ const person = people[personIndex];
44
+ const items = person?.items ?? [];
45
+ const [index, setIndex] = useState(0);
46
+ const [paused, setPaused] = useState(false);
47
+ /* Held by a finger or the mouse: apart from `paused`, so releasing does not undo the button. */
48
+ const [held, setHeld] = useState(false);
49
+ const stopped = paused || held;
50
+ const [progress, setProgress] = useState(0);
51
+ const video = useRef(null);
52
+ const press = useRef(null);
53
+ const item = items[Math.min(index, items.length - 1)];
54
+ const isVideo = item?.type === "video";
55
+ /* A new person starts at their first item. */
56
+ useEffect(() => {
57
+ setIndex(0);
58
+ setProgress(0);
59
+ }, [personIndex]);
60
+ const next = () => {
61
+ setProgress(0);
62
+ if (index < items.length - 1)
63
+ setIndex(index + 1);
64
+ else if (personIndex < people.length - 1)
65
+ onPersonChange(personIndex + 1);
66
+ else
67
+ onClose();
68
+ };
69
+ const previous = () => {
70
+ setProgress(0);
71
+ if (index > 0)
72
+ setIndex(index - 1);
73
+ else if (personIndex > 0)
74
+ onPersonChange(personIndex - 1);
75
+ };
76
+ useEffect(() => {
77
+ if (open && person !== undefined && item !== undefined)
78
+ onSeen?.(person.id, item.id);
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- once per item shown
80
+ }, [open, person?.id, item?.id]);
81
+ /* An image's clock. A video keeps its own (`onTimeUpdate`). */
82
+ useEffect(() => {
83
+ if (!open || stopped || item === undefined || isVideo)
84
+ return;
85
+ const length = item.duration ?? IMAGE_MS;
86
+ let start = performance.now() - progress * length;
87
+ let frame = 0;
88
+ const tick = (time) => {
89
+ if (document.hidden)
90
+ start = time - progress * length;
91
+ const share = Math.min(1, (time - start) / length);
92
+ setProgress(share);
93
+ if (share >= 1)
94
+ next();
95
+ else
96
+ frame = requestAnimationFrame(tick);
97
+ };
98
+ frame = requestAnimationFrame(tick);
99
+ return () => cancelAnimationFrame(frame);
100
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- restarts per item and on pause
101
+ }, [open, stopped, item?.id, isVideo]);
102
+ useEffect(() => {
103
+ const player = video.current;
104
+ if (player === null)
105
+ return;
106
+ if (stopped)
107
+ player.pause();
108
+ else
109
+ void player.play().catch(() => undefined);
110
+ }, [stopped, item?.id]);
111
+ /* On the window: the focus starts ON the dialog, and a key pressed there never reaches a
112
+ handler inside it (as in `Lightbox`). */
113
+ useEffect(() => {
114
+ if (!open)
115
+ return;
116
+ const keys = (event) => {
117
+ if (event.key === "ArrowRight")
118
+ next();
119
+ else if (event.key === "ArrowLeft")
120
+ previous();
121
+ else if (event.key === " ")
122
+ setPaused((was) => !was);
123
+ else
124
+ return;
125
+ event.preventDefault();
126
+ };
127
+ window.addEventListener("keydown", keys);
128
+ return () => window.removeEventListener("keydown", keys);
129
+ });
130
+ const down = (event) => {
131
+ /* The side buttons move by themselves; their press is not also a tap on the halves. */
132
+ if (event.target instanceof Element && event.target.closest("button") !== null)
133
+ return;
134
+ const box = event.currentTarget.getBoundingClientRect();
135
+ press.current = {
136
+ x: event.clientX - box.left,
137
+ y: event.clientY,
138
+ at: Date.now(),
139
+ width: box.width,
140
+ };
141
+ setHeld(true);
142
+ };
143
+ const up = (event) => {
144
+ const start = press.current;
145
+ if (start === null)
146
+ return;
147
+ press.current = null;
148
+ setHeld(false);
149
+ if (event.clientY - start.y > SWIPE_CLOSE)
150
+ onClose();
151
+ else if (Date.now() - start.at < HOLD_MS) {
152
+ if (start.x < start.width / 3)
153
+ previous();
154
+ else
155
+ next();
156
+ }
157
+ };
158
+ return (_jsx(ModalOverlay, { isOpen: open && item !== undefined, onOpenChange: (shown) => {
159
+ if (!shown)
160
+ onClose();
161
+ }, isDismissable: true, className: "fixed inset-0 z-50 bg-scrim/95", children: _jsx(Modal, { className: "fixed inset-0 outline-0", children: _jsx(Dialog, { "data-ui": "story-viewer", "aria-label": fillCopy(copy.stories.viewer, { name: person?.name ?? "" }), className: "mx-auto flex size-full max-w-(--container-short) flex-col outline-0", children: _jsxs(SurfaceProvider, { value: "chrome", children: [_jsxs("div", { className: "flex shrink-0 flex-col gap-2 px-3 pt-3", children: [_jsx("div", { "data-ui": "story-viewer.progress", className: "flex gap-1", "aria-hidden": true, children: items.map((entry, at) => (_jsx("span", { className: "h-0.5 flex-1 overflow-hidden rounded-pill bg-chrome-ink/30", children: _jsx("span", { className: "block h-full bg-chrome-ink", style: {
162
+ width: `${String(at < index ? 100 : at === index ? progress * 100 : 0)}%`,
163
+ } }) }, entry.id))) }), _jsxs("div", { className: "flex items-center gap-2", children: [person === undefined ? null : (_jsx(Avatar, { name: person.name, size: "lg", ...(person.avatar === undefined ? {} : { src: person.avatar }) })), _jsxs("p", { className: "flex min-w-0 flex-1 items-baseline gap-2 text-meta text-chrome-ink", children: [_jsx("span", { className: "truncate font-semibold", children: person?.name }), item?.when === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro text-chrome-muted", children: formatRelative(new Date(item.when), now, copy) })), _jsx("span", { className: "sr-only", "aria-live": "polite", children: fillCopy(copy.stories.position, {
164
+ index: index + 1,
165
+ total: items.length,
166
+ }) })] }), _jsx(IconButton, { icon: paused ? Play : Pause, label: paused ? copy.stories.play : copy.stories.pause, size: "md", onClick: () => setPaused((was) => !was) }), _jsx(IconButton, { icon: X, label: copy.stories.close, size: "md", onClick: onClose })] })] }), _jsxs("div", { "data-ui": "story-viewer.media", onPointerDown: down, onPointerUp: up, onPointerCancel: () => {
167
+ press.current = null;
168
+ setHeld(false);
169
+ }, className: "relative flex min-h-0 flex-1 touch-none items-center justify-center px-3 py-3 select-none", children: [item === undefined ? null : isVideo ? (_jsx("video", { ref: video, src: item.src, "aria-label": item.alt, autoPlay: true, playsInline: true, muted: true, preload: "auto", onTimeUpdate: (event) => {
170
+ const player = event.currentTarget;
171
+ if (player.duration > 0)
172
+ setProgress(player.currentTime / player.duration);
173
+ }, onEnded: next, className: "max-h-full max-w-full rounded-control" }, item.id)) : (_jsx("img", { src: item.src, alt: item.alt, draggable: false, className: "max-h-full max-w-full rounded-control object-contain" }, item.id)), _jsx("span", { className: "absolute top-1/2 left-0 hidden -translate-y-1/2 sm:flex", children: _jsx(IconButton, { icon: ChevronLeft, label: copy.stories.previous, size: "lg", onClick: previous }) }), _jsx("span", { className: "absolute top-1/2 right-0 hidden -translate-y-1/2 sm:flex", children: _jsx(IconButton, { icon: ChevronRight, label: copy.stories.next, size: "lg", onClick: next }) })] }), item?.caption === undefined && item?.action === undefined ? null : (_jsxs("div", { className: "safe-bottom flex shrink-0 flex-col items-center gap-3 px-4 pb-5 text-center", children: [item?.caption === undefined ? null : (_jsx("p", { className: "text-meta text-chrome-ink", children: item.caption })), item?.action === undefined ? null : (_jsx(ButtonLink, { href: item.action.href, role: "primary", size: "md", icon: ExternalLink, children: item.action.label }))] }))] }) }) }) }));
174
+ }
@@ -0,0 +1,5 @@
1
+ export { Carousel, type CarouselPerView, type CarouselProps, } from "./Carousel.js";
2
+ export { DrawOnScroll, type DrawOnScrollProps, EnterOnScroll, type EnterOnScrollProps, } from "./OnScroll.js";
3
+ export { Ribbon, type RibbonProps } from "./Ribbon.js";
4
+ export { Appear, type AppearProps, Rise, type RiseProps, } from "./Rise.js";
5
+ export { StoryBar, type StoryBarProps, type StoryItem, type StoryPerson, StoryRing, type StoryRingProps, StoryViewer, type StoryViewerProps, } from "./Stories.js";
@@ -0,0 +1,9 @@
1
+ /* MEDIA AND SOCIAL — slides that turn (Carousel), a person's stories at full screen
2
+ (StoryRing, StoryBar, StoryViewer), and a site's motion: a headline that rises (Rise,
3
+ Appear), lines drawn by the scroll (DrawOnScroll, EnterOnScroll) and items that pass by
4
+ themselves (Ribbon). Data-agnostic: the application passes the content. */
5
+ export { Carousel, } from "./Carousel.js";
6
+ export { DrawOnScroll, EnterOnScroll, } from "./OnScroll.js";
7
+ export { Ribbon } from "./Ribbon.js";
8
+ export { Appear, Rise, } from "./Rise.js";
9
+ export { StoryBar, StoryRing, StoryViewer, } from "./Stories.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether the person asked the system for less motion.
3
+ *
4
+ * Context: the server cannot know, so it answers «yes» — nothing turns or plays by itself
5
+ * until the browser has said otherwise, and the first paint matches on both sides.
6
+ */
7
+ export declare function useReducedMotion(): boolean;
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { useSyncExternalStore } from "react";
3
+ const QUERY = "(prefers-reduced-motion: reduce)";
4
+ function subscribe(changed) {
5
+ const media = window.matchMedia(QUERY);
6
+ media.addEventListener("change", changed);
7
+ return () => media.removeEventListener("change", changed);
8
+ }
9
+ /**
10
+ * Whether the person asked the system for less motion.
11
+ *
12
+ * Context: the server cannot know, so it answers «yes» — nothing turns or plays by itself
13
+ * until the browser has said otherwise, and the first paint matches on both sides.
14
+ */
15
+ export function useReducedMotion() {
16
+ return useSyncExternalStore(subscribe, () => window.matchMedia(QUERY).matches, () => true);
17
+ }
@@ -0,0 +1,49 @@
1
+ import { type LucideIcon } from "lucide-react";
2
+ import { type ReactNode } from "react";
3
+ export type PortalNavItem = {
4
+ key: string;
5
+ label: string;
6
+ /** A real address: the menu works server-rendered, before and without JS. */
7
+ href: string;
8
+ icon?: LucideIcon;
9
+ /** How many are waiting there: «3» unpaid fees, «1» new message. Zero is not drawn. */
10
+ count?: number;
11
+ };
12
+ export type PortalNavSection = {
13
+ /** «Mi cuenta», «Comunidad». Absent for a first section without a heading. */
14
+ title?: string;
15
+ items: readonly PortalNavItem[];
16
+ };
17
+ export type PortalNavLink = {
18
+ href: string;
19
+ className: string;
20
+ "aria-current"?: "page";
21
+ children: ReactNode;
22
+ };
23
+ export type PortalNavProps = {
24
+ sections: readonly PortalNavSection[];
25
+ /** The `key` of the page the person is on. */
26
+ current?: string;
27
+ /** The person, at the top: their face, their name, a line under it («Socio 0412»). */
28
+ person?: {
29
+ name: string;
30
+ avatar?: string;
31
+ detail?: string;
32
+ };
33
+ /** What the menu is, said: «Mi portal». */
34
+ label?: string;
35
+ /** The application's own link (Next's `Link`), with the props it must pass on. */
36
+ renderLink?: (link: PortalNavLink) => ReactNode;
37
+ };
38
+ /**
39
+ * A portal's side menu, INSIDE a site's page: the person at the top, sections with their
40
+ * headings, items with icons and counts, the current one marked — and on a phone, folded
41
+ * into one button.
42
+ *
43
+ * Context: `Sidebar` is the whole chrome of a back office (full height, in `AppFrame`) and
44
+ * `NavigationTree` a tree of modules; neither sits in a public site's column. This one is
45
+ * plain links (`href`, `aria-current="page"`), so the server renders it whole and it works
46
+ * before hydration; the fold is the only thing that needs JS, and closed it hides only on a
47
+ * phone — from `md` up the menu is always there.
48
+ */
49
+ export declare function PortalNav({ sections, current, person, label, renderLink }: PortalNavProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useUiCopy } from "../../foundations/copy.js";
4
+ import { Count } from "../../primitives/tag/Count.js";
5
+ import { Avatar } from "../../primitives/value/Avatar.js";
6
+ import { ChevronDown } from "lucide-react";
7
+ import { useId, useState } from "react";
8
+ /**
9
+ * A portal's side menu, INSIDE a site's page: the person at the top, sections with their
10
+ * headings, items with icons and counts, the current one marked — and on a phone, folded
11
+ * into one button.
12
+ *
13
+ * Context: `Sidebar` is the whole chrome of a back office (full height, in `AppFrame`) and
14
+ * `NavigationTree` a tree of modules; neither sits in a public site's column. This one is
15
+ * plain links (`href`, `aria-current="page"`), so the server renders it whole and it works
16
+ * before hydration; the fold is the only thing that needs JS, and closed it hides only on a
17
+ * phone — from `md` up the menu is always there.
18
+ */
19
+ export function PortalNav({ sections, current, person, label, renderLink }) {
20
+ const copy = useUiCopy();
21
+ const [open, setOpen] = useState(false);
22
+ const listId = useId();
23
+ const name = label ?? copy.portalNav.label;
24
+ const currentLabel = sections
25
+ .flatMap((section) => section.items)
26
+ .find((item) => item.key === current)?.label;
27
+ const link = (item) => {
28
+ const here = item.key === current;
29
+ const Icon = item.icon;
30
+ const children = (_jsxs(_Fragment, { children: [Icon === undefined ? null : (_jsx(Icon, { "aria-hidden": true, strokeWidth: 2, className: "size-(--size-icon-md) shrink-0" })), _jsx("span", { className: "min-w-0 flex-1 truncate", children: item.label }), item.count === undefined || item.count <= 0 ? null : _jsx(Count, { value: item.count })] }));
31
+ const props = {
32
+ href: item.href,
33
+ className: `flex min-h-(--size-control-md) items-center gap-2.5 rounded-control px-2.5 text-meta no-underline transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-primary ${here ? "bg-primary/8 font-semibold text-primary" : "text-ink hover:bg-ink/4"}`,
34
+ ...(here ? { "aria-current": "page" } : {}),
35
+ children,
36
+ };
37
+ return renderLink === undefined ? _jsx("a", { ...props }) : renderLink(props);
38
+ };
39
+ return (_jsxs("nav", { "data-ui": "portal-nav", "aria-label": name, className: "flex min-w-0 flex-col gap-2", children: [person === undefined ? null : (_jsxs("div", { "data-ui": "portal-nav.person", className: "flex min-w-0 items-center gap-3 px-2.5 py-2", children: [_jsx(Avatar, { name: person.name, size: "xl", ...(person.avatar === undefined ? {} : { src: person.avatar }) }), _jsxs("div", { className: "flex min-w-0 flex-col", children: [_jsx("span", { className: "truncate text-body font-semibold text-ink", children: person.name }), person.detail === undefined ? null : (_jsx("span", { className: "truncate text-micro text-muted", children: person.detail }))] })] })), _jsxs("button", { type: "button", "data-ui": "portal-nav.toggle", "aria-expanded": open, "aria-controls": listId, onClick: () => setOpen((was) => !was), className: "flex min-h-(--size-control-md) items-center justify-between gap-2 rounded-control border border-line px-3 text-meta font-medium text-ink focus-visible:outline-2 focus-visible:outline-primary md:hidden", children: [_jsx("span", { className: "truncate", children: currentLabel ?? name }), _jsx(ChevronDown, { "aria-hidden": true, className: `size-(--size-icon-md) shrink-0 transition-transform duration-(--duration-quick) ${open ? "rotate-180" : ""}` })] }), _jsx("div", { id: listId, "data-ui": "portal-nav.sections", className: `flex-col gap-4 md:flex ${open ? "flex" : "hidden"}`, children: sections.map((section, at) => (_jsxs("div", { className: "flex flex-col gap-0.5", children: [section.title === undefined ? null : (_jsx("h2", { className: "px-2.5 pb-1 text-micro font-semibold text-muted uppercase", children: section.title })), _jsx("ul", { className: "flex flex-col gap-0.5", children: section.items.map((item) => (_jsx("li", { children: link(item) }, item.key))) })] }, section.title ?? at))) })] }));
40
+ }
@@ -1 +1,2 @@
1
1
  export { NavigationTree, type NavItem, } from "./NavigationTree.js";
2
+ export { PortalNav, type PortalNavItem, type PortalNavLink, type PortalNavProps, type PortalNavSection, } from "./PortalNav.js";
@@ -1,3 +1,6 @@
1
1
  /* NAVIGATION — an application's side tree. The command palette (⌘K) belongs to the
2
2
  workspace (composer), not here. */
3
3
  export { NavigationTree, } from "./NavigationTree.js";
4
+ /* A portal's side menu inside a site's page: the person, sections, counts, real links, and
5
+ one button on a phone. */
6
+ export { PortalNav, } from "./PortalNav.js";
@@ -1,6 +1,6 @@
1
- import { type PreviewKind, previewKind } from "./previewKind.js";
2
- export type { PreviewKind };
3
- export { previewKind };
1
+ import { type OfficeKind, officeKind, type PreviewKind, previewKind } from "./previewKind.js";
2
+ export type { OfficeKind, PreviewKind };
3
+ export { officeKind, previewKind };
4
4
  export type PreviewFile = {
5
5
  /** The file name as saved: it picks the kind together with `type`. */
6
6
  name: string;
@@ -10,6 +10,8 @@ export type PreviewFile = {
10
10
  type?: string;
11
11
  /** In bytes. Written for the locale in the header. */
12
12
  size?: number;
13
+ /** A video's still, shown before it plays — the server's thumbnail. */
14
+ poster?: string;
13
15
  };
14
16
  export type FilePreviewProps = {
15
17
  file: PreviewFile;
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { formatFileSize } from "../attachments/files.js";
4
- import { previewKind, } from "./previewKind.js";
4
+ import { officeKind, previewKind, } from "./previewKind.js";
5
5
  import { useUiCopy } from "../../foundations/copy.js";
6
6
  import { Button, ButtonLink } from "../../primitives/button/Button.js";
7
7
  import { Empty, Failed, Skeleton } from "../../primitives/notice/Notice.js";
8
- import { Download } from "lucide-react";
8
+ import { Download, ExternalLink, FileSpreadsheet, FileText, Presentation, } from "lucide-react";
9
9
  import { lazy, Suspense, useEffect, useState } from "react";
10
10
  /* ==================================================================== *
11
11
  * FILE PREVIEW — the file itself, drawn by what it is.
@@ -22,6 +22,10 @@ import { lazy, Suspense, useEffect, useState } from "react";
22
22
  * pdf pdf.js, loaded on demand (PdfPreview)
23
23
  * markdown streamdown, sanitized (Markdown)
24
24
  * text the text in mono, up to a limit (a log can be gigabytes)
25
+ * video the browser's own <video>, its controls, a poster if any
26
+ * audio the browser's own <audio>, its controls
27
+ * office a card with the icon of its family and «Abrir» — Word,
28
+ * Excel and PowerPoint are drawn honestly only by their program
25
29
  * other the icon's name and the download — no preview pretended
26
30
  *
27
31
  * ── The download is always there ────────────────────────────────────
@@ -36,7 +40,7 @@ const PdfPreview = lazy(() => import("./PdfPreview.js"));
36
40
  const MarkdownView = lazy(() => import("../../primitives/value/Markdown.js").then((m) => ({ default: m.Markdown })));
37
41
  /** A text preview larger than this is not read into the tab: download instead. */
38
42
  const MAX_TEXT_BYTES = 1_000_000;
39
- export { previewKind };
43
+ export { officeKind, previewKind };
40
44
  export function FilePreview({ file, pdfWorkerUrl }) {
41
45
  const copy = useUiCopy();
42
46
  const kind = previewKind(file.name, file.type);
@@ -52,8 +56,40 @@ function Body({ kind, file, pdfWorkerUrl, }) {
52
56
  }
53
57
  if (kind === "markdown" || kind === "text")
54
58
  return _jsx(TextPreview, { kind: kind, file: file });
59
+ if (kind === "video")
60
+ return _jsx(VideoPreview, { file: file });
61
+ if (kind === "audio")
62
+ return _jsx(AudioPreview, { file: file });
63
+ if (kind === "office")
64
+ return _jsx(OfficeCard, { file: file });
55
65
  return _jsx(Unsupported, {});
56
66
  }
67
+ /* The browser's own players: their controls are keyboard- and screen-reader-ready in every
68
+ engine, and a hand-made bar would be one more thing to get wrong. `preload="metadata"`: the
69
+ length and the first frame, not the whole file, until the person presses play. */
70
+ function VideoPreview({ file }) {
71
+ const copy = useUiCopy();
72
+ return (_jsx("video", { "data-ui": "file-preview.video", src: file.url, poster: file.poster, controls: true, playsInline: true, preload: "metadata", "aria-label": file.name, className: "max-h-full max-w-full rounded-control bg-scrim/95", children: copy.preview.unsupported }));
73
+ }
74
+ function AudioPreview({ file }) {
75
+ const copy = useUiCopy();
76
+ return (_jsx("div", { className: "flex w-full max-w-(--container-prose) items-center self-center", children: _jsx("audio", { "data-ui": "file-preview.audio", src: file.url, controls: true, preload: "metadata", "aria-label": file.name, className: "w-full", children: copy.preview.unsupported }) }));
77
+ }
78
+ const OFFICE_ICON = {
79
+ doc: FileText,
80
+ sheet: FileSpreadsheet,
81
+ slides: Presentation,
82
+ };
83
+ /* An Office file has no honest drawing in a browser: a converted copy loses its formulas,
84
+ its page breaks, its fonts. The card says WHICH program it is for — an icon and a word,
85
+ never only a colour — and opens it in a tab of its own, where the browser hands it to its
86
+ program or keeps it; the download stays in the header, once. */
87
+ function OfficeCard({ file }) {
88
+ const copy = useUiCopy();
89
+ const family = officeKind(file.name, file.type) ?? "doc";
90
+ const Icon = OFFICE_ICON[family];
91
+ return (_jsxs("div", { "data-ui": "file-preview.office", "data-kind": family, className: "flex max-w-(--container-short) flex-col items-center gap-3 self-center text-center", children: [_jsx("span", { className: "flex size-16 items-center justify-center rounded-ui-card bg-surface text-primary shadow-raised", children: _jsx(Icon, { "aria-hidden": true, className: "size-8", strokeWidth: 1.5 }) }), _jsx("p", { className: "text-body font-medium text-ink", children: copy.preview.office[family] }), _jsx("p", { className: "text-meta text-muted", children: copy.preview.officeSentence }), _jsx(ButtonLink, { href: file.url, target: "_blank", rel: "noopener noreferrer", role: "secondary", size: "sm", icon: ExternalLink, children: copy.preview.open })] }));
92
+ }
57
93
  function ImagePreview({ file }) {
58
94
  const copy = useUiCopy();
59
95
  const [actual, setActual] = useState(false);
@@ -1,2 +1,2 @@
1
1
  export { FilePreview, type FilePreviewProps, type PreviewFile, } from "./FilePreview.js";
2
- export { type PreviewKind, previewKind, } from "./previewKind.js";
2
+ export { type OfficeKind, officeKind, type PreviewKind, previewKind, } from "./previewKind.js";
@@ -1,3 +1,3 @@
1
1
  /* PREVIEW — the file itself, drawn by what it is: an image, a PDF, markdown or text. */
2
2
  export { FilePreview, } from "./FilePreview.js";
3
- export { previewKind, } from "./previewKind.js";
3
+ export { officeKind, previewKind, } from "./previewKind.js";
@@ -1,3 +1,13 @@
1
- export type PreviewKind = "image" | "pdf" | "markdown" | "text" | "other";
2
- /** The renderer for a file. Pure, so the choice is tested without a browser. */
1
+ /** The three Office families a preview names apart — the icon and the word say which. */
2
+ export type OfficeKind = "doc" | "sheet" | "slides";
3
+ /**
4
+ * The renderer for a file. Pure, so the choice is tested without a browser.
5
+ *
6
+ * Context: `video` and `audio` are the browser's own players (`<video>`, `<audio>`, their
7
+ * controls), and `office` is a document only its program draws honestly — a card that says
8
+ * which one it is and opens or downloads it. A CSV stays `text`: it is read, not opened.
9
+ */
10
+ export type PreviewKind = "image" | "pdf" | "markdown" | "text" | "video" | "audio" | "office" | "other";
11
+ /** Which Office family a file is — `undefined` when it is none. */
12
+ export declare function officeKind(name: string, type?: string): OfficeKind | undefined;
3
13
  export declare function previewKind(name: string, type?: string): PreviewKind;
@@ -3,15 +3,57 @@ import { attachmentKind, fileExtension } from "../attachments/files.js";
3
3
  viewer to do it): a server component that decides how a file will be shown reads this. */
4
4
  const TEXT_EXTENSIONS = new Set(["txt", "csv", "json", "log", "xml", "yaml", "yml"]);
5
5
  const MARKDOWN_EXTENSIONS = new Set(["md", "markdown"]);
6
- /** The renderer for a file. Pure, so the choice is tested without a browser. */
6
+ /* What a browser plays with its own element. `ogg` is audio unless the server says video. */
7
+ const VIDEO_EXTENSIONS = new Set(["mp4", "m4v", "webm", "ogv", "mov"]);
8
+ const AUDIO_EXTENSIONS = new Set(["mp3", "m4a", "aac", "wav", "oga", "ogg", "opus", "flac"]);
9
+ const OFFICE_EXTENSIONS = {
10
+ doc: "doc",
11
+ docx: "doc",
12
+ odt: "doc",
13
+ rtf: "doc",
14
+ xls: "sheet",
15
+ xlsx: "sheet",
16
+ xlsm: "sheet",
17
+ ods: "sheet",
18
+ ppt: "slides",
19
+ pptx: "slides",
20
+ pps: "slides",
21
+ ppsx: "slides",
22
+ odp: "slides",
23
+ };
24
+ /** Which Office family a file is — `undefined` when it is none. */
25
+ export function officeKind(name, type) {
26
+ const mime = (type ?? "").toLowerCase();
27
+ if (mime.includes("presentation") || mime.includes("ms-powerpoint"))
28
+ return "slides";
29
+ if (mime.includes("spreadsheet") || mime.includes("ms-excel"))
30
+ return "sheet";
31
+ if (mime.includes("wordprocessing") ||
32
+ mime.includes("msword") ||
33
+ mime.includes("opendocument.text")) {
34
+ return "doc";
35
+ }
36
+ return OFFICE_EXTENSIONS[fileExtension(name)];
37
+ }
7
38
  export function previewKind(name, type) {
8
39
  const kind = attachmentKind(name, type);
9
40
  if (kind === "image" || kind === "pdf")
10
41
  return kind;
42
+ const mime = (type ?? "").toLowerCase();
11
43
  const extension = fileExtension(name).toLowerCase();
44
+ if (mime.startsWith("video/"))
45
+ return "video";
46
+ if (mime.startsWith("audio/"))
47
+ return "audio";
12
48
  if (MARKDOWN_EXTENSIONS.has(extension))
13
49
  return "markdown";
14
- if (TEXT_EXTENSIONS.has(extension) || type?.startsWith("text/") === true)
50
+ if (TEXT_EXTENSIONS.has(extension) || mime.startsWith("text/"))
15
51
  return "text";
52
+ if (VIDEO_EXTENSIONS.has(extension))
53
+ return "video";
54
+ if (AUDIO_EXTENSIONS.has(extension))
55
+ return "audio";
56
+ if (officeKind(name, type) !== undefined)
57
+ return "office";
16
58
  return "other";
17
59
  }
@@ -0,0 +1,64 @@
1
+ import type { InboxItem } from "./Inbox.js";
2
+ import { type LucideIcon } from "lucide-react";
3
+ import { type ReactNode } from "react";
4
+ /** A notification: an `InboxItem`, with who it is from and one thing to do about it. */
5
+ export type NotificationItem = InboxItem & {
6
+ /** Who did it — a person's face reads faster than an icon. Wins over `icon`. */
7
+ avatar?: {
8
+ name: string;
9
+ src?: string;
10
+ };
11
+ /** One action of its own: «Responder», «Ver el pago». */
12
+ action?: {
13
+ label: string;
14
+ onPress: () => void;
15
+ };
16
+ };
17
+ export type NotificationBellProps = {
18
+ unread?: number;
19
+ /** «Notificaciones» by default. */
20
+ label?: string;
21
+ icon?: LucideIcon;
22
+ /** Without a panel it is a plain button (a link to the notifications page, say). */
23
+ onPress?: () => void;
24
+ /** The panel it opens in a popover. A function gets `close`, for an item that navigates. */
25
+ children?: ReactNode | ((close: () => void) => ReactNode);
26
+ /** Opened, when the application holds it. */
27
+ open?: boolean;
28
+ onOpenChange?: (open: boolean) => void;
29
+ };
30
+ /**
31
+ * The bell with the unread count, for any header — a public site's, a portal's, not only the
32
+ * ERP's dark bar (that one is `Inbox`).
33
+ *
34
+ * Context: zero is not drawn, past 99 it says «99+», and the number is in the button's name
35
+ * (the badge is only seen), the way `SystrayButton` does it; this one is drawn on the paper's
36
+ * ink, so it sits in a white header.
37
+ */
38
+ export declare function NotificationBell({ unread, label, icon: Icon, onPress, children, open: openProp, onOpenChange, }: NotificationBellProps): import("react").JSX.Element;
39
+ export type NotificationPanelProps = {
40
+ /** Newest first, as the application sorts them. */
41
+ items: readonly NotificationItem[];
42
+ /** Pressing one: the application opens what it is about. */
43
+ onOpen?: (id: string) => void;
44
+ /** An unread one was opened: the application marks it read. */
45
+ onRead?: (id: string) => void;
46
+ /** «Marcar todo como leído» — drawn while something is unread. */
47
+ onReadAll?: () => void;
48
+ /** «Ver más» — the next page, or the whole history. */
49
+ onMore?: () => void;
50
+ /** «Notificaciones» by default. */
51
+ title?: string;
52
+ /** The clock «Hoy» and the times are read against; now by default. */
53
+ now?: Date;
54
+ };
55
+ /**
56
+ * The notification centre: grouped by «Hoy» and «Antes», a face or an icon, the unread dot,
57
+ * one action per item, «Marcar todo como leído», «Ver más» and the empty state.
58
+ *
59
+ * Context: controlled — it fetches nothing; the application passes the page it has and is
60
+ * told what was opened, read or asked for. Unread is not only a colour: the dot goes with the
61
+ * title in bold and the word said (as `InboxList`). An item's action is a button BESIDE the
62
+ * item, never inside it: one press, one meaning.
63
+ */
64
+ export declare function NotificationPanel({ items, onOpen, onRead, onReadAll, onMore, title, now, }: NotificationPanelProps): import("react").JSX.Element;