@sincpro/web-ui 2.14.2 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -4
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/media/Carousel.d.ts +34 -0
- package/dist/components/media/Carousel.js +148 -0
- package/dist/components/media/Stories.d.ts +71 -0
- package/dist/components/media/Stories.js +174 -0
- package/dist/components/media/index.d.ts +2 -0
- package/dist/components/media/index.js +4 -0
- package/dist/components/media/motion.d.ts +7 -0
- package/dist/components/media/motion.js +17 -0
- package/dist/components/navigation/PortalNav.d.ts +49 -0
- package/dist/components/navigation/PortalNav.js +40 -0
- package/dist/components/navigation/index.d.ts +1 -0
- package/dist/components/navigation/index.js +3 -0
- package/dist/components/preview/FilePreview.d.ts +5 -3
- package/dist/components/preview/FilePreview.js +39 -3
- package/dist/components/preview/index.d.ts +1 -1
- package/dist/components/preview/index.js +1 -1
- package/dist/components/preview/previewKind.d.ts +12 -2
- package/dist/components/preview/previewKind.js +44 -2
- package/dist/components/shell/Notifications.d.ts +64 -0
- package/dist/components/shell/Notifications.js +84 -0
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/copy.es.js +39 -0
- package/dist/foundations/uiCopy.d.ts +67 -0
- package/dist/foundations/uiCopy.js +46 -1
- package/dist/primitives/choice/CheckField.d.ts +26 -0
- package/dist/primitives/choice/CheckField.js +45 -0
- package/dist/primitives/choice/index.d.ts +1 -0
- package/dist/primitives/choice/index.js +2 -0
- package/dist/primitives/field/RichTextEditor.d.ts +13 -1
- package/dist/primitives/field/RichTextEditor.js +152 -8
- package/dist/primitives/field/RichTextInput.d.ts +14 -3
- package/dist/primitives/field/RichTextInput.js +9 -3
- package/dist/primitives/field/index.d.ts +1 -1
- package/dist/primitives/value/RichText.d.ts +15 -3
- package/dist/primitives/value/RichText.js +26 -73
- package/dist/primitives/value/index.d.ts +1 -0
- package/dist/primitives/value/index.js +2 -0
- package/dist/primitives/value/richTextPlain.d.ts +1 -1
- package/dist/primitives/value/richTextPlain.js +2 -2
- package/dist/primitives/value/richTextPolicy.d.ts +39 -0
- package/dist/primitives/value/richTextPolicy.js +195 -0
- package/dist/tokens.css +22 -0
- package/package.json +2 -1
|
@@ -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,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,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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) ||
|
|
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;
|
|
@@ -0,0 +1,84 @@
|
|
|
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 { Button } from "../../primitives/button/Button.js";
|
|
6
|
+
import { Empty } from "../../primitives/notice/Notice.js";
|
|
7
|
+
import { NOTICE_ICON } from "../../primitives/notice/tones.js";
|
|
8
|
+
import { Popover } from "../../primitives/overlay/Popover.js";
|
|
9
|
+
import { Count, countText } from "../../primitives/tag/Count.js";
|
|
10
|
+
import { Avatar } from "../../primitives/value/Avatar.js";
|
|
11
|
+
import { formatRelative } from "../../primitives/value/format.js";
|
|
12
|
+
import { Bell } from "lucide-react";
|
|
13
|
+
import { useMemo, useState } from "react";
|
|
14
|
+
import { Dialog, DialogTrigger, Heading, Pressable } from "react-aria-components";
|
|
15
|
+
/* A badge over an icon is read in a glance: past two digits it says «a lot» (as the systray). */
|
|
16
|
+
const BELL_MAX = 99;
|
|
17
|
+
/**
|
|
18
|
+
* The bell with the unread count, for any header — a public site's, a portal's, not only the
|
|
19
|
+
* ERP's dark bar (that one is `Inbox`).
|
|
20
|
+
*
|
|
21
|
+
* Context: zero is not drawn, past 99 it says «99+», and the number is in the button's name
|
|
22
|
+
* (the badge is only seen), the way `SystrayButton` does it; this one is drawn on the paper's
|
|
23
|
+
* ink, so it sits in a white header.
|
|
24
|
+
*/
|
|
25
|
+
export function NotificationBell({ unread = 0, label, icon: Icon = Bell, onPress, children, open: openProp, onOpenChange, }) {
|
|
26
|
+
const copy = useUiCopy();
|
|
27
|
+
const number = useMemo(() => new Intl.NumberFormat(copy.locale), [copy.locale]);
|
|
28
|
+
const [own, setOwn] = useState(false);
|
|
29
|
+
const open = openProp ?? own;
|
|
30
|
+
const setOpen = (next) => {
|
|
31
|
+
if (openProp === undefined)
|
|
32
|
+
setOwn(next);
|
|
33
|
+
onOpenChange?.(next);
|
|
34
|
+
};
|
|
35
|
+
const name = label ?? copy.inbox.label;
|
|
36
|
+
const said = countText(unread, number.format, BELL_MAX);
|
|
37
|
+
const button = (_jsxs("button", { type: "button", "data-ui": "notification-bell", onClick: children === undefined ? onPress : undefined, "aria-label": unread > 0 ? `${name}: ${said}` : name, title: name, className: `relative inline-flex size-(--size-control-md) items-center justify-center rounded-pill text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${open ? "bg-ink/6 text-ink" : ""}`, ...(children === undefined
|
|
38
|
+
? {}
|
|
39
|
+
: { "aria-haspopup": "dialog", "aria-expanded": open }), children: [_jsx(Icon, { "aria-hidden": true, className: "size-(--size-icon-md)", strokeWidth: 2 }), unread <= 0 ? null : (_jsx("span", { className: "absolute -top-0.5 -right-0.5 flex", children: _jsx(Count, { value: unread, tone: "bad", solid: true, max: BELL_MAX, "aria-hidden": true }) }))] }));
|
|
40
|
+
if (children === undefined)
|
|
41
|
+
return button;
|
|
42
|
+
return (_jsxs(DialogTrigger, { isOpen: open, onOpenChange: setOpen, children: [_jsx(Pressable, { children: button }), _jsx(Popover, { placement: "bottom end", children: _jsx(Dialog, { "aria-label": name, className: "max-h-[inherit] w-(--container-inbox) overflow-auto outline-0", children: _jsx(SurfaceProvider, { value: "canvas", children: typeof children === "function" ? children(() => setOpen(false)) : children }) }) })] }));
|
|
43
|
+
}
|
|
44
|
+
const ICON_TONE = {
|
|
45
|
+
info: "text-info",
|
|
46
|
+
good: "text-good",
|
|
47
|
+
warn: "text-warn",
|
|
48
|
+
bad: "text-bad",
|
|
49
|
+
};
|
|
50
|
+
function sameDay(a, b) {
|
|
51
|
+
return (a.getFullYear() === b.getFullYear() &&
|
|
52
|
+
a.getMonth() === b.getMonth() &&
|
|
53
|
+
a.getDate() === b.getDate());
|
|
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 function NotificationPanel({ items, onOpen, onRead, onReadAll, onMore, title, now, }) {
|
|
65
|
+
const copy = useUiCopy();
|
|
66
|
+
const clock = now ?? new Date();
|
|
67
|
+
const unread = items.filter((item) => item.unread === true).length;
|
|
68
|
+
const today = items.filter((item) => sameDay(new Date(item.when), clock));
|
|
69
|
+
const before = items.filter((item) => !sameDay(new Date(item.when), clock));
|
|
70
|
+
const groups = [
|
|
71
|
+
{ key: "today", label: copy.notifications.today, items: today },
|
|
72
|
+
{ key: "before", label: copy.notifications.before, items: before },
|
|
73
|
+
].filter((group) => group.items.length > 0);
|
|
74
|
+
const row = (item) => {
|
|
75
|
+
const fresh = item.unread === true;
|
|
76
|
+
const Icon = item.icon ?? (item.tone === undefined ? undefined : NOTICE_ICON[item.tone]);
|
|
77
|
+
return (_jsxs("li", { className: `flex items-start ${fresh ? "bg-primary/4" : ""}`, children: [_jsxs("button", { type: "button", "data-ui": "notification-panel.item", "data-unread": fresh ? "" : undefined, onClick: () => {
|
|
78
|
+
if (fresh)
|
|
79
|
+
onRead?.(item.id);
|
|
80
|
+
onOpen?.(item.id);
|
|
81
|
+
}, className: "flex min-w-0 flex-1 items-start gap-3 px-3 py-2.5 text-left transition-colors duration-(--duration-instant) hover:bg-ink/4 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary", children: [item.avatar !== undefined ? (_jsx(Avatar, { name: item.avatar.name, size: "lg", ...(item.avatar.src === undefined ? {} : { src: item.avatar.src }) })) : Icon === undefined ? null : (_jsx(Icon, { "aria-hidden": true, strokeWidth: 2, className: `mt-0.5 size-(--size-icon-md) shrink-0 ${item.tone === undefined ? "text-muted" : ICON_TONE[item.tone]}` })), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsxs("span", { className: `text-meta text-ink ${fresh ? "font-semibold" : "font-normal"}`, children: [fresh ? _jsxs("span", { className: "sr-only", children: [copy.inbox.unread, ": "] }) : null, item.title] }), item.detail === undefined ? null : (_jsx("span", { className: "line-clamp-2 text-meta text-muted", children: item.detail })), _jsx("span", { className: "text-micro text-muted tabular-nums", children: formatRelative(new Date(item.when), now, copy) })] }), fresh ? (_jsx("span", { "aria-hidden": true, className: "mt-1.5 size-2 shrink-0 rounded-pill bg-primary" })) : null] }), item.action === undefined ? null : (_jsx("span", { className: "shrink-0 py-2 pr-2", children: _jsx(Button, { role: "secondary", size: "sm", onClick: item.action.onPress, children: item.action.label }) }))] }, item.id));
|
|
82
|
+
};
|
|
83
|
+
return (_jsxs("div", { "data-ui": "notification-panel", className: "flex min-w-0 flex-col", children: [_jsxs("div", { className: "flex items-center justify-between gap-3 border-b border-line px-3 py-2", children: [_jsxs(Heading, { level: 2, className: "text-meta font-semibold text-ink", children: [title ?? copy.inbox.label, unread === 0 ? null : (_jsx("span", { className: "ml-1.5 font-normal text-muted tabular-nums", children: fillCopy(copy.inbox.unreadCount, { count: unread }) }))] }), onReadAll === undefined || unread === 0 ? null : (_jsx(Button, { role: "ghost", size: "sm", onClick: onReadAll, children: copy.inbox.markAllRead }))] }), items.length === 0 ? (_jsx(Empty, { sentence: copy.inbox.empty })) : (groups.map((group) => (_jsxs("section", { "aria-label": group.label, "data-ui": "notification-panel.group", children: [_jsx("h3", { className: "px-3 pt-3 pb-1 text-micro font-semibold text-muted uppercase", children: group.label }), _jsx("ul", { className: "flex flex-col divide-y divide-line", children: group.items.map(row) })] }, group.key)))), onMore === undefined || items.length === 0 ? null : (_jsx("div", { className: "border-t border-line px-1 py-1", children: _jsx(Button, { role: "ghost", size: "sm", onClick: onMore, children: copy.notifications.more }) }))] }));
|
|
84
|
+
}
|
|
@@ -5,5 +5,6 @@ export { SearchEntry, type SearchEntryProps, } from "./SearchEntry.js";
|
|
|
5
5
|
export { type SidebarDrawer, SidebarToggle, useSidebarDrawer, } from "./sidebarDrawer.js";
|
|
6
6
|
export { type AppEntry, SystrayButton, TopBar, type TopMenu, } from "./TopBar.js";
|
|
7
7
|
export { Inbox, type InboxItem, InboxList, type InboxListProps, type InboxProps, } from "./Inbox.js";
|
|
8
|
+
export { NotificationBell, type NotificationBellProps, type NotificationItem, NotificationPanel, type NotificationPanelProps, } from "./Notifications.js";
|
|
8
9
|
export { KioskFrame, type KioskFrameProps, } from "./KioskFrame.js";
|
|
9
10
|
export { Pane, Panes } from "./Panes.js";
|
|
@@ -13,6 +13,9 @@ export { SystrayButton, TopBar, } from "./TopBar.js";
|
|
|
13
13
|
/* The notifications: a bell with how many are unread and the list in a popover — or the list
|
|
14
14
|
alone, as a portal's page. */
|
|
15
15
|
export { Inbox, InboxList, } from "./Inbox.js";
|
|
16
|
+
/* The notification centre for any header: the bell with its count, and the panel grouped by
|
|
17
|
+
«Hoy» / «Anteriores» with an action per item. Controlled — it fetches nothing. */
|
|
18
|
+
export { NotificationBell, NotificationPanel, } from "./Notifications.js";
|
|
16
19
|
/* A screen of N sets side by side — the reconciliation: each pane scrolls on its own. */
|
|
17
20
|
export { KioskFrame, } from "./KioskFrame.js";
|
|
18
21
|
export { Pane, Panes } from "./Panes.js";
|
|
@@ -343,6 +343,14 @@ export const SPANISH_COPY = {
|
|
|
343
343
|
clear: "Quitar formato",
|
|
344
344
|
mentions: "Personas",
|
|
345
345
|
noMatches: "No coincide nadie",
|
|
346
|
+
image: "Insertar imagen",
|
|
347
|
+
imageUploading: "Subiendo la imagen…",
|
|
348
|
+
imageFailed: "No se pudo subir la imagen.",
|
|
349
|
+
video: "Insertar video",
|
|
350
|
+
videoUrl: "Dirección del video",
|
|
351
|
+
insertVideo: "Insertar",
|
|
352
|
+
badVideo: "Pegá el enlace de un video de {providers}.",
|
|
353
|
+
videoTitle: "Video de {provider}",
|
|
346
354
|
},
|
|
347
355
|
sorting: {
|
|
348
356
|
label: "Ordenar",
|
|
@@ -628,6 +636,31 @@ export const SPANISH_COPY = {
|
|
|
628
636
|
close: "Cerrar",
|
|
629
637
|
empty: "Todavía no hay imágenes",
|
|
630
638
|
},
|
|
639
|
+
carousel: {
|
|
640
|
+
roledescription: "carrusel",
|
|
641
|
+
slide: "diapositiva",
|
|
642
|
+
position: "{index} de {total}",
|
|
643
|
+
previous: "Diapositiva anterior",
|
|
644
|
+
next: "Diapositiva siguiente",
|
|
645
|
+
goTo: "Ir a la diapositiva {index}",
|
|
646
|
+
pause: "Pausar",
|
|
647
|
+
play: "Reproducir",
|
|
648
|
+
},
|
|
649
|
+
stories: {
|
|
650
|
+
label: "Historias",
|
|
651
|
+
open: "Historias de {name}",
|
|
652
|
+
seen: "vistas",
|
|
653
|
+
unseen: "nuevas",
|
|
654
|
+
viewer: "Historias de {name}",
|
|
655
|
+
position: "{index} de {total}",
|
|
656
|
+
previous: "Anterior",
|
|
657
|
+
next: "Siguiente",
|
|
658
|
+
pause: "Pausar",
|
|
659
|
+
play: "Reproducir",
|
|
660
|
+
close: "Cerrar",
|
|
661
|
+
},
|
|
662
|
+
notifications: { today: "Hoy", before: "Anteriores", more: "Ver más" },
|
|
663
|
+
portalNav: { label: "Mi portal" },
|
|
631
664
|
inbox: {
|
|
632
665
|
label: "Notificaciones",
|
|
633
666
|
unread: "Sin leer",
|
|
@@ -748,8 +781,14 @@ export const SPANISH_COPY = {
|
|
|
748
781
|
pdf: "PDF",
|
|
749
782
|
text: "Texto",
|
|
750
783
|
markdown: "Documento",
|
|
784
|
+
video: "Video",
|
|
785
|
+
audio: "Audio",
|
|
786
|
+
office: "Documento de Office",
|
|
751
787
|
other: "Archivo",
|
|
752
788
|
},
|
|
789
|
+
office: { doc: "Documento de Word", sheet: "Hoja de cálculo", slides: "Presentación" },
|
|
790
|
+
officeSentence: "Se ve mejor en su programa. Abrilo o descargalo.",
|
|
791
|
+
open: "Abrir",
|
|
753
792
|
},
|
|
754
793
|
chat: {
|
|
755
794
|
thread: "Conversación",
|
|
@@ -478,6 +478,20 @@ export type UiCopy = {
|
|
|
478
478
|
/** The list that opens on «@»: people to mention. */
|
|
479
479
|
mentions: string;
|
|
480
480
|
noMatches: string;
|
|
481
|
+
/** The button that adds a picture (`images`): chosen, pasted or dropped. */
|
|
482
|
+
image: string;
|
|
483
|
+
/** Said while the application stores the picture. */
|
|
484
|
+
imageUploading: string;
|
|
485
|
+
/** A failed upload, when the application did not say why. */
|
|
486
|
+
imageFailed: string;
|
|
487
|
+
/** The button and the form that add a video (`embeds`). */
|
|
488
|
+
video: string;
|
|
489
|
+
videoUrl: string;
|
|
490
|
+
insertVideo: string;
|
|
491
|
+
/** Said when the address is not a video of an allowed host. `{providers}` lists them. */
|
|
492
|
+
badVideo: string;
|
|
493
|
+
/** The player's name, for whoever cannot see it. `{provider}` is the host. */
|
|
494
|
+
videoTitle: string;
|
|
481
495
|
};
|
|
482
496
|
/** Sorting, when the presentation has no headers to click on. */
|
|
483
497
|
sorting: {
|
|
@@ -934,6 +948,46 @@ export type UiCopy = {
|
|
|
934
948
|
empty: string;
|
|
935
949
|
};
|
|
936
950
|
/** The notifications (`Inbox`, `InboxList`). */
|
|
951
|
+
/** Slides that turn (`Carousel`). */
|
|
952
|
+
carousel: {
|
|
953
|
+
roledescription: string;
|
|
954
|
+
slide: string;
|
|
955
|
+
/** `{index}` of `{total}`. */
|
|
956
|
+
position: string;
|
|
957
|
+
previous: string;
|
|
958
|
+
next: string;
|
|
959
|
+
/** `{index}`: the dot that goes there. */
|
|
960
|
+
goTo: string;
|
|
961
|
+
pause: string;
|
|
962
|
+
play: string;
|
|
963
|
+
};
|
|
964
|
+
/** A person's stories (`StoryBar`, `StoryViewer`). */
|
|
965
|
+
stories: {
|
|
966
|
+
label: string;
|
|
967
|
+
/** `{name}`: the ring that opens them. */
|
|
968
|
+
open: string;
|
|
969
|
+
seen: string;
|
|
970
|
+
unseen: string;
|
|
971
|
+
/** `{name}`: the viewer's name. */
|
|
972
|
+
viewer: string;
|
|
973
|
+
/** `{index}` of `{total}`. */
|
|
974
|
+
position: string;
|
|
975
|
+
previous: string;
|
|
976
|
+
next: string;
|
|
977
|
+
pause: string;
|
|
978
|
+
play: string;
|
|
979
|
+
close: string;
|
|
980
|
+
};
|
|
981
|
+
/** The notification centre (`NotificationPanel`); the rest of its words are `inbox`'s. */
|
|
982
|
+
notifications: {
|
|
983
|
+
today: string;
|
|
984
|
+
before: string;
|
|
985
|
+
more: string;
|
|
986
|
+
};
|
|
987
|
+
/** A portal's side menu (`PortalNav`). */
|
|
988
|
+
portalNav: {
|
|
989
|
+
label: string;
|
|
990
|
+
};
|
|
937
991
|
inbox: {
|
|
938
992
|
label: string;
|
|
939
993
|
unread: string;
|
|
@@ -1118,8 +1172,21 @@ export type UiCopy = {
|
|
|
1118
1172
|
pdf: string;
|
|
1119
1173
|
text: string;
|
|
1120
1174
|
markdown: string;
|
|
1175
|
+
video: string;
|
|
1176
|
+
audio: string;
|
|
1177
|
+
office: string;
|
|
1121
1178
|
other: string;
|
|
1122
1179
|
};
|
|
1180
|
+
/** The Office card's heading, one per family: the word says which program. */
|
|
1181
|
+
office: {
|
|
1182
|
+
doc: string;
|
|
1183
|
+
sheet: string;
|
|
1184
|
+
slides: string;
|
|
1185
|
+
};
|
|
1186
|
+
/** Under it: why there is no drawing, and what to do. */
|
|
1187
|
+
officeSentence: string;
|
|
1188
|
+
/** Opens the file in a tab of its own. */
|
|
1189
|
+
open: string;
|
|
1123
1190
|
};
|
|
1124
1191
|
/** A conversation: the thread of messages and the composer under it. */
|
|
1125
1192
|
chat: {
|
|
@@ -290,6 +290,14 @@ export const ENGLISH_COPY = {
|
|
|
290
290
|
clear: "Clear formatting",
|
|
291
291
|
mentions: "People",
|
|
292
292
|
noMatches: "Nobody matches",
|
|
293
|
+
image: "Insert image",
|
|
294
|
+
imageUploading: "Uploading the image…",
|
|
295
|
+
imageFailed: "The image could not be uploaded.",
|
|
296
|
+
video: "Insert video",
|
|
297
|
+
videoUrl: "Video address",
|
|
298
|
+
insertVideo: "Insert",
|
|
299
|
+
badVideo: "Paste the link of a video from {providers}.",
|
|
300
|
+
videoTitle: "{provider} video",
|
|
293
301
|
},
|
|
294
302
|
sorting: {
|
|
295
303
|
label: "Sort",
|
|
@@ -613,6 +621,31 @@ export const ENGLISH_COPY = {
|
|
|
613
621
|
close: "Close",
|
|
614
622
|
empty: "No images yet",
|
|
615
623
|
},
|
|
624
|
+
carousel: {
|
|
625
|
+
roledescription: "carousel",
|
|
626
|
+
slide: "slide",
|
|
627
|
+
position: "{index} of {total}",
|
|
628
|
+
previous: "Previous slide",
|
|
629
|
+
next: "Next slide",
|
|
630
|
+
goTo: "Go to slide {index}",
|
|
631
|
+
pause: "Pause",
|
|
632
|
+
play: "Play",
|
|
633
|
+
},
|
|
634
|
+
stories: {
|
|
635
|
+
label: "Stories",
|
|
636
|
+
open: "Stories of {name}",
|
|
637
|
+
seen: "seen",
|
|
638
|
+
unseen: "new",
|
|
639
|
+
viewer: "Stories of {name}",
|
|
640
|
+
position: "{index} of {total}",
|
|
641
|
+
previous: "Previous",
|
|
642
|
+
next: "Next",
|
|
643
|
+
pause: "Pause",
|
|
644
|
+
play: "Play",
|
|
645
|
+
close: "Close",
|
|
646
|
+
},
|
|
647
|
+
notifications: { today: "Today", before: "Earlier", more: "See more" },
|
|
648
|
+
portalNav: { label: "My portal" },
|
|
616
649
|
inbox: {
|
|
617
650
|
label: "Notifications",
|
|
618
651
|
unread: "Unread",
|
|
@@ -733,7 +766,19 @@ export const ENGLISH_COPY = {
|
|
|
733
766
|
nextPage: "Next page",
|
|
734
767
|
fit: "Fit",
|
|
735
768
|
actualSize: "Actual size",
|
|
736
|
-
kind: {
|
|
769
|
+
kind: {
|
|
770
|
+
image: "Image",
|
|
771
|
+
pdf: "PDF",
|
|
772
|
+
text: "Text",
|
|
773
|
+
markdown: "Document",
|
|
774
|
+
video: "Video",
|
|
775
|
+
audio: "Audio",
|
|
776
|
+
office: "Office document",
|
|
777
|
+
other: "File",
|
|
778
|
+
},
|
|
779
|
+
office: { doc: "Word document", sheet: "Spreadsheet", slides: "Presentation" },
|
|
780
|
+
officeSentence: "Its program draws it best. Open it or download it.",
|
|
781
|
+
open: "Open",
|
|
737
782
|
},
|
|
738
783
|
chat: {
|
|
739
784
|
thread: "Conversation",
|