@marimo-team/islands 0.21.2-dev26 → 0.21.2-dev28
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/{any-language-editor-DlsjUw_l.js → any-language-editor-BRpxklRq.js} +1 -1
- package/dist/{copy-DIK6DiIA.js → copy-BjkXCUxP.js} +12 -2
- package/dist/{esm-BLobyqMs.js → esm-No_6eSQS.js} +1 -1
- package/dist/{glide-data-editor-pZyd9UJ_.js → glide-data-editor-858wsVkd.js} +1 -1
- package/dist/main.js +376 -308
- package/package.json +1 -1
- package/src/components/data-table/__tests__/utils.test.ts +138 -1
- package/src/components/data-table/context-menu.tsx +9 -5
- package/src/components/data-table/data-table.tsx +3 -0
- package/src/components/data-table/range-focus/__tests__/atoms.test.ts +8 -2
- package/src/components/data-table/range-focus/__tests__/test-utils.ts +2 -0
- package/src/components/data-table/range-focus/__tests__/utils.test.ts +82 -8
- package/src/components/data-table/range-focus/atoms.ts +2 -2
- package/src/components/data-table/range-focus/utils.ts +50 -12
- package/src/components/data-table/types.ts +7 -0
- package/src/components/data-table/utils.ts +87 -0
- package/src/plugins/impl/DataTablePlugin.tsx +23 -2
- package/src/utils/copy.ts +18 -5
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
} from "@/components/data-table/types";
|
|
54
54
|
import {
|
|
55
55
|
getPageIndexForRow,
|
|
56
|
+
loadTableAndRawData,
|
|
56
57
|
loadTableData,
|
|
57
58
|
} from "@/components/data-table/utils";
|
|
58
59
|
import { ErrorBoundary } from "@/components/editor/boundary/ErrorBoundary";
|
|
@@ -174,6 +175,7 @@ const valueCounts: z.ZodType<ValueCounts> = z.array(
|
|
|
174
175
|
interface Data<T> {
|
|
175
176
|
label: string | null;
|
|
176
177
|
data: TableData<T>;
|
|
178
|
+
rawData?: TableData<T> | null;
|
|
177
179
|
totalRows: number | TooManyRows;
|
|
178
180
|
pagination: boolean;
|
|
179
181
|
pageSize: number;
|
|
@@ -221,6 +223,7 @@ type DataTableFunctions = {
|
|
|
221
223
|
total_rows: number | TooManyRows;
|
|
222
224
|
cell_styles?: CellStyleState | null;
|
|
223
225
|
cell_hover_texts?: Record<string, Record<string, string | null>> | null;
|
|
226
|
+
raw_data?: TableData<T> | null;
|
|
224
227
|
}>;
|
|
225
228
|
get_data_url?: GetDataUrl;
|
|
226
229
|
get_row_ids?: GetRowIds;
|
|
@@ -243,6 +246,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
|
|
|
243
246
|
]),
|
|
244
247
|
label: z.string().nullable(),
|
|
245
248
|
data: z.union([z.string(), z.array(z.object({}).passthrough())]),
|
|
249
|
+
rawData: z.union([z.string(), z.array(z.looseObject({}))]).nullish(),
|
|
246
250
|
totalRows: z.union([z.number(), z.literal(TOO_MANY_ROWS)]),
|
|
247
251
|
pagination: z.boolean().default(false),
|
|
248
252
|
pageSize: z.number().default(10),
|
|
@@ -327,6 +331,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
|
|
|
327
331
|
)
|
|
328
332
|
.nullable(),
|
|
329
333
|
cell_hover_texts: cellHoverTextSchema.nullable(),
|
|
334
|
+
raw_data: z.union([z.string(), z.array(z.looseObject({}))]).nullish(),
|
|
330
335
|
}),
|
|
331
336
|
),
|
|
332
337
|
get_row_ids: rpc.input(z.object({}).passthrough()).output(
|
|
@@ -529,17 +534,23 @@ export const LoadingDataTableComponent = memo(
|
|
|
529
534
|
// Data loading
|
|
530
535
|
const { data, error, isPending, isFetching } = useAsyncData<{
|
|
531
536
|
rows: T[];
|
|
537
|
+
rawRows?: T[];
|
|
532
538
|
totalRows: number | TooManyRows;
|
|
533
539
|
cellStyles: CellStyleState | undefined | null;
|
|
534
540
|
cellHoverTexts?: Record<string, Record<string, string | null>> | null;
|
|
535
541
|
}>(async () => {
|
|
536
542
|
// If there is no data, return an empty array
|
|
537
543
|
if (props.totalRows === 0) {
|
|
538
|
-
return {
|
|
544
|
+
return {
|
|
545
|
+
rows: Arrays.EMPTY,
|
|
546
|
+
totalRows: 0,
|
|
547
|
+
cellStyles: {},
|
|
548
|
+
};
|
|
539
549
|
}
|
|
540
550
|
|
|
541
551
|
// Table data is a url string or an array of objects
|
|
542
552
|
let tableData = props.data;
|
|
553
|
+
let rawTableData: TableData<T> | undefined | null = props.rawData;
|
|
543
554
|
let totalRows = props.totalRows;
|
|
544
555
|
let cellStyles = props.cellStyles;
|
|
545
556
|
let cellHoverTexts = props.cellHoverTexts;
|
|
@@ -587,13 +598,19 @@ export const LoadingDataTableComponent = memo(
|
|
|
587
598
|
} else {
|
|
588
599
|
const searchResults = await searchResultsPromise;
|
|
589
600
|
tableData = searchResults.data;
|
|
601
|
+
rawTableData = searchResults.raw_data;
|
|
590
602
|
totalRows = searchResults.total_rows;
|
|
591
603
|
cellStyles = searchResults.cell_styles || {};
|
|
592
604
|
cellHoverTexts = searchResults.cell_hover_texts || {};
|
|
593
605
|
}
|
|
594
|
-
|
|
606
|
+
const [data, rawData] = await loadTableAndRawData(
|
|
607
|
+
tableData,
|
|
608
|
+
rawTableData,
|
|
609
|
+
);
|
|
610
|
+
tableData = data;
|
|
595
611
|
return {
|
|
596
612
|
rows: tableData,
|
|
613
|
+
rawRows: rawData,
|
|
597
614
|
totalRows: totalRows,
|
|
598
615
|
cellStyles,
|
|
599
616
|
cellHoverTexts,
|
|
@@ -715,6 +732,7 @@ export const LoadingDataTableComponent = memo(
|
|
|
715
732
|
<DataTableComponent
|
|
716
733
|
{...props}
|
|
717
734
|
data={data?.rows ?? Arrays.EMPTY}
|
|
735
|
+
rawData={data?.rawRows}
|
|
718
736
|
columnSummaries={columnSummaries}
|
|
719
737
|
sorting={sorting}
|
|
720
738
|
setSorting={setSorting}
|
|
@@ -766,6 +784,7 @@ LoadingDataTableComponent.displayName = "LoadingDataTableComponent";
|
|
|
766
784
|
const DataTableComponent = ({
|
|
767
785
|
label,
|
|
768
786
|
data,
|
|
787
|
+
rawData,
|
|
769
788
|
totalRows,
|
|
770
789
|
maxColumns,
|
|
771
790
|
pagination,
|
|
@@ -814,6 +833,7 @@ const DataTableComponent = ({
|
|
|
814
833
|
}: DataTableProps<unknown> &
|
|
815
834
|
DataTableSearchProps & {
|
|
816
835
|
data: unknown[];
|
|
836
|
+
rawData?: unknown[];
|
|
817
837
|
columnSummaries?: ColumnSummaries;
|
|
818
838
|
getRow: (rowIdx: number) => Promise<GetRowResult>;
|
|
819
839
|
}): JSX.Element => {
|
|
@@ -1015,6 +1035,7 @@ const DataTableComponent = ({
|
|
|
1015
1035
|
<Labeled label={label} align="top" fullWidth={true}>
|
|
1016
1036
|
<DataTable
|
|
1017
1037
|
data={data}
|
|
1038
|
+
rawData={rawData}
|
|
1018
1039
|
columns={columns}
|
|
1019
1040
|
className={className}
|
|
1020
1041
|
maxHeight={maxHeight}
|
package/src/utils/copy.ts
CHANGED
|
@@ -2,21 +2,34 @@
|
|
|
2
2
|
import { Logger } from "./Logger";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Copy text to the clipboard. When `html` is provided, writes both
|
|
6
|
+
* text/html and text/plain so rich content (e.g. hyperlinks) is
|
|
7
|
+
* preserved when pasting into apps like Excel or Google Sheets.
|
|
7
8
|
*
|
|
8
9
|
* As of 2024-10-29, Safari does not support navigator.clipboard.writeText
|
|
9
10
|
* when running localhost http.
|
|
10
11
|
*/
|
|
11
|
-
export async function copyToClipboard(text: string) {
|
|
12
|
+
export async function copyToClipboard(text: string, html?: string) {
|
|
12
13
|
if (navigator.clipboard === undefined) {
|
|
13
14
|
Logger.warn("navigator.clipboard is not supported");
|
|
14
15
|
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (html && navigator.clipboard.write) {
|
|
20
|
+
try {
|
|
21
|
+
const item = new ClipboardItem({
|
|
22
|
+
"text/html": new Blob([html], { type: "text/html" }),
|
|
23
|
+
"text/plain": new Blob([text], { type: "text/plain" }),
|
|
24
|
+
});
|
|
25
|
+
await navigator.clipboard.write([item]);
|
|
26
|
+
return;
|
|
27
|
+
} catch {
|
|
28
|
+
Logger.warn("Failed to write rich text, falling back to plain text");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await navigator.clipboard.writeText(text).catch(() => {
|
|
20
33
|
Logger.warn("Failed to copy to clipboard using navigator.clipboard");
|
|
21
34
|
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
|
|
22
35
|
});
|