@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.
Files changed (95) hide show
  1. package/dist/components/board/Board.d.ts +51 -0
  2. package/dist/components/board/Board.js +15 -0
  3. package/dist/components/board/index.d.ts +1 -0
  4. package/dist/components/board/index.js +2 -0
  5. package/dist/components/canvas/Canvas.d.ts +14 -0
  6. package/dist/components/canvas/Canvas.js +9 -0
  7. package/dist/components/canvas/canvas.css +19 -0
  8. package/dist/components/canvas/index.d.ts +1 -0
  9. package/dist/components/canvas/index.js +2 -0
  10. package/dist/components/chat/ChatComposer.d.ts +10 -0
  11. package/dist/components/chat/ChatComposer.js +29 -0
  12. package/dist/components/chat/ChatThread.d.ts +13 -0
  13. package/dist/components/chat/ChatThread.js +76 -0
  14. package/dist/components/chat/ConversationList.d.ts +22 -0
  15. package/dist/components/chat/ConversationList.js +22 -0
  16. package/dist/components/chat/index.d.ts +4 -0
  17. package/dist/components/chat/index.js +5 -0
  18. package/dist/components/chat/model.d.ts +30 -0
  19. package/dist/components/chat/model.js +53 -0
  20. package/dist/components/frame/Chart.d.ts +12 -7
  21. package/dist/components/frame/Chart.js +17 -17
  22. package/dist/components/frame/FrameView.d.ts +3 -3
  23. package/dist/components/frame/FrameView.js +79 -26
  24. package/dist/components/frame/model.d.ts +12 -3
  25. package/dist/components/frame/model.js +53 -19
  26. package/dist/components/index.d.ts +4 -0
  27. package/dist/components/index.js +4 -0
  28. package/dist/components/listing/AxisLevels.d.ts +24 -0
  29. package/dist/components/listing/AxisLevels.js +58 -0
  30. package/dist/components/listing/ChartExplorer.d.ts +79 -0
  31. package/dist/components/listing/ChartExplorer.js +114 -0
  32. package/dist/components/listing/ColumnsMenu.d.ts +7 -1
  33. package/dist/components/listing/ColumnsMenu.js +16 -5
  34. package/dist/components/listing/GroupingLevels.d.ts +5 -1
  35. package/dist/components/listing/GroupingLevels.js +7 -4
  36. package/dist/components/listing/ListingBar.js +2 -2
  37. package/dist/components/listing/PivotExplorer.js +5 -36
  38. package/dist/components/listing/index.d.ts +2 -0
  39. package/dist/components/listing/index.js +2 -0
  40. package/dist/components/listing/set.d.ts +3 -1
  41. package/dist/components/preview/FilePreview.d.ts +19 -0
  42. package/dist/components/preview/FilePreview.js +112 -0
  43. package/dist/components/preview/PdfPreview.d.ts +7 -0
  44. package/dist/components/preview/PdfPreview.js +47 -0
  45. package/dist/components/preview/index.d.ts +1 -0
  46. package/dist/components/preview/index.js +2 -0
  47. package/dist/components/record/SmartButtons.js +1 -1
  48. package/dist/components/search/FieldPath.d.ts +54 -0
  49. package/dist/components/search/FieldPath.js +159 -0
  50. package/dist/components/search/FilterBuilder.d.ts +38 -5
  51. package/dist/components/search/FilterBuilder.js +129 -25
  52. package/dist/components/search/SearchBar.js +7 -2
  53. package/dist/components/search/criteria.d.ts +23 -1
  54. package/dist/components/search/index.d.ts +4 -2
  55. package/dist/components/search/index.js +4 -0
  56. package/dist/components/search/paths.d.ts +49 -0
  57. package/dist/components/search/paths.js +75 -0
  58. package/dist/components/shell/TopBar.js +1 -1
  59. package/dist/foundations/calendar.d.ts +15 -0
  60. package/dist/foundations/calendar.js +59 -1
  61. package/dist/foundations/chart.d.ts +126 -0
  62. package/dist/foundations/chart.js +297 -0
  63. package/dist/foundations/copy.d.ts +125 -0
  64. package/dist/foundations/copy.es.js +90 -0
  65. package/dist/foundations/copy.js +84 -0
  66. package/dist/foundations/index.d.ts +2 -1
  67. package/dist/foundations/index.js +4 -1
  68. package/dist/foundations/pivot.d.ts +9 -0
  69. package/dist/foundations/pivot.js +1 -0
  70. package/dist/primitives/chart/Chart.d.ts +39 -0
  71. package/dist/primitives/chart/Chart.js +235 -0
  72. package/dist/primitives/chart/index.d.ts +1 -0
  73. package/dist/primitives/chart/index.js +1 -0
  74. package/dist/primitives/field/Field.js +2 -1
  75. package/dist/primitives/index.d.ts +1 -0
  76. package/dist/primitives/index.js +1 -0
  77. package/dist/primitives/notice/Callout.d.ts +4 -1
  78. package/dist/primitives/notice/Callout.js +12 -2
  79. package/dist/primitives/notice/Notice.d.ts +26 -2
  80. package/dist/primitives/notice/Notice.js +64 -4
  81. package/dist/primitives/notice/Toast.js +10 -1
  82. package/dist/primitives/value/Markdown.d.ts +9 -0
  83. package/dist/primitives/value/Markdown.js +18 -0
  84. package/dist/primitives/value/Metric.d.ts +13 -2
  85. package/dist/primitives/value/Metric.js +25 -3
  86. package/dist/primitives/value/index.d.ts +1 -0
  87. package/dist/primitives/value/index.js +1 -0
  88. package/dist/tokens.css +73 -0
  89. package/dist/views/list/List.d.ts +2 -1
  90. package/dist/views/list/List.js +8 -1
  91. package/dist/views/list/ListView.d.ts +1 -1
  92. package/dist/views/list/ListView.js +37 -5
  93. package/dist/views/list/index.d.ts +1 -1
  94. package/dist/views/list/types.d.ts +34 -0
  95. package/package.json +5 -1
