@marimo-team/islands 0.19.8-dev3 → 0.19.8-dev31
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/{Combination-Bg-xN8JV.js → Combination-BTMrlhzT.js} +11 -10
- package/dist/{ConnectedDataExplorerComponent-DewsKLl2.js → ConnectedDataExplorerComponent-BAeQ8DWw.js} +11 -11
- package/dist/{ImageComparisonComponent-Bijp8beW.js → ImageComparisonComponent-DkEXPki_.js} +2 -2
- package/dist/{any-language-editor-DZc6NCTp.js → any-language-editor-D0UQItkS.js} +6 -6
- package/dist/{architectureDiagram-VXUJARFQ--NkyBn9Y.js → architectureDiagram-VXUJARFQ-DPPYVq8H.js} +4 -4
- package/dist/assets/__vite-browser-external-6-UwTyQC.js +1 -0
- package/dist/assets/{worker-SqntmiwV.js → worker-D3e5wDxM.js} +4 -4
- package/dist/{blockDiagram-VD42YOAC-DEZZaTW0.js → blockDiagram-VD42YOAC-BA5N05Y9.js} +4 -4
- package/dist/{button-BWvsJ2Wr.js → button-Cy0ElmIm.js} +2 -2
- package/dist/{c4Diagram-YG6GDRKO-Bj7hwWCO.js → c4Diagram-YG6GDRKO-DJLzuGJJ.js} +3 -3
- package/dist/{channel-B_QrFrGg.js → channel-Dob5kWXR.js} +1 -1
- package/dist/{check-CM_kewwn.js → check-DkNR52Mm.js} +1 -1
- package/dist/{chunk-5FQGJX7Z-D5VFKHmt.js → chunk-5FQGJX7Z-BEb20Lzt.js} +3 -3
- package/dist/{chunk-ABZYJK2D-SZPYmRzN.js → chunk-ABZYJK2D-BXTC53mt.js} +1 -1
- package/dist/{chunk-ATLVNIR6-BI_WwH1o.js → chunk-ATLVNIR6-BJDjUR_c.js} +1 -1
- package/dist/{chunk-B4BG7PRW-BlI9Gm1l.js → chunk-B4BG7PRW-DzmUUpfH.js} +4 -4
- package/dist/{chunk-DI55MBZ5-BXxemMn5.js → chunk-DI55MBZ5-gTd3J8Tu.js} +4 -4
- package/dist/{chunk-EXTU4WIE-CzWtDV99.js → chunk-EXTU4WIE-DyoOs5QX.js} +1 -1
- package/dist/{chunk-JA3XYJ7Z-DQ-2ARfa.js → chunk-JA3XYJ7Z-BGnAIbOP.js} +2 -2
- package/dist/{chunk-JZLCHNYA-CVfjf2vv.js → chunk-JZLCHNYA-CIRgweVQ.js} +4 -4
- package/dist/{chunk-N4CR4FBY-BCZvQ7Jq.js → chunk-N4CR4FBY-DKSvXAIS.js} +5 -5
- package/dist/{chunk-QN33PNHL-DY_2Q2zl.js → chunk-QN33PNHL-B6zC8BTi.js} +1 -1
- package/dist/{chunk-QXUST7PY-BMCjAVR_.js → chunk-QXUST7PY-C7750n_u.js} +5 -5
- package/dist/{chunk-S3R3BYOJ-Ddu0H4Qa.js → chunk-S3R3BYOJ-CBkH6JZZ.js} +1 -1
- package/dist/{chunk-TZMSLE5B-C2wVlbMl.js → chunk-TZMSLE5B-DObGL7xi.js} +1 -1
- package/dist/{classDiagram-2ON5EDUG-D-g7zbyO.js → classDiagram-2ON5EDUG-B9pkKjjc.js} +9 -9
- package/dist/{classDiagram-v2-WZHVMYZB-C7v5zNRD.js → classDiagram-v2-WZHVMYZB-CRhhA0tV.js} +9 -9
- package/dist/{click-outside-container-BCN5BtVO.js → click-outside-container-DNfggvIW.js} +1 -1
- package/dist/{code-block-37QAKDTI-eUgXqGNG.js → code-block-37QAKDTI-u5kgjqmr.js} +2 -2
- package/dist/{compiler-runtime-DHFVbq0b.js → compiler-runtime-B_OLMU9S.js} +1 -1
- package/dist/{copy-B59Bw3-w.js → copy-DRaXIb_a.js} +3 -3
- package/dist/{dagre-6UL2VRFP-DKIPL74O.js → dagre-6UL2VRFP-C2C2XxsB.js} +6 -6
- package/dist/{data-grid-overlay-editor-COyFwFmE.js → data-grid-overlay-editor-BXqtz1ia.js} +4 -4
- package/dist/{diagram-PSM6KHXK-CVTrAZaP.js → diagram-PSM6KHXK-DHBY-94p.js} +5 -5
- package/dist/{diagram-QEK2KX5R-BqHBzu3x.js → diagram-QEK2KX5R-CgMshOwn.js} +3 -3
- package/dist/{diagram-S2PKOQOG-CJD6owcg.js → diagram-S2PKOQOG-F1KPva3Y.js} +3 -3
- package/dist/{dist-Co5PD8Fb.js → dist-BBYTEAvO.js} +1 -1
- package/dist/{erDiagram-Q2GNP2WA-CqOceSf9.js → erDiagram-Q2GNP2WA-18gGng8V.js} +9 -9
- package/dist/{error-banner-C7KLpECd.js → error-banner-D2zjeN_a.js} +5 -5
- package/dist/{esm-D4WO8J3G.js → esm-CgRNPmz8.js} +6 -6
- package/dist/{flowDiagram-NV44I4VS-K7-DUifo.js → flowDiagram-NV44I4VS-iHFiHYe0.js} +9 -9
- package/dist/{ganttDiagram-JELNMOA3-BwUFY9Nu.js → ganttDiagram-JELNMOA3-D7GixxiF.js} +2 -2
- package/dist/{gitGraphDiagram-NY62KEGX-CjGRtLb1.js → gitGraphDiagram-NY62KEGX-CJFHytRK.js} +2 -2
- package/dist/{glide-data-editor-C3T7HsLi.js → glide-data-editor-BYwb17Bf.js} +13 -13
- package/dist/{infoDiagram-WHAUD3N6-DNhmDn-6.js → infoDiagram-WHAUD3N6-B5Lkh3A9.js} +2 -2
- package/dist/{journeyDiagram-XKPGCS4Q-BOdK47P8.js → journeyDiagram-XKPGCS4Q-CV_9R9iP.js} +2 -2
- package/dist/{kanban-definition-3W4ZIXB7-A0JC9d0g.js → kanban-definition-3W4ZIXB7-Dp21D5Ym.js} +6 -6
- package/dist/{katex-DJyOeQ91.js → katex-CX2BKujk.js} +1 -1
- package/dist/{katex-Dm9nZf6A.js → katex-Db0k5oV_.js} +1 -1
- package/dist/{label-C4PtQcza.js → label-CxU5JNBW.js} +6 -6
- package/dist/main.js +282 -193
- package/dist/mermaid-4DMBBIKO-BhDCqnO1.js +6 -0
- package/dist/{mermaid-Bqp2Xw99.js → mermaid-B__BZSXU.js} +39 -39
- package/dist/{mhchem-BqdXeZVX.js → mhchem-w1tkUnWr.js} +1 -1
- package/dist/{mindmap-definition-VGOIOE7T-CS6nKN_L.js → mindmap-definition-VGOIOE7T-B_5mfdYp.js} +8 -8
- package/dist/{number-overlay-editor-Bz_bDJQb.js → number-overlay-editor-D-4WQAGX.js} +2 -2
- package/dist/{pieDiagram-ADFJNKIX-DSa60Grk.js → pieDiagram-ADFJNKIX-B-DGEopK.js} +3 -3
- package/dist/{quadrantDiagram-AYHSOK5B-CFnMbP2J.js → quadrantDiagram-AYHSOK5B-M_yRSIZn.js} +1 -1
- package/dist/{react-DdA8EBol.js → react-Bs6Z0kvn.js} +1 -1
- package/dist/{react-dom-DJW8xUDg.js → react-dom-CqtLRVZP.js} +2 -2
- package/dist/{react-plotly-jVjTu07w.js → react-plotly-BuRa9xtI.js} +1 -1
- package/dist/{react-vega-DgHpnZ04.js → react-vega-3WcLHYC7.js} +2 -2
- package/dist/{react-vega-CjiPWyw0.js → react-vega-DLFvGrpJ.js} +1 -1
- package/dist/{requirementDiagram-UZGBJVZJ-ytLQrFTk.js → requirementDiagram-UZGBJVZJ-9Wt82hOZ.js} +8 -8
- package/dist/{sankeyDiagram-TZEHDZUN-KQqXDoky.js → sankeyDiagram-TZEHDZUN-x_aTXZeN.js} +1 -1
- package/dist/{sequenceDiagram-WL72ISMW-ByLI04T5.js → sequenceDiagram-WL72ISMW-CXXmJqiQ.js} +3 -3
- package/dist/{slides-component-BVjvNo92.js → slides-component-Dp-y50K9.js} +4 -4
- package/dist/{spec-Dmb1KfK3.js → spec-HoYHAQo2.js} +6 -6
- package/dist/{stateDiagram-FKZM4ZOC-Dfz8vBbP.js → stateDiagram-FKZM4ZOC-CiSKS_Mx.js} +9 -9
- package/dist/{stateDiagram-v2-4FDKWEC3-DRYoLdT5.js → stateDiagram-v2-4FDKWEC3-A43Itnjp.js} +9 -9
- package/dist/style.css +1 -1
- package/dist/{timeline-definition-IT6M3QCI-CO48XU1B.js → timeline-definition-IT6M3QCI-DR26eWb4.js} +1 -1
- package/dist/{types-CzEZ3EWT.js → types-Bb-6p8hv.js} +8 -8
- package/dist/{useAsyncData-BjNwqCfS.js → useAsyncData-Dyq3DyOF.js} +3 -3
- package/dist/{useDeepCompareMemoize-CfoxVor3.js → useDeepCompareMemoize-CMGprt3H.js} +5 -5
- package/dist/{useIframeCapabilities-BBO_R0ww.js → useIframeCapabilities-DurI5SJh.js} +2 -2
- package/dist/{useTheme-BYG2SH8J.js → useTheme-SlKl8MlS.js} +5 -6
- package/dist/{vega-component-rDX7xwxH.js → vega-component-DU3aSp4m.js} +10 -10
- package/dist/{xychartDiagram-PRI3JC2R-CUIfjNVD.js → xychartDiagram-PRI3JC2R-BcVxCRox.js} +4 -4
- package/dist/{zod-DITCj31F.js → zod-bjADtMKr.js} +3 -3
- package/package.json +18 -18
- package/src/components/app-config/ai-config.tsx +11 -2
- package/src/components/app-config/user-config-form.tsx +0 -54
- package/src/components/chat/acp/__tests__/state.test.ts +69 -0
- package/src/components/chat/acp/state.ts +6 -6
- package/src/components/chat/chat-panel.tsx +47 -30
- package/src/components/data-table/__tests__/data-table.test.tsx +94 -2
- package/src/components/editor/actions/useCellActionButton.tsx +14 -1
- package/src/components/editor/cell/CreateCellButton.tsx +2 -1
- package/src/components/editor/cell/code/cell-editor.tsx +12 -0
- package/src/components/editor/renderers/cell-array.tsx +2 -1
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +12 -0
- package/src/components/pages/gallery-page.tsx +37 -6
- package/src/core/MarimoApp.tsx +12 -8
- package/src/core/ai/context/providers/file.ts +1 -1
- package/src/core/cells/__tests__/cells.test.ts +120 -0
- package/src/core/cells/cells.ts +14 -0
- package/src/core/codemirror/language/languages/markdown.ts +7 -0
- package/src/core/config/feature-flag.tsx +0 -4
- package/src/core/islands/__tests__/bridge.test.ts +241 -0
- package/src/core/islands/bridge.ts +22 -6
- package/src/core/run-app.tsx +11 -4
- package/src/core/static/__tests__/files.test.ts +195 -1
- package/src/core/static/files.ts +39 -9
- package/src/plugins/core/registerReactComponent.tsx +9 -1
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +164 -0
- package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +7 -1
- package/src/utils/__tests__/blob.test.ts +3 -3
- package/src/utils/__tests__/mime-types.test.ts +8 -10
- package/src/utils/__tests__/url-parser.test.ts +22 -0
- package/src/utils/blob.ts +14 -27
- package/src/utils/mime-types.ts +5 -5
- package/src/utils/url-parser.ts +1 -1
- package/dist/assets/__vite-browser-external-DRa9CT_O.js +0 -1
- package/dist/mermaid-4DMBBIKO-o3xNphpD.js +0 -6
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { TooltipProvider } from "@radix-ui/react-tooltip";
|
|
4
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import { Provider } from "jotai";
|
|
6
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { DownloadAsArgs } from "@/components/data-table/schemas";
|
|
8
|
+
import type { FieldTypesWithExternalType } from "@/components/data-table/types";
|
|
9
|
+
import { store } from "@/core/state/jotai";
|
|
10
|
+
import {
|
|
11
|
+
type GetDataUrl,
|
|
12
|
+
type GetRowIds,
|
|
13
|
+
LoadingDataTableComponent,
|
|
14
|
+
} from "../DataTablePlugin";
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
global.ResizeObserver = class ResizeObserver {
|
|
18
|
+
observe() {
|
|
19
|
+
// do nothing
|
|
20
|
+
}
|
|
21
|
+
unobserve() {
|
|
22
|
+
// do nothing
|
|
23
|
+
}
|
|
24
|
+
disconnect() {
|
|
25
|
+
// do nothing
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("LoadingDataTableComponent", () => {
|
|
31
|
+
/**
|
|
32
|
+
* Regression test for https://github.com/marimo-team/marimo/issues/8023
|
|
33
|
+
*
|
|
34
|
+
* When a table is replaced via mo.output.replace() with updated data,
|
|
35
|
+
* but the initial page data (unsorted first page) hasn't changed,
|
|
36
|
+
* the useAsyncData hook's deps may all remain the same.
|
|
37
|
+
* Previously, the `search` function reference was memoized on
|
|
38
|
+
* [plugin.functions, hostElement] and wouldn't change on reset(),
|
|
39
|
+
* so the useAsyncData effect wouldn't re-fire.
|
|
40
|
+
*
|
|
41
|
+
* The fix adds a resetNonce to the functionMethods memo deps,
|
|
42
|
+
* so when the plugin is reset (table instance changes), the search
|
|
43
|
+
* function reference changes, triggering useAsyncData to re-fetch.
|
|
44
|
+
*
|
|
45
|
+
* This test verifies that when the search function reference changes
|
|
46
|
+
* (simulating reset()), the component re-fetches data even if
|
|
47
|
+
* props.data hasn't changed.
|
|
48
|
+
*/
|
|
49
|
+
it("should refetch data when search function reference changes", async () => {
|
|
50
|
+
const host = document.createElement("div");
|
|
51
|
+
const setValue = vi.fn();
|
|
52
|
+
|
|
53
|
+
// The initial page data string - identical for both renders.
|
|
54
|
+
// This simulates the case where only a row on page 2 changed,
|
|
55
|
+
// so the first page data is the same.
|
|
56
|
+
const initialPageData = JSON.stringify([
|
|
57
|
+
{ id: 1, status: "pending", value: 10 },
|
|
58
|
+
{ id: 2, status: "pending", value: 20 },
|
|
59
|
+
{ id: 3, status: "pending", value: 30 },
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const searchResult = {
|
|
63
|
+
data: [
|
|
64
|
+
{ id: 1, status: "pending", value: 10 },
|
|
65
|
+
{ id: 2, status: "pending", value: 20 },
|
|
66
|
+
{ id: 3, status: "pending", value: 30 },
|
|
67
|
+
],
|
|
68
|
+
total_rows: 4,
|
|
69
|
+
cell_styles: null,
|
|
70
|
+
cell_hover_texts: null,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const searchFn1 = vi.fn().mockResolvedValue(searchResult);
|
|
74
|
+
const searchFn2 = vi.fn().mockResolvedValue(searchResult);
|
|
75
|
+
|
|
76
|
+
const fieldTypes: FieldTypesWithExternalType = [
|
|
77
|
+
["id", ["integer", "integer"]],
|
|
78
|
+
["status", ["string", "string"]],
|
|
79
|
+
["value", ["integer", "integer"]],
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const commonProps = {
|
|
83
|
+
label: null,
|
|
84
|
+
totalRows: 4,
|
|
85
|
+
pagination: true,
|
|
86
|
+
pageSize: 3,
|
|
87
|
+
selection: "single" as const,
|
|
88
|
+
showDownload: false,
|
|
89
|
+
showFilters: false,
|
|
90
|
+
showColumnSummaries: false as const,
|
|
91
|
+
showDataTypes: false,
|
|
92
|
+
showPageSizeSelector: false,
|
|
93
|
+
showColumnExplorer: false,
|
|
94
|
+
showRowExplorer: false,
|
|
95
|
+
showChartBuilder: false,
|
|
96
|
+
rowHeaders: [] as FieldTypesWithExternalType,
|
|
97
|
+
fieldTypes,
|
|
98
|
+
totalColumns: 3,
|
|
99
|
+
maxColumns: "all" as const,
|
|
100
|
+
hasStableRowId: false,
|
|
101
|
+
lazy: false,
|
|
102
|
+
host,
|
|
103
|
+
enableSearch: true,
|
|
104
|
+
value: [] as (number | string | { rowId: string; columnName?: string })[],
|
|
105
|
+
setValue,
|
|
106
|
+
download_as: vi.fn() as DownloadAsArgs,
|
|
107
|
+
get_column_summaries: vi.fn().mockResolvedValue({
|
|
108
|
+
data: null,
|
|
109
|
+
stats: {},
|
|
110
|
+
bin_values: {},
|
|
111
|
+
value_counts: {},
|
|
112
|
+
show_charts: false,
|
|
113
|
+
}),
|
|
114
|
+
get_data_url: vi.fn() as GetDataUrl,
|
|
115
|
+
get_row_ids: vi.fn() as GetRowIds,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
119
|
+
<Provider store={store}>
|
|
120
|
+
<TooltipProvider>{children}</TooltipProvider>
|
|
121
|
+
</Provider>
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// Render with first search function
|
|
125
|
+
const { rerender } = render(
|
|
126
|
+
<Wrapper>
|
|
127
|
+
<LoadingDataTableComponent
|
|
128
|
+
{...commonProps}
|
|
129
|
+
data={initialPageData}
|
|
130
|
+
search={searchFn1}
|
|
131
|
+
/>
|
|
132
|
+
</Wrapper>,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Wait for the table to render with data
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(screen.getAllByRole("row").length).toBeGreaterThan(1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Search was called on initial load (fire-and-forget for canShowInitialPage)
|
|
141
|
+
expect(searchFn1).toHaveBeenCalled();
|
|
142
|
+
|
|
143
|
+
// Now rerender with the same data but a NEW search function reference.
|
|
144
|
+
// This simulates what happens after reset() when resetNonce increments
|
|
145
|
+
// and functionMethods is recreated.
|
|
146
|
+
await act(async () => {
|
|
147
|
+
rerender(
|
|
148
|
+
<Wrapper>
|
|
149
|
+
<LoadingDataTableComponent
|
|
150
|
+
{...commonProps}
|
|
151
|
+
data={initialPageData}
|
|
152
|
+
search={searchFn2}
|
|
153
|
+
/>
|
|
154
|
+
</Wrapper>,
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// The new search function should be called because the search
|
|
159
|
+
// dependency changed in useAsyncData.
|
|
160
|
+
await waitFor(() => {
|
|
161
|
+
expect(searchFn2).toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -8,6 +8,8 @@ import useEvent from "react-use-event-hook";
|
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { MarimoIncomingMessageEvent } from "@/core/dom/events";
|
|
10
10
|
import { asRemoteURL } from "@/core/runtime/config";
|
|
11
|
+
import { resolveVirtualFileURL } from "@/core/static/files";
|
|
12
|
+
import { isStaticNotebook } from "@/core/static/static-state";
|
|
11
13
|
import { useAsyncData } from "@/hooks/useAsyncData";
|
|
12
14
|
import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
|
|
13
15
|
import {
|
|
@@ -93,7 +95,11 @@ const AnyWidgetSlot = (
|
|
|
93
95
|
error,
|
|
94
96
|
refetch,
|
|
95
97
|
} = useAsyncData(async () => {
|
|
96
|
-
|
|
98
|
+
let url = asRemoteURL(jsUrl).toString();
|
|
99
|
+
// In static notebooks, resolve virtual files to blob URLs for import()
|
|
100
|
+
if (isStaticNotebook()) {
|
|
101
|
+
url = resolveVirtualFileURL(url);
|
|
102
|
+
}
|
|
97
103
|
return await import(/* @vite-ignore */ url);
|
|
98
104
|
// Re-render on jsHash change (which is a hash of the contents of the file)
|
|
99
105
|
// instead of a jsUrl change because URLs may change without the contents
|
|
@@ -20,7 +20,7 @@ describe("Blob serialization and deserialization", () => {
|
|
|
20
20
|
|
|
21
21
|
test("deserializeBlob should deserialize a base64 string to a Blob", async () => {
|
|
22
22
|
const serialized = await serializeBlob(testBlob);
|
|
23
|
-
const deserialized =
|
|
23
|
+
const deserialized = deserializeBlob(serialized);
|
|
24
24
|
expect(deserialized).toBeDefined();
|
|
25
25
|
expect(deserialized.size).toBe(testBlob.size);
|
|
26
26
|
expect(deserialized.type).toBe(testBlob.type);
|
|
@@ -28,7 +28,7 @@ describe("Blob serialization and deserialization", () => {
|
|
|
28
28
|
|
|
29
29
|
test("deserialized Blob should contain the original content", async () => {
|
|
30
30
|
const serialized = await serializeBlob(testBlob);
|
|
31
|
-
const deserialized =
|
|
31
|
+
const deserialized = deserializeBlob(serialized);
|
|
32
32
|
const reader = new FileReader();
|
|
33
33
|
// eslint-disable-next-line unicorn/prefer-blob-reading-methods
|
|
34
34
|
reader.readAsText(deserialized);
|
|
@@ -45,7 +45,7 @@ describe("Blob serialization and deserialization", () => {
|
|
|
45
45
|
type: "image/png",
|
|
46
46
|
});
|
|
47
47
|
const serialized = await serializeBlob(imageBlob);
|
|
48
|
-
const deserialized =
|
|
48
|
+
const deserialized = deserializeBlob(serialized);
|
|
49
49
|
expect(deserialized).toBeDefined();
|
|
50
50
|
expect(deserialized.size).toBe(imageBlob.size);
|
|
51
51
|
expect(deserialized.type).toBe(imageBlob.type);
|
|
@@ -132,7 +132,7 @@ describe("mime-types", () => {
|
|
|
132
132
|
|
|
133
133
|
describe("sortByPrecedence", () => {
|
|
134
134
|
it("should sort entries by precedence order", () => {
|
|
135
|
-
const entries:
|
|
135
|
+
const entries: [MimeType, string][] = [
|
|
136
136
|
["text/plain", "plain"],
|
|
137
137
|
["text/html", "html"],
|
|
138
138
|
["image/png", "png"],
|
|
@@ -151,7 +151,7 @@ describe("mime-types", () => {
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it("should place unknown mime types at the end", () => {
|
|
154
|
-
const entries:
|
|
154
|
+
const entries: [MimeType, string][] = [
|
|
155
155
|
["text/plain", "plain"],
|
|
156
156
|
["text/html", "html"],
|
|
157
157
|
["application/json", "json"],
|
|
@@ -173,7 +173,7 @@ describe("mime-types", () => {
|
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
it("should handle empty precedence", () => {
|
|
176
|
-
const entries:
|
|
176
|
+
const entries: [MimeType, string][] = [
|
|
177
177
|
["text/plain", "plain"],
|
|
178
178
|
["text/html", "html"],
|
|
179
179
|
];
|
|
@@ -184,7 +184,7 @@ describe("mime-types", () => {
|
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
it("should not mutate original array", () => {
|
|
187
|
-
const entries:
|
|
187
|
+
const entries: [MimeType, string][] = [
|
|
188
188
|
["text/plain", "plain"],
|
|
189
189
|
["text/html", "html"],
|
|
190
190
|
];
|
|
@@ -198,7 +198,7 @@ describe("mime-types", () => {
|
|
|
198
198
|
|
|
199
199
|
describe("processMimeBundle", () => {
|
|
200
200
|
it("should filter and sort mime entries", () => {
|
|
201
|
-
const entries:
|
|
201
|
+
const entries: [MimeType, string][] = [
|
|
202
202
|
["text/plain", "plain"],
|
|
203
203
|
["text/html", "html"],
|
|
204
204
|
["image/png", "png"],
|
|
@@ -226,7 +226,7 @@ describe("mime-types", () => {
|
|
|
226
226
|
});
|
|
227
227
|
|
|
228
228
|
it("should use default config when not provided", () => {
|
|
229
|
-
const entries:
|
|
229
|
+
const entries: [MimeType, string][] = [
|
|
230
230
|
["text/html", "html"],
|
|
231
231
|
["image/png", "png"],
|
|
232
232
|
["text/markdown", "md"],
|
|
@@ -240,9 +240,7 @@ describe("mime-types", () => {
|
|
|
240
240
|
|
|
241
241
|
it("should preserve data associated with mime types", () => {
|
|
242
242
|
const htmlData = { content: "<h1>Hello</h1>" };
|
|
243
|
-
const entries:
|
|
244
|
-
["text/html", htmlData],
|
|
245
|
-
];
|
|
243
|
+
const entries: [MimeType, typeof htmlData][] = [["text/html", htmlData]];
|
|
246
244
|
|
|
247
245
|
const result = processMimeBundle(entries);
|
|
248
246
|
|
|
@@ -250,7 +248,7 @@ describe("mime-types", () => {
|
|
|
250
248
|
});
|
|
251
249
|
|
|
252
250
|
it("should sort by precedence after filtering", () => {
|
|
253
|
-
const entries:
|
|
251
|
+
const entries: [MimeType, string][] = [
|
|
254
252
|
["text/plain", "plain"],
|
|
255
253
|
["text/markdown", "md"],
|
|
256
254
|
["text/html", "html"],
|
|
@@ -76,4 +76,26 @@ describe("parseContent", () => {
|
|
|
76
76
|
url: "https://avatars.githubusercontent.com/u/123",
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
it("preserves newlines between URLs", () => {
|
|
81
|
+
const parts = parseContent("https://marimo.io\nhttps://github.com\n");
|
|
82
|
+
expect(parts).toEqual([
|
|
83
|
+
{ type: "url", url: "https://marimo.io" },
|
|
84
|
+
{ type: "text", value: "\n" },
|
|
85
|
+
{ type: "url", url: "https://github.com" },
|
|
86
|
+
{ type: "text", value: "\n" },
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("preserves whitespace in mixed content", () => {
|
|
91
|
+
const parts = parseContent(
|
|
92
|
+
"Line 1: https://marimo.io\nLine 2: https://github.com",
|
|
93
|
+
);
|
|
94
|
+
expect(parts).toEqual([
|
|
95
|
+
{ type: "text", value: "Line 1: " },
|
|
96
|
+
{ type: "url", url: "https://marimo.io" },
|
|
97
|
+
{ type: "text", value: "\nLine 2: " },
|
|
98
|
+
{ type: "url", url: "https://github.com" },
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
79
101
|
});
|
package/src/utils/blob.ts
CHANGED
|
@@ -14,32 +14,19 @@ export function serializeBlob<T>(blob: Blob): Promise<DataURLString> {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function deserializeBlob(serializedBlob: DataURLString):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < len; i++) {
|
|
29
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
30
|
-
}
|
|
31
|
-
// Create a new Blob from the array buffer
|
|
32
|
-
const blob = new Blob([bytes], { type: mimeType });
|
|
33
|
-
resolve(blob);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
reject(ensureError(error));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function ensureError(error: unknown): Error {
|
|
41
|
-
if (error instanceof Error) {
|
|
42
|
-
return error;
|
|
17
|
+
export function deserializeBlob(serializedBlob: DataURLString): Blob {
|
|
18
|
+
// Extract the base64 data from the data URL
|
|
19
|
+
const [prefix, base64Data] = serializedBlob.split(",", 2);
|
|
20
|
+
const mimeType = /^data:(.+);base64$/.exec(prefix)?.[1];
|
|
21
|
+
// Decode the base64 string
|
|
22
|
+
const binaryString = atob(base64Data);
|
|
23
|
+
// Convert the binary string to an array buffer
|
|
24
|
+
const len = binaryString.length;
|
|
25
|
+
const bytes = new Uint8Array(len);
|
|
26
|
+
for (let i = 0; i < len; i++) {
|
|
27
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
43
28
|
}
|
|
44
|
-
|
|
29
|
+
// Create a new Blob from the array buffer
|
|
30
|
+
const blob = new Blob([bytes], { type: mimeType });
|
|
31
|
+
return blob;
|
|
45
32
|
}
|
package/src/utils/mime-types.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface MimeTypeConfig {
|
|
|
26
26
|
*/
|
|
27
27
|
export interface ProcessedMimeTypes<T> {
|
|
28
28
|
/** The filtered and sorted mime entries */
|
|
29
|
-
entries:
|
|
29
|
+
entries: [MimeType, T][];
|
|
30
30
|
/** Mime types that were hidden by rules */
|
|
31
31
|
hidden: MimeType[];
|
|
32
32
|
}
|
|
@@ -146,9 +146,9 @@ export function applyHidingRules(
|
|
|
146
146
|
* Mime types not in the map are placed at the end, preserving their original order.
|
|
147
147
|
*/
|
|
148
148
|
export function sortByPrecedence<T>(
|
|
149
|
-
entries:
|
|
149
|
+
entries: [MimeType, T][],
|
|
150
150
|
precedence: ReadonlyMap<MimeType, number>,
|
|
151
|
-
):
|
|
151
|
+
): [MimeType, T][] {
|
|
152
152
|
const unknownPrecedence = precedence.size;
|
|
153
153
|
|
|
154
154
|
return [...entries].sort((a, b) => {
|
|
@@ -162,7 +162,7 @@ export function sortByPrecedence<T>(
|
|
|
162
162
|
* Main entry point: processes mime entries by applying hiding rules and sorting.
|
|
163
163
|
*/
|
|
164
164
|
export function processMimeBundle<T>(
|
|
165
|
-
entries:
|
|
165
|
+
entries: [MimeType, T][],
|
|
166
166
|
config: MimeTypeConfig = getDefaultMimeConfig(),
|
|
167
167
|
): ProcessedMimeTypes<T> {
|
|
168
168
|
if (entries.length === 0) {
|
|
@@ -176,6 +176,6 @@ export function processMimeBundle<T>(
|
|
|
176
176
|
|
|
177
177
|
return {
|
|
178
178
|
entries: sortedEntries,
|
|
179
|
-
hidden:
|
|
179
|
+
hidden: [...hidden],
|
|
180
180
|
};
|
|
181
181
|
}
|
package/src/utils/url-parser.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function parseContent(text: string): ContentPart[] {
|
|
|
19
19
|
return [{ type: "image", url: text }];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const parts = text.split(urlRegex).filter((part) => part
|
|
22
|
+
const parts = text.split(urlRegex).filter((part) => part !== "");
|
|
23
23
|
return parts.map((part) => {
|
|
24
24
|
const isUrl = urlRegex.test(part);
|
|
25
25
|
if (isUrl) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./worker-SqntmiwV.js";var t=e(((e,t)=>{t.exports={}}));export default t();
|