@schemacast/react 0.0.0-stage → 0.5.1

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -2
  3. package/dist/auto-visual.d.ts +32 -0
  4. package/dist/auto-visual.js +27 -0
  5. package/dist/field-by-key.d.ts +3 -0
  6. package/dist/field-by-key.js +7 -0
  7. package/dist/format-field-value.d.ts +16 -0
  8. package/dist/format-field-value.js +84 -0
  9. package/dist/implemented-archetypes.d.ts +2 -0
  10. package/dist/implemented-archetypes.js +17 -0
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.js +10 -0
  13. package/dist/use-selected-view-id.d.ts +6 -0
  14. package/dist/use-selected-view-id.js +17 -0
  15. package/dist/view-switcher.d.ts +26 -0
  16. package/dist/view-switcher.js +63 -0
  17. package/dist/views/archetype-view.d.ts +16 -0
  18. package/dist/views/archetype-view.js +71 -0
  19. package/dist/views/bar-chart-options.d.ts +22 -0
  20. package/dist/views/bar-chart-options.js +103 -0
  21. package/dist/views/bar-chart-view.d.ts +17 -0
  22. package/dist/views/bar-chart-view.js +25 -0
  23. package/dist/views/build-hierarchy-tree-data.d.ts +8 -0
  24. package/dist/views/build-hierarchy-tree-data.js +32 -0
  25. package/dist/views/build-node-graph-data.d.ts +20 -0
  26. package/dist/views/build-node-graph-data.js +44 -0
  27. package/dist/views/chart-series-data.d.ts +61 -0
  28. package/dist/views/chart-series-data.js +150 -0
  29. package/dist/views/chart-value-axes.d.ts +45 -0
  30. package/dist/views/chart-value-axes.js +214 -0
  31. package/dist/views/data-table-constants.d.ts +3 -0
  32. package/dist/views/data-table-constants.js +3 -0
  33. package/dist/views/data-table-rows.d.ts +8 -0
  34. package/dist/views/data-table-rows.js +50 -0
  35. package/dist/views/data-table-view.d.ts +16 -0
  36. package/dist/views/data-table-view.js +76 -0
  37. package/dist/views/detail-card-view.d.ts +16 -0
  38. package/dist/views/detail-card-view.js +59 -0
  39. package/dist/views/edge-weight-width.d.ts +23 -0
  40. package/dist/views/edge-weight-width.js +47 -0
  41. package/dist/views/hierarchy-tree-view.d.ts +16 -0
  42. package/dist/views/hierarchy-tree-view.js +58 -0
  43. package/dist/views/json-tree-view.d.ts +15 -0
  44. package/dist/views/json-tree-view.js +115 -0
  45. package/dist/views/kanban-view.d.ts +16 -0
  46. package/dist/views/kanban-view.js +41 -0
  47. package/dist/views/kpi-grid-view.d.ts +16 -0
  48. package/dist/views/kpi-grid-view.js +34 -0
  49. package/dist/views/line-chart-options.d.ts +16 -0
  50. package/dist/views/line-chart-options.js +98 -0
  51. package/dist/views/line-chart-view.d.ts +16 -0
  52. package/dist/views/line-chart-view.js +31 -0
  53. package/dist/views/node-graph-options.d.ts +26 -0
  54. package/dist/views/node-graph-options.js +111 -0
  55. package/dist/views/node-graph-view.d.ts +16 -0
  56. package/dist/views/node-graph-view.js +28 -0
  57. package/dist/views/pie-chart-view.d.ts +16 -0
  58. package/dist/views/pie-chart-view.js +56 -0
  59. package/dist/views/timeline-view.d.ts +16 -0
  60. package/dist/views/timeline-view.js +86 -0
  61. package/dist/views/use-echarts.d.ts +4 -0
  62. package/dist/views/use-echarts.js +233 -0
  63. package/dist/visual-spec-view.d.ts +28 -0
  64. package/dist/visual-spec-view.js +31 -0
  65. package/package.json +56 -3
  66. package/styles.css +688 -0
