@cognite/aura 1.48322.0 → 1.48345.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/core/message/message-response-table-csv.utils.d.ts +6 -0
- package/dist/components/ui/core/message/message-response-table-csv.utils.js +29 -0
- package/dist/components/ui/core/message/message-response-table-csv.utils.js.map +1 -0
- package/dist/components/ui/core/message/message-response-table-labels.d.ts +8 -0
- package/dist/components/ui/core/message/message-response-table-labels.js +5 -1
- package/dist/components/ui/core/message/message-response-table-labels.js.map +1 -1
- package/dist/components/ui/core/message/message-response-table.js +160 -32
- package/dist/components/ui/core/message/message-response-table.js.map +1 -1
- package/dist/components/ui/core/message/message.js +17 -3
- package/dist/components/ui/core/message/message.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Quotes a cell that contains a comma, quote or line break, doubling any quotes inside it. */
|
|
2
|
+
export declare const escapeCsvCell: (value: string) => string;
|
|
3
|
+
/** Builds CSV text with a header line followed by one line per row. */
|
|
4
|
+
export declare const buildCsv: (headers: string[], rows: string[][]) => string;
|
|
5
|
+
/** Starts a browser download of `csv` as `fileName`. */
|
|
6
|
+
export declare const downloadCsv: (csv: string, fileName: string) => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Quotes a cell that contains a comma, quote or line break, doubling any quotes inside it. */ export const escapeCsvCell = (value)=>/[",\r\n]/.test(value) ? `"${value.replaceAll('"', '""')}"` : value;
|
|
2
|
+
/** Builds CSV text with a header line followed by one line per row. */ export const buildCsv = (headers, rows)=>[
|
|
3
|
+
headers,
|
|
4
|
+
...rows
|
|
5
|
+
].map((cells)=>cells.map(escapeCsvCell).join(',')).join('\n');
|
|
6
|
+
/** Starts a browser download of `csv` as `fileName`. */ export const downloadCsv = (csv, fileName)=>{
|
|
7
|
+
// Prepend a UTF-8 BOM so Excel detects the encoding.
|
|
8
|
+
const content = '' + csv;
|
|
9
|
+
const blob = new Blob([
|
|
10
|
+
content
|
|
11
|
+
], {
|
|
12
|
+
type: 'text/csv;charset=utf-8'
|
|
13
|
+
});
|
|
14
|
+
const url = typeof URL.createObjectURL === 'function' ? URL.createObjectURL(blob) : `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`;
|
|
15
|
+
const anchor = document.createElement('a');
|
|
16
|
+
anchor.href = url;
|
|
17
|
+
anchor.download = fileName;
|
|
18
|
+
// Firefox only starts the download for a link that is in the document.
|
|
19
|
+
document.body.append(anchor);
|
|
20
|
+
anchor.click();
|
|
21
|
+
anchor.remove();
|
|
22
|
+
if (url.startsWith('blob:') && typeof URL.revokeObjectURL === 'function') {
|
|
23
|
+
// Firefox and Safari can abort the download if the URL is revoked
|
|
24
|
+
// synchronously after click(), so defer it.
|
|
25
|
+
setTimeout(()=>URL.revokeObjectURL(url), 100);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=message-response-table-csv.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/message/message-response-table-csv.utils.ts"],"sourcesContent":["/** Quotes a cell that contains a comma, quote or line break, doubling any quotes inside it. */\nexport const escapeCsvCell = (value: string): string =>\n /[\",\\r\\n]/.test(value) ? `\"${value.replaceAll('\"', '\"\"')}\"` : value;\n\n/** Builds CSV text with a header line followed by one line per row. */\nexport const buildCsv = (headers: string[], rows: string[][]): string =>\n [headers, ...rows]\n .map((cells) => cells.map(escapeCsvCell).join(','))\n .join('\\n');\n\n/** Starts a browser download of `csv` as `fileName`. */\nexport const downloadCsv = (csv: string, fileName: string): void => {\n // Prepend a UTF-8 BOM so Excel detects the encoding.\n const content = '' + csv;\n const blob = new Blob([content], { type: 'text/csv;charset=utf-8' });\n const url =\n typeof URL.createObjectURL === 'function'\n ? URL.createObjectURL(blob)\n : `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`;\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.download = fileName;\n // Firefox only starts the download for a link that is in the document.\n document.body.append(anchor);\n anchor.click();\n anchor.remove();\n if (url.startsWith('blob:') && typeof URL.revokeObjectURL === 'function') {\n // Firefox and Safari can abort the download if the URL is revoked\n // synchronously after click(), so defer it.\n setTimeout(() => URL.revokeObjectURL(url), 100);\n }\n};\n"],"names":["escapeCsvCell","value","test","replaceAll","buildCsv","headers","rows","map","cells","join","downloadCsv","csv","fileName","content","blob","Blob","type","url","URL","createObjectURL","encodeURIComponent","anchor","document","createElement","href","download","body","append","click","remove","startsWith","revokeObjectURL","setTimeout"],"mappings":"AAAA,6FAA6F,GAC7F,OAAO,MAAMA,gBAAgB,CAACC,QAC5B,WAAWC,IAAI,CAACD,SAAS,CAAC,CAAC,EAAEA,MAAME,UAAU,CAAC,KAAK,MAAM,CAAC,CAAC,GAAGF,MAAM;AAEtE,qEAAqE,GACrE,OAAO,MAAMG,WAAW,CAACC,SAAmBC,OAC1C;QAACD;WAAYC;KAAK,CACfC,GAAG,CAAC,CAACC,QAAUA,MAAMD,GAAG,CAACP,eAAeS,IAAI,CAAC,MAC7CA,IAAI,CAAC,MAAM;AAEhB,sDAAsD,GACtD,OAAO,MAAMC,cAAc,CAACC,KAAaC;IACvC,qDAAqD;IACrD,MAAMC,UAAU,MAAMF;IACtB,MAAMG,OAAO,IAAIC,KAAK;QAACF;KAAQ,EAAE;QAAEG,MAAM;IAAyB;IAClE,MAAMC,MACJ,OAAOC,IAAIC,eAAe,KAAK,aAC3BD,IAAIC,eAAe,CAACL,QACpB,CAAC,4BAA4B,EAAEM,mBAAmBP,UAAU;IAClE,MAAMQ,SAASC,SAASC,aAAa,CAAC;IACtCF,OAAOG,IAAI,GAAGP;IACdI,OAAOI,QAAQ,GAAGb;IAClB,uEAAuE;IACvEU,SAASI,IAAI,CAACC,MAAM,CAACN;IACrBA,OAAOO,KAAK;IACZP,OAAOQ,MAAM;IACb,IAAIZ,IAAIa,UAAU,CAAC,YAAY,OAAOZ,IAAIa,eAAe,KAAK,YAAY;QACxE,kEAAkE;QAClE,4CAA4C;QAC5CC,WAAW,IAAMd,IAAIa,eAAe,CAACd,MAAM;IAC7C;AACF,EAAE"}
|
|
@@ -7,5 +7,13 @@ export type MessageResponseTableLabels = {
|
|
|
7
7
|
currentPage: string;
|
|
8
8
|
/** Status line in the pagination footer, e.g. "Showing 1–50 of 120". */
|
|
9
9
|
paginationStatus: FormatPaginationStatus;
|
|
10
|
+
/** Button and tooltip that open the expanded view. */
|
|
11
|
+
expandView: string;
|
|
12
|
+
/** Accessible name of the expanded view dialog. */
|
|
13
|
+
expandedView: string;
|
|
14
|
+
/** Button that closes the expanded view. */
|
|
15
|
+
minimize: string;
|
|
16
|
+
/** Button and tooltip that download the table as CSV. */
|
|
17
|
+
downloadCsv: string;
|
|
10
18
|
};
|
|
11
19
|
export declare const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS: MessageResponseTableLabels;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS = {
|
|
2
2
|
currentPage: 'Current page',
|
|
3
|
-
paginationStatus: (pageStart, pageEnd, totalRows)=>`Showing ${pageStart}–${pageEnd} of ${totalRows}
|
|
3
|
+
paginationStatus: (pageStart, pageEnd, totalRows)=>`Showing ${pageStart}–${pageEnd} of ${totalRows}`,
|
|
4
|
+
expandView: 'Expand view',
|
|
5
|
+
expandedView: 'Expanded table view',
|
|
6
|
+
minimize: 'Minimize table',
|
|
7
|
+
downloadCsv: 'Download CSV'
|
|
4
8
|
};
|
|
5
9
|
|
|
6
10
|
//# sourceMappingURL=message-response-table-labels.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/message/message-response-table-labels.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\n/** Formats the pagination status line for the rows on the current page (1-based, inclusive). */\nexport type FormatPaginationStatus = (\n pageStart: number,\n pageEnd: number,\n totalRows: number\n) => ReactNode;\n\n/** User-facing text in `MessageResponseTable`. Aura has no translations, so consumers pass translated labels. */\nexport type MessageResponseTableLabels = {\n /** Accessible name of the page number input that long tables show instead of page links. */\n currentPage: string;\n /** Status line in the pagination footer, e.g. \"Showing 1–50 of 120\". */\n paginationStatus: FormatPaginationStatus;\n};\n\nexport const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS: MessageResponseTableLabels =\n {\n currentPage: 'Current page',\n paginationStatus: (pageStart, pageEnd, totalRows) =>\n `Showing ${pageStart}–${pageEnd} of ${totalRows}`,\n };\n"],"names":["DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS","currentPage","paginationStatus","pageStart","pageEnd","totalRows"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/message/message-response-table-labels.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\n/** Formats the pagination status line for the rows on the current page (1-based, inclusive). */\nexport type FormatPaginationStatus = (\n pageStart: number,\n pageEnd: number,\n totalRows: number\n) => ReactNode;\n\n/** User-facing text in `MessageResponseTable`. Aura has no translations, so consumers pass translated labels. */\nexport type MessageResponseTableLabels = {\n /** Accessible name of the page number input that long tables show instead of page links. */\n currentPage: string;\n /** Status line in the pagination footer, e.g. \"Showing 1–50 of 120\". */\n paginationStatus: FormatPaginationStatus;\n /** Button and tooltip that open the expanded view. */\n expandView: string;\n /** Accessible name of the expanded view dialog. */\n expandedView: string;\n /** Button that closes the expanded view. */\n minimize: string;\n /** Button and tooltip that download the table as CSV. */\n downloadCsv: string;\n};\n\nexport const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS: MessageResponseTableLabels =\n {\n currentPage: 'Current page',\n paginationStatus: (pageStart, pageEnd, totalRows) =>\n `Showing ${pageStart}–${pageEnd} of ${totalRows}`,\n expandView: 'Expand view',\n expandedView: 'Expanded table view',\n minimize: 'Minimize table',\n downloadCsv: 'Download CSV',\n };\n"],"names":["DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS","currentPage","paginationStatus","pageStart","pageEnd","totalRows","expandView","expandedView","minimize","downloadCsv"],"mappings":"AAyBA,OAAO,MAAMA,wCACX;IACEC,aAAa;IACbC,kBAAkB,CAACC,WAAWC,SAASC,YACrC,CAAC,QAAQ,EAAEF,UAAU,CAAC,EAAEC,QAAQ,IAAI,EAAEC,WAAW;IACnDC,YAAY;IACZC,cAAc;IACdC,UAAU;IACVC,aAAa;AACf,EAAE"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Children, isValidElement, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { IconArrowsDiagonal, IconDownload, IconX } from "@tabler/icons-react";
|
|
4
|
+
import { cn } from "../../../../lib/utils.js";
|
|
5
|
+
import { Button } from "../button/button.js";
|
|
3
6
|
import { Card } from "../card/card.js";
|
|
4
|
-
import { DataGrid } from "../data-grid/data-grid.js";
|
|
7
|
+
import { DataGrid, DataGridHeader, DataGridHeaderEnd } from "../data-grid/data-grid.js";
|
|
8
|
+
import { Dialog, DialogClose, DialogContent } from "../dialog/dialog.js";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
|
|
10
|
+
import { buildCsv, downloadCsv } from "./message-response-table-csv.utils.js";
|
|
5
11
|
import { MessageTableFooter } from "./message-response-table-footer.js";
|
|
6
12
|
import { DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS } from "./message-response-table-labels.js";
|
|
7
13
|
const DEFAULT_TABLE_LABEL = 'Atlas AI Chat Table';
|
|
8
14
|
export const MESSAGE_TABLE_PAGE_SIZE = 50;
|
|
15
|
+
const COMPACT_VIEWPORT_BREAKPOINT_PX = 1024;
|
|
16
|
+
const isBelowDesktopBreakpoint = ()=>typeof window !== 'undefined' && window.innerWidth < COMPACT_VIEWPORT_BREAKPOINT_PX;
|
|
9
17
|
const clamp = (value, min, max)=>Math.min(Math.max(value, min), max);
|
|
10
18
|
const getTagName = (element)=>element.props.node?.tagName ?? (typeof element.type === 'string' ? element.type : undefined);
|
|
11
19
|
const getChildren = (element)=>element.props.children;
|
|
@@ -92,7 +100,10 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
|
|
|
92
100
|
const totalRows = allRows.length;
|
|
93
101
|
const totalPages = Math.max(1, Math.ceil(totalRows / MESSAGE_TABLE_PAGE_SIZE));
|
|
94
102
|
const [pageIndex, setPageIndex] = useState(0);
|
|
95
|
-
const
|
|
103
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
104
|
+
const [isCompactViewport, setIsCompactViewport] = useState(isBelowDesktopBreakpoint);
|
|
105
|
+
const inlineGridRef = useRef(null);
|
|
106
|
+
const expandedGridRef = useRef(null);
|
|
96
107
|
// Clamp the page while rows stream in or shrink.
|
|
97
108
|
const currentPageIndex = clamp(pageIndex, 0, totalPages - 1);
|
|
98
109
|
// Pages are sliced here rather than by the grid: its client pagination resets
|
|
@@ -101,13 +112,35 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
|
|
|
101
112
|
const pageRows = allRows.slice(currentPageIndex * MESSAGE_TABLE_PAGE_SIZE, (currentPageIndex + 1) * MESSAGE_TABLE_PAGE_SIZE);
|
|
102
113
|
// Show the top of each new page.
|
|
103
114
|
useEffect(()=>{
|
|
104
|
-
|
|
115
|
+
inlineGridRef.current?.scrollToRow(0);
|
|
116
|
+
expandedGridRef.current?.scrollToRow(0);
|
|
105
117
|
}, [
|
|
106
118
|
currentPageIndex
|
|
107
119
|
]);
|
|
120
|
+
const handleOpen = ()=>{
|
|
121
|
+
setIsCompactViewport(isBelowDesktopBreakpoint());
|
|
122
|
+
setIsExpanded(true);
|
|
123
|
+
};
|
|
108
124
|
const handlePageIndexChange = (nextPageIndex)=>{
|
|
109
125
|
setPageIndex(clamp(nextPageIndex, 0, totalPages - 1));
|
|
110
126
|
};
|
|
127
|
+
const handleDownloadCsv = ()=>{
|
|
128
|
+
if (!parsed.isParsed) return;
|
|
129
|
+
const csv = buildCsv(parsed.headers, parsed.rows.map((row)=>row.text));
|
|
130
|
+
downloadCsv(csv, 'table.csv');
|
|
131
|
+
};
|
|
132
|
+
useEffect(()=>{
|
|
133
|
+
if (!isExpanded) return;
|
|
134
|
+
const handleResize = ()=>{
|
|
135
|
+
setIsCompactViewport(isBelowDesktopBreakpoint());
|
|
136
|
+
};
|
|
137
|
+
window.addEventListener('resize', handleResize, {
|
|
138
|
+
passive: true
|
|
139
|
+
});
|
|
140
|
+
return ()=>window.removeEventListener('resize', handleResize);
|
|
141
|
+
}, [
|
|
142
|
+
isExpanded
|
|
143
|
+
]);
|
|
111
144
|
if (!parsed.isParsed) {
|
|
112
145
|
return /*#__PURE__*/ _jsx("div", {
|
|
113
146
|
"data-slot": "message-table",
|
|
@@ -121,33 +154,30 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
|
|
|
121
154
|
})
|
|
122
155
|
});
|
|
123
156
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// max-h-131 (524px) fits the column header plus 10 single-line rows (36px each) and the footer; the rest scrolls. `w-full` lets the table fill the card's full width.
|
|
149
|
-
className: "max-h-131 w-full",
|
|
150
|
-
children: totalRows > 0 && /*#__PURE__*/ _jsx(MessageTableFooter, {
|
|
157
|
+
const columns = buildColumns(parsed.headers);
|
|
158
|
+
const renderGrid = ({ gridRef, className, header })=>/*#__PURE__*/ _jsxs(DataGrid, {
|
|
159
|
+
data: pageRows,
|
|
160
|
+
columns: columns,
|
|
161
|
+
getRowId: (row)=>row.id,
|
|
162
|
+
rowCount: totalRows,
|
|
163
|
+
manualPagination: true,
|
|
164
|
+
pagination: {
|
|
165
|
+
pageIndex: currentPageIndex,
|
|
166
|
+
pageSize: MESSAGE_TABLE_PAGE_SIZE
|
|
167
|
+
},
|
|
168
|
+
onPaginationChange: (next)=>handlePageIndexChange(next.pageIndex),
|
|
169
|
+
// Read-only tables are scanned rather than edited, so stripe rows instead of drawing column dividers.
|
|
170
|
+
striped: true,
|
|
171
|
+
// Header and rows share one background, so the titles carry the distinction.
|
|
172
|
+
emphasizeHeader: true,
|
|
173
|
+
// Chat answers often put sentences in cells; show them in full rather than truncated.
|
|
174
|
+
wrapCells: true,
|
|
175
|
+
gridRef: gridRef,
|
|
176
|
+
"aria-label": ariaLabel,
|
|
177
|
+
className: className,
|
|
178
|
+
children: [
|
|
179
|
+
header,
|
|
180
|
+
totalRows > 0 && /*#__PURE__*/ _jsx(MessageTableFooter, {
|
|
151
181
|
pageIndex: currentPageIndex,
|
|
152
182
|
pageSize: MESSAGE_TABLE_PAGE_SIZE,
|
|
153
183
|
labels: resolvedLabels,
|
|
@@ -155,8 +185,106 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
|
|
|
155
185
|
totalRows: totalRows,
|
|
156
186
|
onPageIndexChange: handlePageIndexChange
|
|
157
187
|
})
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
191
|
+
"data-slot": "message-table",
|
|
192
|
+
className: "my-4",
|
|
193
|
+
children: [
|
|
194
|
+
/*#__PURE__*/ _jsx(Card, {
|
|
195
|
+
className: "w-full bg-transparent",
|
|
196
|
+
children: renderGrid({
|
|
197
|
+
gridRef: inlineGridRef,
|
|
198
|
+
// max-h-131 (524px) fits the expand button, the column header plus 10 single-line rows (36px each) and the footer; the rest scrolls. `w-full` lets the table fill the card's full width.
|
|
199
|
+
className: 'max-h-131 w-full',
|
|
200
|
+
header: /*#__PURE__*/ _jsx(DataGridHeader, {
|
|
201
|
+
children: /*#__PURE__*/ _jsxs(DataGridHeaderEnd, {
|
|
202
|
+
children: [
|
|
203
|
+
/*#__PURE__*/ _jsxs(Tooltip, {
|
|
204
|
+
children: [
|
|
205
|
+
/*#__PURE__*/ _jsx(TooltipTrigger, {
|
|
206
|
+
render: /*#__PURE__*/ _jsx(Button, {
|
|
207
|
+
variant: "ghost",
|
|
208
|
+
size: "icon-sm",
|
|
209
|
+
type: "button",
|
|
210
|
+
"aria-label": resolvedLabels.downloadCsv,
|
|
211
|
+
onClick: handleDownloadCsv,
|
|
212
|
+
children: /*#__PURE__*/ _jsx(IconDownload, {})
|
|
213
|
+
})
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ _jsx(TooltipContent, {
|
|
216
|
+
children: /*#__PURE__*/ _jsx("p", {
|
|
217
|
+
children: resolvedLabels.downloadCsv
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
}),
|
|
222
|
+
/*#__PURE__*/ _jsxs(Tooltip, {
|
|
223
|
+
children: [
|
|
224
|
+
/*#__PURE__*/ _jsx(TooltipTrigger, {
|
|
225
|
+
render: /*#__PURE__*/ _jsx(Button, {
|
|
226
|
+
variant: "ghost",
|
|
227
|
+
size: "icon-sm",
|
|
228
|
+
type: "button",
|
|
229
|
+
"aria-label": resolvedLabels.expandView,
|
|
230
|
+
onClick: handleOpen,
|
|
231
|
+
children: /*#__PURE__*/ _jsx(IconArrowsDiagonal, {})
|
|
232
|
+
})
|
|
233
|
+
}),
|
|
234
|
+
/*#__PURE__*/ _jsx(TooltipContent, {
|
|
235
|
+
children: /*#__PURE__*/ _jsx("p", {
|
|
236
|
+
children: resolvedLabels.expandView
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
]
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
}),
|
|
246
|
+
/*#__PURE__*/ _jsx(Dialog, {
|
|
247
|
+
open: isExpanded,
|
|
248
|
+
onOpenChange: setIsExpanded,
|
|
249
|
+
children: /*#__PURE__*/ _jsxs(DialogContent, {
|
|
250
|
+
showCloseButton: false,
|
|
251
|
+
"aria-label": resolvedLabels.expandedView,
|
|
252
|
+
"data-slot": "message-table-expanded-dialog",
|
|
253
|
+
className: cn('text-base-foreground mb-0 flex flex-col gap-0 overflow-hidden p-0', isCompactViewport ? 'inset-0 size-full translate-y-0 rounded-none border-0 sm:left-0 sm:max-w-none sm:translate-x-0' : 'max-h-4/5 border-default sm:w-4/5 sm:max-w-none'),
|
|
254
|
+
children: [
|
|
255
|
+
/*#__PURE__*/ _jsx("div", {
|
|
256
|
+
className: "flex shrink-0 items-center justify-end gap-4 border-b border-default px-4 py-2",
|
|
257
|
+
children: /*#__PURE__*/ _jsxs("span", {
|
|
258
|
+
className: "flex shrink-0 items-center gap-1",
|
|
259
|
+
children: [
|
|
260
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
261
|
+
variant: "ghost",
|
|
262
|
+
size: "icon-sm",
|
|
263
|
+
type: "button",
|
|
264
|
+
"aria-label": resolvedLabels.downloadCsv,
|
|
265
|
+
onClick: handleDownloadCsv,
|
|
266
|
+
children: /*#__PURE__*/ _jsx(IconDownload, {})
|
|
267
|
+
}),
|
|
268
|
+
/*#__PURE__*/ _jsx(DialogClose, {
|
|
269
|
+
render: /*#__PURE__*/ _jsx(Button, {
|
|
270
|
+
variant: "ghost",
|
|
271
|
+
size: "icon-sm",
|
|
272
|
+
type: "button",
|
|
273
|
+
"aria-label": resolvedLabels.minimize,
|
|
274
|
+
children: /*#__PURE__*/ _jsx(IconX, {})
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
]
|
|
278
|
+
})
|
|
279
|
+
}),
|
|
280
|
+
renderGrid({
|
|
281
|
+
gridRef: expandedGridRef,
|
|
282
|
+
className: 'flex-1 rounded-none'
|
|
283
|
+
})
|
|
284
|
+
]
|
|
285
|
+
})
|
|
158
286
|
})
|
|
159
|
-
|
|
287
|
+
]
|
|
160
288
|
});
|
|
161
289
|
};
|
|
162
290
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/ui/core/message/message-response-table.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport type { ColumnDef } from '@tanstack/react-table';\nimport type { JSX } from 'react/jsx-runtime';\nimport type { ExtraProps } from 'streamdown';\n\nimport { Card } from '../card/card';\nimport { DataGrid, type DataGridHandle } from '../data-grid/data-grid';\n\nimport { MessageTableFooter } from './message-response-table-footer';\nimport {\n DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS,\n type MessageResponseTableLabels,\n} from './message-response-table-labels';\n\ntype MessageResponseTableProps = JSX.IntrinsicElements['table'] &\n ExtraProps & {\n /** Translated text for the table's controls; any label left out falls back to English. */\n labels?: Partial<MessageResponseTableLabels>;\n };\n\nconst DEFAULT_TABLE_LABEL = 'Atlas AI Chat Table';\n\ntype MessageTableRow = {\n id: string;\n /** Rendered Markdown content of each cell, so links and formatting survive. */\n cells: ReactNode[];\n /** Plain text of each cell. */\n text: string[];\n};\n\ntype ParsedTable =\n | { isParsed: true; headers: string[]; rows: MessageTableRow[] }\n | { isParsed: false };\n\nexport const MESSAGE_TABLE_PAGE_SIZE = 50;\n\nconst clamp = (value: number, min: number, max: number): number =>\n Math.min(Math.max(value, min), max);\n\nconst getTagName = (element: ReactElement): string | undefined =>\n (element.props as ExtraProps).node?.tagName ??\n (typeof element.type === 'string' ? element.type : undefined);\n\nconst getChildren = (element: ReactElement): ReactNode =>\n (element.props as { children?: ReactNode }).children;\n\n/**\n * Flattens rendered Markdown children into an indexable element array.\n * Streamdown hands us an opaque `ReactNode` tree, so there is no alternative API for this.\n */\nconst toElementArray = (node: ReactNode): ReactElement[] =>\n // eslint-disable-next-line @eslint-react/no-children-to-array -- The grid needs Streamdown's rendered table sections, rows and cells as indexable arrays\n Children.toArray(node).filter((child): child is ReactElement =>\n isValidElement(child)\n );\n\nconst extractText = (node: ReactNode): string => {\n if (node === null || node === undefined || typeof node === 'boolean') {\n return '';\n }\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n if (Array.isArray(node)) {\n return node.map(extractText).join('');\n }\n if (isValidElement(node)) {\n return extractText(getChildren(node));\n }\n return '';\n};\n\nconst getCellContents = (row: ReactElement): ReactNode[] =>\n toElementArray(getChildren(row)).map(getChildren);\n\nconst parseTableChildren = (children: ReactNode): ParsedTable => {\n const sections = toElementArray(children);\n\n let header: ReactElement | null = null;\n let body: ReactElement | null = null;\n\n for (const section of sections) {\n const tagName = getTagName(section);\n if (tagName === 'thead' && !header) {\n header = section;\n } else if (tagName === 'tbody' && !body) {\n body = section;\n }\n }\n\n // Fallback for renderers that do not forward hast `node` metadata:\n // a table is conventionally [thead, tbody].\n if (!header && !body && sections.length <= 2) {\n [header = null, body = null] = sections;\n }\n\n const headerRow = header ? toElementArray(getChildren(header))[0] : undefined;\n if (!headerRow) return { isParsed: false };\n\n const headers = getCellContents(headerRow).map((cell) =>\n extractText(cell).trim()\n );\n if (headers.length === 0) return { isParsed: false };\n\n // While the response streams, the header arrives before any body rows.\n const rows = body\n ? toElementArray(getChildren(body)).map((row, index) => {\n const cells = getCellContents(row);\n return {\n id: String(index),\n cells,\n text: cells.map((cell) => extractText(cell).trim()),\n };\n })\n : [];\n\n return { isParsed: true, headers, rows };\n};\n\nconst getColumnId = (index: number): string => `column-${index}`;\n\nconst buildColumns = (headers: string[]): ColumnDef<MessageTableRow>[] =>\n headers.map((header, index) => ({\n id: getColumnId(index),\n header,\n accessorFn: (row) => row.text[index] ?? '',\n cell: ({ row }) => row.original.cells[index] ?? null,\n }));\n\n/**\n * Renders a Markdown table from a chat response as a DataGrid.\n * Not the default `table` renderer yet; opt in with `<MessageResponse components={{ table: MessageResponseTable }}>`.\n * Aura has no translations, so pass a translated `aria-label` to name the table (it defaults to \"Atlas AI Chat Table\")\n * and `labels` to translate its controls.\n */\nexport const MessageResponseTable = ({\n children,\n 'aria-label': ariaLabel = DEFAULT_TABLE_LABEL,\n labels,\n}: MessageResponseTableProps): ReactNode => {\n const resolvedLabels = {\n ...DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS,\n ...labels,\n };\n const parsed = parseTableChildren(children);\n const allRows = parsed.isParsed ? parsed.rows : [];\n const totalRows = allRows.length;\n const totalPages = Math.max(\n 1,\n Math.ceil(totalRows / MESSAGE_TABLE_PAGE_SIZE)\n );\n\n const [pageIndex, setPageIndex] = useState(0);\n const gridRef = useRef<DataGridHandle>(null);\n\n // Clamp the page while rows stream in or shrink.\n const currentPageIndex = clamp(pageIndex, 0, totalPages - 1);\n // Pages are sliced here rather than by the grid: its client pagination resets\n // to the first page whenever `data` changes identity, which happens on every\n // re-render of the streamed Markdown.\n const pageRows = allRows.slice(\n currentPageIndex * MESSAGE_TABLE_PAGE_SIZE,\n (currentPageIndex + 1) * MESSAGE_TABLE_PAGE_SIZE\n );\n\n // Show the top of each new page.\n useEffect(() => {\n gridRef.current?.scrollToRow(0);\n }, [currentPageIndex]);\n\n const handlePageIndexChange = (nextPageIndex: number): void => {\n setPageIndex(clamp(nextPageIndex, 0, totalPages - 1));\n };\n\n if (!parsed.isParsed) {\n return (\n <div\n data-slot=\"message-table\"\n className=\"my-4 overflow-x-auto\"\n tabIndex={0}\n role=\"group\"\n aria-label={ariaLabel}\n >\n <table className=\"w-full\">{children}</table>\n </div>\n );\n }\n\n return (\n <div data-slot=\"message-table\" className=\"my-4\">\n {/* The Card keeps its shape and padding but drops its grey surface, so the grid sits on its default base background and muted stripes. */}\n <Card className=\"w-full bg-transparent\">\n <DataGrid<MessageTableRow>\n data={pageRows}\n columns={buildColumns(parsed.headers)}\n getRowId={(row) => row.id}\n rowCount={totalRows}\n manualPagination\n pagination={{\n pageIndex: currentPageIndex,\n pageSize: MESSAGE_TABLE_PAGE_SIZE,\n }}\n onPaginationChange={(next) => handlePageIndexChange(next.pageIndex)}\n // Read-only tables are scanned rather than edited, so stripe rows instead of drawing column dividers.\n striped\n // Header and rows share one background, so the titles carry the distinction.\n emphasizeHeader\n // Chat answers often put sentences in cells; show them in full rather than truncated.\n wrapCells\n gridRef={gridRef}\n aria-label={ariaLabel}\n // max-h-131 (524px) fits the column header plus 10 single-line rows (36px each) and the footer; the rest scrolls. `w-full` lets the table fill the card's full width.\n className=\"max-h-131 w-full\"\n >\n {totalRows > 0 && (\n <MessageTableFooter\n pageIndex={currentPageIndex}\n pageSize={MESSAGE_TABLE_PAGE_SIZE}\n labels={resolvedLabels}\n totalPages={totalPages}\n totalRows={totalRows}\n onPageIndexChange={handlePageIndexChange}\n />\n )}\n </DataGrid>\n </Card>\n </div>\n );\n};\n"],"names":["Children","isValidElement","useEffect","useRef","useState","Card","DataGrid","MessageTableFooter","DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS","DEFAULT_TABLE_LABEL","MESSAGE_TABLE_PAGE_SIZE","clamp","value","min","max","Math","getTagName","element","props","node","tagName","type","undefined","getChildren","children","toElementArray","toArray","filter","child","extractText","String","Array","isArray","map","join","getCellContents","row","parseTableChildren","sections","header","body","section","length","headerRow","isParsed","headers","cell","trim","rows","index","cells","id","text","getColumnId","buildColumns","accessorFn","original","MessageResponseTable","ariaLabel","labels","resolvedLabels","parsed","allRows","totalRows","totalPages","ceil","pageIndex","setPageIndex","gridRef","currentPageIndex","pageRows","slice","current","scrollToRow","handlePageIndexChange","nextPageIndex","div","data-slot","className","tabIndex","role","aria-label","table","data","columns","getRowId","rowCount","manualPagination","pagination","pageSize","onPaginationChange","next","striped","emphasizeHeader","wrapCells","onPageIndexChange"],"mappings":";AACA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAM9E,SAASC,IAAI,QAAQ,kBAAe;AACpC,SAASC,QAAQ,QAA6B,4BAAyB;AAE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CAACC,OAASjB,sBAAsBiB,KAAKzB,SAAS;gBAClE,sGAAsG;gBACtG0B,OAAO;gBACP,6EAA6E;gBAC7EC,eAAe;gBACf,sFAAsF;gBACtFC,SAAS;gBACT1B,SAASA;gBACTa,cAAYvB;gBACZ,sKAAsK;gBACtKoB,WAAU;0BAETf,YAAY,mBACX,KAACxD;oBACC2D,WAAWG;oBACXoB,UAAU/E;oBACViD,QAAQC;oBACRI,YAAYA;oBACZD,WAAWA;oBACXgC,mBAAmBrB;;;;;AAOjC,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/ui/core/message/message-response-table.tsx"],"sourcesContent":["import type { ReactElement, ReactNode, RefObject } from 'react';\nimport { Children, isValidElement, useEffect, useRef, useState } from 'react';\n\nimport { IconArrowsDiagonal, IconDownload, IconX } from '@tabler/icons-react';\nimport type { ColumnDef } from '@tanstack/react-table';\nimport type { JSX } from 'react/jsx-runtime';\nimport type { ExtraProps } from 'streamdown';\n\nimport { cn } from '../../../../lib/utils';\nimport { Button } from '../button/button';\nimport { Card } from '../card/card';\nimport {\n DataGrid,\n DataGridHeader,\n DataGridHeaderEnd,\n type DataGridHandle,\n} from '../data-grid/data-grid';\nimport { Dialog, DialogClose, DialogContent } from '../dialog/dialog';\nimport { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip/tooltip';\n\nimport { buildCsv, downloadCsv } from './message-response-table-csv.utils';\nimport { MessageTableFooter } from './message-response-table-footer';\nimport {\n DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS,\n type MessageResponseTableLabels,\n} from './message-response-table-labels';\n\ntype MessageResponseTableProps = JSX.IntrinsicElements['table'] &\n ExtraProps & {\n /** Translated text for the table's controls; any label left out falls back to English. */\n labels?: Partial<MessageResponseTableLabels>;\n };\n\nconst DEFAULT_TABLE_LABEL = 'Atlas AI Chat Table';\n\ntype MessageTableRow = {\n id: string;\n /** Rendered Markdown content of each cell, so links and formatting survive. */\n cells: ReactNode[];\n /** Plain text of each cell, used for CSV export. */\n text: string[];\n};\n\ntype ParsedTable =\n | { isParsed: true; headers: string[]; rows: MessageTableRow[] }\n | { isParsed: false };\n\nexport const MESSAGE_TABLE_PAGE_SIZE = 50;\n\nconst COMPACT_VIEWPORT_BREAKPOINT_PX = 1024;\n\nconst isBelowDesktopBreakpoint = (): boolean =>\n typeof window !== 'undefined' &&\n window.innerWidth < COMPACT_VIEWPORT_BREAKPOINT_PX;\n\nconst clamp = (value: number, min: number, max: number): number =>\n Math.min(Math.max(value, min), max);\n\nconst getTagName = (element: ReactElement): string | undefined =>\n (element.props as ExtraProps).node?.tagName ??\n (typeof element.type === 'string' ? element.type : undefined);\n\nconst getChildren = (element: ReactElement): ReactNode =>\n (element.props as { children?: ReactNode }).children;\n\n/**\n * Flattens rendered Markdown children into an indexable element array.\n * Streamdown hands us an opaque `ReactNode` tree, so there is no alternative API for this.\n */\nconst toElementArray = (node: ReactNode): ReactElement[] =>\n // eslint-disable-next-line @eslint-react/no-children-to-array -- The grid needs Streamdown's rendered table sections, rows and cells as indexable arrays\n Children.toArray(node).filter((child): child is ReactElement =>\n isValidElement(child)\n );\n\nconst extractText = (node: ReactNode): string => {\n if (node === null || node === undefined || typeof node === 'boolean') {\n return '';\n }\n if (typeof node === 'string' || typeof node === 'number') {\n return String(node);\n }\n if (Array.isArray(node)) {\n return node.map(extractText).join('');\n }\n if (isValidElement(node)) {\n return extractText(getChildren(node));\n }\n return '';\n};\n\nconst getCellContents = (row: ReactElement): ReactNode[] =>\n toElementArray(getChildren(row)).map(getChildren);\n\nconst parseTableChildren = (children: ReactNode): ParsedTable => {\n const sections = toElementArray(children);\n\n let header: ReactElement | null = null;\n let body: ReactElement | null = null;\n\n for (const section of sections) {\n const tagName = getTagName(section);\n if (tagName === 'thead' && !header) {\n header = section;\n } else if (tagName === 'tbody' && !body) {\n body = section;\n }\n }\n\n // Fallback for renderers that do not forward hast `node` metadata:\n // a table is conventionally [thead, tbody].\n if (!header && !body && sections.length <= 2) {\n [header = null, body = null] = sections;\n }\n\n const headerRow = header ? toElementArray(getChildren(header))[0] : undefined;\n if (!headerRow) return { isParsed: false };\n\n const headers = getCellContents(headerRow).map((cell) =>\n extractText(cell).trim()\n );\n if (headers.length === 0) return { isParsed: false };\n\n // While the response streams, the header arrives before any body rows.\n const rows = body\n ? toElementArray(getChildren(body)).map((row, index) => {\n const cells = getCellContents(row);\n return {\n id: String(index),\n cells,\n text: cells.map((cell) => extractText(cell).trim()),\n };\n })\n : [];\n\n return { isParsed: true, headers, rows };\n};\n\nconst getColumnId = (index: number): string => `column-${index}`;\n\nconst buildColumns = (headers: string[]): ColumnDef<MessageTableRow>[] =>\n headers.map((header, index) => ({\n id: getColumnId(index),\n header,\n accessorFn: (row) => row.text[index] ?? '',\n cell: ({ row }) => row.original.cells[index] ?? null,\n }));\n\n/**\n * Renders a Markdown table from a chat response as a DataGrid.\n * Not the default `table` renderer yet; opt in with `<MessageResponse components={{ table: MessageResponseTable }}>`.\n * Aura has no translations, so pass a translated `aria-label` to name the table (it defaults to \"Atlas AI Chat Table\")\n * and `labels` to translate its controls.\n */\nexport const MessageResponseTable = ({\n children,\n 'aria-label': ariaLabel = DEFAULT_TABLE_LABEL,\n labels,\n}: MessageResponseTableProps): ReactNode => {\n const resolvedLabels = {\n ...DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS,\n ...labels,\n };\n const parsed = parseTableChildren(children);\n const allRows = parsed.isParsed ? parsed.rows : [];\n const totalRows = allRows.length;\n const totalPages = Math.max(\n 1,\n Math.ceil(totalRows / MESSAGE_TABLE_PAGE_SIZE)\n );\n\n const [pageIndex, setPageIndex] = useState(0);\n const [isExpanded, setIsExpanded] = useState(false);\n const [isCompactViewport, setIsCompactViewport] = useState(\n isBelowDesktopBreakpoint\n );\n\n const inlineGridRef = useRef<DataGridHandle>(null);\n const expandedGridRef = useRef<DataGridHandle>(null);\n\n // Clamp the page while rows stream in or shrink.\n const currentPageIndex = clamp(pageIndex, 0, totalPages - 1);\n // Pages are sliced here rather than by the grid: its client pagination resets\n // to the first page whenever `data` changes identity, which happens on every\n // re-render of the streamed Markdown.\n const pageRows = allRows.slice(\n currentPageIndex * MESSAGE_TABLE_PAGE_SIZE,\n (currentPageIndex + 1) * MESSAGE_TABLE_PAGE_SIZE\n );\n\n // Show the top of each new page.\n useEffect(() => {\n inlineGridRef.current?.scrollToRow(0);\n expandedGridRef.current?.scrollToRow(0);\n }, [currentPageIndex]);\n\n const handleOpen = (): void => {\n setIsCompactViewport(isBelowDesktopBreakpoint());\n setIsExpanded(true);\n };\n\n const handlePageIndexChange = (nextPageIndex: number): void => {\n setPageIndex(clamp(nextPageIndex, 0, totalPages - 1));\n };\n\n const handleDownloadCsv = (): void => {\n if (!parsed.isParsed) return;\n const csv = buildCsv(\n parsed.headers,\n parsed.rows.map((row) => row.text)\n );\n downloadCsv(csv, 'table.csv');\n };\n\n useEffect(() => {\n if (!isExpanded) return;\n\n const handleResize = (): void => {\n setIsCompactViewport(isBelowDesktopBreakpoint());\n };\n\n window.addEventListener('resize', handleResize, { passive: true });\n return () => window.removeEventListener('resize', handleResize);\n }, [isExpanded]);\n\n if (!parsed.isParsed) {\n return (\n <div\n data-slot=\"message-table\"\n className=\"my-4 overflow-x-auto\"\n tabIndex={0}\n role=\"group\"\n aria-label={ariaLabel}\n >\n <table className=\"w-full\">{children}</table>\n </div>\n );\n }\n\n const columns = buildColumns(parsed.headers);\n\n const renderGrid = ({\n gridRef,\n className,\n header,\n }: {\n gridRef: RefObject<DataGridHandle | null>;\n className: string;\n header?: ReactNode;\n }): ReactNode => (\n <DataGrid<MessageTableRow>\n data={pageRows}\n columns={columns}\n getRowId={(row) => row.id}\n rowCount={totalRows}\n manualPagination\n pagination={{\n pageIndex: currentPageIndex,\n pageSize: MESSAGE_TABLE_PAGE_SIZE,\n }}\n onPaginationChange={(next) => handlePageIndexChange(next.pageIndex)}\n // Read-only tables are scanned rather than edited, so stripe rows instead of drawing column dividers.\n striped\n // Header and rows share one background, so the titles carry the distinction.\n emphasizeHeader\n // Chat answers often put sentences in cells; show them in full rather than truncated.\n wrapCells\n gridRef={gridRef}\n aria-label={ariaLabel}\n className={className}\n >\n {header}\n {totalRows > 0 && (\n <MessageTableFooter\n pageIndex={currentPageIndex}\n pageSize={MESSAGE_TABLE_PAGE_SIZE}\n labels={resolvedLabels}\n totalPages={totalPages}\n totalRows={totalRows}\n onPageIndexChange={handlePageIndexChange}\n />\n )}\n </DataGrid>\n );\n\n return (\n <div data-slot=\"message-table\" className=\"my-4\">\n {/* The Card keeps its shape and padding but drops its grey surface, so the grid sits on its default base background and muted stripes. */}\n <Card className=\"w-full bg-transparent\">\n {renderGrid({\n gridRef: inlineGridRef,\n // max-h-131 (524px) fits the expand button, the column header plus 10 single-line rows (36px each) and the footer; the rest scrolls. `w-full` lets the table fill the card's full width.\n className: 'max-h-131 w-full',\n header: (\n <DataGridHeader>\n <DataGridHeaderEnd>\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n type=\"button\"\n aria-label={resolvedLabels.downloadCsv}\n onClick={handleDownloadCsv}\n >\n <IconDownload />\n </Button>\n }\n />\n <TooltipContent>\n <p>{resolvedLabels.downloadCsv}</p>\n </TooltipContent>\n </Tooltip>\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n type=\"button\"\n aria-label={resolvedLabels.expandView}\n onClick={handleOpen}\n >\n <IconArrowsDiagonal />\n </Button>\n }\n />\n <TooltipContent>\n <p>{resolvedLabels.expandView}</p>\n </TooltipContent>\n </Tooltip>\n </DataGridHeaderEnd>\n </DataGridHeader>\n ),\n })}\n </Card>\n {/* Dialog portals into the configured portal container and handles Escape, backdrop presses, focus and scroll locking. */}\n <Dialog open={isExpanded} onOpenChange={setIsExpanded}>\n <DialogContent\n showCloseButton={false}\n aria-label={resolvedLabels.expandedView}\n data-slot=\"message-table-expanded-dialog\"\n className={cn(\n 'text-base-foreground mb-0 flex flex-col gap-0 overflow-hidden p-0',\n isCompactViewport\n ? // Full screen: undo the dialog's centring and width cap.\n 'inset-0 size-full translate-y-0 rounded-none border-0 sm:left-0 sm:max-w-none sm:translate-x-0'\n : 'max-h-4/5 border-default sm:w-4/5 sm:max-w-none'\n )}\n >\n <div className=\"flex shrink-0 items-center justify-end gap-4 border-b border-default px-4 py-2\">\n <span className=\"flex shrink-0 items-center gap-1\">\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n type=\"button\"\n aria-label={resolvedLabels.downloadCsv}\n onClick={handleDownloadCsv}\n >\n <IconDownload />\n </Button>\n <DialogClose\n render={\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n type=\"button\"\n aria-label={resolvedLabels.minimize}\n >\n <IconX />\n </Button>\n }\n />\n </span>\n </div>\n\n {renderGrid({\n gridRef: expandedGridRef,\n className: 'flex-1 rounded-none',\n })}\n </DialogContent>\n </Dialog>\n </div>\n );\n};\n"],"names":["Children","isValidElement","useEffect","useRef","useState","IconArrowsDiagonal","IconDownload","IconX","cn","Button","Card","DataGrid","DataGridHeader","DataGridHeaderEnd","Dialog","DialogClose","DialogContent","Tooltip","TooltipContent","TooltipTrigger","buildCsv","downloadCsv","MessageTableFooter","DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS","DEFAULT_TABLE_LABEL","MESSAGE_TABLE_PAGE_SIZE","COMPACT_VIEWPORT_BREAKPOINT_PX","isBelowDesktopBreakpoint","window","innerWidth","clamp","value","min","max","Math","getTagName","element","props","node","tagName","type","undefined","getChildren","children","toElementArray","toArray","filter","child","extractText","String","Array","isArray","map","join","getCellContents","row","parseTableChildren","sections","header","body","section","length","headerRow","isParsed","headers","cell","trim","rows","index","cells","id","text","getColumnId","buildColumns","accessorFn","original","MessageResponseTable","ariaLabel","labels","resolvedLabels","parsed","allRows","totalRows","totalPages","ceil","pageIndex","setPageIndex","isExpanded","setIsExpanded","isCompactViewport","setIsCompactViewport","inlineGridRef","expandedGridRef","currentPageIndex","pageRows","slice","current","scrollToRow","handleOpen","handlePageIndexChange","nextPageIndex","handleDownloadCsv","csv","handleResize","addEventListener","passive","removeEventListener","div","data-slot","className","tabIndex","role","aria-label","table","columns","renderGrid","gridRef","data","getRowId","rowCount","manualPagination","pagination","pageSize","onPaginationChange","next","striped","emphasizeHeader","wrapCells","onPageIndexChange","render","variant","size","onClick","p","expandView","open","onOpenChange","showCloseButton","expandedView","span","minimize"],"mappings":";AACA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE9E,SAASC,kBAAkB,EAAEC,YAAY,EAAEC,KAAK,QAAQ,sBAAsB;AAK9E,SAASC,EAAE,QAAQ,2BAAwB;AAC3C,SAASC,MAAM,QAAQ,sBAAmB;AAC1C,SAASC,IAAI,QAAQ,kBAAe;AACpC,SACEC,QAAQ,EACRC,cAAc,EACdC,iBAAiB,QAEZ,4BAAyB;AAChC,SAASC,MAAM,EAAEC,WAAW,EAAEC,aAAa,QAAQ,sBAAmB;AACtE,SAASC,OAAO,EAAEC,cAAc,EAAEC,cAAc,QAAQ,wBAAqB;AAE7E,SAASC,QAAQ,EAAEC,WAAW,QAAQ,wCAAqC;AAC3E,SAASC,kBAAkB,QAAQ,qCAAkC;AACrE,SACEC,qCAAqC,QAEhC,qCAAkC;AAQzC,MAAMC,sBAAsB;AAc5B,OAAO,MAAMC,0BAA0B,GAAG;AAE1C,MAAMC,iCAAiC;AAEvC,MAAMC,2BAA2B,IAC/B,OAAOC,WAAW,eAClBA,OAAOC,UAAU,GAAGH;AAEtB,MAAMI,QAAQ,CAACC,OAAeC,KAAaC,MACzCC,KAAKF,GAAG,CAACE,KAAKD,GAAG,CAACF,OAAOC,MAAMC;AAEjC,MAAME,aAAa,CAACC,UAClB,AAACA,QAAQC,KAAK,CAAgBC,IAAI,EAAEC,WACnC,CAAA,OAAOH,QAAQI,IAAI,KAAK,WAAWJ,QAAQI,IAAI,GAAGC,SAAQ;AAE7D,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xH;gBAAOyH,MAAMhD;gBAAYiD,cAAchD;0BACtC,cAAA,MAACxE;oBACCyH,iBAAiB;oBACjBzB,cAAYjC,eAAe2D,YAAY;oBACvC9B,aAAU;oBACVC,WAAWrG,GACT,qEACAiF,oBAEI,mGACA;;sCAGN,KAACkB;4BAAIE,WAAU;sCACb,cAAA,MAAC8B;gCAAK9B,WAAU;;kDACd,KAACpG;wCACCyH,SAAQ;wCACRC,MAAK;wCACL3F,MAAK;wCACLwE,cAAYjC,eAAe1D,WAAW;wCACtC+G,SAAS/B;kDAET,cAAA,KAAC/F;;kDAEH,KAACS;wCACCkH,sBACE,KAACxH;4CACCyH,SAAQ;4CACRC,MAAK;4CACL3F,MAAK;4CACLwE,cAAYjC,eAAe6D,QAAQ;sDAEnC,cAAA,KAACrI;;;;;;wBAOV4G,WAAW;4BACVC,SAASxB;4BACTiB,WAAW;wBACb;;;;;;AAKV,EAAE"}
|
|
@@ -3,7 +3,7 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useState }
|
|
|
3
3
|
import { mermaid as mermaidPlugin } from "@streamdown/mermaid";
|
|
4
4
|
import { IconChevronLeft, IconChevronRight, IconPaperclip, IconX } from "@tabler/icons-react";
|
|
5
5
|
import { Streamdown } from "streamdown";
|
|
6
|
-
import { usePortalContainer } from "../../../../lib/portal-container-context.js";
|
|
6
|
+
import { PortalContainerContext, usePortalContainer } from "../../../../lib/portal-container-context.js";
|
|
7
7
|
import { cn, getInitials } from "../../../../lib/utils.js";
|
|
8
8
|
import { Avatar, AvatarFallback, AvatarIcon, AvatarImage } from "../avatar/avatar.js";
|
|
9
9
|
import { Button } from "../button/button.js";
|
|
@@ -351,6 +351,17 @@ const MessageResponseMarkdown = ({ className, components, plugins, controls, por
|
|
|
351
351
|
...props
|
|
352
352
|
});
|
|
353
353
|
};
|
|
354
|
+
/**
|
|
355
|
+
* Shares an explicit `portal` prop with components rendered inside the Markdown,
|
|
356
|
+
* such as the expanded table view, so they portal into the same container as Streamdown.
|
|
357
|
+
*/ const MessageResponsePortalProvider = ({ portal, children })=>{
|
|
358
|
+
const portalContainer = usePortalContainer();
|
|
359
|
+
const explicitPortalElement = typeof portal === 'function' ? portal() ?? undefined : portal;
|
|
360
|
+
return /*#__PURE__*/ _jsx(PortalContainerContext.Provider, {
|
|
361
|
+
value: explicitPortalElement ?? portalContainer,
|
|
362
|
+
children: children
|
|
363
|
+
});
|
|
364
|
+
};
|
|
354
365
|
const MessageResponse = ({ id, role, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'data-testid': dataTestId, ...props })=>/*#__PURE__*/ _jsx("div", {
|
|
355
366
|
"data-slot": "message-response",
|
|
356
367
|
id: id,
|
|
@@ -359,8 +370,11 @@ const MessageResponse = ({ id, role, 'aria-label': ariaLabel, 'aria-labelledby':
|
|
|
359
370
|
"aria-labelledby": ariaLabelledBy,
|
|
360
371
|
"aria-describedby": ariaDescribedBy,
|
|
361
372
|
"data-testid": dataTestId,
|
|
362
|
-
children: /*#__PURE__*/ _jsx(
|
|
363
|
-
|
|
373
|
+
children: /*#__PURE__*/ _jsx(MessageResponsePortalProvider, {
|
|
374
|
+
portal: props.portal,
|
|
375
|
+
children: /*#__PURE__*/ _jsx(MessageResponseMarkdown, {
|
|
376
|
+
...props
|
|
377
|
+
})
|
|
364
378
|
})
|
|
365
379
|
});
|
|
366
380
|
function MessageAttachment({ data, className, onRemove, ...props }) {
|