@cognite/aura 1.48344.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.
@@ -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"}
@@ -13,5 +13,7 @@ export type MessageResponseTableLabels = {
13
13
  expandedView: string;
14
14
  /** Button that closes the expanded view. */
15
15
  minimize: string;
16
+ /** Button and tooltip that download the table as CSV. */
17
+ downloadCsv: string;
16
18
  };
17
19
  export declare const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS: MessageResponseTableLabels;
@@ -3,7 +3,8 @@ export const DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS = {
3
3
  paginationStatus: (pageStart, pageEnd, totalRows)=>`Showing ${pageStart}–${pageEnd} of ${totalRows}`,
4
4
  expandView: 'Expand view',
5
5
  expandedView: 'Expanded table view',
6
- minimize: 'Minimize table'
6
+ minimize: 'Minimize table',
7
+ downloadCsv: 'Download CSV'
7
8
  };
8
9
 
9
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 /** 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};\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 };\n"],"names":["DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS","currentPage","paginationStatus","pageStart","pageEnd","totalRows","expandView","expandedView","minimize"],"mappings":"AAuBA,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;AACZ,EAAE"}
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,12 +1,13 @@
1
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, IconX } from "@tabler/icons-react";
3
+ import { IconArrowsDiagonal, IconDownload, IconX } from "@tabler/icons-react";
4
4
  import { cn } from "../../../../lib/utils.js";
5
5
  import { Button } from "../button/button.js";
6
6
  import { Card } from "../card/card.js";
7
7
  import { DataGrid, DataGridHeader, DataGridHeaderEnd } from "../data-grid/data-grid.js";
8
8
  import { Dialog, DialogClose, DialogContent } from "../dialog/dialog.js";
9
9
  import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip/tooltip.js";
10
+ import { buildCsv, downloadCsv } from "./message-response-table-csv.utils.js";
10
11
  import { MessageTableFooter } from "./message-response-table-footer.js";
11
12
  import { DEFAULT_MESSAGE_RESPONSE_TABLE_LABELS } from "./message-response-table-labels.js";
12
13
  const DEFAULT_TABLE_LABEL = 'Atlas AI Chat Table';
@@ -123,6 +124,11 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
123
124
  const handlePageIndexChange = (nextPageIndex)=>{
124
125
  setPageIndex(clamp(nextPageIndex, 0, totalPages - 1));
125
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
+ };
126
132
  useEffect(()=>{
127
133
  if (!isExpanded) return;
128
134
  const handleResize = ()=>{
@@ -192,26 +198,47 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
192
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.
193
199
  className: 'max-h-131 w-full',
194
200
  header: /*#__PURE__*/ _jsx(DataGridHeader, {
195
- children: /*#__PURE__*/ _jsx(DataGridHeaderEnd, {
196
- children: /*#__PURE__*/ _jsxs(Tooltip, {
197
- children: [
198
- /*#__PURE__*/ _jsx(TooltipTrigger, {
199
- render: /*#__PURE__*/ _jsx(Button, {
200
- variant: "ghost",
201
- size: "icon-sm",
202
- type: "button",
203
- "aria-label": resolvedLabels.expandView,
204
- onClick: handleOpen,
205
- children: /*#__PURE__*/ _jsx(IconArrowsDiagonal, {})
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
+ })
206
219
  })
207
- }),
208
- /*#__PURE__*/ _jsx(TooltipContent, {
209
- children: /*#__PURE__*/ _jsx("p", {
210
- children: resolvedLabels.expandView
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
+ })
211
238
  })
212
- })
213
- ]
214
- })
239
+ ]
240
+ })
241
+ ]
215
242
  })
216
243
  })
217
244
  })
@@ -227,14 +254,27 @@ const buildColumns = (headers)=>headers.map((header, index)=>({
227
254
  children: [
228
255
  /*#__PURE__*/ _jsx("div", {
229
256
  className: "flex shrink-0 items-center justify-end gap-4 border-b border-default px-4 py-2",
230
- children: /*#__PURE__*/ _jsx(DialogClose, {
231
- render: /*#__PURE__*/ _jsx(Button, {
232
- variant: "ghost",
233
- size: "icon-sm",
234
- type: "button",
235
- "aria-label": resolvedLabels.minimize,
236
- children: /*#__PURE__*/ _jsx(IconX, {})
237
- })
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
+ ]
238
278
  })
239
279
  }),
240
280
  renderGrid({
@@ -1 +1 @@
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, 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 { 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 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 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.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 <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 </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","IconX","cn","Button","Card","DataGrid","DataGridHeader","DataGridHeaderEnd","Dialog","DialogClose","DialogContent","Tooltip","TooltipContent","TooltipTrigger","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","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","expandView","onClick","p","open","onOpenChange","showCloseButton","expandedView","minimize"],"mappings":";AACA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAE9E,SAASC,kBAAkB,EAAEC,KAAK,QAAQ,sBAAsB;AAKhE,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,SAAS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ET,cAAA,KAAC1F;;;kDAIP,KAACY;kDACC,cAAA,KAACgH;sDAAGrD,eAAemD,UAAU;;;;;;;gBAMzC;;0BAGF,KAAClH;gBAAOqH,MAAM9C;gBAAY+C,cAAc9C;0BACtC,cAAA,MAACtE;oBACCqH,iBAAiB;oBACjBzB,cAAY/B,eAAeyD,YAAY;oBACvC9B,aAAU;oBACVC,WAAWjG,GACT,qEACA+E,oBAEI,mGACA;;sCAGN,KAACgB;4BAAIE,WAAU;sCACb,cAAA,KAAC1F;gCACC8G,sBACE,KAACpH;oCACCqH,SAAQ;oCACRC,MAAK;oCACLzF,MAAK;oCACLsE,cAAY/B,eAAe0D,QAAQ;8CAEnC,cAAA,KAAChI;;;;wBAMRwG,WAAW;4BACVC,SAAStB;4BACTe,WAAW;wBACb;;;;;;AAKV,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,C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AK;gDACL3F,MAAK;gDACLwE,cAAYjC,eAAeuD,UAAU;gDACrCF,SAASlC;0DAET,cAAA,KAAC7F;;;sDAIP,KAACa;sDACC,cAAA,KAACmH;0DAAGtD,eAAeuD,UAAU;;;;;;;;gBAMzC;;0BAGF,KAACxH;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognite/aura",
3
- "version": "1.48344.0",
3
+ "version": "1.48345.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": [