@@ -1,19 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { SeriesChart } from "./Chart.js";
4
- import { columnSeries, withColumns, } from "./model.js";
3
+ import { cellNumber, withColumns, } from "./model.js";
5
4
  import { useColumnControl } from "../listing/columns.js";
6
5
  import { ColumnsMenu, specsFromColumns, } from "../listing/ColumnsMenu.js";
7
6
  import { Listing } from "../listing/Listing.js";
8
7
  import { ListingBar } from "../listing/ListingBar.js";
9
8
  import { ViewSwitcher } from "../listing/ViewSwitcher.js";
10
- import { useUiCopy } from "../../foundations/copy.js";
9
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
11
10
  import { pathKey, pileIsOpen, pilesOf, } from "../../foundations/grouping.js";
12
- import { Menu } from "../../primitives/menu/Menu.js";
13
- import { Empty } from "../../primitives/notice/Notice.js";
11
+ import { Empty, Skeleton } from "../../primitives/notice/Notice.js";
14
12
  import { SheetTable } from "../../primitives/table/SheetTable.js";
15
13
  import { BarChart3, Table2 } from "lucide-react";
16
- import { useMemo, useState } from "react";
14
+ import { lazy, Suspense, useMemo, useState } from "react";
15
+ /* The chart (Recharts) is fetched the first time a frame is drawn as one. */
16
+ const ChartExplorer = lazy(() => import("../listing/ChartExplorer.js").then((module) => ({
17
+ default: module.ChartExplorer,
18
+ })));
17
19
  /**
18
20
  * ARCHETYPE 3 — a FRAME: the cells of a payload, as a table or as a chart.
19
21
  *
@@ -32,15 +34,11 @@ const PRESENT_ICONS = [
32
34
  { id: "table", icon: Table2 },
33
35
  { id: "chart", icon: BarChart3 },
34
36
  ];
35
- export function FrameView({ frame, identity, caption, present: presentProp, presents = ["table", "chart"], onPresentChange, chartColumn: chartColumnProp, onChartColumnChange, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }) {
37
+ export function FrameView({ frame, identity, caption, present: presentProp, presents = ["table", "chart"], onPresentChange, chartColumn, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }) {
36
38
  const copy = useUiCopy();
37
39
  const [ownedPresent, setOwnedPresent] = useState(presentProp ?? "table");
38
40
  const present = onPresentChange !== undefined ? (presentProp ?? "table") : ownedPresent;
39
41
  const setPresent = onPresentChange ?? setOwnedPresent;
40
- const defaultChart = frame.columns.find((column) => column.numeric)?.id ?? frame.columns[0]?.id ?? "";
41
- const [ownedChart, setOwnedChart] = useState(chartColumnProp ?? defaultChart);
42
- const chartColumn = onChartColumnChange !== undefined ? (chartColumnProp ?? defaultChart) : ownedChart;
43
- const setChartColumn = onChartColumnChange ?? setOwnedChart;
44
42
  const columnSpecs = useMemo(() => specsFromColumns(frame.columns, true), [frame.columns]);
45
43
  const columns = useColumnControl(columnSpecs, {
46
44
  ...(visibleColumnIds === undefined ? {} : { visibleIds: visibleColumnIds }),
@@ -83,29 +81,84 @@ export function FrameView({ frame, identity, caption, present: presentProp, pres
83
81
  walk(piles);
84
82
  return out;
85
83
  }, [shown.rows, grouping]);
86
- const series = useMemo(() => (present === "chart" ? columnSeries(shown, chartColumn) : []), [present, shown, chartColumn]);
84
+ /* The chart folds ROW INDICES, the same way the grouping does: a text column splits them
85
+ (along the axis or into series) and a numeric one is summed or averaged. All the
86
+ columns, hidden ones too — hiding is about the table, not about what can be asked. */
87
+ const chart = useMemo(() => {
88
+ const indexOf = new Map(frame.columns.map((column, index) => [column.id, index]));
89
+ const cell = (row, id) => {
90
+ const at = indexOf.get(id);
91
+ const column = at === undefined ? undefined : frame.columns[at];
92
+ return column === undefined || at === undefined ? null : frame.value(row, column, at);
93
+ };
94
+ const texts = frame.columns.filter((column) => column.numeric !== true);
95
+ const numbers = frame.columns.filter((column) => column.numeric === true);
96
+ const fields = (texts.length > 0 ? texts : frame.columns).map((column) => ({
97
+ field: column.id,
98
+ label: column.header,
99
+ }));
100
+ const values = (rows, id) => rows.map((row) => cellNumber(cell(row, id))).filter((n) => n !== null);
101
+ const measures = numbers.flatMap((column) => [
102
+ {
103
+ id: `sum:${column.id}`,
104
+ header: fillCopy(copy.chart.sumOf, { name: column.header }),
105
+ additive: true,
106
+ fold: (rows) => {
107
+ const found = values(rows, column.id);
108
+ return found.length === 0 ? null : found.reduce((a, b) => a + b, 0);
109
+ },
110
+ },
111
+ {
112
+ id: `avg:${column.id}`,
113
+ header: fillCopy(copy.chart.averageOf, { name: column.header }),
114
+ fold: (rows) => {
115
+ const found = values(rows, column.id);
116
+ return found.length === 0 ? null : found.reduce((a, b) => a + b, 0) / found.length;
117
+ },
118
+ },
119
+ ]);
120
+ /* Where the axis starts: the text column that GROUPS — the fewest distinct values, two
121
+ at least. An identifier (one value per row) charts a bar per row, which is the table
122
+ again; a column with one value charts a single bar. */
123
+ const distinct = (id) => {
124
+ const seen = new Set();
125
+ for (let row = 0; row < frame.rows; row += 1)
126
+ seen.add(String(cell(row, id)));
127
+ return seen.size;
128
+ };
129
+ const splits = fields
130
+ .map((field) => ({ field: field.field, count: distinct(field.field) }))
131
+ .filter((one) => one.count >= 2 && one.count < frame.rows)
132
+ .sort((a, b) => a.count - b.count)[0]?.field;
133
+ const start = frame.columns.find((column) => column.id === chartColumn);
134
+ const axis = start !== undefined && start.numeric !== true ? start.id : (splits ?? fields[0]?.field);
135
+ const measure = start?.numeric === true ? `sum:${start.id}` : (measures[0]?.id ?? undefined);
136
+ return {
137
+ items: Array.from({ length: frame.rows }, (_, index) => index),
138
+ of: (row, level) => {
139
+ const value = cell(row, level.field);
140
+ return value === null || value === "" ? copy.cell.emptyBin : String(value);
141
+ },
142
+ fields,
143
+ measures,
144
+ axis,
145
+ measure,
146
+ };
147
+ }, [frame, chartColumn, copy]);
87
148
  const switcher = presents.length > 1 ? (_jsx(ViewSwitcher, { options: PRESENT_ICONS.filter((option) => presents.includes(option.id)).map((option) => ({
88
149
  id: option.id,
89
150
  label: option.id === "table" ? copy.present.table : copy.present.chart,
90
151
  icon: option.icon,
91
152
  })), current: present, onSelect: (id) => setPresent(id) })) : undefined;
