@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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldPath } from "../search/FieldPath.js";
|
|
3
4
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
5
|
import { Menu } from "../../primitives/menu/Menu.js";
|
|
5
|
-
import { Columns3 } from "lucide-react";
|
|
6
|
+
import { Columns3, Plus } from "lucide-react";
|
|
6
7
|
/**
|
|
7
8
|
* The Odoo columns submenu: required fields stay checked and cannot be
|
|
8
9
|
* unchecked; optional fields toggle. It stays open while toggling so hiding
|
|
@@ -10,11 +11,20 @@ import { Columns3 } from "lucide-react";
|
|
|
10
11
|
*
|
|
11
12
|
* Drawn only when the set declared optional columns. A menu of required-only
|
|
12
13
|
* fields would be a list of things you cannot do.
|
|
14
|
+
*
|
|
15
|
+
* `addPath` adds «Agregar columna» next to it: a `FieldPath` that walks the relations, so a
|
|
16
|
+
* column can be a field of a related record («Cliente > País»). web-ui hands the chosen path
|
|
17
|
+
* back; turning it into a column — and asking the server for it — is the framework's.
|
|
13
18
|
*/
|
|
14
|
-
export function ColumnsMenu({ control, surface, }) {
|
|
19
|
+
export function ColumnsMenu({ control, surface, addPath, }) {
|
|
15
20
|
const copy = useUiCopy();
|
|
16
|
-
if (!control.hasOptional)
|
|
21
|
+
if (!control.hasOptional && addPath === undefined)
|
|
17
22
|
return null;
|
|
23
|
+
const picker = addPath === undefined ? null : (_jsx(FieldPath, { look: "button", icon: Plus, model: addPath.model, ...(addPath.loadModel === undefined ? {} : { loadModel: addPath.loadModel }), ...(addPath.filter === undefined ? {} : { filter: addPath.filter }), ...(addPath.followRelations === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: { followRelations: addPath.followRelations }), value: [], label: copy.fieldPath.addColumn, placeholder: copy.fieldPath.addColumn, onChange: addPath.onPick }));
|
|
26
|
+
if (!control.hasOptional)
|
|
27
|
+
return picker;
|
|
18
28
|
const requiredOptions = control.required.map((column) => ({
|
|
19
29
|
id: column.id,
|
|
20
30
|
label: column.label,
|
|
@@ -34,7 +44,8 @@ export function ColumnsMenu({ control, surface, }) {
|
|
|
34
44
|
{ label: copy.frame.optional, options: optionalOptions },
|
|
35
45
|
];
|
|
36
46
|
const hiddenOptional = control.optional.some((column) => !control.isVisible(column.id));
|
|
37
|
-
|
|
47
|
+
const menu = (_jsx(Menu, { label: copy.frame.columns, icon: Columns3, groups: groups, onSelect: control.toggle, closeOnSelect: false, active: hiddenOptional, ...(surface === undefined ? {} : { surface }), size: "sm" }));
|
|
48
|
+
return picker === null ? (menu) : (_jsxs("span", { className: "flex items-center gap-1.5", children: [menu, picker] }));
|
|
38
49
|
}
|
|
39
50
|
export function specsFromColumns(columns, fallbackOptional) {
|
|
40
51
|
return columns.map((column) => ({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GroupingControl } from "./grouping.js";
|
|
2
|
+
import { type PathPick } from "../search/FieldPath.js";
|
|
2
3
|
import { type GroupableField, type GroupGrain } from "../../foundations/grouping.js";
|
|
3
4
|
/**
|
|
4
5
|
* «AGRUPAR POR», adentro del panel de recortes.
|
|
@@ -31,5 +32,8 @@ export type GroupingLevelsProps = {
|
|
|
31
32
|
/** Cómo se llama cada grano, cuando el producto lo dice con otras palabras.
|
|
32
33
|
* Sin esto, las de la copia en el idioma activo. */
|
|
33
34
|
grainLabel?: (grain: GroupGrain) => string;
|
|
35
|
+
/** «Agrupar por otro campo»: un `FieldPath` que recorre relaciones («Cliente > País»).
|
|
36
|
+
* Devuelve el camino; qué nivel se pone con él lo decide quien orquesta la pantalla. */
|
|
37
|
+
addPath?: PathPick;
|
|
34
38
|
};
|
|
35
|
-
export declare function GroupingLevels({ fields, control, grainLabel }: GroupingLevelsProps): import("react").JSX.Element | null;
|
|
39
|
+
export declare function GroupingLevels({ fields, control, grainLabel, addPath, }: GroupingLevelsProps): import("react").JSX.Element | null;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { FieldPath } from "../search/FieldPath.js";
|
|
3
4
|
import { grainName } from "../../foundations/calendar.js";
|
|
4
5
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
6
|
import { GRAIN_ORDER, levelKey, } from "../../foundations/grouping.js";
|
|
6
|
-
import { ChevronDown, ChevronRight, ChevronUp, X } from "lucide-react";
|
|
7
|
+
import { ChevronDown, ChevronRight, ChevronUp, Plus, X } from "lucide-react";
|
|
7
8
|
import { useState } from "react";
|
|
8
9
|
function fieldLabel(fields, field) {
|
|
9
10
|
return fields.find((one) => one.field === field)?.label ?? field;
|
|
10
11
|
}
|
|
11
|
-
export function GroupingLevels({ fields, control, grainLabel }) {
|
|
12
|
+
export function GroupingLevels({ fields, control, grainLabel, addPath, }) {
|
|
12
13
|
const copy = useUiCopy();
|
|
13
14
|
/* Qué fechas están desplegadas. Arranca desplegada la que ya tenga algún grano
|
|
14
15
|
puesto: si no, lo puesto queda escondido detrás de un chevron y hay que
|
|
15
16
|
adivinar dónde. */
|
|
16
17
|
const [opened, setOpened] = useState(() => control.levels.filter((one) => one.grain !== undefined).map((one) => one.field));
|
|
17
|
-
if (fields.length === 0)
|
|
18
|
+
if (fields.length === 0 && addPath === undefined)
|
|
18
19
|
return null;
|
|
19
20
|
const placed = control.levels;
|
|
20
21
|
const grain = (one) => grainLabel?.(one) ?? grainName(one);
|
|
@@ -34,7 +35,9 @@ export function GroupingLevels({ fields, control, grainLabel }) {
|
|
|
34
35
|
const on = control.has(one.field, g);
|
|
35
36
|
return (_jsxs("button", { type: "button", onClick: () => control.toggle(one.field, g), "aria-pressed": on, className: `flex items-center gap-2 rounded-control px-1.5 py-1 text-left transition-colors duration-(--duration-instant) hover:bg-primary/8 ${on ? "bg-primary/6" : ""}`, children: [_jsx(Mark, { on: on }), _jsx("span", { className: `min-w-0 truncate text-meta ${on ? "font-medium text-ink" : "text-muted"}`, children: grain(g) })] }, g));
|
|
36
37
|
}) }))] }, one.field));
|
|
37
|
-
}),
|
|
38
|
+
}), addPath === undefined ? null : (_jsx("div", { className: "px-1 pt-1", children: _jsx(FieldPath, { look: "button", icon: Plus, model: addPath.model, ...(addPath.loadModel === undefined ? {} : { loadModel: addPath.loadModel }), ...(addPath.filter === undefined ? {} : { filter: addPath.filter }), ...(addPath.followRelations === undefined
|
|
39
|
+
? {}
|
|
40
|
+
: { followRelations: addPath.followRelations }), value: [], label: copy.fieldPath.addLevel, placeholder: copy.fieldPath.addLevel, onChange: addPath.onPick }) })), placed.length === 0 ? null : (_jsxs(_Fragment, { children: [_jsx("div", { className: "my-1 h-px bg-line", role: "separator" }), _jsx("button", { type: "button", onClick: () => control.clear(), className: "rounded-control px-2 py-1 text-left text-meta text-muted transition-colors duration-(--duration-instant) hover:bg-ink/4 hover:text-ink", children: copy.grouping.clear })] }))] }));
|
|
38
41
|
}
|
|
39
42
|
/** La marca de tildado. La columna existe SIEMPRE, tildada o no: sin ella,
|
|
40
43
|
* tildar corre el texto y la lista salta. Apagada se dibuja el aro, la misma
|
|
@@ -137,11 +137,11 @@ export function ListingBar({ actions, title, description, counters, selection, s
|
|
|
137
137
|
ONE dark band per screen. Without its own band the bar sat flush on the page and its
|
|
138
138
|
controls had nothing to belong to. */
|
|
139
139
|
if (!isChrome) {
|
|
140
|
-
return (_jsx(SurfaceProvider, { value: "canvas", children: _jsx("div", { className: `flex min-w-0 flex-col border-b border-line bg-surface ${byDensity(d, "px-
|
|
140
|
+
return (_jsx(SurfaceProvider, { value: "canvas", children: _jsx("div", { className: `flex min-w-0 flex-col border-b border-line bg-surface ${byDensity(d, "px-5 py-3", "px-2.5 py-2")}`, children: bar }) }));
|
|
141
141
|
}
|
|
142
142
|
/* On the chrome the bar IS the band: the background reaches the edges and
|
|
143
143
|
everything inside inherits the surface, so there is no way to forget to
|
|
144
144
|
pass it — which is how the status bar ended up with the canvas palette on
|
|
145
145
|
top of the navy. */
|
|
146
|
-
return (_jsx(SurfaceProvider, { value: "chrome", children: _jsx("div", { className: `flex min-w-0 flex-col bg-chrome ${byDensity(d, "px-
|
|
146
|
+
return (_jsx(SurfaceProvider, { value: "chrome", children: _jsx("div", { className: `flex min-w-0 flex-col bg-chrome ${byDensity(d, "px-5 py-3", "px-2.5 py-2")}`, children: bar }) }));
|
|
147
147
|
}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { AxisLevels, levelLabeler } from "./AxisLevels.js";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
5
|
import { pivotFrom } from "../../foundations/pivot.js";
|
|
6
6
|
import { downloadPivot } from "../../foundations/pivotSheet.js";
|
|
7
7
|
import { Button, IconButton } from "../../primitives/button/Button.js";
|
|
8
8
|
import { Menu } from "../../primitives/menu/Menu.js";
|
|
9
9
|
import { PivotTable } from "../../primitives/table/PivotTable.js";
|
|
10
|
-
import {
|
|
11
|
-
import { ArrowLeftRight, Download, Plus, Sigma } from "lucide-react";
|
|
10
|
+
import { ArrowLeftRight, Download, Sigma } from "lucide-react";
|
|
12
11
|
import { useMemo, useState } from "react";
|
|
13
|
-
const levelId = (level) => `${level.field}:${level.grain ?? ""}`;
|
|
14
|
-
const fromId = (id) => {
|
|
15
|
-
const [field = "", grain = ""] = id.split(":");
|
|
16
|
-
return grain === "" ? { field } : { field, grain: grain };
|
|
17
|
-
};
|
|
18
12
|
/**
|
|
19
13
|
* A pivot people actually pivot: what goes down the rows, what goes across the columns, which
|
|
20
14
|
* measures — chosen on the grid, not fixed in code.
|
|
@@ -34,36 +28,11 @@ export function PivotExplorer({ items, of, fields, measures, defaultMeasures, ro
|
|
|
34
28
|
const [chosen, setChosen] = useState(() => new Set(defaultMeasures ?? measures.slice(0, 1).map((one) => one.id)));
|
|
35
29
|
const rows = outerRows ?? ownRows;
|
|
36
30
|
const following = outerRows !== undefined;
|
|
37
|
-
const labelOf = (
|
|
38
|
-
const field = fields.find((one) => one.field === level.field)?.label ?? level.field;
|
|
39
|
-
return level.grain === undefined
|
|
40
|
-
? field
|
|
41
|
-
: `${field} · ${grainName(level.grain).toLowerCase()}`;
|
|
42
|
-
};
|
|
31
|
+
const labelOf = levelLabeler(fields);
|
|
43
32
|
const shownMeasures = measures.filter((one) => chosen.has(one.id));
|
|
44
33
|
const pivot = useMemo(() => pivotFrom(items, { rows, columns, of, measures: shownMeasures, labelOf }),
|
|
45
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
35
|
[items, rows, columns, of, shownMeasures.map((one) => one.id).join("|")]);
|
|
47
|
-
/* What can be added to an axis: every field (each grain of a date) not on either axis. */
|
|
48
|
-
const used = new Set([...rows, ...columns].map(levelId));
|
|
49
|
-
const options = fields.flatMap((field) => (field.grains ?? [undefined]).map((grain) => {
|
|
50
|
-
const level = grain === undefined ? { field: field.field } : { field: field.field, grain };
|
|
51
|
-
return {
|
|
52
|
-
id: levelId(level),
|
|
53
|
-
label: labelOf(level),
|
|
54
|
-
disabled: used.has(levelId(level)),
|
|
55
|
-
};
|
|
56
|
-
}));
|
|
57
|
-
const axis = (name, levels, set) => (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1.5", children: [_jsx("span", { className: "text-micro font-medium text-muted", children: name }), _jsx(Tags, { label: name, items: levels.map((level) => ({
|
|
58
|
-
id: levelId(level),
|
|
59
|
-
label: labelOf(level),
|
|
60
|
-
...(set === null
|
|
61
|
-
? {}
|
|
62
|
-
: {
|
|
63
|
-
onRemove: () => set(levels.filter((one) => levelId(one) !== levelId(level))),
|
|
64
|
-
removeLabel: fillCopy(words.removeLevel, { level: labelOf(level) }),
|
|
65
|
-
}),
|
|
66
|
-
})) }), set === null ? (_jsx("span", { className: "text-micro text-muted italic", children: words.fromSearch })) : (_jsx(Menu, { label: fillCopy(words.addLevel, { axis: name }), icon: Plus, iconOnly: true, chevron: false, variant: "text", groups: [{ options }], onSelect: (id) => set([...levels, fromId(id)]) }))] }));
|
|
67
36
|
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-5 gap-y-2", children: [_jsx(Menu, { label: words.measures, icon: Sigma, groups: [
|
|
68
37
|
{
|
|
69
38
|
options: measures.map((one) => ({
|
|
@@ -79,7 +48,7 @@ export function PivotExplorer({ items, of, fields, measures, defaultMeasures, ro
|
|
|
79
48
|
else
|
|
80
49
|
next.add(id);
|
|
81
50
|
return next;
|
|
82
|
-
}) }),
|
|
51
|
+
}) }), _jsx(AxisLevels, { name: words.rowsAxis, levels: rows, onChange: following ? null : setOwnRows, fields: fields, used: columns }), _jsx(AxisLevels, { name: words.columnsAxis, levels: columns, onChange: setColumns, fields: fields, used: rows }), _jsxs("div", { className: "ml-auto flex items-center gap-1", children: [following ? null : (_jsx(IconButton, { icon: ArrowLeftRight, label: words.swap, onClick: () => {
|
|
83
52
|
setOwnRows(columns);
|
|
84
53
|
setColumns(rows);
|
|
85
54
|
} })), _jsx(Button, { role: "ghost", size: "sm", icon: Download, onClick: () => downloadPivot(pivot, fileName === undefined ? {} : { name: fileName }), children: words.download })] })] }), _jsx(PivotTable, { pivot: pivot, ...(onCell === undefined ? {} : { onCell }), ...(height === undefined ? {} : { height }) })] }));
|
|
@@ -12,7 +12,9 @@ export { type Selection, useSelection } from "./selection.js";
|
|
|
12
12
|
export { type SetControl, useSetControl } from "./set.js";
|
|
13
13
|
export { toggleCollapsed, type TreeControl, useTreeControl, } from "./tree.js";
|
|
14
14
|
export { type ViewIcon, type ViewOption, ViewSwitcher, } from "./ViewSwitcher.js";
|
|
15
|
+
export { AxisLevels, levelId, levelLabeler, } from "./AxisLevels.js";
|
|
15
16
|
export { type BoardColumn, BoardColumns, type BoardStages, } from "./BoardColumns.js";
|
|
17
|
+
export { type ChartComparison, ChartExplorer, type ChartExplorerProps, } from "./ChartExplorer.js";
|
|
16
18
|
export { type GroupingControl, useGroupingControl, } from "./grouping.js";
|
|
17
19
|
export { GroupingLevels, type GroupingLevelsProps, } from "./GroupingLevels.js";
|
|
18
20
|
export { PivotExplorer, type PivotExplorerProps, } from "./PivotExplorer.js";
|
|
@@ -15,7 +15,9 @@ export { useSetControl } from "./set.js";
|
|
|
15
15
|
export { toggleCollapsed, useTreeControl, } from "./tree.js";
|
|
16
16
|
export { ViewSwitcher, } from "./ViewSwitcher.js";
|
|
17
17
|
/* El control de los niveles. El vocabulario está en `system/grouping.ts`. */
|
|
18
|
+
export { AxisLevels, levelId, levelLabeler, } from "./AxisLevels.js";
|
|
18
19
|
export { BoardColumns, } from "./BoardColumns.js";
|
|
20
|
+
export { ChartExplorer, } from "./ChartExplorer.js";
|
|
19
21
|
export { useGroupingControl, } from "./grouping.js";
|
|
20
22
|
export { GroupingLevels, } from "./GroupingLevels.js";
|
|
21
23
|
export { PivotExplorer, } from "./PivotExplorer.js";
|
|
@@ -32,8 +32,10 @@ import { type Pages } from "./pages.js";
|
|
|
32
32
|
* pivot dos EJES a la vez. Una fila es un montón y una columna
|
|
33
33
|
* también; lo que se lee está en el cruce. Tampoco se
|
|
34
34
|
* ordena: el orden de cada eje es el de sus claves.
|
|
35
|
+
* chart el mismo pivote, dibujado: barras, líneas o torta. El
|
|
36
|
+
* primer agrupado es el eje y el segundo, las series.
|
|
35
37
|
*/
|
|
36
|
-
export type BuiltInPresent = "rows" | "table" | "board" | "sheet" | "report" | "pivot" | "calendar" | "gantt" | "timeline";
|
|
38
|
+
export type BuiltInPresent = "rows" | "table" | "board" | "sheet" | "report" | "pivot" | "chart" | "calendar" | "gantt" | "timeline";
|
|
37
39
|
/** A presentation of a list: one the package draws, or the `id` of a `List.Present` the
|
|
38
40
|
* application wrote. `string & {}` keeps the built-in names in autocomplete. */
|
|
39
41
|
export type ListPresent = BuiltInPresent | (string & {});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type PreviewKind = "image" | "pdf" | "markdown" | "text" | "other";
|
|
2
|
+
export type PreviewFile = {
|
|
3
|
+
/** The file name as saved: it picks the kind together with `type`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Where the file downloads from. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** The MIME type, when the server knows it. */
|
|
8
|
+
type?: string;
|
|
9
|
+
/** In bytes. Written for the locale in the header. */
|
|
10
|
+
size?: number;
|
|
11
|
+
};
|
|
12
|
+
/** The renderer for a file. Pure, so the choice is tested without a browser. */
|
|
13
|
+
export declare function previewKind(name: string, type?: string): PreviewKind;
|
|
14
|
+
export type FilePreviewProps = {
|
|
15
|
+
file: PreviewFile;
|
|
16
|
+
/** The pdf.js worker, when the application serves it itself. */
|
|
17
|
+
pdfWorkerUrl?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function FilePreview({ file, pdfWorkerUrl }: FilePreviewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { attachmentKind, fileExtension, formatFileSize, } from "../attachments/files.js";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { Button, ButtonLink } from "../../primitives/button/Button.js";
|
|
6
|
+
import { Empty, Failed, Skeleton } from "../../primitives/notice/Notice.js";
|
|
7
|
+
import { Download } from "lucide-react";
|
|
8
|
+
import { lazy, Suspense, useEffect, useState } from "react";
|
|
9
|
+
/* ==================================================================== *
|
|
10
|
+
* FILE PREVIEW — the file itself, drawn by what it is.
|
|
11
|
+
*
|
|
12
|
+
* Context: `Attachments` lists a record's files and says WHERE to open one
|
|
13
|
+
* (`onOpen`); this is what the application puts there — a peek, a side panel,
|
|
14
|
+
* a modal of the composer — so the person sees the file without leaving the
|
|
15
|
+
* record. The renderer is chosen by the file's kind, and the kinds with no
|
|
16
|
+
* honest preview (a spreadsheet, a Word file) say so and keep the download.
|
|
17
|
+
*
|
|
18
|
+
* ── Each renderer costs only when it is used ────────────────────────
|
|
19
|
+
*
|
|
20
|
+
* image an <img>, fit to the pane or at its real size
|
|
21
|
+
* pdf pdf.js, loaded on demand (PdfPreview)
|
|
22
|
+
* markdown streamdown, sanitized (Markdown)
|
|
23
|
+
* text the text in mono, up to a limit (a log can be gigabytes)
|
|
24
|
+
* other the icon's name and the download — no preview pretended
|
|
25
|
+
*
|
|
26
|
+
* ── The download is always there ────────────────────────────────────
|
|
27
|
+
*
|
|
28
|
+
* Whatever can or cannot be drawn, the file can be taken: a real `<a
|
|
29
|
+
* download>`, the same one the list uses, so the browser's own download
|
|
30
|
+
* manager keeps a large file out of the tab's memory.
|
|
31
|
+
* ==================================================================== */
|
|
32
|
+
/** The PDF renderer is its own chunk: pdf.js is not in the main bundle. */
|
|
33
|
+
const PdfPreview = lazy(() => import("./PdfPreview.js"));
|
|
34
|
+
/** streamdown is ~160 KB gzipped: a preview of an image or a PDF does not pay for it. */
|
|
35
|
+
const MarkdownView = lazy(() => import("../../primitives/value/Markdown.js").then((m) => ({ default: m.Markdown })));
|
|
36
|
+
/** A text preview larger than this is not read into the tab: download instead. */
|
|
37
|
+
const MAX_TEXT_BYTES = 1_000_000;
|
|
38
|
+
const TEXT_EXTENSIONS = new Set(["txt", "csv", "json", "log", "xml", "yaml", "yml"]);
|
|
39
|
+
const MARKDOWN_EXTENSIONS = new Set(["md", "markdown"]);
|
|
40
|
+
/** The renderer for a file. Pure, so the choice is tested without a browser. */
|
|
41
|
+
export function previewKind(name, type) {
|
|
42
|
+
const kind = attachmentKind(name, type);
|
|
43
|
+
if (kind === "image" || kind === "pdf")
|
|
44
|
+
return kind;
|
|
45
|
+
const extension = fileExtension(name).toLowerCase();
|
|
46
|
+
if (MARKDOWN_EXTENSIONS.has(extension))
|
|
47
|
+
return "markdown";
|
|
48
|
+
if (TEXT_EXTENSIONS.has(extension) || type?.startsWith("text/") === true)
|
|
49
|
+
return "text";
|
|
50
|
+
return "other";
|
|
51
|
+
}
|
|
52
|
+
export function FilePreview({ file, pdfWorkerUrl }) {
|
|
53
|
+
const copy = useUiCopy();
|
|
54
|
+
const kind = previewKind(file.name, file.type);
|
|
55
|
+
const size = file.size === undefined ? "" : ` · ${formatFileSize(file.size, copy.locale)}`;
|
|
56
|
+
return (_jsxs("section", { "aria-label": file.name, className: "flex min-h-0 flex-col gap-4", children: [_jsxs("header", { className: "flex flex-wrap items-center gap-x-4 gap-y-2", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "truncate text-body font-medium text-ink", children: file.name }), _jsxs("p", { className: "text-meta text-muted", children: [copy.preview.kind[kind], size] })] }), _jsx(ButtonLink, { href: file.url, download: file.name, role: "secondary", size: "sm", icon: Download, children: copy.preview.download })] }), _jsx("div", { className: "flex min-h-0 flex-1 justify-center overflow-auto rounded-control bg-ground p-5", children: _jsx(Body, { kind: kind, file: file, pdfWorkerUrl: pdfWorkerUrl }) })] }));
|
|
57
|
+
}
|
|
58
|
+
function Body({ kind, file, pdfWorkerUrl, }) {
|
|
59
|
+
const copy = useUiCopy();
|
|
60
|
+
if (kind === "image")
|
|
61
|
+
return _jsx(ImagePreview, { file: file });
|
|
62
|
+
if (kind === "pdf") {
|
|
63
|
+
return (_jsx(Suspense, { fallback: _jsx(Skeleton, { rows: 3, label: copy.preview.loading }), children: _jsx(PdfPreview, { url: file.url, workerUrl: pdfWorkerUrl }) }));
|
|
64
|
+
}
|
|
65
|
+
if (kind === "markdown" || kind === "text")
|
|
66
|
+
return _jsx(TextPreview, { kind: kind, file: file });
|
|
67
|
+
return _jsx(Unsupported, {});
|
|
68
|
+
}
|
|
69
|
+
function ImagePreview({ file }) {
|
|
70
|
+
const copy = useUiCopy();
|
|
71
|
+
const [actual, setActual] = useState(false);
|
|
72
|
+
return (_jsxs("div", { className: "flex flex-col items-center gap-3", children: [_jsx(Button, { role: "ghost", size: "sm", onClick: () => setActual((a) => !a), children: actual ? copy.preview.fit : copy.preview.actualSize }), _jsx("img", { src: file.url, alt: file.name, className: actual ? "max-w-none" : "max-h-full max-w-full object-contain" })] }));
|
|
73
|
+
}
|
|
74
|
+
function TextPreview({ kind, file }) {
|
|
75
|
+
const copy = useUiCopy();
|
|
76
|
+
const [text, setText] = useState(null);
|
|
77
|
+
const [failure, setFailure] = useState(null);
|
|
78
|
+
const tooLarge = file.size !== undefined && file.size > MAX_TEXT_BYTES;
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (tooLarge)
|
|
81
|
+
return;
|
|
82
|
+
const controller = new AbortController();
|
|
83
|
+
fetch(file.url, { signal: controller.signal })
|
|
84
|
+
.then((response) => {
|
|
85
|
+
if (!response.ok)
|
|
86
|
+
throw new Error(`HTTP ${response.status}`);
|
|
87
|
+
return response.text();
|
|
88
|
+
})
|
|
89
|
+
.then((body) => setText(body))
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
if (controller.signal.aborted)
|
|
92
|
+
return;
|
|
93
|
+
setFailure(error instanceof Error ? error.message : String(error));
|
|
94
|
+
});
|
|
95
|
+
return () => controller.abort();
|
|
96
|
+
}, [file.url, tooLarge]);
|
|
97
|
+
if (tooLarge)
|
|
98
|
+
return _jsx(Unsupported, {});
|
|
99
|
+
if (failure !== null) {
|
|
100
|
+
return (_jsx(Failed, { heading: copy.preview.failed, sentence: copy.preview.unsupported, detail: failure }));
|
|
101
|
+
}
|
|
102
|
+
if (text === null)
|
|
103
|
+
return _jsx(Skeleton, { rows: 4, label: copy.preview.loading });
|
|
104
|
+
if (kind === "markdown") {
|
|
105
|
+
return (_jsx("div", { className: "w-full", children: _jsx(Suspense, { fallback: _jsx(Skeleton, { rows: 4, label: copy.preview.loading }), children: _jsx(MarkdownView, { label: file.name, children: text }) }) }));
|
|
106
|
+
}
|
|
107
|
+
return (_jsx("pre", { className: "w-full font-mono text-meta leading-relaxed whitespace-pre-wrap text-ink select-text", children: text }));
|
|
108
|
+
}
|
|
109
|
+
function Unsupported() {
|
|
110
|
+
const copy = useUiCopy();
|
|
111
|
+
return _jsx(Empty, { sentence: copy.preview.unsupported });
|
|
112
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type PdfPreviewProps = {
|
|
2
|
+
/** Where the PDF downloads from. Same origin, or a CORS-enabled host. */
|
|
3
|
+
url: string;
|
|
4
|
+
/** The pdf.js worker. Absent = the one shipped with the dependency. */
|
|
5
|
+
workerUrl?: string;
|
|
6
|
+
};
|
|
7
|
+
export default function PdfPreview({ url, workerUrl }: PdfPreviewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { IconButton } from "../../primitives/button/Button.js";
|
|
5
|
+
import { Failed } from "../../primitives/notice/Notice.js";
|
|
6
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { Document, Page, pdfjs } from "react-pdf";
|
|
9
|
+
/* ==================================================================== *
|
|
10
|
+
* THE PDF RENDERER — pdf.js through react-pdf, loaded on demand.
|
|
11
|
+
*
|
|
12
|
+
* Context: pdf.js is about a megabyte of code, and most screens never open a
|
|
13
|
+
* PDF. So this module is NOT part of the package's main entry: `FilePreview`
|
|
14
|
+
* loads it with `lazy()`, the bundler splits it into its own chunk, and the
|
|
15
|
+
* chunk arrives only when a person opens a PDF. The tests in Node never import
|
|
16
|
+
* it (pdf.js expects a browser).
|
|
17
|
+
*
|
|
18
|
+
* ── The worker runs off the page ────────────────────────────────────
|
|
19
|
+
*
|
|
20
|
+
* Parsing a PDF is heavy, so pdf.js does it in a Web Worker. The default
|
|
21
|
+
* worker is resolved from this package's own dependency, which a modern
|
|
22
|
+
* bundler (Vite, webpack 5) copies with the chunk. An application that
|
|
23
|
+
* serves the worker from its own origin or a CDN passes `workerUrl`.
|
|
24
|
+
*
|
|
25
|
+
* ── Text and links are not drawn as layers ─────────────────────────
|
|
26
|
+
*
|
|
27
|
+
* react-pdf can paint a selectable text layer and clickable link layer; both
|
|
28
|
+
* need their own stylesheets. The preview is for reading and printing, not
|
|
29
|
+
* for editing, so both are off: one less stylesheet to ship, and no layers to
|
|
30
|
+
* misalign at a zoom the browser chose.
|
|
31
|
+
* ==================================================================== */
|
|
32
|
+
const DEFAULT_WORKER = new URL("pdfjs-dist/build/pdf.worker.min.mjs", import.meta.url).toString();
|
|
33
|
+
export default function PdfPreview({ url, workerUrl }) {
|
|
34
|
+
const copy = useUiCopy();
|
|
35
|
+
/* The worker is a global of pdf.js: setting it again to the same value is a no-op. */
|
|
36
|
+
pdfjs.GlobalWorkerOptions.workerSrc = workerUrl ?? DEFAULT_WORKER;
|
|
37
|
+
const [total, setTotal] = useState(0);
|
|
38
|
+
const [page, setPage] = useState(1);
|
|
39
|
+
const [failure, setFailure] = useState(null);
|
|
40
|
+
if (failure !== null) {
|
|
41
|
+
return (_jsx(Failed, { heading: copy.preview.failed, sentence: copy.preview.unsupported, detail: failure }));
|
|
42
|
+
}
|
|
43
|
+
return (_jsxs("div", { className: "flex min-h-0 flex-col items-center gap-3", children: [_jsxs("nav", { "aria-label": copy.preview.label, className: "flex items-center gap-2", children: [_jsx(IconButton, { icon: ChevronLeft, label: copy.preview.previousPage, disabled: page <= 1, onClick: () => setPage((p) => Math.max(1, p - 1)) }), _jsx("span", { className: "min-w-28 text-center text-meta text-muted tabular-nums", "aria-live": "polite", children: fillCopy(copy.preview.page, { page: String(page), total: String(total) }) }), _jsx(IconButton, { icon: ChevronRight, label: copy.preview.nextPage, disabled: total === 0 || page >= total, onClick: () => setPage((p) => Math.min(total, p + 1)) })] }), _jsx(Document, { file: url, loading: _jsx("p", { className: "text-meta text-muted", children: copy.preview.loading }), onLoadSuccess: ({ numPages }) => {
|
|
44
|
+
setTotal(numPages);
|
|
45
|
+
setPage(1);
|
|
46
|
+
}, onLoadError: (error) => setFailure(error.message), onSourceError: (error) => setFailure(error.message), children: _jsx(Page, { pageNumber: page, renderTextLayer: false, renderAnnotationLayer: false, className: "overflow-hidden rounded-control border border-line bg-surface shadow-sm" }) })] }));
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FilePreview, type FilePreviewProps, type PreviewFile, type PreviewKind, previewKind, } from "./FilePreview.js";
|
|
@@ -34,5 +34,5 @@ export function SmartButtons({ children }) {
|
|
|
34
34
|
return _jsx("div", { className: "flex flex-wrap items-stretch gap-1.5", children: children });
|
|
35
35
|
}
|
|
36
36
|
const items = Children.toArray(children);
|
|
37
|
-
return (_jsx(SmartGroup.Provider, { value: true, children: _jsx("div", { className: "flex min-w-0 items-stretch
|
|
37
|
+
return (_jsx(SmartGroup.Provider, { value: true, children: _jsx("div", { className: "scroll-quiet flex max-w-full min-w-0 items-stretch rounded-control border border-chrome-ink/15 bg-chrome-ink/8", children: items.map((child, i) => (_jsx("div", { className: i === 0 ? "flex shrink-0" : "flex shrink-0 border-l border-chrome-ink/20", children: child }, i))) }) }));
|
|
38
38
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type FieldDefinition, type ModelDefinition } from "./model.js";
|
|
2
|
+
import { type FieldPathStep, type FieldPathValue, type LoadModel, type ModelCache } from "./paths.js";
|
|
3
|
+
import { type LucideIcon } from "lucide-react";
|
|
4
|
+
/** A rule about a field met while walking: its definition, its name, and the path of
|
|
5
|
+
* relations that leads to its model (`[]` at the root). */
|
|
6
|
+
export type FieldPathRule = (field: FieldDefinition, name: string, at: FieldPathValue) => boolean;
|
|
7
|
+
export type FieldPathProps = {
|
|
8
|
+
/** The root model: the record the path starts from. */
|
|
9
|
+
model: ModelDefinition;
|
|
10
|
+
/** The model at the end of a path of relations. Absent = relations are not walked. */
|
|
11
|
+
loadModel?: LoadModel;
|
|
12
|
+
/** A cache shared with other pickers over the same root. Absent = one of its own. */
|
|
13
|
+
models?: ModelCache;
|
|
14
|
+
/** The chosen path; `[]` is nothing chosen. */
|
|
15
|
+
value: FieldPathValue;
|
|
16
|
+
/** The new path, with each step's definition and label already resolved. */
|
|
17
|
+
onChange: (path: string[], steps: FieldPathStep[]) => void;
|
|
18
|
+
/** Which fields can be chosen. Absent = all of them. */
|
|
19
|
+
filter?: FieldPathRule;
|
|
20
|
+
/** Which relations open. Default: all, when `loadModel` is there. */
|
|
21
|
+
followRelations?: boolean | FieldPathRule;
|
|
22
|
+
/** The accessible name of the trigger and of the popover: «Campo», «Columna». */
|
|
23
|
+
label: string;
|
|
24
|
+
/** What the trigger says with nothing chosen. Default: «Elegir un campo». */
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
/** `select` reads like the other controls of a row; `button` is a toolbar action
|
|
27
|
+
* («Agregar columna») that always shows its placeholder. */
|
|
28
|
+
look?: "select" | "button";
|
|
29
|
+
/** The icon of the `button` look. */
|
|
30
|
+
icon?: LucideIcon;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A `FieldPath` offered as an ACTION of another piece: «Agregar columna» in the columns menu,
|
|
34
|
+
* «Agrupar por otro campo» in the grouping panel. The piece draws the button; what the chosen
|
|
35
|
+
* path becomes — a column, a level — is decided by whoever orchestrates the screen.
|
|
36
|
+
*/
|
|
37
|
+
export type PathPick = {
|
|
38
|
+
model: ModelDefinition;
|
|
39
|
+
loadModel?: LoadModel;
|
|
40
|
+
filter?: FieldPathRule;
|
|
41
|
+
followRelations?: FieldPathProps["followRelations"];
|
|
42
|
+
onPick: (path: string[], steps: FieldPathStep[]) => void;
|
|
43
|
+
};
|
|
44
|
+
/** The cache a picker uses: the one it was given, or its own over its root. */
|
|
45
|
+
export declare function useModelCache(model: ModelDefinition, loadModel?: LoadModel, models?: ModelCache): ModelCache;
|
|
46
|
+
/**
|
|
47
|
+
* The steps of a path, once its models arrived: `undefined` while they come, `null` when the
|
|
48
|
+
* path does not exist in the model (or a model could not be loaded).
|
|
49
|
+
*
|
|
50
|
+
* The rows of a filter use it to learn the LAST field's operators and type: «Monto» reached
|
|
51
|
+
* through two relations compares like a number, not like the relation it came through.
|
|
52
|
+
*/
|
|
53
|
+
export declare function useFieldPathSteps(models: ModelCache, path: FieldPathValue): FieldPathStep[] | null | undefined;
|
|
54
|
+
export declare function FieldPath({ model, loadModel, models: shared, value, onChange, filter, followRelations, label, placeholder, look, icon, }: FieldPathProps): import("react").JSX.Element;
|