@@ -0,0 +1,98 @@
1
+ import { buildLongFormatLine, LINE_SAMPLING_MIN_POINTS } from '@schemacast/core';
2
+ export { LINE_SAMPLING_MIN_POINTS };
3
+ import { fieldByKey } from '../field-by-key.js';
4
+ import { buildCategoryAxis, buildNumericXAxis, buildSeriesLegend, isNumericAxisField, numericSeries, numericXSeries, readNumericSeriesValue, seriesLabel, shouldOmitSingleSeriesYAxisName, } from './chart-series-data.js';
5
+ import { buildValueAxis, buildValueAxisPlan, formatChartTooltip } from './chart-value-axes.js';
6
+ /**
7
+ * Builds a line-chart option with shared unit-aware value-axis behavior. A numeric x (a step,
8
+ * epoch or version) gets a `value` axis and `[x, y]` points; date and category x keep the
9
+ * category axis.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const option = buildLineChartOption(spec, spec.primaryView.bindings);
14
+ * ```
15
+ */
16
+ export function buildLineChartOption(spec, bindings) {
17
+ const xKey = bindings.x;
18
+ const yKeys = bindings.y ?? [];
19
+ if (xKey === undefined || yKeys.length === 0) {
20
+ return null;
21
+ }
22
+ if (bindings.groupBy !== undefined) {
23
+ return buildLongFormatLineOption(spec, xKey, yKeys[0], bindings.groupBy);
24
+ }
25
+ const hasNumericX = isNumericAxisField(fieldByKey(spec.fields, xKey));
26
+ const seriesNames = yKeys.map((key) => seriesLabel(spec.fields, key));
27
+ const omitYAxisName = shouldOmitSingleSeriesYAxisName(seriesNames, undefined);
28
+ const axisPlan = buildValueAxisPlan(spec, yKeys, spec.data, true);
29
+ const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis, { omitName: omitYAxisName }));
30
+ return {
31
+ tooltip: {
32
+ trigger: 'axis',
33
+ formatter: (parameters) => formatChartTooltip(parameters, spec.fields, yKeys),
34
+ },
35
+ legend: buildSeriesLegend(seriesNames),
36
+ grid: {
37
+ left: axes.length > 1 ? 104 : 88,
38
+ right: axes.length > 1 ? 104 : 24,
39
+ containLabel: true,
40
+ },
41
+ xAxis: hasNumericX
42
+ ? buildNumericXAxis(spec.fields, xKey)
43
+ : buildCategoryAxis(spec.data, xKey, spec.fields),
44
+ yAxis: axes.length === 1 ? axes[0] : axes,
45
+ series: yKeys.map((yKey, index) => ({
46
+ name: seriesLabel(spec.fields, yKey),
47
+ type: 'line',
48
+ yAxisIndex: axisPlan.seriesAxisIndexes[index] ?? 0,
49
+ ...(spec.data.length >= LINE_SAMPLING_MIN_POINTS ? { sampling: 'lttb' } : {}),
50
+ data: hasNumericX
51
+ ? numericXSeries(spec.data, xKey, yKey, spec.fields)
52
+ : numericSeries(spec.data, yKey, spec.fields),
53
+ })),
54
+ };
55
+ }
56
+ /**
57
+ * One line per group value over a shared, sorted x axis. A group with no row at an x holds
58
+ * `null` there, so the line breaks (a gap) and never drops to zero. All lines share one y axis
59
+ * because they plot the same metric.
60
+ */
61
+ function buildLongFormatLineOption(spec, xKey, yKey, groupKey) {
62
+ if (yKey === undefined) {
63
+ return null;
64
+ }
65
+ const line = buildLongFormatLine(spec.data, { xKey, groupKey, yKey }, spec.fields);
66
+ const xField = fieldByKey(spec.fields, xKey);
67
+ const hasNumericX = isNumericAxisField(xField);
68
+ const seriesNames = line.series.map((series) => series.name);
69
+ const omitYAxisName = shouldOmitSingleSeriesYAxisName(seriesNames, undefined);
70
+ const axisPlan = buildValueAxisPlan(spec, [yKey], spec.data, true);
71
+ const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis, { omitName: omitYAxisName }));
72
+ const seriesYKeys = line.series.map(() => yKey);
73
+ const xNumbers = line.xValues.map((value) => readNumericSeriesValue(value, xField?.semanticType));
74
+ return {
75
+ tooltip: {
76
+ trigger: 'axis',
77
+ formatter: (parameters) => formatChartTooltip(parameters, spec.fields, seriesYKeys),
78
+ },
79
+ legend: buildSeriesLegend(seriesNames),
80
+ grid: { left: 88, right: 24, containLabel: true },
81
+ xAxis: hasNumericX
82
+ ? buildNumericXAxis(spec.fields, xKey)
83
+ : buildCategoryAxis(line.xValues.map((value) => ({ [xKey]: value })), xKey, spec.fields),
84
+ yAxis: axes[0],
85
+ series: line.series.map((series) => ({
86
+ name: series.name,
87
+ type: 'line',
88
+ ...(line.xValues.length >= LINE_SAMPLING_MIN_POINTS ? { sampling: 'lttb' } : {}),
89
+ data: hasNumericX
90
+ ? series.values.map((value, index) => [
91
+ xNumbers[index] ?? null,
92
+ value,
93
+ ])
94
+ : series.values,
95
+ })),
96
+ };
97
+ }
98
+ //# sourceMappingURL=line-chart-options.js.map
@@ -0,0 +1,16 @@
1
+ import type { FieldBindings, VisualSpec } from '@schemacast/core';
2
+ import type { ReactElement } from 'react';
3
+ export interface LineChartViewProps {
4
+ readonly spec: VisualSpec;
5
+ readonly bindings: FieldBindings;
6
+ }
7
+ /**
8
+ * ECharts `line-chart` for time series or ordered categories (lazy-loaded parent).
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <LineChartView spec={spec} bindings={spec.primaryView.bindings} />
13
+ * ```
14
+ */
15
+ export declare function LineChartView({ spec, bindings }: LineChartViewProps): ReactElement;
16
+ //# sourceMappingURL=line-chart-view.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { buildLineChartOption } from './line-chart-options.js';
4
+ import { useEcharts } from './use-echarts.js';
5
+ /**
6
+ * ECharts `line-chart` for time series or ordered categories (lazy-loaded parent).
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * <LineChartView spec={spec} bindings={spec.primaryView.bindings} />
11
+ * ```
12
+ */
13
+ export function LineChartView({ spec, bindings }) {
14
+ const xKey = bindings.x;
15
+ const yKeys = bindings.y ?? [];
16
+ const groupKey = bindings.groupBy;
17
+ const option = useMemo(() => buildLineChartOption(spec, {
18
+ x: xKey,
19
+ y: yKeys,
20
+ ...(groupKey === undefined ? {} : { groupBy: groupKey }),
21
+ }), [spec.data, spec.fields, xKey, yKeys, groupKey]);
22
+ const chartRef = useEcharts(option, spec.isStreaming, true);
23
+ if (spec.isStreaming && spec.data.length === 0) {
24
+ return _jsx("p", { "data-testid": "line-chart-streaming", children: "Preparing chart from stream\u2026" });
25
+ }
26
+ if (option === null) {
27
+ return _jsx("p", { "data-testid": "line-chart-empty", children: "Chart bindings are incomplete." });
28
+ }
29
+ return (_jsx("div", { "data-testid": "line-chart-view", "data-y-keys": yKeys.join(','), ref: chartRef, style: { width: '100%', height: 320 } }));
30
+ }
31
+ //# sourceMappingURL=line-chart-view.js.map
@@ -0,0 +1,26 @@
1
+ import type { FieldBindings, VisualSpec } from '@schemacast/core';
2
+ import type { EChartsOption } from 'echarts';
3
+ /**
4
+ * Builds the force-directed graph option. Edges are drawn with a line width scaled by the
5
+ * `edgeWeight` binding (when there is one) and the weight shows in the edge tooltip. Edge labels
6
+ * are never drawn on the graph; they appear on hover only.
7
+ *
8
+ * @returns The option, or `null` when the graph has no nodes.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const option = buildNodeGraphOption(spec, spec.primaryView.bindings);
13
+ * ```
14
+ */
15
+ export declare function buildNodeGraphOption(spec: VisualSpec, bindings: FieldBindings): EChartsOption | null;
16
+ /**
17
+ * Formats the node or edge tooltip. An edge shows its label, its direction, and its weight
18
+ * (`weight: 12`) when the graph binds an edge weight.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * formatGraphTooltip(params, nodeNames, 'weight');
23
+ * ```
24
+ */
25
+ export declare function formatGraphTooltip(params: unknown, nodeNames: ReadonlyMap<string, string>, weightKey?: string): string;
26
+ //# sourceMappingURL=node-graph-options.d.ts.map
@@ -0,0 +1,111 @@
1
+ import { buildNodeGraphData } from './build-node-graph-data.js';
2
+ /**
3
+ * Builds the force-directed graph option. Edges are drawn with a line width scaled by the
4
+ * `edgeWeight` binding (when there is one) and the weight shows in the edge tooltip. Edge labels
5
+ * are never drawn on the graph; they appear on hover only.
6
+ *
7
+ * @returns The option, or `null` when the graph has no nodes.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const option = buildNodeGraphOption(spec, spec.primaryView.bindings);
12
+ * ```
13
+ */
14
+ export function buildNodeGraphOption(spec, bindings) {
15
+ const graphData = buildNodeGraphData(spec, bindings);
16
+ if (graphData.nodes.length === 0) {
17
+ return null;
18
+ }
19
+ const categories = [...new Set(graphData.nodes.flatMap((node) => node.category ?? []))];
20
+ const nodeNames = new Map(graphData.nodes.map((node) => [node.id, node.name]));
21
+ return {
22
+ ...(categories.length > 0
23
+ ? { legend: { data: categories, top: 0, textStyle: { fontSize: 11 } } }
24
+ : {}),
25
+ tooltip: {
26
+ trigger: 'item',
27
+ renderMode: 'richText',
28
+ formatter: (params) => formatGraphTooltip(params, nodeNames, bindings.edgeWeight),
29
+ },
30
+ series: [
31
+ {
32
+ type: 'graph',
33
+ layout: 'force',
34
+ roam: true,
35
+ draggable: true,
36
+ left: '10%',
37
+ right: '10%',
38
+ top: categories.length > 0 ? '16%' : '10%',
39
+ bottom: '10%',
40
+ symbolSize: 24,
41
+ label: { show: true, formatter: '{b}', position: 'right', distance: 8 },
42
+ labelLayout: { moveOverlap: 'shiftY', hideOverlap: true },
43
+ force: {
44
+ initLayout: 'circular',
45
+ repulsion: 900,
46
+ edgeLength: 160,
47
+ gravity: 0.08,
48
+ layoutAnimation: !spec.isStreaming,
49
+ },
50
+ edgeSymbol: ['none', 'arrow'],
51
+ edgeSymbolSize: [0, 10],
52
+ categories: categories.map((name) => ({ name })),
53
+ data: graphData.nodes.map((node) => ({
54
+ id: node.id,
55
+ name: node.name,
56
+ ...(node.category === undefined ? {} : { category: node.category }),
57
+ })),
58
+ links: graphData.links.map((link) => ({
59
+ source: link.source,
60
+ target: link.target,
61
+ name: link.label ?? '',
62
+ ...(link.weight === undefined ? {} : { value: link.weight }),
63
+ ...(link.width === undefined ? {} : { lineStyle: { width: link.width } }),
64
+ })),
65
+ // Labels stay hidden until hover (see `emphasis`) so a busy graph stays readable.
66
+ edgeLabel: {
67
+ show: false,
68
+ formatter: '{b}',
69
+ position: 'end',
70
+ rotate: 0,
71
+ fontSize: 10,
72
+ },
73
+ emphasis: { edgeLabel: { show: true } },
74
+ },
75
+ ],
76
+ };
77
+ }
78
+ /**
79
+ * Formats the node or edge tooltip. An edge shows its label, its direction, and its weight
80
+ * (`weight: 12`) when the graph binds an edge weight.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * formatGraphTooltip(params, nodeNames, 'weight');
85
+ * ```
86
+ */
87
+ export function formatGraphTooltip(params, nodeNames, weightKey) {
88
+ if (!isRecord(params) || !isRecord(params.data)) {
89
+ return '';
90
+ }
91
+ const data = params.data;
92
+ if (params.dataType === 'edge') {
93
+ const source = typeof data.source === 'string' ? data.source : '';
94
+ const target = typeof data.target === 'string' ? data.target : '';
95
+ const direction = `${nodeNames.get(source) ?? source} → ${nodeNames.get(target) ?? target}`;
96
+ const lines = [
97
+ ...(typeof data.name === 'string' && data.name !== '' ? [data.name] : []),
98
+ direction,
99
+ ...(weightKey !== undefined && typeof data.value === 'number'
100
+ ? [`${weightKey}: ${data.value}`]
101
+ : []),
102
+ ];
103
+ return lines.join('\n');
104
+ }
105
+ const name = typeof data.name === 'string' ? data.name : '';
106
+ return typeof data.category === 'string' ? `${name}\n${data.category}` : name;
107
+ }
108
+ function isRecord(value) {
109
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
110
+ }
111
+ //# sourceMappingURL=node-graph-options.js.map
@@ -0,0 +1,16 @@
1
+ import type { FieldBindings, VisualSpec } from '@schemacast/core';
2
+ import type { ReactElement } from 'react';
3
+ export interface NodeGraphViewProps {
4
+ readonly spec: VisualSpec;
5
+ readonly bindings: FieldBindings;
6
+ }
7
+ /**
8
+ * ECharts force-directed `node-graph` with human-readable node labels.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <NodeGraphView spec={spec} bindings={spec.primaryView.bindings} />
13
+ * ```
14
+ */
15
+ export declare function NodeGraphView({ spec, bindings }: NodeGraphViewProps): ReactElement;
16
+ //# sourceMappingURL=node-graph-view.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { buildNodeGraphData } from './build-node-graph-data.js';
4
+ import { buildNodeGraphOption } from './node-graph-options.js';
5
+ import { useEcharts } from './use-echarts.js';
6
+ /**
7
+ * ECharts force-directed `node-graph` with human-readable node labels.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <NodeGraphView spec={spec} bindings={spec.primaryView.bindings} />
12
+ * ```
13
+ */
14
+ export function NodeGraphView({ spec, bindings }) {
15
+ const graphData = useMemo(() => buildNodeGraphData(spec, bindings), [bindings, spec]);
16
+ const option = useMemo(() => buildNodeGraphOption(spec, bindings), [bindings, spec]);
17
+ const chartRef = useEcharts(option, spec.isStreaming, true);
18
+ if (spec.isStreaming && spec.data.length === 0) {
19
+ return _jsx("p", { "data-testid": "node-graph-streaming", children: "Preparing graph from stream\u2026" });
20
+ }
21
+ if (option === null) {
22
+ return _jsx("p", { "data-testid": "node-graph-empty", children: "No nodes in view data." });
23
+ }
24
+ return (_jsxs("div", { "data-testid": "node-graph-view", children: [_jsx("ul", { "data-testid": "node-graph-node-labels", className: "sr-only", children: graphData.nodes.map((node) => (_jsx("li", { children: node.name }, node.id))) }), _jsx("ul", { "data-testid": "node-graph-edge-labels", className: "sr-only", children: graphData.links.map((link, index) => (_jsxs("li", { children: [link.label ?? `${link.source}→${link.target}`, link.weight === undefined
25
+ ? ''
26
+ : ` (${bindings.edgeWeight ?? 'weight'}: ${link.weight})`] }, `${link.source}-${link.target}-${index}`))) }), _jsx("div", { role: "region", "aria-label": "Scrollable node graph", tabIndex: 0, style: { width: '100%', overflowX: 'auto' }, children: _jsx("div", { ref: chartRef, style: { width: '100%', minWidth: 760, height: 480 } }) })] }));
27
+ }
28
+ //# sourceMappingURL=node-graph-view.js.map
@@ -0,0 +1,16 @@
1
+ import type { FieldBindings, VisualSpec } from '@schemacast/core';
2
+ import type { ReactElement } from 'react';
3
+ export interface PieChartViewProps {
4
+ readonly spec: VisualSpec;
5
+ readonly bindings: FieldBindings;
6
+ }
7
+ /**
8
+ * ECharts `pie-chart` for part-to-whole metrics (lazy-loaded parent).
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <PieChartView spec={spec} bindings={spec.primaryView.bindings} />
13
+ * ```
14
+ */
15
+ export declare function PieChartView({ spec, bindings }: PieChartViewProps): ReactElement;
16
+ //# sourceMappingURL=pie-chart-view.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { fieldByKey } from '../field-by-key.js';
4
+ import { formatFieldValue } from '../format-field-value.js';
5
+ import { numericSeries, seriesLabel } from './chart-series-data.js';
6
+ import { useEcharts } from './use-echarts.js';
7
+ /**
8
+ * ECharts `pie-chart` for part-to-whole metrics (lazy-loaded parent).
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <PieChartView spec={spec} bindings={spec.primaryView.bindings} />
13
+ * ```
14
+ */
15
+ export function PieChartView({ spec, bindings }) {
16
+ const categoryKey = bindings.x;
17
+ const valueKey = bindings.y?.[0];
18
+ const option = useMemo(() => {
19
+ if (categoryKey === undefined || valueKey === undefined) {
20
+ return null;
21
+ }
22
+ const values = numericSeries(spec.data, valueKey, spec.fields);
23
+ const slices = spec.data.flatMap((row, index) => {
24
+ const value = values[index];
25
+ if (value === null || value === undefined) {
26
+ return [];
27
+ }
28
+ return [
29
+ {
30
+ name: formatFieldValue(row[categoryKey], fieldByKey(spec.fields, categoryKey)),
31
+ value,
32
+ },
33
+ ];
34
+ });
35
+ return {
36
+ tooltip: { trigger: 'item' },
37
+ series: [
38
+ {
39
+ name: seriesLabel(spec.fields, valueKey),
40
+ type: 'pie',
41
+ radius: '65%',
42
+ data: slices,
43
+ },
44
+ ],
45
+ };
46
+ }, [categoryKey, spec.data, spec.fields, valueKey]);
47
+ const chartRef = useEcharts(option, spec.isStreaming, true);
48
+ if (spec.isStreaming && spec.data.length === 0) {
49
+ return _jsx("p", { "data-testid": "pie-chart-streaming", children: "Preparing chart from stream\u2026" });
50
+ }
51
+ if (option === null) {
52
+ return _jsx("p", { "data-testid": "pie-chart-empty", children: "Chart bindings are incomplete." });
53
+ }
54
+ return _jsx("div", { "data-testid": "pie-chart-view", ref: chartRef, style: { width: '100%', height: 320 } });
55
+ }
56
+ //# sourceMappingURL=pie-chart-view.js.map
@@ -0,0 +1,16 @@
1
+ import type { FieldBindings, VisualSpec } from '@schemacast/core';
2
+ import type { ReactElement } from 'react';
3
+ export interface TimelineViewProps {
4
+ readonly spec: VisualSpec;
5
+ readonly bindings: FieldBindings;
6
+ }
7
+ /**
8
+ * Renders time-ranged events as an ordered `timeline` list.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <TimelineView spec={spec} bindings={spec.primaryView.bindings} />
13
+ * ```
14
+ */
15
+ export declare function TimelineView({ spec, bindings }: TimelineViewProps): ReactElement;
16
+ //# sourceMappingURL=timeline-view.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { fieldByKey } from '../field-by-key.js';
3
+ import { formatFieldValue } from '../format-field-value.js';
4
+ const DATE_ONLY_PATTERN = /^(\d{4}-\d{2}-\d{2})$/;
5
+ const ISO_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2}T/;
6
+ /**
7
+ * Renders time-ranged events as an ordered `timeline` list.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <TimelineView spec={spec} bindings={spec.primaryView.bindings} />
12
+ * ```
13
+ */
14
+ export function TimelineView({ spec, bindings }) {
15
+ const startKey = bindings.startDate;
16
+ const endKey = bindings.endDate;
17
+ const titleKey = bindings.title ?? bindings.subtitle;
18
+ if (startKey === undefined || titleKey === undefined) {
19
+ return _jsx("p", { "data-testid": "timeline-view", children: "Missing timeline bindings." });
20
+ }
21
+ return (_jsx("ol", { className: "schemacast-timeline", "data-testid": "timeline-view", children: spec.data.map((row, index) => {
22
+ const title = String(row[titleKey] ?? '');
23
+ const start = formatTimelineDate(row[startKey], fieldByKey(spec.fields, startKey));
24
+ const endDate = endKey !== undefined
25
+ ? formatTimelineDate(row[endKey], fieldByKey(spec.fields, endKey))
26
+ : undefined;
27
+ const dateRange = formatTimelineRange(start, endDate);
28
+ return (_jsxs("li", { className: "schemacast-timeline-item", "data-testid": "timeline-item", children: [_jsx("span", { className: "schemacast-timeline-marker", "aria-hidden": "true" }), _jsxs("div", { className: "schemacast-timeline-content", children: [_jsx("strong", { className: "schemacast-timeline-title", "data-testid": "timeline-title", children: title }), _jsx("span", { className: "schemacast-timeline-date", "data-testid": "timeline-date", children: dateRange })] })] }, `${title}-${index}`));
29
+ }) }));
30
+ }
31
+ function formatTimelineDate(value, field) {
32
+ if (typeof value === 'string') {
33
+ const dateOnlyMatch = DATE_ONLY_PATTERN.exec(value);
34
+ if (dateOnlyMatch !== null) {
35
+ const parsedDate = new Date(`${value}T00:00:00.000Z`);
36
+ if (Number.isFinite(parsedDate.getTime()) && parsedDate.toISOString().startsWith(value)) {
37
+ const dateLabel = new Intl.DateTimeFormat('en-US', {
38
+ dateStyle: 'medium',
39
+ timeZone: 'UTC',
40
+ }).format(parsedDate);
41
+ return {
42
+ text: dateLabel,
43
+ dayKey: dateLabel,
44
+ dateLabel,
45
+ isDateOnly: true,
46
+ };
47
+ }
48
+ }
49
+ if (ISO_DATETIME_PATTERN.test(value)) {
50
+ const parsedDate = new Date(value);
51
+ if (Number.isFinite(parsedDate.getTime())) {
52
+ const formattedDate = formatFieldValue(value, field);
53
+ const dateLabel = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }).format(parsedDate);
54
+ const timeLabel = new Intl.DateTimeFormat('en-US', { timeStyle: 'short' }).format(parsedDate);
55
+ return {
56
+ text: formattedDate === value ? `${dateLabel}, ${timeLabel}` : formattedDate,
57
+ dayKey: dateLabel,
58
+ dateLabel,
59
+ timeLabel,
60
+ isDateOnly: false,
61
+ };
62
+ }
63
+ }
64
+ }
65
+ return {
66
+ text: formatFieldValue(value, field),
67
+ isDateOnly: false,
68
+ };
69
+ }
70
+ function formatTimelineRange(start, end) {
71
+ if (end === undefined || end.text.length === 0) {
72
+ return start.text;
73
+ }
74
+ if (start.dayKey !== undefined && start.dayKey === end.dayKey) {
75
+ if (start.isDateOnly && end.isDateOnly) {
76
+ return start.text;
77
+ }
78
+ const sharedDate = start.dateLabel ?? end.dateLabel;
79
+ const timeRange = [start.timeLabel, end.timeLabel].filter((timeLabel) => timeLabel !== undefined);
80
+ if (sharedDate !== undefined && timeRange.length > 0) {
81
+ return `${sharedDate}, ${timeRange.join(' – ')}`;
82
+ }
83
+ }
84
+ return `${start.text} – ${end.text}`;
85
+ }
86
+ //# sourceMappingURL=timeline-view.js.map
@@ -0,0 +1,4 @@
1
+ import type { EChartsOption } from 'echarts';
2
+ import { type RefObject } from 'react';
3
+ export declare function useEcharts(option: EChartsOption | null, isStreaming: boolean, useAutoVisualTheme?: boolean): RefObject<HTMLDivElement | null>;
4
+ //# sourceMappingURL=use-echarts.d.ts.map