@sincpro/web-ui 1.9.0 → 1.11.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/dist/components/board/Board.d.ts +51 -0
- package/dist/components/board/Board.js +15 -0
- package/dist/components/board/index.d.ts +1 -0
- package/dist/components/board/index.js +2 -0
- package/dist/components/canvas/Canvas.d.ts +14 -0
- package/dist/components/canvas/Canvas.js +9 -0
- package/dist/components/canvas/canvas.css +19 -0
- package/dist/components/canvas/index.d.ts +1 -0
- package/dist/components/canvas/index.js +2 -0
- package/dist/components/chat/ChatComposer.d.ts +10 -0
- package/dist/components/chat/ChatComposer.js +29 -0
- package/dist/components/chat/ChatThread.d.ts +13 -0
- package/dist/components/chat/ChatThread.js +76 -0
- package/dist/components/chat/ConversationList.d.ts +22 -0
- package/dist/components/chat/ConversationList.js +22 -0
- package/dist/components/chat/index.d.ts +4 -0
- package/dist/components/chat/index.js +5 -0
- package/dist/components/chat/model.d.ts +30 -0
- package/dist/components/chat/model.js +53 -0
- package/dist/components/frame/Chart.d.ts +12 -7
- package/dist/components/frame/Chart.js +17 -17
- package/dist/components/frame/FrameView.d.ts +3 -3
- package/dist/components/frame/FrameView.js +79 -26
- package/dist/components/frame/model.d.ts +12 -3
- package/dist/components/frame/model.js +53 -19
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/listing/AxisLevels.d.ts +24 -0
- package/dist/components/listing/AxisLevels.js +58 -0
- package/dist/components/listing/ChartExplorer.d.ts +79 -0
- package/dist/components/listing/ChartExplorer.js +114 -0
- package/dist/components/listing/ColumnsMenu.d.ts +7 -1
- package/dist/components/listing/ColumnsMenu.js +16 -5
- package/dist/components/listing/GroupingLevels.d.ts +5 -1
- package/dist/components/listing/GroupingLevels.js +7 -4
- package/dist/components/listing/ListingBar.js +2 -2
- package/dist/components/listing/PivotExplorer.js +5 -36
- package/dist/components/listing/index.d.ts +2 -0
- package/dist/components/listing/index.js +2 -0
- package/dist/components/listing/set.d.ts +3 -1
- package/dist/components/preview/FilePreview.d.ts +19 -0
- package/dist/components/preview/FilePreview.js +112 -0
- package/dist/components/preview/PdfPreview.d.ts +7 -0
- package/dist/components/preview/PdfPreview.js +47 -0
- package/dist/components/preview/index.d.ts +1 -0
- package/dist/components/preview/index.js +2 -0
- package/dist/components/record/SmartButtons.js +1 -1
- package/dist/components/search/FieldPath.d.ts +54 -0
- package/dist/components/search/FieldPath.js +159 -0
- package/dist/components/search/FilterBuilder.d.ts +38 -5
- package/dist/components/search/FilterBuilder.js +129 -25
- package/dist/components/search/SearchBar.js +7 -2
- package/dist/components/search/criteria.d.ts +23 -1
- package/dist/components/search/index.d.ts +4 -2
- package/dist/components/search/index.js +4 -0
- package/dist/components/search/paths.d.ts +49 -0
- package/dist/components/search/paths.js +75 -0
- package/dist/components/shell/TopBar.js +1 -1
- package/dist/foundations/calendar.d.ts +15 -0
- package/dist/foundations/calendar.js +59 -1
- package/dist/foundations/chart.d.ts +126 -0
- package/dist/foundations/chart.js +297 -0
- package/dist/foundations/copy.d.ts +125 -0
- package/dist/foundations/copy.es.js +90 -0
- package/dist/foundations/copy.js +84 -0
- package/dist/foundations/index.d.ts +2 -1
- package/dist/foundations/index.js +4 -1
- package/dist/foundations/pivot.d.ts +9 -0
- package/dist/foundations/pivot.js +1 -0
- package/dist/primitives/chart/Chart.d.ts +39 -0
- package/dist/primitives/chart/Chart.js +235 -0
- package/dist/primitives/chart/index.d.ts +1 -0
- package/dist/primitives/chart/index.js +1 -0
- package/dist/primitives/field/Field.js +2 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/notice/Callout.d.ts +4 -1
- package/dist/primitives/notice/Callout.js +12 -2
- package/dist/primitives/notice/Notice.d.ts +26 -2
- package/dist/primitives/notice/Notice.js +64 -4
- package/dist/primitives/notice/Toast.js +10 -1
- package/dist/primitives/value/Markdown.d.ts +9 -0
- package/dist/primitives/value/Markdown.js +18 -0
- package/dist/primitives/value/Metric.d.ts +13 -2
- package/dist/primitives/value/Metric.js +25 -3
- package/dist/primitives/value/index.d.ts +1 -0
- package/dist/primitives/value/index.js +1 -0
- package/dist/tokens.css +73 -0
- package/dist/views/list/List.d.ts +2 -1
- package/dist/views/list/List.js +8 -1
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +37 -5
- package/dist/views/list/index.d.ts +1 -1
- package/dist/views/list/types.d.ts +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A BOARD: the tiles of a dashboard — Odoo's «Tableros», a BI page — over one slice of data.
|
|
4
|
+
*
|
|
5
|
+
* Context: a board is not a third view. Each tile is a piece that already exists (a `Chart`,
|
|
6
|
+
* a `List`, a `PivotTable`, `Metrics`); what the board adds is the ORDER of the page, and two
|
|
7
|
+
* rules that a page of loose cards breaks:
|
|
8
|
+
*
|
|
9
|
+
* 1. **One filter row, above everything it scopes.** The period and the branch are chosen
|
|
10
|
+
* once and every tile re-reads the same slice. A filter inside one tile would make two
|
|
11
|
+
* tiles of the same page answer about two different sets, and nothing on screen would
|
|
12
|
+
* say so.
|
|
13
|
+
* 2. **The headline numbers first**, then the tiles. What is read in two seconds goes where
|
|
14
|
+
* the eye lands.
|
|
15
|
+
*
|
|
16
|
+
* The grid asks the CONTAINER and not the window (`@container`): a board inside a panel of
|
|
17
|
+
* the workspace is as narrow as the panel, whatever the screen measures.
|
|
18
|
+
*
|
|
19
|
+
* It knows no domain and folds nothing: the application reads its data with the filters and
|
|
20
|
+
* hands each tile what to draw — the same `Pivot` the list's chart and pivot read.
|
|
21
|
+
*/
|
|
22
|
+
export type BoardProps = {
|
|
23
|
+
/** What the board is about: «Ventas». */
|
|
24
|
+
title: string;
|
|
25
|
+
description?: ReactNode;
|
|
26
|
+
/** The filters that scope EVERY tile, in one row. */
|
|
27
|
+
filters?: ReactNode;
|
|
28
|
+
/** The headline numbers — `Metrics` — read before the tiles. */
|
|
29
|
+
metrics?: ReactNode;
|
|
30
|
+
/** The tiles: `BoardTile`s. */
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
};
|
|
33
|
+
export declare function Board({ title, description, filters, metrics, children }: BoardProps): import("react").JSX.Element;
|
|
34
|
+
declare const SPAN: {
|
|
35
|
+
readonly 1: "";
|
|
36
|
+
readonly 2: "@3xl:col-span-2";
|
|
37
|
+
readonly full: "col-span-full";
|
|
38
|
+
};
|
|
39
|
+
export type BoardTileProps = {
|
|
40
|
+
title: string;
|
|
41
|
+
/** One line under the title: what it counts, or what a press on it does. */
|
|
42
|
+
description?: ReactNode;
|
|
43
|
+
/** The tile's own buttons, at its top right: open the list behind it, download. */
|
|
44
|
+
actions?: ReactNode;
|
|
45
|
+
/** How many columns it takes: a time series reads better wide. */
|
|
46
|
+
span?: keyof typeof SPAN;
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
};
|
|
49
|
+
/** One tile of a `Board`: a titled surface around a chart, a list or a number. */
|
|
50
|
+
export declare function BoardTile({ title, description, actions, span, children, }: BoardTileProps): import("react").JSX.Element;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function Board({ title, description, filters, metrics, children }) {
|
|
3
|
+
return (
|
|
4
|
+
/* Its own gutter: a board is a page (or a whole panel), not a piece inside one. */
|
|
5
|
+
_jsxs("div", { className: "@container flex min-w-0 flex-col gap-5 p-4 sm:p-6", children: [_jsxs("header", { className: "flex min-w-0 flex-wrap items-end justify-between gap-x-6 gap-y-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-display font-semibold text-ink", children: title }), description === undefined ? null : (_jsx("p", { className: "mt-1 text-body text-muted", children: description }))] }), filters === undefined ? null : (_jsx("div", { className: "flex min-w-0 flex-wrap items-end gap-3", children: filters }))] }), metrics, _jsx("div", { className: "grid min-w-0 grid-cols-1 gap-4 @3xl:grid-cols-2 @7xl:grid-cols-3", children: children })] }));
|
|
6
|
+
}
|
|
7
|
+
const SPAN = {
|
|
8
|
+
1: "",
|
|
9
|
+
2: "@3xl:col-span-2",
|
|
10
|
+
full: "col-span-full",
|
|
11
|
+
};
|
|
12
|
+
/** One tile of a `Board`: a titled surface around a chart, a list or a number. */
|
|
13
|
+
export function BoardTile({ title, description, actions, span = 1, children, }) {
|
|
14
|
+
return (_jsxs("section", { "aria-label": title, className: `flex min-w-0 flex-col gap-4 rounded-box border border-line-strong bg-surface p-4 ${SPAN[span]}`, children: [_jsxs("header", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h2", { className: "text-lead font-semibold text-ink", children: title }), description === undefined ? null : (_jsx("p", { className: "mt-0.5 text-meta text-muted", children: description }))] }), actions === undefined ? null : (_jsx("div", { className: "flex shrink-0 items-center gap-1", children: actions }))] }), children] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Board, type BoardProps, BoardTile, type BoardTileProps, } from "./Board.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "@sincpro/web-ui/components/canvas/canvas.css";
|
|
2
|
+
import { type Connection, type Edge, type EdgeChange, type Node, type NodeChange } from "@xyflow/react";
|
|
3
|
+
export type CanvasProps<N extends Node = Node, E extends Edge = Edge> = {
|
|
4
|
+
nodes: N[];
|
|
5
|
+
edges: E[];
|
|
6
|
+
onNodesChange?: (changes: NodeChange<N>[]) => void;
|
|
7
|
+
onEdgesChange?: (changes: EdgeChange<E>[]) => void;
|
|
8
|
+
onConnect?: (connection: Connection) => void;
|
|
9
|
+
/** Shown, not edited: no dragging, no connecting, no selecting what is not there. */
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
/** The accessible name of the region. «Lienzo» by default. */
|
|
12
|
+
label?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function Canvas<N extends Node = Node, E extends Edge = Edge>({ nodes, edges, onNodesChange, onEdgesChange, onConnect, readOnly, label, }: CanvasProps<N, E>): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import "@sincpro/web-ui/components/canvas/canvas.css";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { Background, Controls, ReactFlow, } from "@xyflow/react";
|
|
6
|
+
export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, onConnect, readOnly = false, label, }) {
|
|
7
|
+
const copy = useUiCopy();
|
|
8
|
+
return (_jsxs("div", { role: "region", "aria-label": label ?? copy.canvas.label, className: "relative h-96 min-h-0 w-full overflow-hidden rounded-control border border-line bg-ground", children: [_jsxs(ReactFlow, { nodes: nodes, edges: edges, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, nodesDraggable: !readOnly, nodesConnectable: !readOnly, elementsSelectable: !readOnly, fitView: true, "aria-label": label ?? copy.canvas.label, children: [_jsx(Background, {}), _jsx(Controls, { showInteractive: !readOnly })] }), readOnly ? (_jsx("span", { className: "pointer-events-none absolute top-3 left-3 rounded-control border border-line bg-surface px-2 py-0.5 text-micro font-medium text-muted", children: copy.canvas.readOnly })) : null] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* React Flow's own stylesheet, then the product's tokens on top of it. Its variables
|
|
2
|
+
are the only hook the library offers for colour, so the canvas reads as the same
|
|
3
|
+
paper and ink as the rest of the screen, in light and dark alike. */
|
|
4
|
+
@import "@xyflow/react/dist/style.css";
|
|
5
|
+
|
|
6
|
+
.react-flow {
|
|
7
|
+
--xy-background-color: var(--color-ground);
|
|
8
|
+
--xy-node-background-color-default: var(--color-surface);
|
|
9
|
+
--xy-node-border-default: 1px solid var(--color-line-strong);
|
|
10
|
+
--xy-node-boxshadow-selected: 0 0 0 2px var(--color-primary);
|
|
11
|
+
--xy-edge-stroke-default: var(--color-muted);
|
|
12
|
+
--xy-edge-stroke-selected-default: var(--color-primary);
|
|
13
|
+
--xy-controls-button-background-color-default: var(--color-surface);
|
|
14
|
+
--xy-controls-button-border-color-default: var(--color-line);
|
|
15
|
+
--xy-controls-button-color-default: var(--color-ink);
|
|
16
|
+
--xy-minimap-background-color-default: var(--color-surface);
|
|
17
|
+
--xy-minimap-mask-background-color-default: var(--color-scrim);
|
|
18
|
+
--xy-handle-background-color-default: var(--color-primary);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Canvas, type CanvasProps } from "./Canvas.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ChatComposerProps = {
|
|
2
|
+
/** The text, trimmed, when it is sent. */
|
|
3
|
+
onSend: (text: string) => void;
|
|
4
|
+
/** The conversation is closed, or the application is not connected. */
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** The accessible name of the box. «Mensaje» by default. */
|
|
7
|
+
label?: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function ChatComposer({ onSend, disabled, label, placeholder, }: ChatComposerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { Button } from "../../primitives/button/Button.js";
|
|
5
|
+
import { TextArea } from "../../primitives/field/Field.js";
|
|
6
|
+
import { Send } from "lucide-react";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
export function ChatComposer({ onSend, disabled = false, label, placeholder, }) {
|
|
9
|
+
const copy = useUiCopy();
|
|
10
|
+
const [text, setText] = useState("");
|
|
11
|
+
const body = text.trim();
|
|
12
|
+
const blocked = disabled || body === "";
|
|
13
|
+
function send() {
|
|
14
|
+
if (blocked)
|
|
15
|
+
return;
|
|
16
|
+
onSend(body);
|
|
17
|
+
setText("");
|
|
18
|
+
}
|
|
19
|
+
function onKeyDown(event) {
|
|
20
|
+
if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing)
|
|
21
|
+
return;
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
send();
|
|
24
|
+
}
|
|
25
|
+
return (_jsxs("div", { onKeyDown: onKeyDown,
|
|
26
|
+
/* A container, so the send button follows the width of the COMPOSER, not of the
|
|
27
|
+
screen: in a narrow side panel on a desk it is as tight as on a phone. */
|
|
28
|
+
className: "@container flex items-end gap-3 border-t border-line bg-surface px-5 py-4", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(TextArea, { value: text, onChange: setText, rows: 2, disabled: disabled, "aria-label": label ?? copy.chat.composer, placeholder: placeholder ?? copy.chat.placeholder }) }), _jsx(Button, { role: "secondary", icon: Send, disabled: blocked, onClick: send, children: _jsx("span", { className: "sr-only @xs:not-sr-only", children: copy.chat.send }) })] }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ChatMessage } from "./model.js";
|
|
2
|
+
export type ChatThreadProps = {
|
|
3
|
+
messages: readonly ChatMessage[];
|
|
4
|
+
/** Present = the top draws «Cargar mensajes anteriores». */
|
|
5
|
+
onLoadOlder?: () => void;
|
|
6
|
+
/** The application is fetching the earlier page right now. */
|
|
7
|
+
loadingOlder?: boolean;
|
|
8
|
+
/** The accessible name of the log. «Conversación» by default. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** The «now» the day names are relative to. */
|
|
11
|
+
now?: Date;
|
|
12
|
+
};
|
|
13
|
+
export declare function ChatThread({ messages, onLoadOlder, loadingOlder, label, now, }: ChatThreadProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { dayLabel, groupByDay, startsRun, } from "./model.js";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { Button } from "../../primitives/button/Button.js";
|
|
6
|
+
import { Empty } from "../../primitives/notice/Notice.js";
|
|
7
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
8
|
+
/* ==================================================================== *
|
|
9
|
+
* THE THREAD — a conversation read from the first message to the last.
|
|
10
|
+
*
|
|
11
|
+
* Context: the chat of a CRM or a help desk is read like WhatsApp or Telegram:
|
|
12
|
+
* the newest message is at the bottom, the older ones are above, and the
|
|
13
|
+
* reading starts where it ended. So the thread OPENS at the bottom, STAYS
|
|
14
|
+
* there while new messages arrive IF the person is already there, and does
|
|
15
|
+
* not drag them down when they are reading something above.
|
|
16
|
+
*
|
|
17
|
+
* ── Reading up is never interrupted ─────────────────────────────────
|
|
18
|
+
*
|
|
19
|
+
* Scrolled up, a new message does not move the view; a button «Ir al último
|
|
20
|
+
* mensaje» brings them back. Scrolled to the bottom, the thread follows.
|
|
21
|
+
*
|
|
22
|
+
* ── Older messages are asked for, not poured in ─────────────────────
|
|
23
|
+
*
|
|
24
|
+
* `onLoadOlder` draws a button at the top. The application fetches the
|
|
25
|
+
* earlier page and prepends it; the thread keeps the reading where it was by
|
|
26
|
+
* the application's own paging, not by a scroll guess here.
|
|
27
|
+
*
|
|
28
|
+
* ── Days and runs ───────────────────────────────────────────────────
|
|
29
|
+
*
|
|
30
|
+
* A separator names each day («Hoy», «Ayer», the date written out). Messages
|
|
31
|
+
* from the same author in a row share one name above them: the eye reads
|
|
32
|
+
* the run as one voice.
|
|
33
|
+
* ==================================================================== */
|
|
34
|
+
/** How close to the bottom still counts as «at the bottom», in pixels. */
|
|
35
|
+
const AT_BOTTOM = 48;
|
|
36
|
+
export function ChatThread({ messages, onLoadOlder, loadingOlder = false, label, now, }) {
|
|
37
|
+
const copy = useUiCopy();
|
|
38
|
+
const scroller = useRef(null);
|
|
39
|
+
/* A ref, not state: the scroll handler writes it on every frame and nothing
|
|
40
|
+
draws from it, so it must not cause a render. */
|
|
41
|
+
const pinned = useRef(true);
|
|
42
|
+
const [showJump, setShowJump] = useState(false);
|
|
43
|
+
const clock = now ?? new Date();
|
|
44
|
+
/* Runs after the messages change and before the paint: the thread moves to the
|
|
45
|
+
newest message in the same frame, so nobody sees it open at the top. */
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
const el = scroller.current;
|
|
48
|
+
if (el === null || !pinned.current)
|
|
49
|
+
return;
|
|
50
|
+
el.scrollTop = el.scrollHeight;
|
|
51
|
+
}, [messages]);
|
|
52
|
+
function onScroll(event) {
|
|
53
|
+
const el = event.currentTarget;
|
|
54
|
+
const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
55
|
+
pinned.current = distance < AT_BOTTOM;
|
|
56
|
+
setShowJump(!pinned.current);
|
|
57
|
+
}
|
|
58
|
+
function toLatest() {
|
|
59
|
+
const el = scroller.current;
|
|
60
|
+
if (el === null)
|
|
61
|
+
return;
|
|
62
|
+
el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });
|
|
63
|
+
pinned.current = true;
|
|
64
|
+
setShowJump(false);
|
|
65
|
+
}
|
|
66
|
+
const groups = groupByDay(messages);
|
|
67
|
+
const words = { today: copy.chat.today, yesterday: copy.chat.yesterday };
|
|
68
|
+
return (_jsxs("div", { className: "relative flex min-h-0 flex-1 flex-col", children: [_jsxs("div", { ref: scroller, role: "log",
|
|
69
|
+
/* A scrollable region is reachable by keyboard (axe): the arrows scroll it. */
|
|
70
|
+
tabIndex: 0, "aria-label": label ?? copy.chat.thread, "aria-live": "polite", onScroll: onScroll, className: "flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-5 py-4", children: [onLoadOlder === undefined ? null : (_jsx("div", { className: "flex justify-center pb-3", children: _jsx(Button, { role: "ghost", size: "sm", disabled: loadingOlder, onClick: onLoadOlder, children: loadingOlder ? copy.chat.loadingOlder : copy.chat.loadOlder }) })), messages.length === 0 ? _jsx(Empty, { sentence: copy.chat.empty }) : null, groups.map((group) => (_jsxs("section", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "my-3 flex justify-center", children: _jsx("span", { className: "rounded-control border border-line bg-surface px-3 py-0.5 text-micro font-medium text-muted", children: dayLabel(group.day, clock, words, copy.locale) }) }), group.messages.map((message, index) => (_jsx(Bubble, { message: message, first: startsRun(group.messages, index), locale: copy.locale }, message.id)))] }, group.key)))] }), showJump ? (_jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-3 flex justify-center", children: _jsx("div", { className: "pointer-events-auto", children: _jsx(Button, { role: "secondary", size: "sm", onClick: toLatest, children: copy.chat.jumpLatest }) }) })) : null] }));
|
|
71
|
+
}
|
|
72
|
+
function Bubble({ message, first, locale, }) {
|
|
73
|
+
const copy = useUiCopy();
|
|
74
|
+
const time = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).format(message.at);
|
|
75
|
+
return (_jsx("div", { className: `flex ${message.mine ? "justify-end" : "justify-start"} ${first ? "mt-2" : ""}`, children: _jsxs("div", { className: `max-w-prose rounded-control border px-3 py-2 ${message.mine ? "border-primary/30 bg-primary/10" : "border-line bg-surface"} ${message.pending === true ? "opacity-70" : ""}`, children: [first && !message.mine ? (_jsx("p", { className: "text-meta font-medium text-muted", children: message.author })) : null, _jsx("p", { className: "text-body break-words whitespace-pre-wrap text-ink", children: message.body }), _jsxs("p", { className: "mt-1 text-micro text-muted", children: [_jsx("time", { dateTime: message.at.toISOString(), children: time }), message.pending === true ? ` · ${copy.chat.sending}` : null] })] }) }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type Conversation = {
|
|
2
|
+
id: string;
|
|
3
|
+
/** Who, or what, the conversation is with. */
|
|
4
|
+
title: string;
|
|
5
|
+
/** The last message, cut to one line by the row. */
|
|
6
|
+
preview?: string;
|
|
7
|
+
/** When the last message was written. */
|
|
8
|
+
at?: Date;
|
|
9
|
+
/** Messages nobody has read yet in this conversation. */
|
|
10
|
+
unread?: number;
|
|
11
|
+
};
|
|
12
|
+
export type ConversationListProps = {
|
|
13
|
+
conversations: readonly Conversation[];
|
|
14
|
+
/** The conversation open in the thread. */
|
|
15
|
+
selectedId?: string;
|
|
16
|
+
onSelect: (id: string) => void;
|
|
17
|
+
/** The accessible name of the list. «Conversaciones» by default. */
|
|
18
|
+
label?: string;
|
|
19
|
+
/** The «now» the times are relative to. */
|
|
20
|
+
now?: Date;
|
|
21
|
+
};
|
|
22
|
+
export declare function ConversationList({ conversations, selectedId, onSelect, label, now, }: ConversationListProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { dayLabel } from "./model.js";
|
|
4
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { Empty } from "../../primitives/notice/Notice.js";
|
|
6
|
+
import { ListBox, ListBoxItem } from "react-aria-components";
|
|
7
|
+
export function ConversationList({ conversations, selectedId, onSelect, label, now, }) {
|
|
8
|
+
const copy = useUiCopy();
|
|
9
|
+
const clock = now ?? new Date();
|
|
10
|
+
const words = { today: copy.chat.today, yesterday: copy.chat.yesterday };
|
|
11
|
+
if (conversations.length === 0)
|
|
12
|
+
return _jsx(Empty, { sentence: copy.chat.empty });
|
|
13
|
+
return (_jsx(ListBox, { "aria-label": label ?? copy.chat.conversations, selectionMode: "single", disallowEmptySelection: true, selectedKeys: selectedId === undefined ? [] : [selectedId], onSelectionChange: (keys) => {
|
|
14
|
+
if (keys === "all")
|
|
15
|
+
return;
|
|
16
|
+
const [first] = keys;
|
|
17
|
+
if (first !== undefined)
|
|
18
|
+
onSelect(String(first));
|
|
19
|
+
}, className: "flex min-h-0 flex-col gap-1 overflow-y-auto p-2 outline-none", children: conversations.map((conversation) => (_jsxs(ListBoxItem, { id: conversation.id, textValue: conversation.title, className: ({ isSelected, isFocusVisible }) => `cursor-pointer rounded-control border px-3 py-2.5 outline-none ${isSelected
|
|
20
|
+
? "border-primary/40 bg-primary/10"
|
|
21
|
+
: "border-transparent hover:bg-ink/4"} ${isFocusVisible ? "outline-2 outline-offset-1 outline-primary" : ""}`, children: [_jsxs("div", { className: "flex min-w-0 items-baseline gap-2", children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-body font-medium text-ink", children: conversation.title }), conversation.at === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro text-muted", children: dayLabel(conversation.at, clock, words, copy.locale) }))] }), _jsxs("div", { className: "mt-0.5 flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-meta text-muted", children: conversation.preview ?? "" }), conversation.unread === undefined || conversation.unread === 0 ? null : (_jsxs("span", { className: "shrink-0 rounded-control bg-ink px-2 text-micro font-semibold text-surface tabular-nums", children: [conversation.unread, _jsx("span", { className: "sr-only", children: fillCopy(copy.chat.unread, { count: String(conversation.unread) }) })] }))] })] }, conversation.id))) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ChatComposer, type ChatComposerProps, } from "./ChatComposer.js";
|
|
2
|
+
export { ChatThread, type ChatThreadProps } from "./ChatThread.js";
|
|
3
|
+
export { type Conversation, ConversationList, type ConversationListProps, } from "./ConversationList.js";
|
|
4
|
+
export { type ChatMessage, type DayGroup, dayKey, dayLabel, groupByDay, startsRun, } from "./model.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* A conversation: the thread, the composer and the list of conversations. */
|
|
2
|
+
export { ChatComposer, } from "./ChatComposer.js";
|
|
3
|
+
export { ChatThread } from "./ChatThread.js";
|
|
4
|
+
export { ConversationList, } from "./ConversationList.js";
|
|
5
|
+
export { dayKey, dayLabel, groupByDay, startsRun, } from "./model.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ChatMessage = {
|
|
2
|
+
id: string;
|
|
3
|
+
/** Who wrote it, as the screen names them: «Ana Ruiz». */
|
|
4
|
+
author: string;
|
|
5
|
+
/** The text. Plain: a message is not a page of its own. */
|
|
6
|
+
body: string;
|
|
7
|
+
at: Date;
|
|
8
|
+
/** Written by the person looking at the thread. Drawn on the other side. */
|
|
9
|
+
mine?: boolean;
|
|
10
|
+
/** Sent but not yet confirmed by the server. Said, never a silent success. */
|
|
11
|
+
pending?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type DayGroup = {
|
|
14
|
+
/** `YYYY-MM-DD` in local time: a stable key, and the day's identity. */
|
|
15
|
+
key: string;
|
|
16
|
+
day: Date;
|
|
17
|
+
messages: ChatMessage[];
|
|
18
|
+
};
|
|
19
|
+
/** The local calendar day of a date, as `YYYY-MM-DD`. */
|
|
20
|
+
export declare function dayKey(date: Date): string;
|
|
21
|
+
/** Messages in the order they were written, cut into the days they were written on.
|
|
22
|
+
* The input may come unsorted (a reconnect delivers out of order); the output never is. */
|
|
23
|
+
export declare function groupByDay(messages: readonly ChatMessage[]): DayGroup[];
|
|
24
|
+
/** A day's name for the separator: «Hoy», «Ayer», or the date written out. */
|
|
25
|
+
export declare function dayLabel(day: Date, now: Date, words: {
|
|
26
|
+
today: string;
|
|
27
|
+
yesterday: string;
|
|
28
|
+
}, locale: string): string;
|
|
29
|
+
/** Whether a message opens a new run from its author: the name is drawn only then. */
|
|
30
|
+
export declare function startsRun(messages: readonly ChatMessage[], index: number): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* ==================================================================== *
|
|
2
|
+
* THE CHAT MODEL — the shapes a conversation is made of, and the pure rules
|
|
3
|
+
* that turn them into a thread: which day a message belongs to, what the day
|
|
4
|
+
* is called. No React here, so the rules are tested in Node.
|
|
5
|
+
* ==================================================================== */
|
|
6
|
+
/** The local calendar day of a date, as `YYYY-MM-DD`. */
|
|
7
|
+
export function dayKey(date) {
|
|
8
|
+
const y = date.getFullYear();
|
|
9
|
+
const m = String(date.getMonth() + 1).padStart(2, "0");
|
|
10
|
+
const d = String(date.getDate()).padStart(2, "0");
|
|
11
|
+
return `${y}-${m}-${d}`;
|
|
12
|
+
}
|
|
13
|
+
/** Messages in the order they were written, cut into the days they were written on.
|
|
14
|
+
* The input may come unsorted (a reconnect delivers out of order); the output never is. */
|
|
15
|
+
export function groupByDay(messages) {
|
|
16
|
+
const ordered = [...messages].sort((a, b) => a.at.getTime() - b.at.getTime());
|
|
17
|
+
const groups = [];
|
|
18
|
+
for (const message of ordered) {
|
|
19
|
+
const key = dayKey(message.at);
|
|
20
|
+
const last = groups[groups.length - 1];
|
|
21
|
+
if (last !== undefined && last.key === key) {
|
|
22
|
+
last.messages.push(message);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const day = new Date(message.at.getFullYear(), message.at.getMonth(), message.at.getDate());
|
|
26
|
+
groups.push({ key, day, messages: [message] });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return groups;
|
|
30
|
+
}
|
|
31
|
+
/** A day's name for the separator: «Hoy», «Ayer», or the date written out. */
|
|
32
|
+
export function dayLabel(day, now, words, locale) {
|
|
33
|
+
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
|
|
34
|
+
if (dayKey(day) === dayKey(now))
|
|
35
|
+
return words.today;
|
|
36
|
+
if (dayKey(day) === dayKey(yesterday))
|
|
37
|
+
return words.yesterday;
|
|
38
|
+
return new Intl.DateTimeFormat(locale, {
|
|
39
|
+
weekday: "long",
|
|
40
|
+
day: "numeric",
|
|
41
|
+
month: "long",
|
|
42
|
+
}).format(day);
|
|
43
|
+
}
|
|
44
|
+
/** Whether a message opens a new run from its author: the name is drawn only then. */
|
|
45
|
+
export function startsRun(messages, index) {
|
|
46
|
+
if (index === 0)
|
|
47
|
+
return true;
|
|
48
|
+
const previous = messages[index - 1];
|
|
49
|
+
const current = messages[index];
|
|
50
|
+
if (previous === undefined || current === undefined)
|
|
51
|
+
return true;
|
|
52
|
+
return previous.author !== current.author || previous.mine !== current.mine;
|
|
53
|
+
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { SeriesBar } from "./model.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* How ONE column is spread: its values counted, drawn with the system's `Chart`.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* Context: this used to be its own drawing — 6 px progress bars stretched across the page,
|
|
6
|
+
* the count 1,200 px from its bar, an empty stretch drawn with a stub as if it had rows.
|
|
7
|
+
* Now it is the same chart every other set uses, read from the bars `columnSeries` decides:
|
|
8
|
+
* a text column ranked (bars lying down, the count at the tip), a numeric one as a
|
|
9
|
+
* histogram (columns along the number line, round edges, an empty stretch at zero).
|
|
10
|
+
*
|
|
11
|
+
* Grouping by a field and measuring is `ChartExplorer`'s question; this one is narrower and
|
|
12
|
+
* stays for it: «how are the values of this column spread».
|
|
10
13
|
*/
|
|
11
|
-
export declare function SeriesChart({ series }: {
|
|
14
|
+
export declare function SeriesChart({ series, label, }: {
|
|
12
15
|
series: readonly SeriesBar[];
|
|
16
|
+
/** What is being counted: «ciudad», «importe en tramos». */
|
|
17
|
+
label?: string;
|
|
13
18
|
}): import("react").JSX.Element;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { chartFromRecord } from "../../foundations/chart.js";
|
|
3
4
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { Chart } from "../../primitives/chart/Chart.js";
|
|
6
|
+
import { useMemo } from "react";
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
8
|
+
* How ONE column is spread: its values counted, drawn with the system's `Chart`.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Context: this used to be its own drawing — 6 px progress bars stretched across the page,
|
|
11
|
+
* the count 1,200 px from its bar, an empty stretch drawn with a stub as if it had rows.
|
|
12
|
+
* Now it is the same chart every other set uses, read from the bars `columnSeries` decides:
|
|
13
|
+
* a text column ranked (bars lying down, the count at the tip), a numeric one as a
|
|
14
|
+
* histogram (columns along the number line, round edges, an empty stretch at zero).
|
|
15
|
+
*
|
|
16
|
+
* Grouping by a field and measuring is `ChartExplorer`'s question; this one is narrower and
|
|
17
|
+
* stays for it: «how are the values of this column spread».
|
|
12
18
|
*/
|
|
13
|
-
export function SeriesChart({ series }) {
|
|
19
|
+
export function SeriesChart({ series, label, }) {
|
|
14
20
|
const copy = useUiCopy();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return (_jsx("ul", { className: "flex flex-col gap-2.5 px-3 py-3", children: series.map((bar) => {
|
|
20
|
-
const width = Math.max((bar.count / peak) * 100, 2);
|
|
21
|
-
const count = bar.count.toLocaleString(copy.locale);
|
|
22
|
-
return (_jsxs("li", { className: "flex min-w-0 flex-col gap-1", title: `${bar.label}: ${count}`, children: [_jsxs("div", { className: "flex min-w-0 items-baseline justify-between gap-3", children: [_jsx("span", { className: "min-w-0 truncate text-meta text-ink", children: bar.label }), _jsx("span", { className: "shrink-0 text-micro tabular-nums text-muted", children: count })] }), _jsx("div", { className: "h-1.5 overflow-hidden rounded-pill bg-ink/8", children: _jsx("div", { className: "h-full rounded-pill bg-data", style: { width: `${width}%` } }) })] }, bar.label));
|
|
23
|
-
}) }));
|
|
21
|
+
const histogram = series.some((bar) => bar.bin !== undefined);
|
|
22
|
+
const data = useMemo(() => chartFromRecord(series.map((bar) => [bar.label, bar.count]), { header: copy.chart.count }), [series, copy.chart.count]);
|
|
23
|
+
return (_jsx(Chart, { data: data, kind: "bar", horizontal: !histogram, label: label ?? copy.frame.series }));
|
|
24
24
|
}
|
|
@@ -9,9 +9,9 @@ export type FrameViewProps = {
|
|
|
9
9
|
present?: FramePresent;
|
|
10
10
|
presents?: readonly FramePresent[];
|
|
11
11
|
onPresentChange?: (next: FramePresent) => void;
|
|
12
|
-
/**
|
|
12
|
+
/** Where the chart starts: a text column goes along its axis, a numeric one is the measure
|
|
13
|
+
* (its sum). By default, the first text column by the sum of the first numeric one. */
|
|
13
14
|
chartColumn?: string;
|
|
14
|
-
onChartColumnChange?: (id: string) => void;
|
|
15
15
|
visibleColumnIds?: readonly string[];
|
|
16
16
|
onVisibleColumnIdsChange?: (ids: readonly string[]) => void;
|
|
17
17
|
/** Search, filters, pagination: the same slots as a list. A frame inside a
|
|
@@ -30,4 +30,4 @@ export type FrameViewProps = {
|
|
|
30
30
|
*/
|
|
31
31
|
grouping?: Grouping<number>;
|
|
32
32
|
};
|
|
33
|
-
export declare function FrameView({ frame, identity, caption, present: presentProp, presents, onPresentChange, chartColumn
|
|
33
|
+
export declare function FrameView({ frame, identity, caption, present: presentProp, presents, onPresentChange, chartColumn, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }: FrameViewProps): import("react").JSX.Element;
|