92
- const chartMenu = present === "chart" ? (_jsx(Menu, { label: copy.frame.series, groups: [
93
- {
94
- label: copy.frame.column,
95
- options: shown.columns.map((column) => ({
96
- id: column.id,
97
- label: column.type === undefined
98
- ? column.header
99
- : `${column.header} · ${column.type}`,
100
- checked: column.id === chartColumn,
101
- })),
102
- },
103
- ], onSelect: setChartColumn })) : null;
104
- const bar = (_jsx(ListingBar, { ...(identity?.title === undefined ? {} : { title: identity.title }), ...(identity?.description === undefined ? {} : { description: identity.description }), ...(identity?.counters === undefined ? {} : { counters: identity.counters }), ...(search === undefined ? {} : { search }), ...(pagination === undefined ? {} : { pagination }), views: _jsxs(_Fragment, { children: [_jsx(ColumnsMenu, { control: columns }), chartMenu, switcher] }) }));
153
+ const bar = (_jsx(ListingBar, { ...(identity?.title === undefined ? {} : { title: identity.title }), ...(identity?.description === undefined ? {} : { description: identity.description }), ...(identity?.counters === undefined ? {} : { counters: identity.counters }), ...(search === undefined ? {} : { search }), ...(pagination === undefined ? {} : { pagination }), views: _jsxs(_Fragment, { children: [present === "chart" ? null : _jsx(ColumnsMenu, { control: columns }), switcher] }) }));
105
154
  if (frame.rows === 0 || frame.columns.length === 0) {
106
155
  return (_jsx(Listing, { bar: bar, children: _jsx(Empty, { sentence: copy.frame.empty }) }));
107
156
  }
