@asteby/metacore-runtime-react 52.1.0 → 53.1.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/CHANGELOG.md +24 -0
- package/dist/addon-loader.d.ts +22 -1
- package/dist/addon-loader.d.ts.map +1 -1
- package/dist/addon-loader.js +23 -5
- package/dist/addon-page-host.d.ts +80 -0
- package/dist/addon-page-host.d.ts.map +1 -0
- package/dist/addon-page-host.js +216 -0
- package/dist/addon-page-loader.d.ts +40 -0
- package/dist/addon-page-loader.d.ts.map +1 -0
- package/dist/addon-page-loader.js +87 -0
- package/dist/dynamic-view.d.ts +20 -1
- package/dist/dynamic-view.d.ts.map +1 -1
- package/dist/dynamic-view.js +26 -3
- package/dist/federated-error-boundary.d.ts +46 -0
- package/dist/federated-error-boundary.d.ts.map +1 -0
- package/dist/federated-error-boundary.js +55 -0
- package/dist/host-api.d.ts +22 -0
- package/dist/host-api.d.ts.map +1 -0
- package/dist/host-api.js +140 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/testing.d.ts +42 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +53 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/calendar-view.d.ts +23 -0
- package/dist/views/calendar-view.d.ts.map +1 -0
- package/dist/views/calendar-view.js +138 -0
- package/dist/views/chart-view.d.ts +14 -0
- package/dist/views/chart-view.d.ts.map +1 -0
- package/dist/views/chart-view.js +77 -0
- package/dist/views/data-source.d.ts +30 -0
- package/dist/views/data-source.d.ts.map +1 -0
- package/dist/views/data-source.js +103 -0
- package/dist/views/index.d.ts +4 -0
- package/dist/views/index.d.ts.map +1 -0
- package/dist/views/index.js +2 -0
- package/dist/views/map-view.d.ts +39 -0
- package/dist/views/map-view.d.ts.map +1 -0
- package/dist/views/map-view.js +143 -0
- package/dist/views/panels.d.ts +13 -0
- package/dist/views/panels.d.ts.map +1 -0
- package/dist/views/panels.js +119 -0
- package/dist/views/registry.d.ts +46 -0
- package/dist/views/registry.d.ts.map +1 -0
- package/dist/views/registry.js +139 -0
- package/dist/views/skeleton.d.ts +5 -0
- package/dist/views/skeleton.d.ts.map +1 -0
- package/dist/views/skeleton.js +6 -0
- package/dist/views/split-view.d.ts +6 -0
- package/dist/views/split-view.d.ts.map +1 -0
- package/dist/views/split-view.js +52 -0
- package/dist/views/timeline-view.d.ts +25 -0
- package/dist/views/timeline-view.d.ts.map +1 -0
- package/dist/views/timeline-view.js +130 -0
- package/dist/views/types.d.ts +87 -0
- package/dist/views/types.d.ts.map +1 -0
- package/dist/views/types.js +1 -0
- package/package.json +18 -6
- package/src/__tests__/addon-page-host.test.tsx +122 -0
- package/src/__tests__/addon-page-loader.test.tsx +201 -0
- package/src/__tests__/declarative-views.test.tsx +351 -0
- package/src/__tests__/host-api.test.ts +153 -0
- package/src/__tests__/index-static-graph.test.ts +18 -0
- package/src/addon-loader.tsx +51 -8
- package/src/addon-page-host.tsx +319 -0
- package/src/addon-page-loader.tsx +203 -0
- package/src/dynamic-view.tsx +61 -3
- package/src/federated-error-boundary.tsx +121 -0
- package/src/host-api.ts +166 -0
- package/src/index.ts +38 -0
- package/src/testing.tsx +108 -0
- package/src/types.ts +13 -0
- package/src/views/calendar-view.tsx +234 -0
- package/src/views/chart-view.tsx +122 -0
- package/src/views/data-source.ts +127 -0
- package/src/views/index.ts +37 -0
- package/src/views/map-view.tsx +217 -0
- package/src/views/panels.tsx +177 -0
- package/src/views/registry.tsx +202 -0
- package/src/views/skeleton.tsx +13 -0
- package/src/views/split-view.tsx +115 -0
- package/src/views/timeline-view.tsx +229 -0
- package/src/views/types.ts +105 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: map` and `kind: map` detail panels — CONTRACT + ACCESSIBLE
|
|
3
|
+
// FALLBACK. The interactive renderer (MapLibre, clustering, layers, dark
|
|
4
|
+
// style) belongs to `@asteby/metacore-maps`, which registers itself with
|
|
5
|
+
// `registerViewRenderer('map', …)` / `registerPanelRenderer('map', …)`. Until a
|
|
6
|
+
// host does, this chunk renders what every map must offer anyway: the
|
|
7
|
+
// equivalent keyboard-navigable list of features, each with an "open in map"
|
|
8
|
+
// link. The pure helpers below (features, route) are the shared contract the
|
|
9
|
+
// maps package builds on, so both renderers read the manifest identically.
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { MapPin } from 'lucide-react';
|
|
13
|
+
import { buildRelationFilterParams } from '../dynamic-relation-helpers';
|
|
14
|
+
import { displayValue } from './data-source';
|
|
15
|
+
import { ViewSkeleton } from './skeleton';
|
|
16
|
+
const MAX_FEATURES = 500;
|
|
17
|
+
function num(v) {
|
|
18
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' && v.trim() !== '' ? Number(v) : NaN;
|
|
19
|
+
return Number.isFinite(n) ? n : null;
|
|
20
|
+
}
|
|
21
|
+
/** Coordinates of a row: `point {lat,lng}` columns or a GeoJSON Point column. */
|
|
22
|
+
export function rowCoordinates(row, point, geometry) {
|
|
23
|
+
if (point) {
|
|
24
|
+
const lat = num(row[point.lat]);
|
|
25
|
+
const lng = num(row[point.lng]);
|
|
26
|
+
if (lat === null || lng === null || Math.abs(lat) > 90 || Math.abs(lng) > 180)
|
|
27
|
+
return null;
|
|
28
|
+
return { lat, lng };
|
|
29
|
+
}
|
|
30
|
+
if (geometry) {
|
|
31
|
+
let g = row[geometry];
|
|
32
|
+
if (typeof g === 'string') {
|
|
33
|
+
try {
|
|
34
|
+
g = JSON.parse(g);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const geo = g;
|
|
41
|
+
if (geo?.type === 'Point' && Array.isArray(geo.coordinates)) {
|
|
42
|
+
const lng = num(geo.coordinates[0]);
|
|
43
|
+
const lat = num(geo.coordinates[1]);
|
|
44
|
+
if (lat !== null && lng !== null)
|
|
45
|
+
return { lat, lng };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** Pure: rows → map features (rows without valid coordinates are skipped). */
|
|
51
|
+
export function toMapFeatures(rows, view) {
|
|
52
|
+
const out = [];
|
|
53
|
+
rows.forEach((row, i) => {
|
|
54
|
+
const c = rowCoordinates(row, view.point, view.geometry);
|
|
55
|
+
if (!c)
|
|
56
|
+
return;
|
|
57
|
+
out.push({
|
|
58
|
+
key: String(row.id ?? i),
|
|
59
|
+
...c,
|
|
60
|
+
color: view.color_by ? displayValue(row[view.color_by]) || undefined : undefined,
|
|
61
|
+
popup: (view.popup ?? []).map((field) => ({ field, value: displayValue(row[field]) })),
|
|
62
|
+
row,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** Pure: ordered route points of a record's children (`route.order_by` ascending). */
|
|
68
|
+
export function toRoutePoints(children, route) {
|
|
69
|
+
return [...children]
|
|
70
|
+
.sort((a, b) => String(a[route.order_by] ?? '').localeCompare(String(b[route.order_by] ?? '')))
|
|
71
|
+
.map((r) => rowCoordinates(r, route.point, undefined))
|
|
72
|
+
.filter((p) => p !== null);
|
|
73
|
+
}
|
|
74
|
+
/** "Open in map" link (OpenStreetMap; no key, no tracking script). */
|
|
75
|
+
export function openInMapHref(lat, lng) {
|
|
76
|
+
return `https://www.openstreetmap.org/?mlat=${lat}&mlon=${lng}#map=16/${lat}/${lng}`;
|
|
77
|
+
}
|
|
78
|
+
export function MapFeatureList({ features, onOpen, }) {
|
|
79
|
+
const { t } = useTranslation();
|
|
80
|
+
if (features.length === 0) {
|
|
81
|
+
return (_jsx("p", { className: "py-8 text-center text-sm text-muted-foreground", "data-testid": "map-empty", children: t('metacore.views.map_empty', 'No hay ubicaciones para mostrar.') }));
|
|
82
|
+
}
|
|
83
|
+
return (_jsx("ul", { className: "divide-y rounded-lg border", "data-testid": "map-feature-list", children: features.map((f) => {
|
|
84
|
+
const label = f.popup[0]?.value || f.key;
|
|
85
|
+
return (_jsxs("li", { className: "flex items-start gap-3 p-3", children: [_jsx(MapPin, { "aria-hidden": true, className: "mt-0.5 h-4 w-4 shrink-0 text-primary" }), _jsxs("div", { className: "min-w-0 flex-1", children: [onOpen ? (_jsx("button", { type: "button", className: "truncate text-left text-sm font-medium text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onOpen(f.row), children: label })) : (_jsx("span", { className: "truncate text-sm font-medium text-foreground", children: label })), f.popup.length > 1 || f.color ? (_jsx("p", { className: "truncate text-xs text-muted-foreground", children: [f.color, ...f.popup.slice(1).map((p) => p.value)].filter(Boolean).join(' · ') })) : null] }), _jsx("a", { href: openInMapHref(f.lat, f.lng), target: "_blank", rel: "noopener noreferrer", className: "shrink-0 text-xs text-primary underline-offset-2 hover:underline", "aria-label": t('metacore.views.open_in_map_of', 'Abrir en mapa: {{label}}', { label }), children: t('metacore.views.open_in_map', 'Abrir en mapa') })] }, f.key));
|
|
86
|
+
}) }));
|
|
87
|
+
}
|
|
88
|
+
/** `view_type: map` fallback renderer: the accessible list of features. */
|
|
89
|
+
export default function MapViewFallback(props) {
|
|
90
|
+
const { model, view, data, onOpenRecord, className } = props;
|
|
91
|
+
const { t } = useTranslation();
|
|
92
|
+
const [rows, setRows] = React.useState(null);
|
|
93
|
+
const [error, setError] = React.useState(false);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
let cancelled = false;
|
|
96
|
+
data
|
|
97
|
+
.list(model, { per_page: MAX_FEATURES })
|
|
98
|
+
.then((res) => !cancelled && setRows(res.rows))
|
|
99
|
+
.catch(() => !cancelled && setError(true));
|
|
100
|
+
return () => {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
};
|
|
103
|
+
}, [data, model]);
|
|
104
|
+
if (error) {
|
|
105
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
106
|
+
}
|
|
107
|
+
if (!rows)
|
|
108
|
+
return _jsx(ViewSkeleton, {});
|
|
109
|
+
return (_jsx("div", { className: className, "data-testid": "map-view-fallback", children: _jsx(MapFeatureList, { features: toMapFeatures(rows, view), onOpen: onOpenRecord }) }));
|
|
110
|
+
}
|
|
111
|
+
/** `kind: map` panel fallback: the record's point and its route stops. */
|
|
112
|
+
export function MapPanel({ panel, record, metadata, data }) {
|
|
113
|
+
const view = panel.map;
|
|
114
|
+
const route = view?.route;
|
|
115
|
+
const rel = route ? metadata?.relations?.find((r) => r.name === route.relation) : undefined;
|
|
116
|
+
const [stops, setStops] = React.useState([]);
|
|
117
|
+
const recordId = record.id;
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
if (!route || !rel || recordId === undefined || recordId === null)
|
|
120
|
+
return;
|
|
121
|
+
let cancelled = false;
|
|
122
|
+
data
|
|
123
|
+
.list(rel.through, {
|
|
124
|
+
...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope),
|
|
125
|
+
per_page: MAX_FEATURES,
|
|
126
|
+
sortBy: route.order_by,
|
|
127
|
+
order: 'asc',
|
|
128
|
+
})
|
|
129
|
+
.then((res) => !cancelled && setStops(toRoutePoints(res.rows, route)))
|
|
130
|
+
.catch(() => undefined);
|
|
131
|
+
return () => {
|
|
132
|
+
cancelled = true;
|
|
133
|
+
};
|
|
134
|
+
}, [data, route, rel, recordId]);
|
|
135
|
+
if (!view)
|
|
136
|
+
return null;
|
|
137
|
+
const own = toMapFeatures([record], { ...view, popup: view.popup ?? [] });
|
|
138
|
+
const features = [
|
|
139
|
+
...stops.map((s, i) => ({ key: `stop-${i}`, ...s, popup: [{ field: '#', value: `#${i + 1}` }], row: {} })),
|
|
140
|
+
...own,
|
|
141
|
+
];
|
|
142
|
+
return _jsx(MapFeatureList, { features: features });
|
|
143
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { PanelRendererProps } from './types';
|
|
3
|
+
export type StatFormat = 'number' | 'currency' | 'percent' | 'compact' | 'date' | 'datetime' | 'relative_date';
|
|
4
|
+
/** Pure: format one stat value for display. `now` is injectable for tests. */
|
|
5
|
+
export declare function formatStat(value: unknown, format: string | undefined, opts?: {
|
|
6
|
+
locale?: string;
|
|
7
|
+
currency?: string;
|
|
8
|
+
timeZone?: string;
|
|
9
|
+
now?: Date;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function StatsPanelView({ panel, record, metadata, locale, currency, timeZone }: PanelRendererProps): React.JSX.Element;
|
|
12
|
+
export declare function RelationPanelView({ panel, record, metadata, data, onOpenRecord }: PanelRendererProps): React.JSX.Element | null;
|
|
13
|
+
//# sourceMappingURL=panels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/views/panels.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIjD,MAAM,MAAM,UAAU,GAChB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,SAAS,GACT,MAAM,GACN,UAAU,GACV,eAAe,CAAA;AAErB,8EAA8E;AAC9E,wBAAgB,UAAU,CACtB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAO,GACjF,MAAM,CA4CR;AAED,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,kBAAkB,qBAiBzG;AAED,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,kBAAkB,4BAuFpG"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// `kind: relation` and `kind: stats` detail panels. Lazy chunk. Both only
|
|
3
|
+
// display server values: a relation panel lists the record's children (first
|
|
4
|
+
// `limit` rows), a stats panel formats a few of the record's own fields.
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { buildRelationFilterParams } from '../dynamic-relation-helpers';
|
|
8
|
+
import { displayValue, toDate } from './data-source';
|
|
9
|
+
import { ViewSkeleton } from './skeleton';
|
|
10
|
+
/** Pure: format one stat value for display. `now` is injectable for tests. */
|
|
11
|
+
export function formatStat(value, format, opts = {}) {
|
|
12
|
+
if (value === null || value === undefined || value === '')
|
|
13
|
+
return '—';
|
|
14
|
+
const { locale, currency, timeZone } = opts;
|
|
15
|
+
const num = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : NaN;
|
|
16
|
+
try {
|
|
17
|
+
switch (format) {
|
|
18
|
+
case 'currency':
|
|
19
|
+
if (Number.isNaN(num))
|
|
20
|
+
break;
|
|
21
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency: currency || 'MXN' }).format(num);
|
|
22
|
+
case 'percent':
|
|
23
|
+
if (Number.isNaN(num))
|
|
24
|
+
break;
|
|
25
|
+
return new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(num);
|
|
26
|
+
case 'compact':
|
|
27
|
+
if (Number.isNaN(num))
|
|
28
|
+
break;
|
|
29
|
+
return new Intl.NumberFormat(locale, { notation: 'compact' }).format(num);
|
|
30
|
+
case 'number':
|
|
31
|
+
if (Number.isNaN(num))
|
|
32
|
+
break;
|
|
33
|
+
return new Intl.NumberFormat(locale).format(num);
|
|
34
|
+
case 'date':
|
|
35
|
+
case 'datetime': {
|
|
36
|
+
const d = toDate(value);
|
|
37
|
+
if (!d)
|
|
38
|
+
break;
|
|
39
|
+
return new Intl.DateTimeFormat(locale, {
|
|
40
|
+
dateStyle: 'medium',
|
|
41
|
+
...(format === 'datetime' ? { timeStyle: 'short' } : {}),
|
|
42
|
+
timeZone,
|
|
43
|
+
}).format(d);
|
|
44
|
+
}
|
|
45
|
+
case 'relative_date': {
|
|
46
|
+
const d = toDate(value);
|
|
47
|
+
if (!d)
|
|
48
|
+
break;
|
|
49
|
+
const now = opts.now ?? new Date();
|
|
50
|
+
const diffMs = d.getTime() - now.getTime();
|
|
51
|
+
const abs = Math.abs(diffMs);
|
|
52
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
|
|
53
|
+
if (abs < 3_600_000)
|
|
54
|
+
return rtf.format(Math.round(diffMs / 60_000), 'minute');
|
|
55
|
+
if (abs < 86_400_000)
|
|
56
|
+
return rtf.format(Math.round(diffMs / 3_600_000), 'hour');
|
|
57
|
+
return rtf.format(Math.round(diffMs / 86_400_000), 'day');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* invalid locale/currency: fall through to the raw value */
|
|
63
|
+
}
|
|
64
|
+
return displayValue(value);
|
|
65
|
+
}
|
|
66
|
+
export function StatsPanelView({ panel, record, metadata, locale, currency, timeZone }) {
|
|
67
|
+
const { t } = useTranslation();
|
|
68
|
+
const items = panel.stats?.items ?? [];
|
|
69
|
+
const labelOf = (field, label) => label ? t(label) : metadata?.columns?.find((c) => c.key === field)?.label ?? field;
|
|
70
|
+
return (_jsx("dl", { className: "grid grid-cols-2 gap-3 sm:grid-cols-4", "data-testid": "stats-panel", children: items.map((it) => (_jsxs("div", { className: "rounded-md bg-muted/40 p-3", children: [_jsx("dt", { className: "text-xs text-muted-foreground", children: labelOf(it.field, it.label) }), _jsx("dd", { className: "mt-1 text-lg font-semibold tabular-nums text-foreground", children: formatStat(record[it.field], it.format, { locale, currency, timeZone }) })] }, it.field))) }));
|
|
71
|
+
}
|
|
72
|
+
export function RelationPanelView({ panel, record, metadata, data, onOpenRecord }) {
|
|
73
|
+
const { t } = useTranslation();
|
|
74
|
+
const cfg = panel.relation;
|
|
75
|
+
const rel = metadata?.relations?.find((r) => r.name === cfg?.name);
|
|
76
|
+
const limit = Math.min(Math.max(cfg?.limit ?? 10, 1), 50);
|
|
77
|
+
const [rows, setRows] = React.useState(null);
|
|
78
|
+
const [total, setTotal] = React.useState();
|
|
79
|
+
const [error, setError] = React.useState(false);
|
|
80
|
+
const recordId = record.id;
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
if (!rel || rel.kind !== 'one_to_many' || recordId === undefined || recordId === null)
|
|
83
|
+
return;
|
|
84
|
+
let cancelled = false;
|
|
85
|
+
setRows(null);
|
|
86
|
+
setError(false);
|
|
87
|
+
data
|
|
88
|
+
.list(rel.through, {
|
|
89
|
+
...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope),
|
|
90
|
+
per_page: limit,
|
|
91
|
+
})
|
|
92
|
+
.then((res) => {
|
|
93
|
+
if (cancelled)
|
|
94
|
+
return;
|
|
95
|
+
setRows(res.rows);
|
|
96
|
+
setTotal(res.total);
|
|
97
|
+
}, () => !cancelled && setError(true));
|
|
98
|
+
return () => {
|
|
99
|
+
cancelled = true;
|
|
100
|
+
};
|
|
101
|
+
}, [data, rel, recordId, limit]);
|
|
102
|
+
if (!cfg)
|
|
103
|
+
return null;
|
|
104
|
+
if (!rel || rel.kind !== 'one_to_many') {
|
|
105
|
+
return _jsx("p", { className: "text-xs text-muted-foreground", children: cfg.name });
|
|
106
|
+
}
|
|
107
|
+
if (error) {
|
|
108
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
109
|
+
}
|
|
110
|
+
if (!rows)
|
|
111
|
+
return _jsx(ViewSkeleton, { height: 160 });
|
|
112
|
+
if (rows.length === 0) {
|
|
113
|
+
return _jsx("p", { className: "py-4 text-sm text-muted-foreground", children: t('metacore.views.empty', 'Sin datos todavía.') });
|
|
114
|
+
}
|
|
115
|
+
const columns = cfg.columns && cfg.columns.length > 0
|
|
116
|
+
? cfg.columns
|
|
117
|
+
: Object.keys(rows[0]).filter((k) => k !== 'id' && k !== rel.foreign_key && k !== 'organization_id').slice(0, 4);
|
|
118
|
+
return (_jsxs("div", { className: "overflow-x-auto", "data-testid": "relation-panel", children: [_jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { children: _jsx("tr", { className: "border-b text-left text-xs text-muted-foreground", children: columns.map((c) => (_jsx("th", { scope: "col", className: "px-2 py-1.5 font-medium", children: c }, c))) }) }), _jsx("tbody", { children: rows.map((row, i) => (_jsx("tr", { className: ['border-b last:border-0', onOpenRecord ? 'cursor-pointer hover:bg-muted/40' : ''].join(' '), onClick: onOpenRecord ? () => onOpenRecord(rel.through, row) : undefined, children: columns.map((c) => (_jsx("td", { className: "px-2 py-1.5", children: displayValue(row[c]) }, c))) }, String(row.id ?? i)))) })] }), total !== undefined && total > rows.length ? (_jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: t('metacore.views.showing_of', '{{shown}} de {{total}}', { shown: rows.length, total }) })) : null] }));
|
|
119
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { DetailPanel, NavView } from '@asteby/metacore-sdk';
|
|
3
|
+
import type { DeclarativeViewType, PanelRendererLoader, PanelRendererProps, ViewRendererLoader, ViewRendererProps } from './types';
|
|
4
|
+
import { ViewSkeleton } from './skeleton';
|
|
5
|
+
export { ViewSkeleton };
|
|
6
|
+
export declare const DECLARATIVE_VIEW_TYPES: readonly DeclarativeViewType[];
|
|
7
|
+
export declare function isDeclarativeViewType(t: string | undefined | null): t is DeclarativeViewType;
|
|
8
|
+
/**
|
|
9
|
+
* Register (or replace) the renderer of a view type. Returns a function that
|
|
10
|
+
* restores the previous loader. Replacing drops the cached lazy component.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerViewRenderer(type: string, loader: ViewRendererLoader): () => void;
|
|
13
|
+
/** Register (or replace) the renderer of a detail panel kind (incl. `custom`). */
|
|
14
|
+
export declare function registerPanelRenderer(kind: string, loader: PanelRendererLoader): () => void;
|
|
15
|
+
export declare function hasViewRenderer(type: string): boolean;
|
|
16
|
+
export declare function hasPanelRenderer(kind: string): boolean;
|
|
17
|
+
/** Warm a renderer chunk (hover/focus on a nav entry). Resolves false when none. */
|
|
18
|
+
export declare function preloadViewRenderer(type: string): Promise<boolean>;
|
|
19
|
+
export interface DeclarativeViewProps extends Omit<ViewRendererProps, 'view'> {
|
|
20
|
+
viewType: DeclarativeViewType | string;
|
|
21
|
+
/** The nav entry's `view` block (served in the table metadata). */
|
|
22
|
+
view: NavView | null | undefined;
|
|
23
|
+
/** Rendered when the type has no renderer or its block is missing. */
|
|
24
|
+
fallback?: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Render a declarative view by type: picks `view[viewType]`, lazy-loads that
|
|
28
|
+
* renderer, isolates it in an error boundary. Unknown types render `fallback`
|
|
29
|
+
* (hosts pass the table, the same rule DynamicView applies).
|
|
30
|
+
*/
|
|
31
|
+
export declare function DeclarativeView({ viewType, view, fallback, ...rest }: DeclarativeViewProps): React.JSX.Element;
|
|
32
|
+
export interface DetailPanelsProps extends Omit<PanelRendererProps, 'panel'> {
|
|
33
|
+
panels: DetailPanel[] | null | undefined;
|
|
34
|
+
/** Permission check for `panel.permission` (default: everything visible). */
|
|
35
|
+
can?: (permission: string) => boolean;
|
|
36
|
+
/** i18n for panel titles (raw keys pass through by default). */
|
|
37
|
+
translate?: (key: string) => string;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Detail panels of a record in a 2-column grid (`span: half` takes one
|
|
42
|
+
* column, `full` both). Each panel is lazy and isolated: one failing panel
|
|
43
|
+
* never blanks the detail page.
|
|
44
|
+
*/
|
|
45
|
+
export declare function DetailPanels({ panels, can, translate, className, ...rest }: DetailPanelsProps): React.JSX.Element | null;
|
|
46
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/views/registry.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,KAAK,EACR,mBAAmB,EAEnB,mBAAmB,EACnB,kBAAkB,EAElB,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,eAAO,MAAM,sBAAsB,EAAE,SAAS,mBAAmB,EAMvD,CAAA;AAEV,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,IAAI,mBAAmB,CAE5F;AAqBD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,MAAM,IAAI,CASzF;AAED,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAS3F;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGlE;AAwBD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACzE,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAAA;IACtC,mEAAmE;IACnE,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,sEAAsE;IACtE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAe,EAAE,GAAG,IAAI,EAAE,EAAE,oBAAoB,qBAWjG;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACxE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,GAAG,SAAS,CAAA;IACxC,6EAA6E;IAC7E,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAA;IACrC,gEAAgE;IAChE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACnC,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,4BAmC7F"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Declarative view & panel renderer registry.
|
|
3
|
+
//
|
|
4
|
+
// Every renderer is a separate lazy chunk keyed by type: an addon that only
|
|
5
|
+
// declares a `timeline` never downloads the chart, calendar or map code, and
|
|
6
|
+
// none of them is in the host's first paint (the package index reaches this
|
|
7
|
+
// module, never the renderers — see __tests__/index-static-graph.test.ts).
|
|
8
|
+
//
|
|
9
|
+
// Built-in: chart, timeline, calendar, split (views) and map/timeline/chart/
|
|
10
|
+
// relation/stats (panels). `map` ships an accessible list fallback until a
|
|
11
|
+
// maps package registers the real renderer:
|
|
12
|
+
//
|
|
13
|
+
// registerViewRenderer('map', () => import('@asteby/metacore-maps/view'))
|
|
14
|
+
// registerPanelRenderer('map', () => import('@asteby/metacore-maps/panel'))
|
|
15
|
+
//
|
|
16
|
+
// `custom` panels (level C, a federated component) have no built-in: the host
|
|
17
|
+
// registers one that mounts the addon's expose.
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { FederatedErrorBoundary } from '../federated-error-boundary';
|
|
20
|
+
import { ViewSkeleton } from './skeleton';
|
|
21
|
+
export { ViewSkeleton };
|
|
22
|
+
export const DECLARATIVE_VIEW_TYPES = [
|
|
23
|
+
'map',
|
|
24
|
+
'timeline',
|
|
25
|
+
'calendar',
|
|
26
|
+
'chart',
|
|
27
|
+
'split',
|
|
28
|
+
];
|
|
29
|
+
export function isDeclarativeViewType(t) {
|
|
30
|
+
return !!t && DECLARATIVE_VIEW_TYPES.includes(t);
|
|
31
|
+
}
|
|
32
|
+
const viewLoaders = new Map([
|
|
33
|
+
['chart', () => import('./chart-view')],
|
|
34
|
+
['timeline', () => import('./timeline-view')],
|
|
35
|
+
['calendar', () => import('./calendar-view')],
|
|
36
|
+
['split', () => import('./split-view')],
|
|
37
|
+
['map', () => import('./map-view')],
|
|
38
|
+
]);
|
|
39
|
+
const panelLoaders = new Map([
|
|
40
|
+
['chart', () => import('./chart-view').then((m) => ({ default: m.ChartPanel }))],
|
|
41
|
+
['timeline', () => import('./timeline-view').then((m) => ({ default: m.TimelinePanel }))],
|
|
42
|
+
['map', () => import('./map-view').then((m) => ({ default: m.MapPanel }))],
|
|
43
|
+
['relation', () => import('./panels').then((m) => ({ default: m.RelationPanelView }))],
|
|
44
|
+
['stats', () => import('./panels').then((m) => ({ default: m.StatsPanelView }))],
|
|
45
|
+
]);
|
|
46
|
+
const lazyViews = new Map();
|
|
47
|
+
const lazyPanels = new Map();
|
|
48
|
+
/**
|
|
49
|
+
* Register (or replace) the renderer of a view type. Returns a function that
|
|
50
|
+
* restores the previous loader. Replacing drops the cached lazy component.
|
|
51
|
+
*/
|
|
52
|
+
export function registerViewRenderer(type, loader) {
|
|
53
|
+
const prev = viewLoaders.get(type);
|
|
54
|
+
viewLoaders.set(type, loader);
|
|
55
|
+
lazyViews.delete(type);
|
|
56
|
+
return () => {
|
|
57
|
+
if (prev)
|
|
58
|
+
viewLoaders.set(type, prev);
|
|
59
|
+
else
|
|
60
|
+
viewLoaders.delete(type);
|
|
61
|
+
lazyViews.delete(type);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Register (or replace) the renderer of a detail panel kind (incl. `custom`). */
|
|
65
|
+
export function registerPanelRenderer(kind, loader) {
|
|
66
|
+
const prev = panelLoaders.get(kind);
|
|
67
|
+
panelLoaders.set(kind, loader);
|
|
68
|
+
lazyPanels.delete(kind);
|
|
69
|
+
return () => {
|
|
70
|
+
if (prev)
|
|
71
|
+
panelLoaders.set(kind, prev);
|
|
72
|
+
else
|
|
73
|
+
panelLoaders.delete(kind);
|
|
74
|
+
lazyPanels.delete(kind);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function hasViewRenderer(type) {
|
|
78
|
+
return viewLoaders.has(type);
|
|
79
|
+
}
|
|
80
|
+
export function hasPanelRenderer(kind) {
|
|
81
|
+
return panelLoaders.has(kind);
|
|
82
|
+
}
|
|
83
|
+
/** Warm a renderer chunk (hover/focus on a nav entry). Resolves false when none. */
|
|
84
|
+
export function preloadViewRenderer(type) {
|
|
85
|
+
const loader = viewLoaders.get(type);
|
|
86
|
+
return loader ? loader().then(() => true, () => false) : Promise.resolve(false);
|
|
87
|
+
}
|
|
88
|
+
function lazyView(type) {
|
|
89
|
+
const loader = viewLoaders.get(type);
|
|
90
|
+
if (!loader)
|
|
91
|
+
return null;
|
|
92
|
+
let c = lazyViews.get(type);
|
|
93
|
+
if (!c) {
|
|
94
|
+
c = React.lazy(loader);
|
|
95
|
+
lazyViews.set(type, c);
|
|
96
|
+
}
|
|
97
|
+
return c;
|
|
98
|
+
}
|
|
99
|
+
function lazyPanel(kind) {
|
|
100
|
+
const loader = panelLoaders.get(kind);
|
|
101
|
+
if (!loader)
|
|
102
|
+
return null;
|
|
103
|
+
let c = lazyPanels.get(kind);
|
|
104
|
+
if (!c) {
|
|
105
|
+
c = React.lazy(loader);
|
|
106
|
+
lazyPanels.set(kind, c);
|
|
107
|
+
}
|
|
108
|
+
return c;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Render a declarative view by type: picks `view[viewType]`, lazy-loads that
|
|
112
|
+
* renderer, isolates it in an error boundary. Unknown types render `fallback`
|
|
113
|
+
* (hosts pass the table, the same rule DynamicView applies).
|
|
114
|
+
*/
|
|
115
|
+
export function DeclarativeView({ viewType, view, fallback = null, ...rest }) {
|
|
116
|
+
const block = view?.[viewType];
|
|
117
|
+
const Renderer = lazyView(viewType);
|
|
118
|
+
if (!Renderer || !block)
|
|
119
|
+
return _jsx(_Fragment, { children: fallback });
|
|
120
|
+
return (_jsx(FederatedErrorBoundary, { addonKey: `view:${viewType}`, resetKeys: [rest.model, viewType], children: _jsx(React.Suspense, { fallback: _jsx(ViewSkeleton, {}), children: _jsx(Renderer, { ...rest, view: block }) }) }));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Detail panels of a record in a 2-column grid (`span: half` takes one
|
|
124
|
+
* column, `full` both). Each panel is lazy and isolated: one failing panel
|
|
125
|
+
* never blanks the detail page.
|
|
126
|
+
*/
|
|
127
|
+
export function DetailPanels({ panels, can, translate, className, ...rest }) {
|
|
128
|
+
const visible = (panels ?? []).filter((p) => !p.permission || !can || can(p.permission));
|
|
129
|
+
if (visible.length === 0)
|
|
130
|
+
return null;
|
|
131
|
+
const tr = translate ?? ((k) => k);
|
|
132
|
+
return (_jsx("div", { className: ['grid grid-cols-1 gap-4 lg:grid-cols-2', className].filter(Boolean).join(' '), children: visible.map((panel) => {
|
|
133
|
+
const Renderer = lazyPanel(panel.kind);
|
|
134
|
+
return (_jsxs("section", { "data-panel": panel.key, "aria-label": tr(panel.title), className: [
|
|
135
|
+
'min-w-0 rounded-lg border bg-card p-4',
|
|
136
|
+
panel.span === 'half' ? '' : 'lg:col-span-2',
|
|
137
|
+
].join(' '), children: [_jsx("h3", { className: "mb-3 text-sm font-medium text-foreground", children: tr(panel.title) }), Renderer ? (_jsx(FederatedErrorBoundary, { addonKey: `panel:${panel.key}`, resetKeys: [rest.record], children: _jsx(React.Suspense, { fallback: _jsx(ViewSkeleton, { height: 200 }), children: _jsx(Renderer, { ...rest, panel: panel }) }) })) : (_jsx("p", { className: "text-xs text-muted-foreground", "data-testid": "panel-unsupported", children: panel.kind }))] }, panel.key));
|
|
138
|
+
}) }));
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skeleton.d.ts","sourceRoot":"","sources":["../../src/views/skeleton.tsx"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,EAAE,MAAY,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,+BASjE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Fixed-height placeholder shared by the registry and the lazy renderers.
|
|
3
|
+
/** Fixed-height skeleton (no layout shift while a renderer chunk loads). */
|
|
4
|
+
export function ViewSkeleton({ height = 360 }) {
|
|
5
|
+
return (_jsx("div", { "aria-busy": "true", "data-testid": "view-skeleton", className: "w-full animate-pulse rounded-lg bg-muted", style: { height } }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ViewRendererProps } from './types';
|
|
3
|
+
/** Pure: which metadata columns to hide so the list shows only `columns`. */
|
|
4
|
+
export declare function hiddenColumnsFor(allColumns: string[], columns: string[] | undefined): string[];
|
|
5
|
+
export default function SplitViewRenderer(props: ViewRendererProps<'split'>): React.JSX.Element;
|
|
6
|
+
//# sourceMappingURL=split-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-view.d.ts","sourceRoot":"","sources":["../../src/views/split-view.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAI9F;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,qBA6F1E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: split` — master-detail on one screen: the model's list (the
|
|
3
|
+
// same DynamicTable every model uses, restricted to `split.columns`) and the
|
|
4
|
+
// selected record's detail panels (`split.panels`, else the model's
|
|
5
|
+
// `detail.panels`). Stacks below 1280 px. Lazy chunk.
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { X } from 'lucide-react';
|
|
9
|
+
import { Button } from '@asteby/metacore-ui/primitives';
|
|
10
|
+
import { DynamicTable } from '../dynamic-table';
|
|
11
|
+
import { DetailPanels } from './registry';
|
|
12
|
+
import { displayValue } from './data-source';
|
|
13
|
+
import { ViewSkeleton } from './skeleton';
|
|
14
|
+
/** Pure: which metadata columns to hide so the list shows only `columns`. */
|
|
15
|
+
export function hiddenColumnsFor(allColumns, columns) {
|
|
16
|
+
if (!columns || columns.length === 0)
|
|
17
|
+
return [];
|
|
18
|
+
const keep = new Set(columns);
|
|
19
|
+
return allColumns.filter((c) => !keep.has(c));
|
|
20
|
+
}
|
|
21
|
+
export default function SplitViewRenderer(props) {
|
|
22
|
+
const { model, view, metadata, data, locale, currency, timeZone, className } = props;
|
|
23
|
+
const { t } = useTranslation();
|
|
24
|
+
const [selected, setSelected] = React.useState(null);
|
|
25
|
+
const [record, setRecord] = React.useState(null);
|
|
26
|
+
const detailRef = React.useRef(null);
|
|
27
|
+
const selectedId = selected?.id !== undefined && selected?.id !== null ? String(selected.id) : null;
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (!selectedId) {
|
|
30
|
+
setRecord(null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let cancelled = false;
|
|
34
|
+
setRecord(null);
|
|
35
|
+
data.record(model, selectedId).then((r) => !cancelled && setRecord(r ?? selected),
|
|
36
|
+
// The list row is still a usable record for the panels.
|
|
37
|
+
() => !cancelled && setRecord(selected));
|
|
38
|
+
return () => {
|
|
39
|
+
cancelled = true;
|
|
40
|
+
};
|
|
41
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
42
|
+
}, [data, model, selectedId]);
|
|
43
|
+
// Move focus to the detail for keyboard and screen-reader users.
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (record)
|
|
46
|
+
detailRef.current?.focus();
|
|
47
|
+
}, [record]);
|
|
48
|
+
const hidden = React.useMemo(() => hiddenColumnsFor((metadata?.columns ?? []).map((c) => c.key), view.columns), [metadata, view.columns]);
|
|
49
|
+
const panels = view.panels ?? metadata?.detail?.panels ?? [];
|
|
50
|
+
const titleKey = view.columns?.[0];
|
|
51
|
+
return (_jsxs("div", { className: ['grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1.1fr)]', className].filter(Boolean).join(' '), "data-testid": "split-view", children: [_jsx("div", { className: "min-w-0", children: _jsx(DynamicTable, { model: model, hiddenColumns: hidden, onRowClick: (row) => setSelected(row), timeZone: timeZone, currency: currency }) }), _jsx("section", { ref: detailRef, tabIndex: -1, "aria-live": "polite", "aria-label": t('metacore.views.detail', 'Detalle'), className: "min-w-0 rounded-lg border bg-background p-4 outline-none xl:sticky xl:top-4 xl:max-h-[calc(100dvh-8rem)] xl:overflow-auto", children: !selected ? (_jsx("p", { className: "py-16 text-center text-sm text-muted-foreground", "data-testid": "split-empty", children: t('metacore.views.select_record', 'Selecciona un registro para ver su detalle.') })) : !record ? (_jsx(ViewSkeleton, { height: 240 })) : (_jsxs(_Fragment, { children: [_jsxs("header", { className: "mb-4 flex items-start justify-between gap-2", children: [_jsx("h2", { className: "text-base font-semibold text-foreground", children: displayValue(titleKey ? record[titleKey] : record.id) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": t('metacore.views.close_detail', 'Cerrar detalle'), onClick: () => setSelected(null), children: _jsx(X, { "aria-hidden": true, className: "h-4 w-4" }) })] }), _jsx(DetailPanels, { model: model, panels: panels, record: record, metadata: metadata, data: data, locale: locale, currency: currency, timeZone: timeZone, translate: (k) => t(k) })] })) })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { TimelineView } from '@asteby/metacore-sdk';
|
|
3
|
+
import type { PanelRendererProps, ViewRendererProps } from './types';
|
|
4
|
+
export interface TimelineEntry {
|
|
5
|
+
key: string;
|
|
6
|
+
at: Date | null;
|
|
7
|
+
title: string;
|
|
8
|
+
status?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
group?: string;
|
|
11
|
+
row: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/** Pure: rows → ordered entries (newest first), grouped when `group_by` is set. */
|
|
14
|
+
export declare function toTimelineEntries(rows: Record<string, unknown>[], view: TimelineView): TimelineEntry[];
|
|
15
|
+
export declare function TimelineList({ entries, locale, timeZone, onOpen, }: {
|
|
16
|
+
entries: TimelineEntry[];
|
|
17
|
+
locale?: string;
|
|
18
|
+
timeZone?: string;
|
|
19
|
+
onOpen?: (row: Record<string, unknown>) => void;
|
|
20
|
+
}): React.JSX.Element;
|
|
21
|
+
/** `view_type: timeline` on a nav entry: the model's rows, newest first, paged. */
|
|
22
|
+
export default function TimelineViewRenderer(props: ViewRendererProps<'timeline'>): React.JSX.Element;
|
|
23
|
+
/** `kind: timeline` panel: child rows of a relation or a capability's items. */
|
|
24
|
+
export declare function TimelinePanel({ panel, record, metadata, data, locale, timeZone }: PanelRendererProps): React.JSX.Element | null;
|
|
25
|
+
//# sourceMappingURL=timeline-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline-view.d.ts","sourceRoot":"","sources":["../../src/views/timeline-view.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAYpE,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,EAAE,EAAE,IAAI,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,aAAa,EAAE,CAUtG;AAYD,wBAAgB,YAAY,CAAC,EACzB,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,GACT,EAAE;IACC,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CAClD,qBA2DA;AAED,mFAAmF;AACnF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,CAAC,UAAU,CAAC,qBA8ChF;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,kBAAkB,4BAoDpG"}
|