@marimo-team/frontend 0.23.2-dev41 → 0.23.2-dev44
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/assets/__vite-browser-external-DgbEhFq1.js +1 -0
- package/dist/assets/{edit-page-C28CPNWD.js → edit-page-mEKXGNP8.js} +3 -3
- package/dist/assets/file-explorer-panel-DH1Yf6zQ.js +26 -0
- package/dist/assets/{index-ddxYLCBl.js → index-BMa4-yRO.js} +6 -6
- package/dist/assets/{panels-CHFFNaFY.js → panels-ChT_IPtH.js} +1 -1
- package/dist/assets/{run-page-Tt0WlqGQ.js → run-page-BtEws7vt.js} +1 -1
- package/dist/assets/state-BpNPsbIR.js +3 -0
- package/dist/assets/{worker-BPV9SmHz.js → worker-ztl1wuLb.js} +2 -2
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/__mocks__/requests.ts +1 -0
- package/src/components/editor/file-tree/__tests__/requesting-tree.test.ts +33 -0
- package/src/components/editor/file-tree/file-explorer.tsx +8 -33
- package/src/components/editor/file-tree/requesting-tree.tsx +41 -0
- package/src/components/editor/file-tree/state.tsx +1 -0
- package/src/core/islands/bridge.ts +1 -0
- package/src/core/network/requests-lazy.ts +1 -0
- package/src/core/network/requests-network.ts +8 -0
- package/src/core/network/requests-static.ts +1 -0
- package/src/core/network/requests-toasting.tsx +1 -0
- package/src/core/network/types.ts +3 -0
- package/src/core/wasm/bridge.ts +11 -0
- package/src/core/wasm/worker/types.ts +3 -0
- package/src/core/wasm/worker/worker.ts +1 -0
- package/dist/assets/__vite-browser-external-DT1nudb6.js +0 -1
- package/dist/assets/file-explorer-panel-DeoEBy9i.js +0 -26
- package/dist/assets/state-BV4n_RxL.js +0 -3
|
@@ -8,6 +8,7 @@ import { RequestingTree } from "../requesting-tree";
|
|
|
8
8
|
const sendListFiles = vi.fn();
|
|
9
9
|
const sendCreateFileOrFolder = vi.fn();
|
|
10
10
|
const sendDeleteFileOrFolder = vi.fn();
|
|
11
|
+
const sendCopyFileOrFolder = vi.fn();
|
|
11
12
|
const sendRenameFileOrFolder = vi.fn();
|
|
12
13
|
|
|
13
14
|
vi.mock("@/components/ui/use-toast", () => MockModules.toast());
|
|
@@ -21,6 +22,7 @@ describe("RequestingTree", () => {
|
|
|
21
22
|
listFiles: sendListFiles,
|
|
22
23
|
createFileOrFolder: sendCreateFileOrFolder,
|
|
23
24
|
deleteFileOrFolder: sendDeleteFileOrFolder,
|
|
25
|
+
copyFileOrFolder: sendCopyFileOrFolder,
|
|
24
26
|
renameFileOrFolder: sendRenameFileOrFolder,
|
|
25
27
|
});
|
|
26
28
|
sendListFiles.mockResolvedValue({
|
|
@@ -169,6 +171,17 @@ describe("RequestingTree", () => {
|
|
|
169
171
|
`);
|
|
170
172
|
});
|
|
171
173
|
|
|
174
|
+
test("copy should duplicate a file", async () => {
|
|
175
|
+
sendCopyFileOrFolder.mockResolvedValue({ success: true });
|
|
176
|
+
|
|
177
|
+
await requestingTree.copy("1.1", "file1_copy");
|
|
178
|
+
expect(sendCopyFileOrFolder).toHaveBeenCalledWith({
|
|
179
|
+
path: "/root/file1",
|
|
180
|
+
newPath: "/root/file1_copy",
|
|
181
|
+
});
|
|
182
|
+
expect(mockOnChange).toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
|
|
172
185
|
test("createFile should create a new file", async () => {
|
|
173
186
|
sendCreateFileOrFolder.mockResolvedValue({ success: true });
|
|
174
187
|
|
|
@@ -236,6 +249,7 @@ describe("RequestingTree", () => {
|
|
|
236
249
|
listFiles: sendListFiles,
|
|
237
250
|
createFileOrFolder: sendCreateFileOrFolder,
|
|
238
251
|
deleteFileOrFolder: sendDeleteFileOrFolder,
|
|
252
|
+
copyFileOrFolder: sendCopyFileOrFolder,
|
|
239
253
|
renameFileOrFolder: sendRenameFileOrFolder,
|
|
240
254
|
});
|
|
241
255
|
sendListFiles.mockRejectedValue(new Error("Network error"));
|
|
@@ -263,6 +277,23 @@ describe("RequestingTree", () => {
|
|
|
263
277
|
});
|
|
264
278
|
});
|
|
265
279
|
|
|
280
|
+
test("copy should handle API failure", async () => {
|
|
281
|
+
sendCopyFileOrFolder.mockResolvedValue({
|
|
282
|
+
success: false,
|
|
283
|
+
message: "Error duplicating",
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
await requestingTree.copy("1.1", "file1_copy");
|
|
287
|
+
expect(sendCopyFileOrFolder).toHaveBeenCalledWith({
|
|
288
|
+
path: "/root/file1",
|
|
289
|
+
newPath: "/root/file1_copy",
|
|
290
|
+
});
|
|
291
|
+
expect(toast).toHaveBeenCalledWith({
|
|
292
|
+
title: "Failed",
|
|
293
|
+
description: "Error duplicating",
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
266
297
|
test("move should handle missing parent node gracefully", async () => {
|
|
267
298
|
await requestingTree.move(["1.x"], "2");
|
|
268
299
|
expect(sendRenameFileOrFolder).not.toHaveBeenCalled();
|
|
@@ -284,6 +315,7 @@ describe("RequestingTree", () => {
|
|
|
284
315
|
listFiles: sendListFiles,
|
|
285
316
|
createFileOrFolder: sendCreateFileOrFolder,
|
|
286
317
|
deleteFileOrFolder: sendDeleteFileOrFolder,
|
|
318
|
+
copyFileOrFolder: sendCopyFileOrFolder,
|
|
287
319
|
renameFileOrFolder: sendRenameFileOrFolder,
|
|
288
320
|
});
|
|
289
321
|
|
|
@@ -305,6 +337,7 @@ describe("RequestingTree", () => {
|
|
|
305
337
|
listFiles: sendListFiles,
|
|
306
338
|
createFileOrFolder: sendCreateFileOrFolder,
|
|
307
339
|
deleteFileOrFolder: sendDeleteFileOrFolder,
|
|
340
|
+
copyFileOrFolder: sendCopyFileOrFolder,
|
|
308
341
|
renameFileOrFolder: sendRenameFileOrFolder,
|
|
309
342
|
});
|
|
310
343
|
|
|
@@ -381,6 +381,7 @@ const Show = ({
|
|
|
381
381
|
{node.data.name}
|
|
382
382
|
{node.data.isMarimoFile && !isWasm() && (
|
|
383
383
|
<span
|
|
384
|
+
data-testid="file-explorer-open-marimo-button"
|
|
384
385
|
className="shrink-0 ml-2 text-sm hidden group-hover:inline hover:underline"
|
|
385
386
|
onClick={onOpenMarimoFile}
|
|
386
387
|
>
|
|
@@ -419,8 +420,7 @@ const Edit = ({ node }: { node: NodeApi<FileInfo> }) => {
|
|
|
419
420
|
};
|
|
420
421
|
|
|
421
422
|
const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
|
|
422
|
-
const { openFile,
|
|
423
|
-
useRequestClient();
|
|
423
|
+
const { openFile, sendFileDetails } = useRequestClient();
|
|
424
424
|
const disableFileDownloads = useAtomValue(disableFileDownloadsAtom);
|
|
425
425
|
|
|
426
426
|
const fileType: FileIconType = node.data.isDirectory
|
|
@@ -502,37 +502,14 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
|
|
|
502
502
|
});
|
|
503
503
|
|
|
504
504
|
const handleDuplicate = useEvent(async () => {
|
|
505
|
-
if (!tree
|
|
505
|
+
if (!tree) {
|
|
506
506
|
return;
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
const [name, extension] = fileSplit(node.data.name);
|
|
510
510
|
const duplicateName = `${name}_copy${extension}`;
|
|
511
511
|
|
|
512
|
-
|
|
513
|
-
// First get the file contents
|
|
514
|
-
const details = await sendFileDetails({ path: node.data.path });
|
|
515
|
-
|
|
516
|
-
// Get the parent directory path
|
|
517
|
-
const parentPath = node.parent?.data.path || "";
|
|
518
|
-
|
|
519
|
-
// Create the duplicate file by creating a new file with the same contents
|
|
520
|
-
await sendCreateFileOrFolder({
|
|
521
|
-
path: parentPath,
|
|
522
|
-
type: "file",
|
|
523
|
-
name: duplicateName,
|
|
524
|
-
contents: details.contents ? btoa(details.contents) : undefined,
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// Refresh the parent folder to show the new file
|
|
528
|
-
await tree.refreshAll([parentPath]);
|
|
529
|
-
} catch {
|
|
530
|
-
toast({
|
|
531
|
-
title: "Failed to duplicate file",
|
|
532
|
-
description: "Unable to create a duplicate of the file",
|
|
533
|
-
variant: "danger",
|
|
534
|
-
});
|
|
535
|
-
}
|
|
512
|
+
await tree.copy(node.id, duplicateName);
|
|
536
513
|
});
|
|
537
514
|
|
|
538
515
|
const renderActions = () => {
|
|
@@ -581,12 +558,10 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
|
|
|
581
558
|
<Edit3Icon className={ic} />
|
|
582
559
|
Rename
|
|
583
560
|
</DropdownMenuItem>
|
|
584
|
-
{
|
|
585
|
-
<
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
</DropdownMenuItem>
|
|
589
|
-
)}
|
|
561
|
+
<DropdownMenuItem onSelect={handleDuplicate}>
|
|
562
|
+
<CopyIcon className={ic} />
|
|
563
|
+
Duplicate
|
|
564
|
+
</DropdownMenuItem>
|
|
590
565
|
<DropdownMenuItem
|
|
591
566
|
onSelect={async () => {
|
|
592
567
|
await copyToClipboard(node.data.path);
|
|
@@ -17,6 +17,7 @@ export class RequestingTree {
|
|
|
17
17
|
listFiles: EditRequests["sendListFiles"];
|
|
18
18
|
createFileOrFolder: EditRequests["sendCreateFileOrFolder"];
|
|
19
19
|
deleteFileOrFolder: EditRequests["sendDeleteFileOrFolder"];
|
|
20
|
+
copyFileOrFolder: EditRequests["sendCopyFileOrFolder"];
|
|
20
21
|
renameFileOrFolder: EditRequests["sendRenameFileOrFolder"];
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -24,6 +25,7 @@ export class RequestingTree {
|
|
|
24
25
|
listFiles: EditRequests["sendListFiles"];
|
|
25
26
|
createFileOrFolder: EditRequests["sendCreateFileOrFolder"];
|
|
26
27
|
deleteFileOrFolder: EditRequests["sendDeleteFileOrFolder"];
|
|
28
|
+
copyFileOrFolder: EditRequests["sendCopyFileOrFolder"];
|
|
27
29
|
renameFileOrFolder: EditRequests["sendRenameFileOrFolder"];
|
|
28
30
|
}) {
|
|
29
31
|
this.callbacks = callbacks;
|
|
@@ -74,9 +76,44 @@ export class RequestingTree {
|
|
|
74
76
|
return true;
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
async copy(id: string, newName: string): Promise<void> {
|
|
80
|
+
const node = this.delegate.find(id);
|
|
81
|
+
if (!node) {
|
|
82
|
+
toast({
|
|
83
|
+
title: "Failed",
|
|
84
|
+
description: `Node with id ${id} not found in the tree`,
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const currentPath = node.data.path as FilePath;
|
|
89
|
+
const parentPath = this.path.dirname(currentPath);
|
|
90
|
+
const newPath = this.path.join(parentPath, newName);
|
|
91
|
+
const newFile = await this.callbacks
|
|
92
|
+
.copyFileOrFolder({
|
|
93
|
+
path: currentPath,
|
|
94
|
+
newPath: newPath,
|
|
95
|
+
})
|
|
96
|
+
.then(this.handleResponse);
|
|
97
|
+
if (!newFile?.info) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.delegate.create({
|
|
101
|
+
parentId: node.parent?.id ?? null,
|
|
102
|
+
index: 0,
|
|
103
|
+
data: newFile.info,
|
|
104
|
+
});
|
|
105
|
+
this.onChange(this.delegate.data);
|
|
106
|
+
// Refresh the parent folder
|
|
107
|
+
await this.refreshAll([parentPath]);
|
|
108
|
+
}
|
|
109
|
+
|
|
77
110
|
async rename(id: string, name: string): Promise<void> {
|
|
78
111
|
const node = this.delegate.find(id);
|
|
79
112
|
if (!node) {
|
|
113
|
+
toast({
|
|
114
|
+
title: "Failed",
|
|
115
|
+
description: `Node with id ${id} not found in the tree`,
|
|
116
|
+
});
|
|
80
117
|
return;
|
|
81
118
|
}
|
|
82
119
|
const currentPath = node.data.path as FilePath;
|
|
@@ -172,6 +209,10 @@ export class RequestingTree {
|
|
|
172
209
|
async delete(id: string): Promise<void> {
|
|
173
210
|
const node = this.delegate.find(id);
|
|
174
211
|
if (!node) {
|
|
212
|
+
toast({
|
|
213
|
+
title: "Failed",
|
|
214
|
+
description: `Node with id ${id} not found in the tree`,
|
|
215
|
+
});
|
|
175
216
|
return;
|
|
176
217
|
}
|
|
177
218
|
|
|
@@ -15,6 +15,7 @@ export const treeAtom = atom<RequestingTree>((get) => {
|
|
|
15
15
|
listFiles: client.sendListFiles,
|
|
16
16
|
createFileOrFolder: client.sendCreateFileOrFolder,
|
|
17
17
|
deleteFileOrFolder: client.sendDeleteFileOrFolder,
|
|
18
|
+
copyFileOrFolder: client.sendCopyFileOrFolder,
|
|
18
19
|
renameFileOrFolder: client.sendRenameFileOrFolder,
|
|
19
20
|
});
|
|
20
21
|
});
|
|
@@ -237,6 +237,7 @@ export class IslandsPyodideBridge implements RunRequests, EditRequests {
|
|
|
237
237
|
sendPdb = throwNotImplemented;
|
|
238
238
|
sendCreateFileOrFolder = throwNotImplemented;
|
|
239
239
|
sendDeleteFileOrFolder = throwNotImplemented;
|
|
240
|
+
sendCopyFileOrFolder = throwNotImplemented;
|
|
240
241
|
sendRenameFileOrFolder = throwNotImplemented;
|
|
241
242
|
sendUpdateFile = throwNotImplemented;
|
|
242
243
|
sendFileDetails = throwNotImplemented;
|
|
@@ -90,6 +90,7 @@ const ACTIONS: Record<keyof AllRequests, Action> = {
|
|
|
90
90
|
sendSearchFiles: "startConnection",
|
|
91
91
|
sendCreateFileOrFolder: "throwError",
|
|
92
92
|
sendDeleteFileOrFolder: "throwError",
|
|
93
|
+
sendCopyFileOrFolder: "throwError",
|
|
93
94
|
sendRenameFileOrFolder: "throwError",
|
|
94
95
|
sendUpdateFile: "throwError",
|
|
95
96
|
sendFileDetails: "throwError",
|
|
@@ -312,6 +312,14 @@ export function createNetworkRequests(): EditRequests & RunRequests {
|
|
|
312
312
|
})
|
|
313
313
|
.then(handleResponse);
|
|
314
314
|
},
|
|
315
|
+
sendCopyFileOrFolder: async (request) => {
|
|
316
|
+
await waitForConnectionOpen();
|
|
317
|
+
return getClient()
|
|
318
|
+
.POST("/api/files/copy", {
|
|
319
|
+
body: request,
|
|
320
|
+
})
|
|
321
|
+
.then(handleResponse);
|
|
322
|
+
},
|
|
315
323
|
sendRenameFileOrFolder: async (request) => {
|
|
316
324
|
await waitForConnectionOpen();
|
|
317
325
|
return getClient()
|
|
@@ -66,6 +66,7 @@ export function createStaticRequests(): EditRequests & RunRequests {
|
|
|
66
66
|
sendPdb: throwNotInEditMode,
|
|
67
67
|
sendCreateFileOrFolder: throwNotInEditMode,
|
|
68
68
|
sendDeleteFileOrFolder: throwNotInEditMode,
|
|
69
|
+
sendCopyFileOrFolder: throwNotInEditMode,
|
|
69
70
|
sendRenameFileOrFolder: throwNotInEditMode,
|
|
70
71
|
sendUpdateFile: throwNotInEditMode,
|
|
71
72
|
sendFileDetails: throwNotInEditMode,
|
|
@@ -51,6 +51,7 @@ export function createErrorToastingRequests(
|
|
|
51
51
|
sendPdb: "Failed to start debug session",
|
|
52
52
|
sendCreateFileOrFolder: "Failed to create file or folder",
|
|
53
53
|
sendDeleteFileOrFolder: "Failed to delete file or folder",
|
|
54
|
+
sendCopyFileOrFolder: "Failed to duplicate file or folder",
|
|
54
55
|
sendRenameFileOrFolder: "Failed to rename file or folder",
|
|
55
56
|
sendUpdateFile: "Failed to update file",
|
|
56
57
|
sendFileDetails: "Failed to get file details",
|
|
@@ -23,6 +23,8 @@ export type ExportAsIPYNBRequest = schemas["ExportAsIPYNBRequest"];
|
|
|
23
23
|
export type ExportAsScriptRequest = schemas["ExportAsScriptRequest"];
|
|
24
24
|
export type ExportAsPDFRequest = schemas["ExportAsPDFRequest"];
|
|
25
25
|
export type UpdateCellOutputsRequest = schemas["UpdateCellOutputsRequest"];
|
|
26
|
+
export type FileCopyRequest = schemas["FileCopyRequest"];
|
|
27
|
+
export type FileCopyResponse = schemas["FileCopyResponse"];
|
|
26
28
|
export type FileCreateRequest = schemas["FileCreateRequest"];
|
|
27
29
|
export type FileCreateResponse = schemas["FileCreateResponse"];
|
|
28
30
|
export type FileDeleteRequest = schemas["FileDeleteRequest"];
|
|
@@ -168,6 +170,7 @@ export interface EditRequests {
|
|
|
168
170
|
sendDeleteFileOrFolder: (
|
|
169
171
|
request: FileDeleteRequest,
|
|
170
172
|
) => Promise<FileDeleteResponse>;
|
|
173
|
+
sendCopyFileOrFolder: (request: FileCopyRequest) => Promise<FileCopyResponse>;
|
|
171
174
|
sendRenameFileOrFolder: (
|
|
172
175
|
request: FileMoveRequest,
|
|
173
176
|
) => Promise<FileMoveResponse>;
|
package/src/core/wasm/bridge.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
EditRequests,
|
|
18
18
|
ExportAsHTMLRequest,
|
|
19
19
|
ExportAsMarkdownRequest,
|
|
20
|
+
FileCopyResponse,
|
|
20
21
|
FileCreateResponse,
|
|
21
22
|
FileDeleteResponse,
|
|
22
23
|
FileDetailsResponse,
|
|
@@ -443,6 +444,16 @@ export class PyodideBridge implements RunRequests, EditRequests {
|
|
|
443
444
|
return response as FileDeleteResponse;
|
|
444
445
|
};
|
|
445
446
|
|
|
447
|
+
sendCopyFileOrFolder: EditRequests["sendCopyFileOrFolder"] = async (
|
|
448
|
+
request,
|
|
449
|
+
) => {
|
|
450
|
+
const response = await this.rpc.proxy.request.bridge({
|
|
451
|
+
functionName: "copy_file_or_directory",
|
|
452
|
+
payload: request,
|
|
453
|
+
});
|
|
454
|
+
return response as FileCopyResponse;
|
|
455
|
+
};
|
|
456
|
+
|
|
446
457
|
sendRenameFileOrFolder: EditRequests["sendRenameFileOrFolder"] = async (
|
|
447
458
|
request,
|
|
448
459
|
) => {
|
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
CopyNotebookRequest,
|
|
12
12
|
ExportAsHTMLRequest,
|
|
13
13
|
ExportAsMarkdownRequest,
|
|
14
|
+
FileCopyRequest,
|
|
15
|
+
FileCopyResponse,
|
|
14
16
|
FileCreateRequest,
|
|
15
17
|
FileCreateResponse,
|
|
16
18
|
FileDeleteRequest,
|
|
@@ -86,6 +88,7 @@ export interface RawBridge {
|
|
|
86
88
|
delete_file_or_directory(
|
|
87
89
|
request: FileDeleteRequest,
|
|
88
90
|
): Promise<FileDeleteResponse>;
|
|
91
|
+
copy_file_or_directory(request: FileCopyRequest): Promise<FileCopyResponse>;
|
|
89
92
|
move_file_or_directory(request: FileMoveRequest): Promise<FileMoveResponse>;
|
|
90
93
|
update_file(request: FileUpdateRequest): Promise<FileUpdateResponse>;
|
|
91
94
|
load_packages(request: string): Promise<string>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./worker-BPV9SmHz.js";var t=e(((e,t)=>{t.exports={}}));export default t();
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var Ot=Object.defineProperty;var $t=(t,e,n)=>e in t?Ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var V=(t,e,n)=>$t(t,typeof e!="symbol"?e+"":e,n);import{s as Ae}from"./chunk-LvLJmgfZ.js";import{i as Tt,l as de,n as B,p as Ee,u as ne}from"./useEvent-D91BmmQi.js";import{t as Rt}from"./react-Bj1aDYRI.js";import{E as At,Mn as Ie,_i as Be,hr as Et,pi as It}from"./cells-9Zp_JbEx.js";import"./react-dom-CSu739Rf.js";import{t as te}from"./compiler-runtime-B3qBwwSJ.js";import{_ as ye,v as Bt}from"./useEventListener-BR0C1MaI.js";import{t as Vt}from"./invariant-BUdrueMv.js";import{p as Ht,u as Ve}from"./utils-DIGrmLDO.js";import{S as he}from"./config-Calf6e81.js";import{t as q}from"./cn-DCUzRj2J.js";import{t as Lt}from"./jsx-runtime-BqBOg78p.js";import"./fullscreen-BDxedMYP.js";import{n as Ut}from"./multi-map-rafH3cg3.js";import{o as qt}from"./alert-dialog-BGBdrcqJ.js";import"./popover-UExmgBsf.js";import{a as z,c as ae,p as He,r as Le,t as Ue}from"./dropdown-menu-D1A3cFC8.js";import{a as Wt,gt as je,i as qe,o as me}from"./JsonOutput-CaMHqTRB.js";import{c as Kt,i as be,r as pe}from"./download-CsVG4qrR.js";import{t as T}from"./tooltip-Gcwqb_SK.js";import{n as Gt,t as O}from"./button-D9nb17Rw.js";import{St as Jt}from"./dist-BrR4M-k3.js";import"./cjs-BRGiG41H.js";import"./main-B0OX4z33.js";import"./useNonce-DfoVjkkH.js";import{n as Yt,r as ve}from"./requests-DIwGYs0l.js";import{t as H}from"./createLucideIcon-D5guW7EU.js";import{a as We,c as Ke,i as Ge,n as fe,o as we,r as Zt,t as Qt}from"./state-Dlj7aAV2.js";import{n as Xt}from"./LazyAnyLanguageCodeMirror-DQ37z5WJ.js";import{t as ea}from"./x-C-6liIBr.js";import{n as Ne}from"./maps-C48Oksn0.js";import{n as ke}from"./markdown-renderer-BclMAJo1.js";import{u as ta}from"./toDate-B5A0DFEz.js";import{t as Ce}from"./copy-BwrPA9zQ.js";import{t as aa}from"./eye-off-n1Li95bE.js";import{a as na,i as Je,n as Ye,r as sa,t as ra}from"./file-icons-DLa7-MLk.js";import{t as Ze}from"./file-BrdxGLRX.js";import{i as Qe,r as ia,t as Xe}from"./add-connection-dialog-BTUO6NJ0.js";import{n as Fe,t as la}from"./spinner-jEqwgi_c.js";import{t as et}from"./plus-BueqiM86.js";import{t as tt}from"./refresh-cw-BmiNHssk.js";import{t as oa}from"./save-B_q9ApPf.js";import{t as ca}from"./trash-2-C5AzNaHr.js";import{t as da}from"./triangle-alert-CBEvAwaa.js";import{i as ha,n as ma,t as pa}from"./es-CjWf0wU3.js";import"./dist-BwejP-9J.js";import"./dist-G3xLh7ZX.js";import"./dist-idZNafp8.js";import"./dist-DfWgLTCQ.js";import"./dist-Dg3CCt0r.js";import{t as R}from"./use-toast-PYIpV284.js";import{t as Se}from"./paths-DsQUzvvb.js";import"./session-DdhIEena.js";import"./purify.es-CeTCD9Zj.js";import"./dates-CtmdgiVR.js";import{n as se}from"./copy-BnK_ki61.js";import{t as fa}from"./copy-icon-D189KR4Z.js";import{t as at}from"./context-BrNoqz7t.js";import{n as nt}from"./ImperativeModal-CAFE3UV7.js";import{r as xa}from"./errors-DVkmLSXX.js";import{n as ua,t as st}from"./blob-CpeNXBj-.js";import"./utils-DVodi8oQ.js";import"./vega-loader.browser-CRZ52CKf.js";import"./defaultLocale-D_rSvXvJ.js";import"./defaultLocale-C92Rrpmf.js";import{a as ga,i as ya,n as _e,r as ja,t as ba}from"./tree-Dtn4o2IZ.js";import{n as va,t as wa}from"./alert-DD-RU0QZ.js";import{n as rt}from"./error-banner-BxlXxssi.js";import{n as Pe}from"./useAsyncData-BRNkjHs1.js";import{a as Na,o as it,t as ka,u as Ca}from"./command-DQS2IzwJ.js";import"./chunk-5FQGJX7Z-nCjg4iIq.js";import"./html-to-image-BB3CKaMw.js";import{o as Fa}from"./focus-COBUb5b6.js";import"./react-resizable-panels.browser.esm-xQHRvEag.js";import{a as Sa}from"./renderShortcut-B-72v1dC.js";import{t as _a}from"./bundle.esm-sq57iaa5.js";import{t as lt}from"./useAddCell-DgomfDJt.js";import{a as Pa,c as De,d as Me,l as ot,u as ct}from"./components-D8goxQ66.js";import{t as Da}from"./empty-state-CrP10sqm.js";import{t as ze}from"./formatting-CbFi9xG8.js";import{a as Ma,i as za,n as dt,r as ht,t as mt}from"./components-Cdl3TnkR.js";import{n as pt,t as Oa}from"./marimo-icons-Ce24dQVN.js";import{t as $a}from"./links-DhwG_EVu.js";var Ta=H("book-plus",[["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]),Ra=H("copy-minus",[["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),ft=H("file-plus-corner",[["path",{d:"M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35",key:"17jvcc"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M14 19h6",key:"bvotb8"}],["path",{d:"M17 16v6",key:"18yu1i"}]]),Aa=H("file-symlink",[["path",{d:"M4 11V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h7",key:"huwfnr"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m10 18 3-3-3-3",key:"18f6ys"}]]),xt=H("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),ut=H("list-tree",[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]]),Ea=H("pen-line",[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]),Ia=H("square-play",[["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}],["path",{d:"M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z",key:"kmsa83"}]]),gt=H("view",[["path",{d:"M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2",key:"mrq65r"}],["path",{d:"M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2",key:"be3xqs"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["path",{d:"M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0",key:"11ak4c"}]]),M=Ae(Rt(),1),Ba=te(),a=Ae(Lt(),1);const yt=t=>{let e=(0,Ba.c)(17),{filename:n,filenameIcon:i,onBack:r,onRefresh:s,onDownload:c,actions:o}=t,h;e[0]===r?h=e[1]:(h=r&&(0,a.jsx)(T,{content:"Back to file list",children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:r,children:(0,a.jsx)(Ke,{className:"h-4 w-4"})})}),e[0]=r,e[1]=h);let l;e[2]!==n||e[3]!==i?(l=n?(0,a.jsxs)("span",{className:"flex items-center gap-1.5 flex-1 min-w-0 text-xs font-semibold truncate",children:[i,n]}):(0,a.jsx)("span",{className:"flex-1"}),e[2]=n,e[3]=i,e[4]=l):l=e[4];let f;e[5]===s?f=e[6]:(f=s&&(0,a.jsx)(T,{content:"Refresh",children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:s,children:(0,a.jsx)(tt,{className:"h-3.5 w-3.5"})})}),e[5]=s,e[6]=f);let x;e[7]===c?x=e[8]:(x=c&&(0,a.jsx)(T,{content:"Download",children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:c,children:(0,a.jsx)(je,{className:"h-3.5 w-3.5"})})}),e[7]=c,e[8]=x);let j;e[9]!==o||e[10]!==f||e[11]!==x?(j=(0,a.jsxs)("div",{className:"flex items-center gap-0.5 shrink-0",children:[f,o,x]}),e[9]=o,e[10]=f,e[11]=x,e[12]=j):j=e[12];let g;return e[13]!==h||e[14]!==l||e[15]!==j?(g=(0,a.jsxs)("div",{className:"flex items-center shrink-0 border-b px-1 gap-1",children:[h,l,j]}),e[13]=h,e[14]=l,e[15]=j,e[16]=g):g=e[16],g};var Va=new Set(["http","file","in-memory"]);function Oe(t){return JSON.stringify(t).slice(1,-1)}const jt=[{id:"read-file",label:"Insert read snippet",icon:Ta,getCode:t=>{if(t.entry.kind==="directory")return null;let e=Oe(t.entry.path);return t.backendType==="obstore"?`_data = ${t.variableName}.get("${e}").bytes()
|
|
2
|
-
_data`:`_data = ${t.variableName}.cat_file("${e}")
|
|
3
|
-
_data`}},{id:"download-file",label:"Insert download snippet",icon:Aa,getCode:t=>{if(t.entry.kind==="directory")return null;let e=Oe(t.entry.path);if(t.backendType==="obstore")return Va.has(t.protocol)?null:`from datetime import timedelta
|
|
4
|
-
from obstore import sign
|
|
5
|
-
|
|
6
|
-
signed_url = sign(
|
|
7
|
-
${t.variableName}, "GET", "${e}",
|
|
8
|
-
expires_in=timedelta(hours=1),
|
|
9
|
-
)
|
|
10
|
-
signed_url`;let n=Oe(t.entry.path.split("/").pop()||"download");return`${t.variableName}.get("${e}", "${n}")`}}];var Ha=100*1024*1024;function La(t){let e=t.endsWith("/")?t.slice(0,-1):t,n=e.split("/");return n[n.length-1]||e}const Ua=({entry:t,namespace:e,protocol:n,backendType:i,onBack:r})=>{let{locale:s}=at(),c=lt(),o=La(t.path),h=t.mimeType||"text/plain",l=me(h),f=l&&t.size>Ha&&t.size>0,{data:x,isPending:j,error:g,refetch:m}=Pe(async()=>{if(f)return null;let y=await we.request({namespace:e,path:t.path,preview:!l});if(y.error)throw Error(y.error);if(!y.url)throw Error("No URL returned");if(l)return{type:"media",url:y.url};let w=await fetch(y.url);if(!w.ok)throw Error(`Failed to fetch preview: ${w.statusText}`);return{type:"text",content:await w.text()}},[e,t.path,l,f]),N=(0,M.useCallback)(async()=>{try{let y=await we.request({namespace:e,path:t.path});if(y.error){R({title:"Download failed",description:y.error,variant:"danger"});return}y.url&&be(y.url,y.filename??o)}catch(y){ye.error("Failed to download storage entry",y),R({title:"Download failed",description:String(y),variant:"danger"})}},[e,t.path,o]),v=jt.map(y=>{let w=y.getCode({variableName:e,protocol:n,entry:t,backendType:i});if(w===null)return null;let u=y.icon;return(0,a.jsx)(T,{content:y.label,children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:()=>c(w),"aria-label":y.label,children:(0,a.jsx)(u,{className:"h-3.5 w-3.5"})})},y.id)}),p=(0,a.jsx)(yt,{filename:o,filenameIcon:Je(o),onBack:r,onDownload:N,actions:v}),b=({includeMime:y=!1})=>(0,a.jsxs)("div",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 p-4 text-xs",children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Path"}),(0,a.jsxs)("div",{className:"truncate flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"font-mono text-[11px]",children:t.path}),(0,a.jsx)(fa,{value:t.path,className:"h-3 w-3"})]}),y&&(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Type"}),y&&(0,a.jsx)("span",{children:h}),t.size>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Size"}),(0,a.jsx)("span",{children:ze(t.size,s)})]}),t.lastModified!=null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-muted-foreground font-medium",children:"Modified"}),(0,a.jsx)("span",{children:new Date(t.lastModified*1e3).toLocaleString()})]})]});return f?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"px-4 pb-4 text-xs text-muted-foreground italic",children:["File is too large to preview (",ze(t.size,s),")."]})]}):j?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({}),(0,a.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground min-h-24",children:[(0,a.jsx)(Fe,{className:"h-4 w-4 animate-spin"}),"Loading preview..."]})]}):g?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"px-4 pb-4 text-xs text-destructive",children:["Failed to load preview: ",g.message]}),(0,a.jsx)("div",{className:"px-4 pb-4",children:(0,a.jsxs)(O,{variant:"secondary",size:"xs",onClick:m,children:[(0,a.jsx)(tt,{className:"h-3 w-3 mr-1"}),"Retry"]})})]}):x?(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({}),(0,a.jsx)(qe,{mimeType:h,contents:x.type==="text"?x.content:void 0,mediaSource:x.type==="media"?{url:x.url}:void 0})]}):(0,a.jsxs)("div",{className:"flex flex-col h-full",children:[p,b({includeMime:!0}),(0,a.jsxs)("div",{className:"p-4 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(Ze,{className:"h-4 w-4"}),"Preview not available for this file type."]})]})};var $e=te(),qa=16;function L(t){return{paddingLeft:t*qa}}function Wa(t,e){return new Date(t*1e3).toLocaleDateString(e,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function bt(t){let e=t.endsWith("/")?t.slice(0,-1):t,n=e.split("/");return n[n.length-1]||e}function Te(t,e,n,i){let r=n.toLowerCase();if(bt(t.path).toLowerCase().includes(r))return!0;if(t.kind==="directory"){let s=i.get(We(e,t.path));if(s)return s.some(c=>Te(c,e,n,i))}return!1}function vt(t,e,n,i){return n.trim()?t.filter(r=>Te(r,e,n,i)):t}var Ka=t=>{let e=(0,$e.c)(36),{namespace:n,protocol:i,rootPath:r,backendType:s,prefix:c,depth:o,locale:h,searchValue:l,onOpenFile:f}=t,{entriesByPath:x}=fe(),{entries:j,isPending:g,error:m}=Ge(n,c);if(g){let p;e[0]===o?p=e[1]:(p=L(o),e[0]=o,e[1]=p);let b;e[2]===Symbol.for("react.memo_cache_sentinel")?(b=(0,a.jsx)(Fe,{className:"h-3 w-3 animate-spin"}),e[2]=b):b=e[2];let y;return e[3]===p?y=e[4]:(y=(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-xs text-muted-foreground",style:p,children:[b,"Loading..."]}),e[3]=p,e[4]=y),y}if(m){let p;e[5]===o?p=e[6]:(p=L(o),e[5]=o,e[6]=p);let b;return e[7]!==m.message||e[8]!==p?(b=(0,a.jsxs)("div",{className:"py-1 text-xs text-destructive",style:p,children:["Failed to load: ",m.message]}),e[7]=m.message,e[8]=p,e[9]=b):b=e[9],b}if(j.length===0){let p;e[10]===o?p=e[11]:(p=L(o),e[10]=o,e[11]=p);let b;return e[12]===p?b=e[13]:(b=(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:p,children:"Empty"}),e[12]=p,e[13]=b),b}let N;if(e[14]!==s||e[15]!==j||e[16]!==o||e[17]!==x||e[18]!==h||e[19]!==n||e[20]!==f||e[21]!==i||e[22]!==r||e[23]!==l){let p=vt(j,n,l,x),b;e[25]!==s||e[26]!==o||e[27]!==h||e[28]!==n||e[29]!==f||e[30]!==i||e[31]!==r||e[32]!==l?(b=y=>(0,a.jsx)(wt,{entry:y,namespace:n,protocol:i,rootPath:r,backendType:s,depth:o,locale:h,searchValue:l,onOpenFile:f},y.path),e[25]=s,e[26]=o,e[27]=h,e[28]=n,e[29]=f,e[30]=i,e[31]=r,e[32]=l,e[33]=b):b=e[33],N=p.map(b),e[14]=s,e[15]=j,e[16]=o,e[17]=x,e[18]=h,e[19]=n,e[20]=f,e[21]=i,e[22]=r,e[23]=l,e[24]=N}else N=e[24];let v;return e[34]===N?v=e[35]:(v=(0,a.jsx)(a.Fragment,{children:N}),e[34]=N,e[35]=v),v},wt=({entry:t,namespace:e,protocol:n,rootPath:i,backendType:r,depth:s,locale:c,searchValue:o,onOpenFile:h})=>{var w;let[l,f]=(0,M.useState)(!1),{entriesByPath:x}=fe(),j=lt(),g=t.kind==="directory",m=bt(t.path),N=!!o.trim(),v=g&&N&&m.toLowerCase().includes(o.trim().toLowerCase()),p=g&&N&&!!((w=x.get(We(e,t.path)))!=null&&w.some(u=>Te(u,e,o,x))),b=l||p,y=(0,M.useCallback)(async()=>{try{let u=await we.request({namespace:e,path:t.path});if(u.error){R({title:"Download failed",description:u.error,variant:"danger"});return}u.url&&be(u.url,u.filename??"download")}catch(u){ye.error("Failed to download storage entry",u),R({title:"Download failed",description:String(u),variant:"danger"})}},[e,t.path]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(it,{className:q("text-xs flex items-center gap-1.5 cursor-pointer rounded-none group h-6.5",g&&"font-medium"),style:L(s),value:`${e}:${t.path}`,onSelect:()=>{g?f(!b):h({entry:t,namespace:e,protocol:n,backendType:r})},children:[g?(0,a.jsx)(Me,{isExpanded:b,className:"h-3 w-3"}):(0,a.jsx)("span",{className:"w-3 shrink-0"}),g?(0,a.jsx)(na,{className:q("h-3.5 w-3.5 shrink-0",Ye.directory)}):Je(m),(0,a.jsx)("span",{className:"truncate flex-1 text-left",children:m}),(0,a.jsxs)("div",{className:"flex items-center",children:[t.size>0&&(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground pr-2 opacity-0 group-hover:opacity-100 transition-opacity tabular-nums",children:ze(t.size,c)}),t.lastModified!=null&&(0,a.jsx)(T,{content:`Last modified: ${new Date(t.lastModified*1e3).toLocaleString()}`,children:(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground pr-1 opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap",children:Wa(t.lastModified,c)})}),(0,a.jsxs)(Ue,{children:[(0,a.jsx)(He,{asChild:!0,children:(0,a.jsx)(ot,{iconClassName:"h-3 w-3",onClick:u=>u.stopPropagation()})}),(0,a.jsxs)(Le,{align:"end",onClick:u=>u.stopPropagation(),onCloseAutoFocus:u=>u.preventDefault(),children:[!g&&(0,a.jsxs)(z,{onSelect:()=>h({entry:t,namespace:e,protocol:n,backendType:r}),children:[(0,a.jsx)(gt,{className:"h-3.5 w-3.5 mr-2"}),"View"]}),(0,a.jsxs)(z,{onSelect:async()=>{await se(t.path),R({title:"Copied to clipboard"})},children:[(0,a.jsx)(Ce,{className:De}),"Copy path"]}),!g&&(0,a.jsxs)(z,{onSelect:()=>y(),children:[(0,a.jsx)(je,{className:"h-3.5 w-3.5 mr-2"}),"Download"]}),(0,a.jsx)(ae,{}),jt.map(u=>{let d=u.getCode({variableName:e,protocol:n,entry:t,backendType:r});if(d===null)return null;let k=u.icon;return(0,a.jsxs)(z,{onSelect:()=>j(d),children:[(0,a.jsx)(k,{className:De}),u.label]},u.id)})]})]})]})]}),g&&b&&(0,a.jsx)(Ka,{namespace:e,protocol:n,rootPath:i,backendType:r,prefix:t.path,depth:s+1,locale:c,searchValue:v?"":o,onOpenFile:h})]})},Ga=t=>{let e=(0,$e.c)(43),{namespace:n,locale:i,searchValue:r,onOpenFile:s}=t,[c,o]=(0,M.useState)(!0),{entriesByPath:h}=fe(),{clearNamespaceCache:l}=Zt(),f=n.name??n.displayName,{entries:x,isPending:j,error:g,refetch:m}=Ge(f),N;e[0]!==l||e[1]!==f||e[2]!==m?(N=y=>{y.stopPropagation(),l(f),m()},e[0]=l,e[1]=f,e[2]=m,e[3]=N):N=e[3];let v=N,p=j?n.storageEntries:x,b;if(e[4]!==p||e[5]!==h||e[6]!==g||e[7]!==v||e[8]!==c||e[9]!==j||e[10]!==i||e[11]!==n.backendType||e[12]!==n.displayName||e[13]!==n.name||e[14]!==n.protocol||e[15]!==n.rootPath||e[16]!==f||e[17]!==s||e[18]!==r){let y=vt(p,f,r,h),w;e[20]===c?w=e[21]:(w=()=>o(!c),e[20]=c,e[21]=w);let u;e[22]===c?u=e[23]:(u=(0,a.jsx)(Me,{isExpanded:c,className:"h-3 w-3"}),e[22]=c,e[23]=u);let d;e[24]===n.protocol?d=e[25]:(d=(0,a.jsx)(ia,{protocol:n.protocol}),e[24]=n.protocol,e[25]=d);let k;e[26]===n.displayName?k=e[27]:(k=(0,a.jsx)("span",{children:n.displayName}),e[26]=n.displayName,e[27]=k);let _;e[28]===n.name?_=e[29]:(_=n.name&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground font-normal",children:["(",(0,a.jsx)(Ma,{variableName:n.name}),")"]}),e[28]=n.name,e[29]=_);let F;e[30]===v?F=e[31]:(F=(0,a.jsx)(ct,{onClick:v,tooltip:"Refresh storage connection",className:"p-0",iconClassName:"h-3 w-3"}),e[30]=v,e[31]=F);let P=n.rootPath||"(root)",S;e[32]===P?S=e[33]:(S=(0,a.jsx)("span",{className:"text-[10px] text-muted-foreground font-normal tabular-nums ml-auto",children:P}),e[32]=P,e[33]=S);let D;e[34]!==n.name||e[35]!==S||e[36]!==w||e[37]!==u||e[38]!==d||e[39]!==k||e[40]!==_||e[41]!==F?(D=(0,a.jsxs)(it,{value:n.name,onSelect:w,className:"flex flex-row font-semibold h-7 text-xs gap-1.5 bg-(--slate-2) text-muted-foreground rounded-none",children:[u,d,k,_,F,S]}),e[34]=n.name,e[35]=S,e[36]=w,e[37]=u,e[38]=d,e[39]=k,e[40]=_,e[41]=F,e[42]=D):D=e[42],b=(0,a.jsxs)(a.Fragment,{children:[D,c&&(0,a.jsxs)(a.Fragment,{children:[j&&p.length===0&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-xs text-muted-foreground",style:L(1),children:[(0,a.jsx)(Fe,{className:"h-3 w-3 animate-spin"}),"Loading..."]}),g&&p.length===0&&(0,a.jsx)(Pa,{error:g,style:L(1),className:"py-1 text-xs h-auto overflow-auto max-h-32 items-start",showIcon:!1}),!j&&p.length===0&&!g&&(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:L(1),children:"No entries"}),r&&y.length===0&&p.length>0&&(0,a.jsx)("div",{className:"py-1 text-xs text-muted-foreground italic",style:L(1),children:"No matches"}),y.map(E=>(0,a.jsx)(wt,{entry:E,namespace:f,protocol:n.protocol,rootPath:n.rootPath,backendType:n.backendType,depth:1,locale:i,searchValue:r,onOpenFile:s},E.path))]})]}),e[4]=p,e[5]=h,e[6]=g,e[7]=v,e[8]=c,e[9]=j,e[10]=i,e[11]=n.backendType,e[12]=n.displayName,e[13]=n.name,e[14]=n.protocol,e[15]=n.rootPath,e[16]=f,e[17]=s,e[18]=r,e[19]=b}else b=e[19];return b};const Ja=()=>{let t=(0,$e.c)(31),{namespaces:e}=fe(),{locale:n}=at(),[i,r]=(0,M.useState)(""),[s,c]=(0,M.useState)(null),o=!!i.trim();if(e.length===0){let w;t[0]===Symbol.for("react.memo_cache_sentinel")?(w=(0,a.jsxs)("span",{children:["Create an obstore or fsspec connection in your notebook. See the"," ",(0,a.jsx)("a",{className:"text-link",href:"https://docs.marimo.io/guides/working_with_data/remote_storage/#quick-start",target:"_blank",rel:"noopener noreferrer",children:"docs"}),"."]}),t[0]=w):w=t[0];let u;return t[1]===Symbol.for("react.memo_cache_sentinel")?(u=(0,a.jsx)(Da,{title:"No storage connected",description:w,action:(0,a.jsx)(Xe,{defaultTab:"storage",children:(0,a.jsxs)(O,{variant:"outline",size:"sm",children:["Add remote storage",(0,a.jsx)(et,{className:"h-4 w-4 ml-2"})]})}),icon:(0,a.jsx)(Qe,{className:"h-8 w-8"})}),t[1]=u):u=t[1],u}let h;t[2]===s?h=t[3]:(h=s&&(0,a.jsx)(Ua,{entry:s.entry,namespace:s.namespace,protocol:s.protocol,backendType:s.backendType,onBack:()=>c(null)}),t[2]=s,t[3]=h);let l=s&&"hidden",f;t[4]===l?f=t[5]:(f=q("border-b bg-background rounded-none h-full pb-10 overflow-auto outline-hidden scrollbar-thin",l),t[4]=l,t[5]=f);let x;t[6]===i?x=t[7]:(x=(0,a.jsx)(Na,{placeholder:"Search entries...",className:"h-6 m-1",value:i,onValueChange:r,rootClassName:"flex-1 border-b-0"}),t[6]=i,t[7]=x);let j;t[8]===o?j=t[9]:(j=o&&(0,a.jsx)(O,{variant:"text",size:"xs",className:"float-right border-none px-2 m-0 h-full",onClick:()=>r(""),children:(0,a.jsx)(ea,{className:"h-4 w-4"})}),t[8]=o,t[9]=j);let g;t[10]===Symbol.for("react.memo_cache_sentinel")?(g=(0,a.jsx)(T,{content:"Filters loaded entries only. Expand directories to include their contents in the search.",delayDuration:200,children:(0,a.jsx)(ta,{className:"h-3.5 w-3.5 shrink-0 cursor-help text-muted-foreground hover:text-foreground mr-2"})}),t[10]=g):g=t[10];let m;t[11]===Symbol.for("react.memo_cache_sentinel")?(m=(0,a.jsx)(Xe,{defaultTab:"storage",children:(0,a.jsx)(O,{variant:"ghost",size:"sm",className:"px-2 border-0 border-l border-muted-background rounded-none focus-visible:ring-0 focus-visible:ring-offset-0",children:(0,a.jsx)(et,{className:"h-4 w-4"})})}),t[11]=m):m=t[11];let N;t[12]!==x||t[13]!==j?(N=(0,a.jsxs)("div",{className:"flex items-center w-full border-b",children:[x,j,g,m]}),t[12]=x,t[13]=j,t[14]=N):N=t[14];let v;if(t[15]!==n||t[16]!==e||t[17]!==i){let w;t[19]!==n||t[20]!==i?(w=u=>(0,a.jsx)(Ga,{namespace:u,locale:n,searchValue:i,onOpenFile:c},u.name??u.displayName),t[19]=n,t[20]=i,t[21]=w):w=t[21],v=e.map(w),t[15]=n,t[16]=e,t[17]=i,t[18]=v}else v=t[18];let p;t[22]===v?p=t[23]:(p=(0,a.jsx)(Ca,{className:"flex flex-col",children:v}),t[22]=v,t[23]=p);let b;t[24]!==f||t[25]!==N||t[26]!==p?(b=(0,a.jsxs)(ka,{className:f,shouldFilter:!1,children:[N,p]}),t[24]=f,t[25]=N,t[26]=p,t[27]=b):b=t[27];let y;return t[28]!==h||t[29]!==b?(y=(0,a.jsxs)("div",{className:"h-full flex flex-col",children:[h,b]}),t[28]=h,t[29]=b,t[30]=y):y=t[30],y};var Nt=te(),kt=(0,M.createContext)(null);function Ya(){return(0,M.useContext)(kt)??void 0}var Za=t=>{let e=(0,Nt.c)(3),{children:n}=t,i=ya(),r;return e[0]!==n||e[1]!==i?(r=(0,a.jsx)(kt.Provider,{value:i,children:n}),e[0]=n,e[1]=i,e[2]=r):r=e[2],r};const Qa=t=>{let e=(0,Nt.c)(5),{children:n}=t,[i,r]=(0,M.useState)(null),s;e[0]!==n||e[1]!==i?(s=i&&(0,a.jsx)(ga,{backend:ja,options:{rootElement:i},children:(0,a.jsx)(Za,{children:n})}),e[0]=n,e[1]=i,e[2]=s):s=e[2];let c;return e[3]===s?c=e[4]:(c=(0,a.jsx)("div",{ref:r,className:"contents",children:s}),e[3]=s,e[4]=c),c};var Re=new Map;const Xa=({file:t,onOpenNotebook:e})=>{let{sendFileDetails:n,sendUpdateFile:i}=ve(),r=ne(Ht),s=ne(Ve),c=ne(It),[o,h]=(0,M.useState)(""),{data:l,isPending:f,error:x,setData:j,refetch:g}=Pe(async()=>{let d=await n({path:t.path}),k=d.contents||"";return h(Re.get(t.path)||k),d},[t.path]),m=async()=>{o!==(l==null?void 0:l.contents)&&await i({path:t.path,contents:o}).then(d=>{d.success&&(j(k=>({...k,contents:o})),h(o))})},N=(0,M.useRef)(o);if(N.current=o,(0,M.useEffect)(()=>()=>{if(!(l!=null&&l.contents))return;let d=N.current;d===l.contents?Re.delete(t.path):Re.set(t.path,d)},[t.path,l==null?void 0:l.contents]),x)return(0,a.jsx)(rt,{error:x});if(f||!l)return null;let v=l.mimeType||"text/plain",p=v in Wt,b=c&&l.file.isMarimoFile&&(t.path===c||t.path.endsWith(`/${c}`));if(!l.contents&&!p)return(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-2 p-6",children:[(0,a.jsx)("div",{className:"font-bold text-muted-foreground",children:"Name"}),(0,a.jsx)("div",{children:l.file.name}),(0,a.jsx)("div",{className:"font-bold text-muted-foreground",children:"Type"}),(0,a.jsx)("div",{children:v})]});let y=(0,a.jsx)(yt,{filename:l.file.name,onRefresh:g,onDownload:s?void 0:()=>{if(l.isBase64&&l.contents){me(v)?be(ke(l.contents,v),l.file.name):pe(st(ke(l.contents,l.mimeType||"application/octet-stream")),l.file.name);return}pe(new Blob([l.contents||o],{type:v}),l.file.name)},actions:(0,a.jsxs)(a.Fragment,{children:[t.isMarimoFile&&!he()&&(0,a.jsx)(T,{content:"Open notebook",children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:d=>e(d),children:(0,a.jsx)(Ne,{className:"h-3.5 w-3.5"})})}),!me(v)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(T,{content:"Copy contents to clipboard",children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:async()=>{await se(o)},children:(0,a.jsx)(Ce,{className:"h-3.5 w-3.5"})})}),(0,a.jsx)(T,{content:Sa("global.save"),children:(0,a.jsx)(O,{variant:"text",size:"xs",onClick:m,disabled:o===l.contents,children:(0,a.jsx)(oa,{className:"h-3.5 w-3.5"})})})]})]})}),w=me(v),u=!w&&v!=="text/csv";return(0,a.jsxs)(a.Fragment,{children:[y,u&&b&&(0,a.jsxs)(wa,{variant:"warning",className:"rounded-none",children:[(0,a.jsx)(da,{className:"h-4 w-4"}),(0,a.jsx)(va,{children:"Editing the notebook file directly while running in marimo's editor may cause unintended changes. Please use with caution."})]}),(0,a.jsx)(qe,{mimeType:v,contents:w?void 0:u?o:l.contents??void 0,mediaSource:w?{base64:l.contents,mime:v}:void 0,readOnly:!u,onChange:h,extensions:[Jt.of([{key:r.getHotkey("global.save").key,stopPropagation:!0,run:()=>o===l.contents?!1:(m(),!0)}])]})]})};var en=class{constructor(t){V(this,"delegate",new _e([]));V(this,"rootPath","");V(this,"onChange",Bt.NOOP);V(this,"path",new Se("/"));V(this,"initialize",async t=>{if(this.onChange=t,this.delegate.data.length===0)try{let e=await this.callbacks.listFiles({path:this.rootPath});this.delegate=new _e(e.files),this.rootPath=e.root,this.path=Se.guessDeliminator(e.root)}catch(e){R({title:"Failed",description:xa(e)})}this.onChange(this.delegate.data)});V(this,"refreshAll",async t=>{let e=[this.rootPath,...t.map(i=>{var r;return(r=this.delegate.find(i))==null?void 0:r.data.path})].filter(Boolean),n=await Promise.all(e.map(i=>this.callbacks.listFiles({path:i}).catch(()=>({files:[]}))));for(let[i,r]of e.entries()){let s=n[i];r===this.rootPath?this.delegate=new _e(s.files):this.delegate.update({id:r,changes:{children:s.files}})}this.onChange(this.delegate.data)});V(this,"relativeFromRoot",t=>{let e=this.rootPath.endsWith(this.path.deliminator)?this.rootPath:`${this.rootPath}${this.path.deliminator}`;return t.startsWith(e)?t.slice(e.length):t});V(this,"handleResponse",t=>t.success?t:(R({title:"Failed",description:t.message}),null));this.callbacks=t}async expand(t){let e=this.delegate.find(t);if(!e||!e.data.isDirectory)return!1;if(e.children&&e.children.length>0)return!0;let n=await this.callbacks.listFiles({path:e.data.path});return this.delegate.update({id:t,changes:{children:n.files}}),this.onChange(this.delegate.data),!0}async rename(t,e){let n=this.delegate.find(t);if(!n)return;let i=n.data.path,r=this.path.join(this.path.dirname(i),e);await this.callbacks.renameFileOrFolder({path:i,newPath:r}).then(this.handleResponse),this.delegate.update({id:t,changes:{name:e,path:r}}),this.onChange(this.delegate.data),await this.refreshAll([r])}async move(t,e){var i;let n=e?((i=this.delegate.find(e))==null?void 0:i.data.path)??e:this.rootPath;await Promise.all(t.map(r=>{this.delegate.move({id:r,parentId:e,index:0});let s=this.delegate.find(r);if(!s)return Promise.resolve();let c=this.path.join(n,this.path.basename(s.data.path));return this.delegate.update({id:r,changes:{path:c}}),this.callbacks.renameFileOrFolder({path:s.data.path,newPath:c}).then(this.handleResponse)})),this.onChange(this.delegate.data),await this.refreshAll([n])}async createFile(t,e,n="file"){var s;let i=e?((s=this.delegate.find(e))==null?void 0:s.data.path)??e:this.rootPath,r=await this.callbacks.createFileOrFolder({path:i,type:n,name:t}).then(this.handleResponse);r!=null&&r.info&&(this.delegate.create({parentId:e,index:0,data:r.info}),this.onChange(this.delegate.data),await this.refreshAll([i]))}async createFolder(t,e){var r;let n=e?((r=this.delegate.find(e))==null?void 0:r.data.path)??e:this.rootPath,i=await this.callbacks.createFileOrFolder({path:n,type:"directory",name:t}).then(this.handleResponse);i!=null&&i.info&&(this.delegate.create({parentId:e,index:0,data:i.info}),this.onChange(this.delegate.data),await this.refreshAll([n]))}async delete(t){let e=this.delegate.find(t);e&&(await this.callbacks.deleteFileOrFolder({path:e.data.path}).then(this.handleResponse),this.delegate.drop({id:t}),this.onChange(this.delegate.data))}};const Ct=Ee(t=>{let e=t(Yt);return Vt(e,"no requestClientAtom set"),new en({listFiles:e.sendListFiles,createFileOrFolder:e.sendCreateFileOrFolder,deleteFileOrFolder:e.sendDeleteFileOrFolder,renameFileOrFolder:e.sendRenameFileOrFolder})}),tn=Ee({});async function an(){await Tt.get(Ct).refreshAll([])}var U=" ";const Ft={directory:t=>`os.listdir("${t}")`,python:t=>`with open("${t}", "r") as _f:
|
|
11
|
-
${U}...
|
|
12
|
-
`,json:t=>`with open("${t}", "r") as _f:
|
|
13
|
-
${U}_data = json.load(_f)
|
|
14
|
-
`,code:t=>`with open("${t}", "r") as _f:
|
|
15
|
-
${U}...
|
|
16
|
-
`,text:t=>`with open("${t}", "r") as _f:
|
|
17
|
-
${U}...
|
|
18
|
-
`,image:t=>`mo.image("${t}")`,audio:t=>`mo.audio("${t}")`,video:t=>`mo.video("${t}")`,pdf:t=>`with open("${t}", "rb") as _f:
|
|
19
|
-
${U}...
|
|
20
|
-
`,zip:t=>`with open("${t}", "rb") as _f:
|
|
21
|
-
${U}...
|
|
22
|
-
`,data:t=>`with open("${t}", "r") as _f:
|
|
23
|
-
${U}...
|
|
24
|
-
`,unknown:t=>`with open("${t}", "r") as _f:
|
|
25
|
-
${U}...
|
|
26
|
-
`};var nn=te(),sn=1024*1024*100;function St(t){let e=(0,nn.c)(7),n;e[0]===t?n=e[1]:(n=t===void 0?{}:t,e[0]=t,e[1]=n);let i=n,{sendCreateFileOrFolder:r}=ve(),s;e[2]===r?s=e[3]:(s=async o=>{if(o.length===0)return;let h=o.length===1;await Kt(h?"Uploading file...":"Uploading files...",async l=>{l.addTotal(o.length);for(let f of o){let x=hn(dn(f)),j="";x&&(j=Se.guessDeliminator(x).dirname(x));let g=(await ua(f)).split(",")[1];await r({path:j,type:"file",name:f.name,contents:g}),l.increment(1)}await an()},{title:h?"File uploaded":`${o.length} files uploaded`})},e[2]=r,e[3]=s);let c;return e[4]!==i||e[5]!==s?(c={multiple:!0,maxSize:sn,onError:cn,onDropRejected:rn,onDrop:s,...i},e[4]=i,e[5]=s,e[6]=c):c=e[6],pa(c)}function rn(t){R({title:"File upload failed",description:(0,a.jsx)("div",{className:"flex flex-col gap-1",children:t.map(ln)}),variant:"danger"})}function ln(t){return(0,a.jsxs)("div",{children:[t.file.name," (",t.errors.map(on).join(", "),")"]},t.file.name)}function on(t){return t.message}function cn(t){ye.error(t),R({title:"File upload failed",description:t.message,variant:"danger"})}function dn(t){if(t.webkitRelativePath)return t.webkitRelativePath;if("path"in t&&typeof t.path=="string")return t.path;if("relativePath"in t&&typeof t.relativePath=="string")return t.relativePath}function hn(t){if(t)return t.replace(/^\/+/,"")}var re=te(),mn=Be("marimo:showHiddenFiles",!0,Ie,{getOnInit:!0}),_t=M.createContext(null);const pn=t=>{let e=(0,re.c)(72),{height:n}=t,i=(0,M.useRef)(null),r=Ya(),[s]=de(Ct),c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=[],e[0]=c):c=e[0];let[o,h]=(0,M.useState)(c),[l,f]=(0,M.useState)(null),[x,j]=de(mn),{openPrompt:g}=nt(),[m,N]=de(tn),v;e[1]===s?v=e[2]:(v=()=>s.initialize(h),e[1]=s,e[2]=v);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[],e[3]=p):p=e[3];let{isPending:b,error:y}=Pe(v,p),w;e[4]!==m||e[5]!==s?(w=()=>s.refreshAll(Object.keys(m).filter(C=>m[C])),e[4]=m,e[5]=s,e[6]=w):w=e[6];let u=B(w),d;e[7]!==j||e[8]!==x?(d=()=>{j(!x)},e[7]=j,e[8]=x,e[9]=d):d=e[9];let k=B(d),_;e[10]!==g||e[11]!==s?(_=async()=>{g({title:"Folder name",onConfirm:async C=>{s.createFolder(C,null)}})},e[10]=g,e[11]=s,e[12]=_):_=e[12];let F=B(_),P;e[13]!==g||e[14]!==s?(P=async()=>{g({title:"File name",onConfirm:async C=>{s.createFile(C,null)}})},e[13]=g,e[14]=s,e[15]=P):P=e[15];let S=B(P),D;e[16]!==g||e[17]!==s?(D=async()=>{g({title:"Notebook name",onConfirm:async C=>{s.createFile(C,null,"notebook")}})},e[16]=g,e[17]=s,e[18]=D):D=e[18];let E=B(D),I;e[19]===N?I=e[20]:(I=()=>{var C;(C=i.current)==null||C.closeAll(),N({})},e[19]=N,e[20]=I);let xe=B(I),ie;e[21]!==o||e[22]!==x?(ie=Dt(o,x),e[21]=o,e[22]=x,e[23]=ie):ie=e[23];let ue=ie;if(b){let C;return e[24]===Symbol.for("react.memo_cache_sentinel")?(C=(0,a.jsx)(la,{size:"medium",centered:!0}),e[24]=C):C=e[24],C}if(y){let C;return e[25]===y?C=e[26]:(C=(0,a.jsx)(rt,{error:y}),e[25]=y,e[26]=C),C}if(l){let C;e[27]===Symbol.for("react.memo_cache_sentinel")?(C=()=>f(null),e[27]=C):C=e[27];let $;e[28]===Symbol.for("react.memo_cache_sentinel")?($=(0,a.jsx)(O,{onClick:C,"data-testid":"file-explorer-back-button",variant:"text",size:"xs",className:"mb-0",children:(0,a.jsx)(Ke,{size:16})}),e[28]=$):$=e[28];let A;e[29]===l.name?A=e[30]:(A=(0,a.jsxs)("div",{className:"flex items-center pl-1 pr-3 shrink-0 border-b justify-between",children:[$,(0,a.jsx)("span",{className:"font-bold",children:l.name})]}),e[29]=l.name,e[30]=A);let X;e[31]!==l.path||e[32]!==s?(X=zt=>Pt(zt,s.relativeFromRoot(l.path)),e[31]=l.path,e[32]=s,e[33]=X):X=e[33];let ee;e[34]!==l||e[35]!==X?(ee=(0,a.jsx)(M.Suspense,{children:(0,a.jsx)(Xa,{onOpenNotebook:X,file:l})}),e[34]=l,e[35]=X,e[36]=ee):ee=e[36];let ce;return e[37]!==A||e[38]!==ee?(ce=(0,a.jsxs)(a.Fragment,{children:[A,ee]}),e[37]=A,e[38]=ee,e[39]=ce):ce=e[39],ce}let W;e[40]!==xe||e[41]!==S||e[42]!==F||e[43]!==E||e[44]!==k||e[45]!==u||e[46]!==s?(W=(0,a.jsx)(xn,{onRefresh:u,onHidden:k,onCreateFile:S,onCreateNotebook:E,onCreateFolder:F,onCollapseAll:xe,tree:s}),e[40]=xe,e[41]=S,e[42]=F,e[43]=E,e[44]=k,e[45]=u,e[46]=s,e[47]=W):W=e[47];let ge=n-33,K,G,J;e[48]===s?(K=e[49],G=e[50],J=e[51]):(K=async C=>{let{ids:$}=C;for(let A of $)await s.delete(A)},G=async C=>{let{id:$,name:A}=C;await s.rename($,A)},J=async C=>{let{dragIds:$,parentId:A}=C;await s.move($,A)},e[48]=s,e[49]=K,e[50]=G,e[51]=J);let le;e[52]===Symbol.for("react.memo_cache_sentinel")?(le=C=>{let $=C[0];$&&($.data.isDirectory||f($.data))},e[52]=le):le=e[52];let Y;e[53]!==m||e[54]!==N||e[55]!==s?(Y=async C=>{if(await s.expand(C)){let $=m[C]??!1;N({...m,[C]:!$})}},e[53]=m,e[54]=N,e[55]=s,e[56]=Y):Y=e[56];let Z;e[57]!==r||e[58]!==m||e[59]!==ge||e[60]!==K||e[61]!==G||e[62]!==J||e[63]!==Y||e[64]!==ue?(Z=(0,a.jsx)(ba,{width:"100%",ref:i,height:ge,className:"h-full",data:ue,initialOpenState:m,openByDefault:!1,dndManager:r,renderCursor:vn,disableDrop:wn,onDelete:K,onRename:G,onMove:J,onSelect:le,onToggle:Y,padding:15,rowHeight:30,indent:fn,overscanCount:1e3,disableMultiSelection:!0,children:yn}),e[57]=r,e[58]=m,e[59]=ge,e[60]=K,e[61]=G,e[62]=J,e[63]=Y,e[64]=ue,e[65]=Z):Z=e[65];let Q;e[66]!==Z||e[67]!==s?(Q=(0,a.jsx)(_t,{value:s,children:Z}),e[66]=Z,e[67]=s,e[68]=Q):Q=e[68];let oe;return e[69]!==W||e[70]!==Q?(oe=(0,a.jsxs)(a.Fragment,{children:[W,Q]}),e[69]=W,e[70]=Q,e[71]=oe):oe=e[71],oe};var fn=15,xn=t=>{let e=(0,re.c)(37),{onRefresh:n,onHidden:i,onCreateFile:r,onCreateNotebook:s,onCreateFolder:c,onCollapseAll:o}=t,h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={noDrag:!0,noDragEventsBubbling:!0},e[0]=h):h=e[0];let{getRootProps:l,getInputProps:f}=St(h),x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=(0,a.jsx)(pt,{size:16}),e[1]=x):x=e[1];let j;e[2]===s?j=e[3]:(j=(0,a.jsx)(T,{content:"Add notebook",children:(0,a.jsx)(O,{"data-testid":"file-explorer-add-notebook-button",onClick:s,variant:"text",size:"xs",children:x})}),e[2]=s,e[3]=j);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=(0,a.jsx)(ft,{size:16}),e[4]=g):g=e[4];let m;e[5]===r?m=e[6]:(m=(0,a.jsx)(T,{content:"Add file",children:(0,a.jsx)(O,{"data-testid":"file-explorer-add-file-button",onClick:r,variant:"text",size:"xs",children:g})}),e[5]=r,e[6]=m);let N;e[7]===Symbol.for("react.memo_cache_sentinel")?(N=(0,a.jsx)(xt,{size:16}),e[7]=N):N=e[7];let v;e[8]===c?v=e[9]:(v=(0,a.jsx)(T,{content:"Add folder",children:(0,a.jsx)(O,{"data-testid":"file-explorer-add-folder-button",onClick:c,variant:"text",size:"xs",children:N})}),e[8]=c,e[9]=v);let p;e[10]===l?p=e[11]:(p=l({}),e[10]=l,e[11]=p);let b,y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=Gt({variant:"text",size:"xs"}),b=(0,a.jsx)(ha,{size:16}),e[12]=b,e[13]=y):(b=e[12],y=e[13]);let w;e[14]===p?w=e[15]:(w=(0,a.jsx)(T,{content:"Upload file",children:(0,a.jsx)("button",{"data-testid":"file-explorer-upload-button",...p,className:y,children:b})}),e[14]=p,e[15]=w);let u;e[16]===f?u=e[17]:(u=f({}),e[16]=f,e[17]=u);let d;e[18]===u?d=e[19]:(d=(0,a.jsx)("input",{...u,type:"file"}),e[18]=u,e[19]=d);let k;e[20]===n?k=e[21]:(k=(0,a.jsx)(ct,{"data-testid":"file-explorer-refresh-button",onClick:n}),e[20]=n,e[21]=k);let _;e[22]===Symbol.for("react.memo_cache_sentinel")?(_=(0,a.jsx)(aa,{size:16}),e[22]=_):_=e[22];let F;e[23]===i?F=e[24]:(F=(0,a.jsx)(T,{content:"Toggle hidden files",children:(0,a.jsx)(O,{"data-testid":"file-explorer-hidden-files-button",onClick:i,variant:"text",size:"xs",children:_})}),e[23]=i,e[24]=F);let P;e[25]===Symbol.for("react.memo_cache_sentinel")?(P=(0,a.jsx)(Ra,{size:16}),e[25]=P):P=e[25];let S;e[26]===o?S=e[27]:(S=(0,a.jsx)(T,{content:"Collapse all folders",children:(0,a.jsx)(O,{"data-testid":"file-explorer-collapse-button",onClick:o,variant:"text",size:"xs",children:P})}),e[26]=o,e[27]=S);let D;return e[28]!==w||e[29]!==d||e[30]!==k||e[31]!==F||e[32]!==S||e[33]!==j||e[34]!==m||e[35]!==v?(D=(0,a.jsxs)("div",{className:"flex items-center justify-end px-2 shrink-0 border-b",children:[j,m,v,w,d,k,F,S]}),e[28]=w,e[29]=d,e[30]=k,e[31]=F,e[32]=S,e[33]=j,e[34]=m,e[35]=v,e[36]=D):D=e[36],D},un=t=>{let e=(0,re.c)(9),{node:n,onOpenMarimoFile:i}=t,r;e[0]===n?r=e[1]:(r=o=>{n.data.isDirectory||(o.stopPropagation(),n.select())},e[0]=n,e[1]=r);let s;e[2]!==n.data.isMarimoFile||e[3]!==i?(s=n.data.isMarimoFile&&!he()&&(0,a.jsxs)("span",{className:"shrink-0 ml-2 text-sm hidden group-hover:inline hover:underline",onClick:i,children:["open ",(0,a.jsx)(Ne,{className:"inline ml-1",size:12})]}),e[2]=n.data.isMarimoFile,e[3]=i,e[4]=s):s=e[4];let c;return e[5]!==n.data.name||e[6]!==r||e[7]!==s?(c=(0,a.jsxs)("span",{className:"flex-1 overflow-hidden text-ellipsis",onClick:r,children:[n.data.name,s]}),e[5]=n.data.name,e[6]=r,e[7]=s,e[8]=c):c=e[8],c},gn=t=>{let e=(0,re.c)(10),{node:n}=t,i=(0,M.useRef)(null),r,s;e[0]===n.data.name?(r=e[1],s=e[2]):(r=()=>{var l,f;(l=i.current)==null||l.focus(),(f=i.current)==null||f.setSelectionRange(0,n.data.name.lastIndexOf("."))},s=[n.data.name],e[0]=n.data.name,e[1]=r,e[2]=s),(0,M.useEffect)(r,s);let c,o;e[3]===n?(c=e[4],o=e[5]):(c=()=>n.reset(),o=l=>{l.key==="Escape"&&n.reset(),l.key==="Enter"&&n.submit(l.currentTarget.value)},e[3]=n,e[4]=c,e[5]=o);let h;return e[6]!==n.data.name||e[7]!==c||e[8]!==o?(h=(0,a.jsx)("input",{ref:i,className:"flex-1 bg-transparent border border-border text-muted-foreground",defaultValue:n.data.name,onClick:Nn,onBlur:c,onKeyDown:o}),e[6]=n.data.name,e[7]=c,e[8]=o,e[9]=h):h=e[9],h},yn=({node:t,style:e,dragHandle:n})=>{let{openFile:i,sendCreateFileOrFolder:r,sendFileDetails:s}=ve(),c=ne(Ve),o=t.data.isDirectory?"directory":sa(t.data.name),h=ra[o],{openConfirm:l,openPrompt:f}=nt(),{createNewCell:x}=At(),j=Fa(),g=d=>{x({code:d,before:!1,cellId:j??"__end__"})},m=(0,M.use)(_t),N=async d=>{Pt(d,m?m.relativeFromRoot(t.data.path):t.data.path)},v=async d=>{d.stopPropagation(),d.preventDefault(),l({title:"Delete file",description:`Are you sure you want to delete ${t.data.name}?`,confirmAction:(0,a.jsx)(qt,{onClick:async()=>{await t.tree.delete(t.id)},"aria-label":"Confirm",children:"Delete"})})},p=B(async()=>{t.open(),f({title:"Folder name",onConfirm:async d=>{m==null||m.createFolder(d,t.id)}})}),b=B(async()=>{t.open(),f({title:"File name",onConfirm:async d=>{m==null||m.createFile(d,t.id)}})}),y=B(async()=>{t.open(),f({title:"Notebook name",onConfirm:async d=>{m==null||m.createFile(d,t.id,"notebook")}})}),w=B(async()=>{var F;if(!m||t.data.isDirectory)return;let[d,k]=ma(t.data.name),_=`${d}_copy${k}`;try{let P=await s({path:t.data.path}),S=((F=t.parent)==null?void 0:F.data.path)||"";await r({path:S,type:"file",name:_,contents:P.contents?btoa(P.contents):void 0}),await m.refreshAll([S])}catch{R({title:"Failed to duplicate file",description:"Unable to create a duplicate of the file",variant:"danger"})}}),u=()=>{let d=De;return(0,a.jsxs)(Le,{align:"end",className:"print:hidden w-[220px]",onClick:k=>k.stopPropagation(),onCloseAutoFocus:k=>k.preventDefault(),children:[!t.data.isDirectory&&(0,a.jsxs)(z,{onSelect:()=>t.select(),children:[(0,a.jsx)(gt,{className:d}),"Open file"]}),!t.data.isDirectory&&!he()&&(0,a.jsxs)(z,{onSelect:()=>{i({path:t.data.path})},children:[(0,a.jsx)(Ne,{className:d}),"Open file in external editor"]}),t.data.isDirectory&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(z,{onSelect:()=>y(),children:[(0,a.jsx)(pt,{className:d}),"Create notebook"]}),(0,a.jsxs)(z,{onSelect:()=>b(),children:[(0,a.jsx)(ft,{className:d}),"Create file"]}),(0,a.jsxs)(z,{onSelect:()=>p(),children:[(0,a.jsx)(xt,{className:d}),"Create folder"]}),(0,a.jsx)(ae,{})]}),(0,a.jsxs)(z,{onSelect:()=>t.edit(),children:[(0,a.jsx)(Ea,{className:d}),"Rename"]}),!t.data.isDirectory&&(0,a.jsxs)(z,{onSelect:w,children:[(0,a.jsx)(Ce,{className:d}),"Duplicate"]}),(0,a.jsxs)(z,{onSelect:async()=>{await se(t.data.path),R({title:"Copied to clipboard"})},children:[(0,a.jsx)(ut,{className:d}),"Copy path"]}),m&&(0,a.jsxs)(z,{onSelect:async()=>{await se(m.relativeFromRoot(t.data.path)),R({title:"Copied to clipboard"})},children:[(0,a.jsx)(ut,{className:d}),"Copy relative path"]}),(0,a.jsx)(ae,{}),(0,a.jsxs)(z,{onSelect:()=>{let{path:k}=t.data;g(Ft[o](k))},children:[(0,a.jsx)(Xt,{className:d}),"Insert snippet for reading file"]}),(0,a.jsxs)(z,{onSelect:async()=>{R({title:"Copied to clipboard",description:"Code to open the file has been copied to your clipboard. You can also drag and drop this file into the editor"});let{path:k}=t.data;await se(Ft[o](k))},children:[(0,a.jsx)(Et,{className:d}),"Copy snippet for reading file"]}),t.data.isMarimoFile&&!he()&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(ae,{}),(0,a.jsxs)(z,{onSelect:N,children:[(0,a.jsx)(Ia,{className:d}),"Open notebook"]})]}),(0,a.jsx)(ae,{}),!t.data.isDirectory&&!c&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(z,{onSelect:async()=>{let k=await s({path:t.data.path});k.isBase64&&k.contents?pe(st(ke(k.contents,k.mimeType||"application/octet-stream")),t.data.name):pe(new Blob([k.contents||""]),t.data.name)},children:[(0,a.jsx)(je,{className:d}),"Download"]}),(0,a.jsx)(ae,{})]}),(0,a.jsxs)(z,{onSelect:v,variant:"danger",children:[(0,a.jsx)(ca,{className:d}),"Delete"]})]})};return(0,a.jsxs)("div",{style:e,ref:n,className:q("flex items-center cursor-pointer ml-1 text-muted-foreground whitespace-nowrap group"),draggable:!0,onClick:d=>{d.stopPropagation(),t.data.isDirectory&&t.toggle()},children:[(0,a.jsx)(jn,{node:t}),(0,a.jsxs)("span",{className:q("flex items-center pl-1 py-1 cursor-pointer hover:bg-accent/50 hover:text-accent-foreground rounded-l flex-1 overflow-hidden group",t.willReceiveDrop&&t.data.isDirectory&&"bg-accent/80 hover:bg-accent/80 text-accent-foreground"),children:[t.data.isMarimoFile?(0,a.jsx)(Oa,{className:"w-5 h-5 shrink-0 mr-2",strokeWidth:1.5}):(0,a.jsx)(h,{className:q("w-5 h-5 shrink-0 mr-2",Ye[o]),strokeWidth:1.5}),t.isEditing?(0,a.jsx)(gn,{node:t}):(0,a.jsx)(un,{node:t,onOpenMarimoFile:N}),(0,a.jsxs)(Ue,{modal:!1,children:[(0,a.jsx)(He,{asChild:!0,tabIndex:-1,onClick:d=>d.stopPropagation(),children:(0,a.jsx)(ot,{"data-testid":"file-explorer-more-button",iconClassName:"w-5 h-5"})}),u()]})]})]})},jn=t=>{let e=(0,re.c)(3),{node:n}=t;if(!n.data.isDirectory){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=(0,a.jsx)("span",{className:"w-4 h-4 shrink-0"}),e[0]=r):r=e[0],r}let i;return e[1]===n.isOpen?i=e[2]:(i=(0,a.jsx)(Me,{isExpanded:n.isOpen,className:"w-4 h-4"}),e[1]=n.isOpen,e[2]=i),i};function Pt(t,e){t.stopPropagation(),t.preventDefault(),$a(e)}function Dt(t,e){if(e)return t;let n=[];for(let i of t){if(bn(i.name))continue;let r=i;if(i.children){let s=Dt(i.children,e);s!==i.children&&(r={...i,children:s})}n.push(r)}return n}function bn(t){return!!t.startsWith(".")}function vn(){return null}function wn(t){let{parentNode:e}=t;return!e.data.isDirectory}function Nn(t){return t.stopPropagation()}var Mt=te(),kn=Be("marimo:file-explorer-panel:state",{openSections:["files"],hasUserInteracted:!1},Ie),Cn=t=>{let e=(0,Mt.c)(20),{height:n}=t,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={noClick:!0,noKeyboard:!0},e[0]=i):i=e[0];let{getRootProps:r,getInputProps:s,isDragActive:c}=St(i),o;e[1]===r?o=e[2]:(o=r(),e[1]=r,e[2]=o);let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=q("flex flex-col overflow-hidden relative"),e[3]=h):h=e[3];let l;e[4]===n?l=e[5]:(l={height:n},e[4]=n,e[5]=l);let f;e[6]===s?f=e[7]:(f=s(),e[6]=s,e[7]=f);let x;e[8]===f?x=e[9]:(x=(0,a.jsx)("input",{...f}),e[8]=f,e[9]=x);let j;e[10]===c?j=e[11]:(j=c&&(0,a.jsx)("div",{className:"absolute inset-0 flex items-center uppercase justify-center text-xl font-bold text-primary/90 bg-accent/85 z-10 border-2 border-dashed border-primary/90 rounded-lg pointer-events-none",children:"Drop files here"}),e[10]=c,e[11]=j);let g;e[12]===n?g=e[13]:(g=(0,a.jsx)(pn,{height:n}),e[12]=n,e[13]=g);let m;return e[14]!==o||e[15]!==l||e[16]!==x||e[17]!==j||e[18]!==g?(m=(0,a.jsx)(Qa,{children:(0,a.jsxs)("div",{...o,className:h,style:l,children:[x,j,g]})}),e[14]=o,e[15]=l,e[16]=x,e[17]=j,e[18]=g,e[19]=m):m=e[19],m},Fn=33,Sn=()=>{let t=(0,Mt.c)(36),{ref:e,height:n}=_a(),i=n===void 0?500:n,[r,s]=de(kn),c=ne(Qt).length,o;e:{if(!r.hasUserInteracted&&c>0){if(r.openSections.includes("remote-storage")){o=r.openSections;break e}let I;t[0]===r.openSections?I=t[1]:(I=[...r.openSections,"remote-storage"],t[0]=r.openSections,t[1]=I),o=I;break e}o=r.openSections}let h=o,l;t[2]===s?l=t[3]:(l=I=>{s({openSections:I,hasUserInteracted:!0})},t[2]=s,t[3]=l);let f=l,x=i-Fn*2,j;t[4]===h?j=t[5]:(j=h.includes("remote-storage"),t[4]=h,t[5]=j);let g=j,m;t[6]!==h||t[7]!==g?(m=g&&h.includes("files"),t[6]=h,t[7]=g,t[8]=m):m=t[8];let N=m,v;t[9]!==x||t[10]!==N?(v=N?Math.round(x*.4):x,t[9]=x,t[10]=N,t[11]=v):v=t[11];let p=v,b=Math.max(200,N?x-p:x),y;t[12]===Symbol.for("react.memo_cache_sentinel")?(y=(0,a.jsx)(Qe,{className:"w-4 h-4"}),t[12]=y):y=t[12];let w;t[13]===c?w=t[14]:(w=c>0&&(0,a.jsx)(za,{children:c}),t[13]=c,t[14]=w);let u;t[15]===w?u=t[16]:(u=(0,a.jsxs)(ht,{children:[y," Remote storage",w]}),t[15]=w,t[16]=u);let d;t[17]===p?d=t[18]:(d={maxHeight:p},t[17]=p,t[18]=d);let k;t[19]===Symbol.for("react.memo_cache_sentinel")?(k=(0,a.jsx)(Ja,{}),t[19]=k):k=t[19];let _;t[20]===d?_=t[21]:(_=(0,a.jsx)(mt,{className:"overflow-auto",style:d,children:k}),t[20]=d,t[21]=_);let F;t[22]!==_||t[23]!==u?(F=(0,a.jsxs)(dt,{value:"remote-storage",children:[u,_]}),t[22]=_,t[23]=u,t[24]=F):F=t[24];let P;t[25]===Symbol.for("react.memo_cache_sentinel")?(P=(0,a.jsxs)(ht,{children:[(0,a.jsx)(Ze,{className:"w-4 h-4"}),"Files"]}),t[25]=P):P=t[25];let S;t[26]===b?S=t[27]:(S=(0,a.jsxs)(dt,{value:"files",children:[P,(0,a.jsx)(mt,{children:(0,a.jsx)(Cn,{height:b})})]}),t[26]=b,t[27]=S);let D;t[28]!==f||t[29]!==h||t[30]!==F||t[31]!==S?(D=(0,a.jsxs)(Ut,{type:"multiple",value:h,onValueChange:f,children:[F,S]}),t[28]=f,t[29]=h,t[30]=F,t[31]=S,t[32]=D):D=t[32];let E;return t[33]!==e||t[34]!==D?(E=(0,a.jsx)("div",{ref:e,className:"h-full overflow-auto",children:D}),t[33]=e,t[34]=D,t[35]=E):E=t[35],E};export{Sn as default};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var $t=Object.defineProperty;var He=f=>{throw TypeError(f)};var zt=(f,h,y)=>h in f?$t(f,h,{enumerable:!0,configurable:!0,writable:!0,value:y}):f[h]=y;var n=(f,h,y)=>zt(f,typeof h!="symbol"?h+"":h,y),ue=(f,h,y)=>h.has(f)||He("Cannot "+y);var o=(f,h,y)=>(ue(f,h,"read from private field"),y?y.call(f):h.get(f)),_=(f,h,y)=>h.has(f)?He("Cannot add the same private member more than once"):h instanceof WeakSet?h.add(f):h.set(f,y),C=(f,h,y,V)=>(ue(f,h,"write to private field"),V?V.call(f,y):h.set(f,y),y),A=(f,h,y)=>(ue(f,h,"access private method"),y);import{i as z,p as de,u as Vt}from"./useEvent-D91BmmQi.js";import{An as Qt,Si as Y,b as Yt,ci as Gt,di as Jt,gi as Kt,it as Oe,pi as Xt,x as Zt,xi as er,__tla as tr}from"./cells-9Zp_JbEx.js";import{t as rr}from"./get-C-qh_et5.js";import{t as sr}from"./debounce-DhnxH9Rh.js";import{t as nr}from"./_baseSet-CxV9N1bc.js";import{_ as p,y as g}from"./useEventListener-BR0C1MaI.js";import{t as ar}from"./invariant-BUdrueMv.js";import{S as ir}from"./utils-DIGrmLDO.js";import{S as or,n as lr}from"./config-Calf6e81.js";import{n as ur}from"./switch-CqJGGLBT.js";import{n as $e}from"./globals-DY_dRKpv.js";import{at as ce,ot as ze,__tla as dr}from"./JsonOutput-CaMHqTRB.js";import{t as cr}from"./createReducer-1ePoj7v6.js";import{r as pr}from"./strings-md4mFbOQ.js";import{t as pe}from"./requests-DIwGYs0l.js";import{a as Ve,l as fr,r as Qe,__tla as hr}from"./markdown-renderer-BclMAJo1.js";import{t as mr}from"./DeferredRequestRegistry-C2V-hXrK.js";import{t as gr}from"./preload-helper-BFv3hW2s.js";import{t as Ye}from"./Deferred-Bk0r4KDZ.js";import{t as Ge}from"./uuid-CCkGk34L.js";import{t as yr}from"./use-toast-PYIpV284.js";import{t as wr}from"./useRunCells-DM6jetbr.js";import{n as br,r as vr,t as _r}from"./share-CJEPnWjm.js";import{t as Cr}from"./blob-CpeNXBj-.js";import{i as Je,r as Rr,t as xr}from"./events-CWUex2qo.js";let G,Ke,Xe,fe,Ze,et,he,tt,J,rt,st,me,ge,nt,at,it,ot,ne,lt,ut,ye,dt,we,qr=Promise.all([(()=>{try{return tr}catch{}})(),(()=>{try{return dr}catch{}})(),(()=>{try{return hr}catch{}})()]).then(async()=>{var U,ee,pt,Le,M,W,E,Ne,F,Ae,P,Q,D,ae,Ue,We,te,I,L,H,R,j,N,ft,ht,mt,re;function f(t,e,r){return t==null?t:nr(t,e,r)}G=f,Ze=de(null);var{valueAtom:h,useActions:y}=cr(()=>({banners:[]}),{addBanner:(t,e)=>({...t,banners:[...t.banners,{...e,id:Ge()}]}),removeBanner:(t,e)=>({...t,banners:t.banners.filter(r=>r.id!==e)}),clearBanners:t=>({...t,banners:[]})});dt=()=>Vt(h),Ke=function(){return y()};let V,ve,_e;V=class{constructor(){n(this,"subscriptions",new Map)}addSubscription(t,e){var r;this.subscriptions.has(t)||this.subscriptions.set(t,new Set),(r=this.subscriptions.get(t))==null||r.add(e)}removeSubscription(t,e){var r;(r=this.subscriptions.get(t))==null||r.delete(e)}notify(t,e){for(let r of this.subscriptions.get(t)??[])r(e)}},we=class be{constructor(e){n(this,"subscriptions",new V);this.producer=e}static withProducerCallback(e){return new be(e)}static empty(){return new be}startProducer(){this.producer&&this.producer(e=>{this.subscriptions.notify("message",e)})}connect(){return new Promise(e=>setTimeout(e,0)).then(()=>{this.subscriptions.notify("open",new Event("open"))})}get readyState(){return WebSocket.OPEN}reconnect(e,r){this.close(),this.connect()}close(){this.subscriptions.notify("close",new Event("close"))}send(e){return this.subscriptions.notify("message",new MessageEvent("message",{data:e})),Promise.resolve()}addEventListener(e,r){this.subscriptions.addSubscription(e,r),e==="open"&&r(new Event("open")),e==="message"&&this.startProducer()}removeEventListener(e,r){this.subscriptions.removeSubscription(e,r)}},ve=1e10,_e=1e3;function K(t,e){let r=t.map(s=>`"${s}"`).join(", ");return Error(`This RPC instance cannot ${e} because the transport did not provide one or more of these methods: ${r}`)}function yt(t={}){let e={};function r(l){e=l}let s={};function a(l){var c;s.unregisterHandler&&s.unregisterHandler(),s=l,(c=s.registerHandler)==null||c.call(s,Ot)}let i;function u(l){if(typeof l=="function"){i=l;return}i=(c,w)=>{let m=l[c];if(m)return m(w);let b=l._;if(!b)throw Error(`The requested method has no handler: ${c}`);return b(c,w)}}let{maxRequestTime:d=_e}=t;t.transport&&a(t.transport),t.requestHandler&&u(t.requestHandler),t._debugHooks&&r(t._debugHooks);let v=0;function x(){return v<=ve?++v:v=0}let q=new Map,S=new Map;function O(l,...c){let w=c[0];return new Promise((m,b)=>{var $;if(!s.send)throw K(["send"],"make requests");let k=x(),B={type:"request",id:k,method:l,params:w};q.set(k,{resolve:m,reject:b}),d!==1/0&&S.set(k,setTimeout(()=>{S.delete(k),b(Error("RPC request timed out."))},d)),($=e.onSend)==null||$.call(e,B),s.send(B)})}let se=new Proxy(O,{get:(l,c,w)=>c in l?Reflect.get(l,c,w):m=>O(c,m)}),je=se;function Te(l,...c){var b;let w=c[0];if(!s.send)throw K(["send"],"send messages");let m={type:"message",id:l,payload:w};(b=e.onSend)==null||b.call(e,m),s.send(m)}let Be=new Proxy(Te,{get:(l,c,w)=>c in l?Reflect.get(l,c,w):m=>Te(c,m)}),De=Be,T=new Map,le=new Set;function Dt(l,c){var w;if(!s.registerHandler)throw K(["registerHandler"],"register message listeners");if(l==="*"){le.add(c);return}T.has(l)||T.set(l,new Set),(w=T.get(l))==null||w.add(c)}function Ht(l,c){var w,m;if(l==="*"){le.delete(c);return}(w=T.get(l))==null||w.delete(c),((m=T.get(l))==null?void 0:m.size)===0&&T.delete(l)}async function Ot(l){var c,w;if((c=e.onReceive)==null||c.call(e,l),!("type"in l))throw Error("Message does not contain a type.");if(l.type==="request"){if(!s.send||!i)throw K(["send","requestHandler"],"handle requests");let{id:m,method:b,params:k}=l,B;try{B={type:"response",id:m,success:!0,payload:await i(b,k)}}catch($){if(!($ instanceof Error))throw $;B={type:"response",id:m,success:!1,error:$.message}}(w=e.onSend)==null||w.call(e,B),s.send(B);return}if(l.type==="response"){let m=S.get(l.id);m!=null&&clearTimeout(m);let{resolve:b,reject:k}=q.get(l.id)??{};l.success?b==null||b(l.payload):k==null||k(Error(l.error));return}if(l.type==="message"){for(let b of le)b(l.id,l.payload);let m=T.get(l.id);if(!m)return;for(let b of m)b(l.payload);return}throw Error(`Unexpected RPC message type: ${l.type}`)}return{setTransport:a,setRequestHandler:u,request:se,requestProxy:je,send:Be,sendProxy:De,addMessageListener:Dt,removeMessageListener:Ht,proxy:{send:De,request:je},_setDebugHooks:r}}function wt(t){return yt(t)}var Ce="[transport-id]";function bt(t,e){let{transportId:r}=e;return r==null?t:{[Ce]:r,data:t}}function vt(t,e){let{transportId:r,filter:s}=e,a=s==null?void 0:s();if(r!=null&&a!=null)throw Error("Cannot use both `transportId` and `filter` at the same time");let i=t;if(r){if(t[Ce]!==r)return[!0];i=t.data}return a===!1?[!0]:[!1,i]}function _t(t,e={}){let{transportId:r,filter:s,remotePort:a}=e,i=t,u=a??t,d;return{send(v){u.postMessage(bt(v,{transportId:r}))},registerHandler(v){d=x=>{let q=x.data,[S,O]=vt(q,{transportId:r,filter:()=>s==null?void 0:s(x)});S||v(O)},i.addEventListener("message",d)},unregisterHandler(){d&&i.removeEventListener("message",d)}}}function Ct(t,e){return _t(t,e)}function Re(t){return wt({transport:Ct(t,{transportId:"marimo-transport"}),maxRequestTime:2e4,_debugHooks:{onSend:e=>{p.debug("[rpc] Parent -> Worker",e)},onReceive:e=>{p.debug("[rpc] Worker -> Parent",e)}}})}ye=de("Initializing..."),Xe=de(t=>{let e=t(Yt),r=Object.values(e.cellRuntime);return r.some(s=>!fr(s.output))?!0:r.every(s=>s.status==="idle")});var xe=br(),qe="marimo:file",Se=new Gt(null);const Rt={saveFile(t){Se.set(qe,t)},readFile(){return Se.get(qe)}};var xt={saveFile(t){Y.setCodeForHash((0,xe.compressToEncodedURIComponent)(t))},readFile(){let t=Y.getCodeFromHash()||Y.getCodeFromSearchParam();return t?(0,xe.decompressFromEncodedURIComponent)(t):null}};const qt={saveFile(t){},readFile(){let t=document.querySelector("marimo-code");return t?decodeURIComponent(t.textContent||"").trim():null}};var St={saveFile(t){},readFile(){if(window.location.hostname!=="marimo.app")return null;let t=new URL("files/wasm-intro.py",document.baseURI);return fetch(t.toString()).then(e=>e.ok?e.text():null).catch(()=>null)}};const Et={saveFile(t){},readFile(){return z.get(Jt)??null}};var kt={saveFile(t){},readFile(){return["import marimo","app = marimo.App()","","@app.cell","def __():"," return","",'if __name__ == "__main__":'," app.run()"].join(`
|
|
2
|
-
`)}},Ee=class{constructor(t){this.stores=t}insert(t,e){this.stores.splice(t,0,e)}saveFile(t){this.stores.forEach(e=>e.saveFile(t))}readFile(){for(let t of this.stores){let e=t.readFile();if(e)return e}return null}};let X;J=new Ee([Et,qt,xt]),X=new Ee([Rt,St,kt]),ge=class ct{constructor(){n(this,"initialized",new Ye);n(this,"sendRename",async({filename:e})=>(e===null||(Y.setFilename(e),await this.rpc.proxy.request.bridge({functionName:"rename_file",payload:e})),null));n(this,"sendSave",async e=>{if(!this.saveRpc)return p.warn("Save RPC not initialized"),null;await this.saveRpc.saveNotebook(e);let r=await this.readCode();return r.contents&&(J.saveFile(r.contents),X.saveFile(r.contents)),this.rpc.proxy.request.saveNotebook(e).catch(s=>{p.error(s)}),null});n(this,"sendCopy",async()=>{g()});n(this,"sendStdin",async e=>(await this.rpc.proxy.request.bridge({functionName:"put_input",payload:e.text}),null));n(this,"sendPdb",async()=>{g()});n(this,"sendRun",async e=>(await this.rpc.proxy.request.loadPackages(e.codes.join(`
|
|
3
|
-
`)),await this.putControlRequest({type:"execute-cells",...e}),null));n(this,"sendRunScratchpad",async e=>(await this.rpc.proxy.request.loadPackages(e.code),await this.putControlRequest({type:"execute-scratchpad",...e}),null));n(this,"sendInterrupt",async()=>(this.interruptBuffer!==void 0&&(this.interruptBuffer[0]=2),null));n(this,"sendShutdown",async()=>(window.close(),null));n(this,"sendFormat",async e=>await this.rpc.proxy.request.bridge({functionName:"format",payload:e}));n(this,"sendDeleteCell",async e=>(await this.putControlRequest({type:"delete-cell",...e}),null));n(this,"sendInstallMissingPackages",async e=>(this.putControlRequest({type:"install-packages",...e}),null));n(this,"sendCodeCompletionRequest",async e=>(z.get(Zt)||await this.rpc.proxy.request.bridge({functionName:"code_complete",payload:e}),null));n(this,"saveUserConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_user_config",payload:e}),ur.post("/kernel/save_user_config",e,{baseUrl:"/"}).catch(r=>(p.error(r),null))));n(this,"saveAppConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_app_config",payload:e}),null));n(this,"saveCellConfig",async e=>(await this.putControlRequest({type:"update-cell-config",...e}),null));n(this,"sendRestart",async()=>{let e=await this.readCode();return e.contents&&(J.saveFile(e.contents),X.saveFile(e.contents)),vr(),null});n(this,"readCode",async()=>this.saveRpc?{contents:await this.saveRpc.readNotebook()}:(p.warn("Save RPC not initialized"),{contents:""}));n(this,"readSnippets",async()=>await this.rpc.proxy.request.bridge({functionName:"read_snippets",payload:void 0}));n(this,"openFile",async({path:e})=>{let r=_r({code:null,baseUrl:window.location.origin});return window.open(r,"_blank"),null});n(this,"sendListFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"list_files",payload:e}));n(this,"sendSearchFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"search_files",payload:e}));n(this,"sendComponentValues",async e=>(await this.putControlRequest({type:"update-ui-element",...e,token:Ge()}),null));n(this,"sendInstantiate",async e=>null);n(this,"sendFunctionRequest",async e=>(await this.putControlRequest({type:"invoke-function",...e}),null));n(this,"sendCreateFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"create_file_or_directory",payload:e}));n(this,"sendDeleteFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"delete_file_or_directory",payload:e}));n(this,"sendRenameFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"move_file_or_directory",payload:e}));n(this,"sendUpdateFile",async e=>await this.rpc.proxy.request.bridge({functionName:"update_file",payload:e}));n(this,"sendFileDetails",async e=>await this.rpc.proxy.request.bridge({functionName:"file_details",payload:e}));n(this,"exportAsHTML",async e=>await this.rpc.proxy.request.bridge({functionName:"export_html",payload:e}));n(this,"exportAsMarkdown",async e=>await this.rpc.proxy.request.bridge({functionName:"export_markdown",payload:e}));n(this,"previewDatasetColumn",async e=>(await this.putControlRequest({type:"preview-dataset-column",...e}),null));n(this,"previewSQLTable",async e=>(await this.putControlRequest({type:"preview-sql-table",...e}),null));n(this,"previewSQLTableList",async e=>(await this.putControlRequest({type:"list-sql-tables",...e}),null));n(this,"previewSQLSchemaList",async e=>(await this.putControlRequest({type:"list-sql-schemas",...e}),null));n(this,"previewDataSourceConnection",async e=>(await this.putControlRequest({type:"list-data-source-connection",...e}),null));n(this,"validateSQL",async e=>(await this.putControlRequest({type:"validate-sql",...e}),null));n(this,"sendModelValue",async e=>(await this.putControlRequest({type:"model",...e}),null));n(this,"sendDocumentTransaction",()=>Promise.resolve(null));n(this,"addPackage",async e=>this.rpc.proxy.request.addPackage(e));n(this,"removePackage",async e=>this.rpc.proxy.request.removePackage(e));n(this,"getPackageList",async()=>await this.rpc.proxy.request.listPackages());n(this,"getDependencyTree",async()=>({tree:{dependencies:[],name:"",tags:[],version:null}}));n(this,"listSecretKeys",async e=>(await this.putControlRequest({type:"list-secret-keys",...e}),null));n(this,"getUsageStats",g);n(this,"openTutorial",g);n(this,"getRecentFiles",g);n(this,"getWorkspaceFiles",g);n(this,"getRunningNotebooks",g);n(this,"shutdownSession",g);n(this,"exportAsIPYNB",g);n(this,"exportAsPDF",g);n(this,"autoExportAsHTML",g);n(this,"autoExportAsMarkdown",g);n(this,"autoExportAsIPYNB",g);n(this,"updateCellOutputs",g);n(this,"writeSecret",g);n(this,"invokeAiTool",g);n(this,"clearCache",g);n(this,"getCacheInfo",g);n(this,"listStorageEntries",g);n(this,"downloadStorage",g);or()&&(this.rpc=Re(new Worker(new URL(""+new URL("worker-BPV9SmHz.js",import.meta.url).href,""+import.meta.url),{type:"module",name:$e()})),this.rpc.addMessageListener("ready",()=>{this.startSession()}),this.rpc.addMessageListener("initialized",()=>{this.saveRpc=this.getSaveWorker(),this.setInterruptBuffer(),this.initialized.resolve()}),this.rpc.addMessageListener("initializingMessage",({message:e})=>{z.set(ye,e)}),this.rpc.addMessageListener("initializedError",({error:e})=>{this.initialized.status==="resolved"&&(p.error(e),yr({title:"Error initializing",description:e,variant:"danger"})),this.initialized.reject(Error(e))}),this.rpc.addMessageListener("kernelMessage",({message:e})=>{var r;(r=this.messageConsumer)==null||r.call(this,new MessageEvent("message",{data:e}))}))}static get INSTANCE(){let e="_marimo_private_PyodideBridge";return window[e]||(window[e]=new ct),window[e]}getSaveWorker(){return Oe()==="read"?(p.debug("Skipping SaveWorker in read-mode"),{readFile:g,readNotebook:g,saveNotebook:g}):Re(new Worker(new URL(""+new URL("save-worker-CtJsIYIM.js",import.meta.url).href,""+import.meta.url),{type:"module",name:$e()})).proxy.request}async startSession(){let e=await J.readFile(),r=await X.readFile(),s=z.get(Xt)??Y.getFilename(),a=z.get(ir),i={},u=new URLSearchParams(window.location.search);for(let d of u.keys()){let v=u.getAll(d);i[d]=v.length===1?v[0]:v}await this.rpc.proxy.request.startSession({queryParameters:i,code:e||r||"",filename:s,userConfig:{...a,runtime:{...a.runtime,auto_instantiate:Oe()==="read"?!0:a.runtime.auto_instantiate}}})}setInterruptBuffer(){crossOriginIsolated?(this.interruptBuffer=new Uint8Array(new SharedArrayBuffer(1)),this.rpc.proxy.request.setInterruptBuffer(this.interruptBuffer)):p.warn("Not running in a secure context; interrupts are not available.")}attachMessageConsumer(e){this.messageConsumer=e,this.rpc.proxy.send.consumerReady({})}async putControlRequest(e){await this.rpc.proxy.request.bridge({functionName:"put_control_request",payload:e})}},rt=function(){return we.withProducerCallback(t=>{ge.INSTANCE.attachMessageConsumer(t)})},tt=function(t=ce()){let e=window.fetch;return window.fetch=async(r,s)=>{let a=r instanceof Request?r.url:r.toString();if(a.startsWith("data:"))return e(r,s);try{let i=Z(a,t);if(i){let u=await(await e(i)).arrayBuffer();return new Response(u,{headers:{"Content-Type":Mt(a)}})}return e(r,s)}catch(i){return p.error("Error parsing URL",i),e(r,s)}},()=>{window.fetch=e}};function Mt(t){return t.endsWith(".csv")?"text/csv":t.endsWith(".json")?"application/json":t.endsWith(".txt")?"text/plain":"application/octet-stream"}it=function(t,e=ce()){let r=t.http.bind(t),s=t.load.bind(t);return t.http=async a=>{let i=Z(a,e);if(i)return await window.fetch(i).then(u=>u.text());try{return await r(a)}catch(u){if(a.startsWith("data:"))return await window.fetch(a).then(d=>d.text());throw u}},t.load=async a=>{let i=Z(a,e);if(i)return await window.fetch(i).then(u=>u.text());try{return await s(a)}catch(u){if(a.startsWith("data:"))return await window.fetch(a).then(d=>d.text());throw u}},()=>{t.http=r,t.load=s}};function ke(t){return t.startsWith(".")?t.slice(1):t}function Pt(t,e=ce()){let r=Z(t,e);if(!r)return t;let s=Cr(r);return URL.createObjectURL(s)}function Z(t,e){let r=document.baseURI;r.startsWith("blob:")&&(r=r.replace("blob:",""));let s=new URL(t,r).pathname,a=Me(t),i=Me(s);return e[t]||e[ke(t)]||e[s]||e[ke(s)]||a&&e[a]||i&&e[i]}function Me(t){let e=t.indexOf("/@file/");return e===-1?null:t.slice(e)}function ie(t,e=[]){let r=[];if(t instanceof DataView)r.push(e);else if(Array.isArray(t))for(let[s,a]of t.entries())r.push(...ie(a,[...e,s]));else if(typeof t=="object"&&t)for(let[s,a]of Object.entries(t))r.push(...ie(a,[...e,s]));return r}function Ft(t){let e=ie(t);if(e.length===0)return{state:t,buffers:[],bufferPaths:[]};let r=structuredClone(t),s=[],a=[];for(let i of e){let u=rr(t,i);if(u instanceof DataView){let d=Ve(u);s.push(d),a.push(i),G(r,i,d)}}return{state:r,buffers:s,bufferPaths:a}}function Pe(t){let{state:e,bufferPaths:r,buffers:s}=t;if(!r||r.length===0)return e;s&&ar(s.length===r.length,"Buffers and buffer paths not the same length");let a=e;for(let[i,u]of r.entries()){let d=s==null?void 0:s[i];if(d==null){p.warn("[anywidget] Could not find buffer at path",u);continue}typeof d=="string"?G(a,u,Qe(d)):G(a,u,d)}return a}he=function(t){return typeof t!="string"||t.length===0?!1:!!(/^(\.?\/)?@file\/[^?#]+$/.test(t)||It(t)&&z.get(wr))};function It(t){return t.startsWith("data:text/javascript;base64,")||t.startsWith("data:application/javascript;base64,")||t.startsWith("data:text/css;base64,")}const Fe={invoke:async()=>{let t="anywidget.invoke not supported in marimo. Please file an issue at https://github.com/marimo-team/marimo/issues";throw p.warn(t),Error(t)}};function Lt(t){if(typeof AbortSignal.any=="function")return AbortSignal.any(t);let e=new AbortController;for(let r of t){if(r.aborted)return e.abort(r.reason),e.signal;r.addEventListener("abort",()=>e.abort(r.reason),{once:!0})}return e.signal}var Nt=(Le=class{constructor(){_(this,ee);_(this,U,new Map)}getModule(t,e){let r=o(this,U).get(e);if(r)return r;let s=A(this,ee,pt).call(this,t).catch(a=>{throw o(this,U).delete(e),a});return o(this,U).set(e,s),s}invalidate(t){p.debug(`[WidgetDefRegistry] Invalidating module cache for hash=${t}`),o(this,U).delete(t)}},U=new WeakMap,ee=new WeakSet,pt=async function(t){if(!he(t))throw Error(`Refusing to load anywidget module from untrusted URL: ${String(t)}`);let e=lr(t).toString();return ze()&&(e=Pt(e)),gr(()=>import(e).then(async r=>(await r.__tla,r)),[],import.meta.url)},Le),At=(Ne=class{constructor(){_(this,M);_(this,W);_(this,E)}async bind(t,e){var i,u;if(o(this,E)&&o(this,W)===t)return o(this,E);o(this,E)&&o(this,W)!==t&&(p.debug("[WidgetBinding] Hot-reload detected, aborting previous binding"),(i=o(this,M))==null||i.abort(),C(this,M,void 0),C(this,E,void 0)),C(this,W,t),C(this,M,new AbortController);let r=o(this,M).signal,s=typeof t=="function"?await t():t,a=await((u=s.initialize)==null?void 0:u.call(s,{model:e,experimental:Fe}));return a&&r.addEventListener("abort",a),C(this,E,async(d,v)=>{var q;let x=await((q=s.render)==null?void 0:q.call(s,{model:e,el:d,experimental:Fe}));x&&Lt([v,r]).addEventListener("abort",()=>{let S=v.aborted?"view unmount":"binding destroyed";p.debug(`[WidgetBinding] Render cleanup triggered (reason: ${S})`),x()})}),o(this,E)}destroy(){var t;p.debug("[WidgetBinding] Destroying binding, aborting initialize lifecycle"),(t=o(this,M))==null||t.abort(),C(this,M,void 0),C(this,W,void 0),C(this,E,void 0)}},M=new WeakMap,W=new WeakMap,E=new WeakMap,Ne),Ut=(Ae=class{constructor(){_(this,F,new Map)}getOrCreate(t){let e=o(this,F).get(t);return e||(e=new At,o(this,F).set(t,e)),e}destroy(t){let e=o(this,F).get(t);e&&(p.debug(`[BindingManager] Destroying binding for model=${t}`),e.destroy(),o(this,F).delete(t))}has(t){return o(this,F).has(t)}},F=new WeakMap,Ae);ut=new Nt,me=new Ut;var Wt=(Ue=class{constructor(t=1e4){_(this,D);_(this,P,new Map);_(this,Q);C(this,Q,t)}get(t){let e=A(this,D,ae).call(this,t);return e.deferred.status==="pending"&&setTimeout(()=>{e.deferred.status==="pending"&&(e.deferred.reject(Error(`Model not found for key: ${t}`)),o(this,P).delete(t))},o(this,Q)),e.deferred.promise}create(t,e){let r=A(this,D,ae).call(this,t);r.deferred.resolve(e(r.controller.signal))}set(t,e){A(this,D,ae).call(this,t).deferred.resolve(e)}getSync(t){let e=o(this,P).get(t);if(e&&e.deferred.status==="resolved")return e.deferred.value}delete(t){var e;p.debug(`[ModelManager] Deleting model=${t}, aborting lifecycle signal`),(e=o(this,P).get(t))==null||e.controller.abort(),o(this,P).delete(t)}},P=new WeakMap,Q=new WeakMap,D=new WeakSet,ae=function(t){let e=o(this,P).get(t);return e||(e={deferred:new Ye,controller:new AbortController},o(this,P).set(t,e)),e},Ue),Ie=Symbol("marimo");function oe(t){return t[Ie]}ne=new Wt;var jt=(We=Ie,j=class{constructor(e,r,s){_(this,N);_(this,te,"change");_(this,I);_(this,L);_(this,H);_(this,R,{});n(this,We,{updateAndEmitDiffs:e=>A(this,N,ht).call(this,e),emitCustomMessage:(e,r)=>A(this,N,mt).call(this,e,r)});n(this,"widget_manager",{async get_model(e){let r=await j._modelManager.get(e);if(!r)throw Error(`Model not found with id: ${e}. This is likely because the model was not registered.`);return r}});_(this,re,sr(()=>{let e=o(this,R)[o(this,te)];if(e)for(let r of e)try{r()}catch(s){p.error("Error emitting event",s)}},0));C(this,L,e),C(this,H,r),C(this,I,new Map),s&&s.addEventListener("abort",()=>{p.debug("[Model] Signal aborted, clearing all listeners"),C(this,R,{})})}off(e,r){var s;if(!e){C(this,R,{});return}if(!r){o(this,R)[e]=new Set;return}(s=o(this,R)[e])==null||s.delete(r)}send(e,r,s){let a=(s??[]).map(i=>i instanceof ArrayBuffer?new DataView(i):new DataView(i.buffer,i.byteOffset,i.byteLength));return o(this,H).sendCustomMessage(e,a).then(()=>r==null?void 0:r())}get(e){return o(this,L)[e]}set(e,r){C(this,L,{...o(this,L),[e]:r}),o(this,I).set(e,r),A(this,N,ft).call(this,`change:${e}`,r),o(this,re).call(this)}save_changes(){if(o(this,I).size===0)return;let e=Object.fromEntries(o(this,I).entries());o(this,I).clear(),o(this,H).sendUpdate(e)}on(e,r){o(this,R)[e]||(o(this,R)[e]=new Set),o(this,R)[e].add(r)}},te=new WeakMap,I=new WeakMap,L=new WeakMap,H=new WeakMap,R=new WeakMap,N=new WeakSet,ft=function(e,r){if(!o(this,R)[e])return;let s=o(this,R)[e];for(let a of s)try{a(r)}catch(i){p.error("Error emitting event",i)}},ht=function(e){e!=null&&Object.keys(e).forEach(r=>{let s=r;o(this,L)[s]!==e[s]&&this.set(s,e[s])})},mt=function(e,r=[]){let s=o(this,R)["msg:custom"];if(s)for(let a of s)try{a(e.content,r)}catch(i){p.error("Error emitting event",i)}},re=new WeakMap,n(j,"_modelManager",ne),j);et=async function(t,e){let r=e.model_id,s=e.message,a=("buffers"in s?s.buffers:[]).map(Qe);switch(s.method){case"open":{let{state:i,buffer_paths:u=[]}=s,d=Pe({state:i,bufferPaths:u,buffers:a}),v=t.getSync(r);if(v){oe(v).updateAndEmitDiffs(d);return}t.create(r,x=>new jt(d,ze()?{sendUpdate:async()=>{},sendCustomMessage:async()=>{}}:{async sendUpdate(q){if(x.aborted){p.debug(`[Model] sendUpdate suppressed for model=${r} (signal aborted)`);return}let{state:S,buffers:O,bufferPaths:se}=Ft(q);await pe().sendModelValue({modelId:r,message:{method:"update",state:S,bufferPaths:se},buffers:O})},async sendCustomMessage(q,S){if(x.aborted){p.debug(`[Model] sendCustomMessage suppressed for model=${r} (signal aborted)`);return}await pe().sendModelValue({modelId:r,message:{method:"custom",content:q},buffers:S.map(Ve)})}},x));return}case"custom":oe(await t.get(r)).emitCustomMessage({method:"custom",content:s.content},a);return;case"close":me.destroy(r),t.delete(r);return;case"update":{let{state:i,buffer_paths:u=[]}=s,d=Pe({state:i,bufferPaths:u,buffers:a});oe(await t.get(r)).updateAndEmitDiffs(d);return}default:pr(s)}},Qt(ne,"MODEL_MANAGER");function Tt(t){return typeof t!="object"||!t?!1:"type"in t&&t.type==="marimo-ui-value-update"}fe=class gt{static get INSTANCE(){let e="_marimo_private_UIElementRegistry";return window[e]||(window[e]=new gt),window[e]}constructor(){this.entries=new Map}has(e){return this.entries.has(e)}set(e,r){this.entries.has(e)&&p.debug("UIElementRegistry overwriting entry for objectId.",e),this.entries.set(e,{objectId:e,value:r,elements:new Set})}registerInstance(e,r){let s=this.entries.get(e);s===void 0?this.entries.set(e,{objectId:e,value:er(r,this),elements:new Set([r])}):s.elements.add(r)}removeInstance(e,r){let s=this.entries.get(e);s!=null&&s.elements.has(r)&&s.elements.delete(r)}removeElementsByCell(e){[...this.entries.keys()].filter(r=>r.startsWith(`${e}-`)).forEach(r=>{this.entries.delete(r)})}lookupValue(e){let r=this.entries.get(e);return r===void 0?void 0:r.value}broadcastMessage(e,r,s){let a=this.entries.get(e);if(a===void 0){p.warn("UIElementRegistry missing entry",e);return}if(Tt(r)){a.value=r.value,a.elements.forEach(i=>{i.dispatchEvent(Je.create({bubbles:!1,composed:!0,detail:{value:r.value,element:i}}))});return}a.elements.forEach(i=>{i.dispatchEvent(xr.create({bubbles:!1,composed:!0,detail:{objectId:e,message:r,buffers:s}}))})}broadcastValueUpdate(e,r,s){let a=this.entries.get(r);a===void 0?p.warn("UIElementRegistry missing entry",r):(a.value=s,a.elements.forEach(i=>{i!==e&&i.dispatchEvent(Je.create({bubbles:!1,composed:!0,detail:{value:s,element:i}}))}),document.dispatchEvent(Rr.create({bubbles:!0,composed:!0,detail:{objectId:r}})))}},at=fe.INSTANCE,st=new mr("function-call-result",async(t,e)=>{await pe().sendFunctionRequest({functionCallId:t,...e})}),lt="68px";var Bt="288px";nt=t=>t?/^\d+$/.test(t)?`${t}px`:t:Bt,ot=Kt({isOpen:!0},(t,e)=>{if(!e)return t;switch(e.type){case"toggle":return{...t,isOpen:e.isOpen??t.isOpen};case"setWidth":return{...t,width:e.width};default:return t}})});export{G as C,Ke as S,Xe as _,qr as __tla,fe as a,Ze as b,et as c,he as d,tt as f,J as g,rt as h,st as i,me as l,ge as m,nt as n,at as o,it as p,ot as r,ne as s,lt as t,ut as u,ye as v,dt as x,we as y};
|