108
- return (_jsx(Listing, { bar: bar, children: present === "chart" ? (_jsx(SeriesChart, { series: series })) : (_jsx(SheetTable, { columns: shown.columns, rows: bands === null ? shown.rows : bands.length, value: (index, column, columnIndex) => {
157
+ return (_jsx(Listing, { bar: bar, children: present === "chart" ? (_jsx("div", { className: "p-3", children: _jsx(Suspense, { fallback: _jsx(Skeleton, { label: copy.failed.loading }), children: _jsx(ChartExplorer, { items: chart.items,
158
+ /* Following the frame's grouping, its levels are read the way it reads them. */
159
+ of: grouping !== undefined && grouping.levels.length > 0 ? grouping.of : chart.of, fields: chart.fields, measures: chart.measures, ...(chart.axis === undefined
160
+ ? {}
161
+ : { defaultCategories: [{ field: chart.axis }] }), ...(chart.measure === undefined ? {} : { defaultMeasure: chart.measure }), ...((grouping?.levels.length ?? 0) > 0 ? { levels: grouping.levels } : {}), ...(identity?.title === undefined ? {} : { label: identity.title }) }) }) })) : (_jsx(SheetTable, { columns: shown.columns, rows: bands === null ? shown.rows : bands.length, value: (index, column, columnIndex) => {
109
162
  const row = bands === null ? index : bands[index]?.row;
110
163
  return row === undefined ? null : shown.value(row, column, columnIndex);
111
164
  }, height: "auto", ...(bands === null
@@ -31,13 +31,22 @@ export type FramePresent = "table" | "chart";
31
31
  export type SeriesBar = {
32
32
  label: string;
33
33
  count: number;
34
+ /** A stretch of a numeric column, `[from, to)` — the last one closed. Present = the
35
+ * bars are a histogram: they go side by side along a number line, not ranked. */
36
+ bin?: {
37
+ from: number;
38
+ to: number;
39
+ };
34
40
  };
35
41
  export declare function frameFromRows(columns: readonly FrameColumn[], rows: readonly (readonly FrameCell[])[]): Frame;
36
42
  /** Keep only some columns. The cells still come from the original frame. */
37
43
  export declare function withColumns(frame: Frame, ids: readonly string[]): Frame;
44
+ /** A cell read as a number: a number, or a text that writes one («12,5»). Anything else is
45
+ * `null` — not a zero. */
46
+ export declare function cellNumber(cell: FrameCell): number | null;
38
47
  /**
39
- * Turn one column into bars: a histogram if the values are numbers, the
40
- * most frequent labels otherwise. Twelve bars is the ceiling — more than
41
- * that is a table again.
48
+ * Turn one column into bars: a histogram with round edges if the values are numbers, the
49
+ * most frequent labels otherwise — the tail gathered into «others». Twelve bars is the
50
+ * ceiling: more than that is a table again.
42
51
  */
43
52
  export declare function columnSeries(frame: Frame, columnId: string): SeriesBar[];
@@ -1,4 +1,4 @@
1
- import { currentCopy, currentCopyLocale } from "../../foundations/copy.js";
1
+ import { currentCopy, currentCopyLocale, fillCopy } from "../../foundations/copy.js";
2
2
  const BINS = 12;
3
3
  const TOP = 12;
4
4
  export function frameFromRows(columns, rows) {
@@ -22,7 +22,9 @@ export function withColumns(frame, ids) {
22
22
  },
23
23
  };
24
24
  }
25
- function asNumber(cell) {
25
+ /** A cell read as a number: a number, or a text that writes one («12,5»). Anything else is
26
+ * `null` — not a zero. */
27
+ export function cellNumber(cell) {
26
28
  if (typeof cell === "number" && Number.isFinite(cell))
27
29
  return cell;
28
30
  if (typeof cell === "string" && cell.trim() !== "") {
@@ -35,9 +37,9 @@ function present(cell) {
35
37
  return cell !== null && cell !== "";
36
38
  }
37
39
  /**
38
- * Turn one column into bars: a histogram if the values are numbers, the
39
- * most frequent labels otherwise. Twelve bars is the ceiling — more than
40
- * that is a table again.
40
+ * Turn one column into bars: a histogram with round edges if the values are numbers, the
41
+ * most frequent labels otherwise — the tail gathered into «others». Twelve bars is the
42
+ * ceiling: more than that is a table again.
41
43
  */
42
44
  export function columnSeries(frame, columnId) {
43
45
  const columnIndex = frame.columns.findIndex((column) => column.id === columnId);
@@ -48,7 +50,7 @@ export function columnSeries(frame, columnId) {
48
50
  for (let row = 0; row < frame.rows; row += 1) {
49
51
  cells.push(frame.value(row, column, columnIndex));
50
52
  }
51
- const numbers = cells.map(asNumber);
53
+ const numbers = cells.map(cellNumber);
52
54
  const numeric = numbers.filter((n) => n !== null);
53
55
  const filled = cells.filter(present).length;
54
56
  if (filled === 0)
@@ -58,23 +60,46 @@ export function columnSeries(frame, columnId) {
58
60
  }
59
61
  return categories(cells);
60
62
  }
63
+ /** A step a person reads without effort: 1, 2, 2.5 or 5 times a power of ten. */
64
+ function niceStep(raw) {
65
+ const power = 10 ** Math.floor(Math.log10(raw));
66
+ const unit = raw / power;
67
+ const nice = unit <= 1 ? 1 : unit <= 2 ? 2 : unit <= 2.5 ? 2.5 : unit <= 5 ? 5 : 10;
68
+ return nice * power;
69
+ }
70
+ /**
71
+ * Stretches with ROUND edges: 0–100, 100–200, not 1,4–35,6. How many follows the number of
72
+ * values (Sturges: ten values make five stretches, six hundred make eleven) and never more
73
+ * than twelve. A stretch with nothing in it stays — it is part of the shape — and counts 0.
74
+ */
61
75
  function histogram(values) {
62
76
  if (values.length === 0)
63
77
  return [];
64
78
  const min = Math.min(...values);
65
79
  const max = Math.max(...values);
66
80
  if (min === max)
67
- return [{ label: String(min), count: values.length }];
68
- const width = (max - min) / BINS;
69
- const counts = Array.from({ length: BINS }, () => 0);
81
+ return [{ label: formatTick(min), count: values.length }];
82
+ const target = Math.min(BINS, Math.max(2, Math.ceil(Math.log2(values.length)) + 1));
83
+ let step = niceStep((max - min) / target);
84
+ let start = Math.floor(min / step) * step;
85
+ let bins = Math.max(1, Math.ceil((max - start) / step));
86
+ while (bins > BINS) {
87
+ step = niceStep(step * 1.01);
88
+ start = Math.floor(min / step) * step;
89
+ bins = Math.max(1, Math.ceil((max - start) / step));
90
+ }
91
+ /* Edges are rounded to the step's own precision: 0.1 × 3 is 0.30000000000000004. */
92
+ const digits = Math.max(0, -Math.floor(Math.log10(step)) + 1);
93
+ const edge = (index) => Number((start + index * step).toFixed(digits));
94
+ const counts = Array.from({ length: bins }, () => 0);
70
95
  for (const value of values) {
71
- const slot = Math.min(BINS - 1, Math.floor((value - min) / width));
96
+ const slot = Math.min(bins - 1, Math.floor((value - start) / step));
72
97
  counts[slot] = (counts[slot] ?? 0) + 1;
73
98
  }
74
99
  return counts.map((count, index) => {
75
- const from = min + index * width;
76
- const to = index === BINS - 1 ? max : from + width;
77
- return { label: `${formatTick(from)}–${formatTick(to)}`, count };
100
+ const from = edge(index);
101
+ const to = edge(index + 1);
102
+ return { label: `${formatTick(from)}–${formatTick(to)}`, count, bin: { from, to } };
78
103
  });
79
104
  }
80
105
  function categories(cells) {
@@ -85,17 +110,26 @@ function categories(cells) {
85
110
  const label = String(cell);
86
111
  tally.set(label, (tally.get(label) ?? 0) + 1);
87
112
  }
88
- return [...tally.entries()]
113
+ const ranked = [...tally.entries()]
89
114
  .sort((a, b) => b[1] - a[1])
90
- .slice(0, TOP)
91
115
  .map(([label, count]) => ({
92
116
  label: label === "" ? currentCopy().cell.emptyBin : label,
93
117
  count,
94
118
  }));
119
+ if (ranked.length <= TOP)
120
+ return ranked;
121
+ /* The tail is gathered, not dropped: the bars still add up to the rows that were counted,
122
+ and «others (388)» says how long the tail is — often the finding itself. */
123
+ const kept = ranked.slice(0, TOP - 1);
124
+ const tail = ranked.slice(TOP - 1);
125
+ return [
126
+ ...kept,
127
+ {
128
+ label: fillCopy(currentCopy().chart.rest, { count: tail.length }),
129
+ count: tail.reduce((total, bar) => total + bar.count, 0),
130
+ },
131
+ ];
95
132
  }
96
133
  function formatTick(n) {
97
- const abs = Math.abs(n);
98
- if (abs >= 100 || Number.isInteger(n))
99
- return String(Math.round(n));
100
- return n.toLocaleString(currentCopyLocale(), { maximumFractionDigits: 1 });
134
+ return n.toLocaleString(currentCopyLocale(), { maximumFractionDigits: 2 });
101
135
  }
@@ -1,7 +1,10 @@
1
1
  export * from "./activity/index.js";
2
2
  export * from "./assist/index.js";
3
3
  export * from "./attachments/index.js";
4
+ export * from "./board/index.js";
4
5
  export * from "./calendar/index.js";
6
+ export * from "./canvas/index.js";
7
+ export * from "./chat/index.js";
5
8
  export * from "./flow/index.js";
6
9
  export * from "./form/index.js";
7
10
  export * from "./frame/index.js";
@@ -9,6 +12,7 @@ export * from "./gantt/index.js";
9
12
  export * from "./lines/index.js";
10
13
  export * from "./listing/index.js";
11
14
  export * from "./navigation/index.js";
15
+ export * from "./preview/index.js";
12
16
  export * from "./record/index.js";
13
17
  export * from "./search/index.js";
14
18
  export * from "./shell/index.js";
@@ -2,7 +2,10 @@
2
2
  export * from "./activity/index.js";
3
3
  export * from "./assist/index.js";
4
4
  export * from "./attachments/index.js";
5
+ export * from "./board/index.js";
5
6
  export * from "./calendar/index.js";
7
+ export * from "./canvas/index.js";
8
+ export * from "./chat/index.js";
6
9
  export * from "./flow/index.js";
7
10
  export * from "./form/index.js";
8
11
  export * from "./frame/index.js";
@@ -10,6 +13,7 @@ export * from "./gantt/index.js";
10
13
  export * from "./lines/index.js";
11
14
  export * from "./listing/index.js";
12
15
  export * from "./navigation/index.js";
16
+ export * from "./preview/index.js";
13
17
  export * from "./record/index.js";
14
18
  export * from "./search/index.js";
15
19
  export * from "./shell/index.js";
@@ -0,0 +1,24 @@
1
+ import type { GroupableField, GroupLevel } from "../../foundations/grouping.js";
2
+ /**
3
+ * The levels of ONE axis, chosen on the screen: a tag per level with its ×, and «+» to add
4
+ * a field (a date with each of its grains).
5
+ *
6
+ * Context: the pivot had it written inline, and the chart asks the same question twice
7
+ * (its axis and its series). Two copies would drift; this is the one both draw.
8
+ */
9
+ export declare const levelId: (level: GroupLevel) => string;
10
+ /** How a level is named: the field's label, and its grain when it is a date. */
11
+ export declare function levelLabeler(fields: readonly GroupableField[]): (level: GroupLevel) => string;
12
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
13
+ export declare function namer(fields: readonly GroupableField[], fallback?: (level: GroupLevel) => string): (level: GroupLevel) => string;
14
+ export declare function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }: {
15
+ name: string;
16
+ levels: readonly GroupLevel[];
17
+ /** `null`: the levels come from somewhere else (the search bar) and are only shown. */
18
+ onChange: ((next: readonly GroupLevel[]) => void) | null;
19
+ fields: readonly GroupableField[];
20
+ /** Levels already on another axis: offered, but not choosable twice. */
21
+ used: readonly GroupLevel[];
22
+ /** How a level not among `fields` is named — the spec's own `labelOf`. */
23
+ labelOf?: (level: GroupLevel) => string;
24
+ }): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { grainName } from "../../foundations/calendar.js";
4
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
+ import { Menu } from "../../primitives/menu/Menu.js";
6
+ import { Tags } from "../../primitives/tag/Tags.js";
7
+ import { Plus } from "lucide-react";
8
+ /**
9
+ * The levels of ONE axis, chosen on the screen: a tag per level with its ×, and «+» to add
10
+ * a field (a date with each of its grains).
11
+ *
12
+ * Context: the pivot had it written inline, and the chart asks the same question twice
13
+ * (its axis and its series). Two copies would drift; this is the one both draw.
14
+ */
15
+ export const levelId = (level) => `${level.field}:${level.grain ?? ""}`;
16
+ const fromId = (id) => {
17
+ const [field = "", grain = ""] = id.split(":");
18
+ return grain === "" ? { field } : { field, grain: grain };
19
+ };
20
+ /** How a level is named: the field's label, and its grain when it is a date. */
21
+ export function levelLabeler(fields) {
22
+ return (level) => {
23
+ const field = fields.find((one) => one.field === level.field)?.label ?? level.field;
24
+ return level.grain === undefined
25
+ ? field
26
+ : `${field} · ${grainName(level.grain).toLowerCase()}`;
27
+ };
28
+ }
29
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
30
+ export function namer(fields, fallback) {
31
+ const named = levelLabeler(fields);
32
+ return (level) => fallback !== undefined && !fields.some((one) => one.field === level.field)
33
+ ? fallback(level)
34
+ : named(level);
35
+ }
36
+ export function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }) {
37
+ const words = useUiCopy().pivot;
38
+ const labelOf = namer(fields, outerLabel);
39
+ const taken = new Set([...levels, ...used].map(levelId));
40
+ const options = fields.flatMap((field) => (field.grains ?? [undefined]).map((grain) => {
41
+ const level = grain === undefined ? { field: field.field } : { field: field.field, grain };
42
+ return {
43
+ id: levelId(level),
44
+ label: labelOf(level),
45
+ disabled: taken.has(levelId(level)),
46
+ };
47
+ }));
48
+ return (_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) => ({
49
+ id: levelId(level),
50
+ label: labelOf(level),
51
+ ...(onChange === null
52
+ ? {}
53
+ : {
54
+ onRemove: () => onChange(levels.filter((one) => levelId(one) !== levelId(level))),
55
+ removeLabel: fillCopy(words.removeLevel, { level: labelOf(level) }),
56
+ }),
57
+ })) }), onChange === null ? (_jsx("span", { className: "text-micro text-muted italic", children: words.fromSearch })) : options.length === 0 ? null : (_jsx(Menu, { label: fillCopy(words.addLevel, { axis: name }), icon: Plus, iconOnly: true, chevron: false, variant: "text", groups: [{ options }], onSelect: (id) => onChange([...levels, fromId(id)]) }))] }));
58
+ }
@@ -0,0 +1,79 @@
1
+ import { type ChartKind, type ChartOrder } from "../../foundations/chart.js";
2
+ import type { GroupableField, GroupLevel, PileOf } from "../../foundations/grouping.js";
3
+ import { type Pivot, type PivotFold, type PivotKey } from "../../foundations/pivot.js";
4
+ /**
5
+ * The PREVIOUS period, to draw beside the current one — Odoo's «compare with».
6
+ *
7
+ * The application knows what «previous» means (the same months last year, the week before)
8
+ * and hands over those records, or that pivot folded by the server. The chart folds them
9
+ * with the same axis and measure and draws them quiet, behind the current ones.
10
+ */
11
+ export type ChartComparison<T> = {
12
+ /** What the current period is called on the legend: «2026». */
13
+ current: string;
14
+ /** What the previous one is called: «2025». It also names the toggle. */
15
+ previous: string;
16
+ items?: readonly T[];
17
+ folded?: Pivot;
18
+ /** On from the start. */
19
+ defaultOn?: boolean;
20
+ };
21
+ export type ChartExplorerProps<T> = {
22
+ /**
23
+ * The pivot already folded by whoever holds the data. Its axes are theirs, so they are
24
+ * shown and not edited; the chart type, the measure and the order stay the person's.
25
+ * Wins over `items` when both are given.
26
+ */
27
+ folded?: Pivot;
28
+ /** The records to fold here, with `of`, `fields` and `measures`. */
29
+ items?: readonly T[];
30
+ /** Which pile a record falls in, at a level — the same contract that groups a list. */
31
+ of?: PileOf<T>;
32
+ /** What the chart can be split by: a field, and its grains when it is a date. */
33
+ fields?: readonly GroupableField[];
34
+ /** How a level is named when it is not among `fields` — the spec's `labelOf`. */
35
+ labelOf?: (level: GroupLevel) => string;
36
+ /** What can be measured, besides the count (always offered). */
37
+ measures?: readonly PivotFold<T>[];
38
+ /** The measure it opens on. The first of `measures` by default; `COUNT_MEASURE` for the count. */
39
+ defaultMeasure?: string;
40
+ /** Several measures at once, each its OWN chart, one under the other: two measures of
41
+ * different scale on one axis flatten the smaller one, and two axes invent a
42
+ * correlation. Wins over `defaultMeasure`. */
43
+ defaultMeasures?: readonly string[];
44
+ /** The levels, CONTROLLED from outside — the search bar's grouping, as in Odoo: the first
45
+ * goes along the axis, the rest are the series. While given, they are not edited here. */
46
+ levels?: readonly GroupLevel[];
47
+ /** Where the axis and the series start when nothing outside decides them. */
48
+ defaultCategories?: readonly GroupLevel[];
49
+ defaultSeries?: readonly GroupLevel[];
50
+ kind?: ChartKind;
51
+ defaultKind?: ChartKind;
52
+ onKindChange?: (kind: ChartKind) => void;
53
+ /** Bars stacked from the start (Odoo stacks them). */
54
+ defaultStacked?: boolean;
55
+ /** A line that adds up from the start: «how much so far». */
56
+ defaultCumulative?: boolean;
57
+ /** The axis ordered by size from the start. */
58
+ defaultOrder?: ChartOrder;
59
+ /** The previous period, to draw beside this one. */
60
+ compare?: ChartComparison<T>;
61
+ /** A bar, a point or a slice was pressed: open the records that fell there. */
62
+ onPoint?: (category: PivotKey, series?: PivotKey) => void;
63
+ /** What the chart shows, for the screen reader: «Ventas por sucursal». */
64
+ label?: string;
65
+ height?: number | string;
66
+ /** The file's name when downloaded. */
67
+ fileName?: string;
68
+ };
69
+ /**
70
+ * Odoo's GRAPH view, for any set: bars, lines or a pie; which measures; split by what along
71
+ * the axis and by what into series; stacked, cumulative, ordered; against the previous
72
+ * period; and a press on a mark opens the records under it.
73
+ *
74
+ * Context: it folds with the same `pivotFrom` the pivot uses, so the numbers on the chart
75
+ * and on the grid can never disagree — and a server-folded pivot (`folded`) draws the same.
76
+ * Inside a list the levels FOLLOW the search bar's grouping and the records are the ones
77
+ * the search left: the chart answers the same question the list is asking.
78
+ */
79
+ export declare function ChartExplorer<T>({ folded, items, of, fields, labelOf: outerLabel, measures, defaultMeasure, defaultMeasures, levels: outerLevels, defaultCategories, defaultSeries, kind: kindProp, defaultKind, onKindChange, defaultStacked, defaultCumulative, defaultOrder, compare, onPoint, label, height, fileName, }: ChartExplorerProps<T>): import("react").JSX.Element;
@@ -0,0 +1,114 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { AxisLevels, namer } from "./AxisLevels.js";
4
+ import { chartCompare, chartFromPivot, chartMeasures, COUNT_MEASURE, orderChart, } from "../../foundations/chart.js";
5
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
6
+ import { pivotFrom, } from "../../foundations/pivot.js";
7
+ import { downloadPivot } from "../../foundations/pivotSheet.js";
8
+ import { Button, IconButton } from "../../primitives/button/Button.js";
9
+ import { Chart } from "../../primitives/chart/Chart.js";
10
+ import { SegmentedControl } from "../../primitives/choice/SegmentedControl.js";
11
+ import { Menu } from "../../primitives/menu/Menu.js";
12
+ import { ArrowDownWideNarrow, ArrowUpNarrowWide, ChartColumnBig, ChartLine, ChartPie, Download, GitCompareArrows, Layers, Sigma, TrendingUp, } from "lucide-react";
13
+ import { useMemo, useState } from "react";
14
+ const KIND_ICON = { bar: ChartColumnBig, line: ChartLine, pie: ChartPie };
15
+ /**
16
+ * Odoo's GRAPH view, for any set: bars, lines or a pie; which measures; split by what along
17
+ * the axis and by what into series; stacked, cumulative, ordered; against the previous
18
+ * period; and a press on a mark opens the records under it.
19
+ *
20
+ * Context: it folds with the same `pivotFrom` the pivot uses, so the numbers on the chart
21
+ * and on the grid can never disagree — and a server-folded pivot (`folded`) draws the same.
22
+ * Inside a list the levels FOLLOW the search bar's grouping and the records are the ones
23
+ * the search left: the chart answers the same question the list is asking.
24
+ */
25
+ export function ChartExplorer({ folded, items, of, fields = [], labelOf: outerLabel, measures = [], defaultMeasure, defaultMeasures, levels: outerLevels, defaultCategories = [], defaultSeries = [], kind: kindProp, defaultKind = "bar", onKindChange, defaultStacked = true, defaultCumulative = false, defaultOrder, compare, onPoint, label, height, fileName, }) {
26
+ const copy = useUiCopy();
27
+ const words = copy.chart;
28
+ const [ownKind, setOwnKind] = useState(kindProp ?? defaultKind);
29
+ const kind = onKindChange === undefined ? ownKind : (kindProp ?? defaultKind);
30
+ const setKind = onKindChange ?? setOwnKind;
31
+ const [ownCategories, setOwnCategories] = useState(defaultCategories);
32
+ const [ownSeries, setOwnSeries] = useState(defaultSeries);
33
+ const following = outerLevels !== undefined && outerLevels.length > 0;
34
+ const categories = following ? outerLevels.slice(0, 1) : ownCategories;
35
+ const series = following ? outerLevels.slice(1) : ownSeries;
36
+ const [chosen, setChosen] = useState(() => defaultMeasures ?? [defaultMeasure ?? measures[0]?.id ?? COUNT_MEASURE]);
37
+ const [stacked, setStacked] = useState(defaultStacked);
38
+ const [cumulative, setCumulative] = useState(defaultCumulative);
39
+ const [order, setOrder] = useState(defaultOrder);
40
+ const [comparing, setComparing] = useState(compare?.defaultOn === true);
41
+ const labelOf = namer(fields, outerLabel);
42
+ const fold = (records, columns) => of === undefined
43
+ ? undefined
44
+ : pivotFrom(records ?? [], { rows: categories, columns, of, measures, labelOf });
45
+ /* A pie is one whole: its series would be split and summed back. */
46
+ const columns = kind === "pie" ? [] : series;
47
+ const pivot = useMemo(() => folded ?? fold(items, columns),
48
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `fold` reads these same inputs
49
+ [folded, items, of, measures, fields, categories, columns]);
50
+ /* Comparing draws two periods of ONE series each: with series of its own, or as a pie
51
+ (one whole), there is nothing to put beside it. */
52
+ const canCompare = compare !== undefined && kind !== "pie" && columns.length === 0;
53
+ const previousPivot = useMemo(() => !canCompare || !comparing ? undefined : (compare.folded ?? fold(compare.items, [])),
54
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- `fold` reads these same inputs
55
+ [canCompare, comparing, compare, of, measures, fields, categories]);
56
+ /* Time is compared by position (the first month with the first month); a thing, by key. */
57
+ const timeAxis = (pivot?.rows.levels.length ?? 0) === 1 && pivot?.rows.levels[0]?.grain !== undefined;
58
+ const available = pivot === undefined ? [] : chartMeasures(pivot);
59
+ const shown = available.filter((one) => chosen.includes(one.id));
60
+ const measuresShown = shown.length > 0 ? shown : available.slice(0, 1);
61
+ const charts = useMemo(() => {
62
+ if (pivot === undefined)
63
+ return [];
64
+ return measuresShown.map((measure) => {
65
+ const reading = {
66
+ measure: measure.id,
67
+ cumulative: kind === "line" && cumulative,
68
+ ...(kind === "pie" ? { maxCategories: 7 } : {}),
69
+ };
70
+ const current = chartFromPivot(pivot, reading);
71
+ if (previousPivot === undefined || compare === undefined) {
72
+ return orderChart(current, order);
73
+ }
74
+ const previous = chartFromPivot(previousPivot, reading);
75
+ return orderChart(chartCompare(current, previous, { current: compare.current, previous: compare.previous }, timeAxis ? "position" : "key"), order);
76
+ });
77
+ }, [pivot, previousPivot, measuresShown, kind, cumulative, order, compare, timeAxis]);
78
+ const manySeries = charts.some((data) => data.series.length > 1 && data.compare !== true);
79
+ const additive = measuresShown.every((one) => one.additive);
80
+ const first = measuresShown[0];
81
+ const measureLabel = first === undefined
82
+ ? words.measure
83
+ : measuresShown.length === 1
84
+ ? first.header
85
+ : fillCopy(words.moreMeasures, {
86
+ name: first.header,
87
+ count: measuresShown.length - 1,
88
+ });
89
+ const toggleOrder = (next) => setOrder((now) => (now === next ? undefined : next));
90
+ const toggleMeasure = (id) => {
91
+ const on = measuresShown.map((one) => one.id);
92
+ /* The last one stays: a chart of no measure is no chart. */
93
+ setChosen(!on.includes(id) ? [...on, id] : on.length === 1 ? on : on.filter((one) => one !== id));
94
+ };
95
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-4", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-5 gap-y-2", children: [_jsx(SegmentedControl, { "aria-label": words.kind, size: "sm", value: kind, onChange: (next) => setKind(next), options: ["bar", "line", "pie"].map((one) => ({
96
+ value: one,
97
+ label: words[one],
98
+ icon: KIND_ICON[one],
99
+ })) }), _jsx(Menu, { label: measureLabel, title: words.measure, icon: Sigma, closeOnSelect: false, groups: [
100
+ {
101
+ label: words.measure,
102
+ options: available.map((one) => ({
103
+ id: one.id,
104
+ label: one.header,
105
+ checked: measuresShown.some((on) => on.id === one.id),
106
+ })),
107
+ },
108
+ ], onSelect: toggleMeasure }), folded === undefined ? (_jsxs(_Fragment, { children: [_jsx(AxisLevels, { name: words.categoriesAxis, levels: categories, onChange: following ? null : setOwnCategories, fields: fields, used: series, labelOf: labelOf }), kind === "pie" || (following && series.length === 0) ? null : (_jsx(AxisLevels, { name: words.seriesAxis, levels: series, onChange: following ? null : setOwnSeries, fields: fields, used: categories, labelOf: labelOf }))] })) : null, _jsxs("div", { className: "ml-auto flex items-center gap-1", children: [canCompare ? (_jsx(IconButton, { icon: GitCompareArrows, label: fillCopy(words.compareWith, { name: compare.previous }), "aria-pressed": comparing, onClick: () => setComparing((now) => !now) })) : null, kind !== "pie" && manySeries ? (_jsx(IconButton, { icon: Layers, label: words.stacked, "aria-pressed": stacked, onClick: () => setStacked((now) => !now) })) : null, kind === "line" ? (_jsx(IconButton, { icon: TrendingUp, label: words.cumulative, "aria-pressed": cumulative && additive, disabled: !additive, onClick: () => setCumulative((now) => !now) })) : null, _jsx(IconButton, { icon: ArrowDownWideNarrow, label: words.descending, "aria-pressed": order === "desc", onClick: () => toggleOrder("desc") }), _jsx(IconButton, { icon: ArrowUpNarrowWide, label: words.ascending, "aria-pressed": order === "asc", onClick: () => toggleOrder("asc") }), pivot === undefined ? null : (_jsx(Button, { role: "ghost", size: "sm", icon: Download, onClick: () => downloadPivot(pivot, fileName === undefined ? {} : { name: fileName }), children: copy.pivot.download }))] })] }), charts.map((data) => (_jsxs("section", { className: "flex min-w-0 flex-col gap-2", children: [charts.length > 1 ? (_jsx("h3", { className: "text-meta font-semibold text-ink", children: data.measure.header })) : null, _jsx(Chart, { data: data, kind: kind, stacked: stacked, label: charts.length > 1
109
+ ? describe(data.measure.header, label ?? data.categoryTitle)
110
+ : (label ?? describe(data.measure.header, data.categoryTitle)), ...(onPoint === undefined ? {} : { onPoint }), ...(height === undefined ? {} : { height }) })] }, data.measure.id)))] }));
111
+ }
112
+ function describe(measure, by) {
113
+ return by === "" ? measure : `${measure} · ${by}`;
114
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ColumnControl, ColumnSpec } from "./columns.js";
2
+ import { type PathPick } from "../search/FieldPath.js";
2
3
  import type { Surface } from "../../foundations/types.js";
3
4
  /**
4
5
  * The Odoo columns submenu: required fields stay checked and cannot be
@@ -7,10 +8,15 @@ import type { Surface } from "../../foundations/types.js";
7
8
  *
8
9
  * Drawn only when the set declared optional columns. A menu of required-only
9
10
  * fields would be a list of things you cannot do.
11
+ *
12
+ * `addPath` adds «Agregar columna» next to it: a `FieldPath` that walks the relations, so a
13
+ * column can be a field of a related record («Cliente > País»). web-ui hands the chosen path
14
+ * back; turning it into a column — and asking the server for it — is the framework's.
10
15
  */
11
- export declare function ColumnsMenu({ control, surface, }: {
16
+ export declare function ColumnsMenu({ control, surface, addPath, }: {
12
17
  control: ColumnControl;
13
18
  surface?: Surface;
19
+ addPath?: PathPick;
14
20
  }): import("react").JSX.Element | null;
15
21
  export declare function specsFromColumns(columns: readonly {
16
22
  id: string;