@marimo-team/frontend 0.19.6-dev1 → 0.19.6-dev2
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/{JsonOutput-BJKlFcc0.js → JsonOutput-BzGZX-Y9.js} +7 -7
- package/dist/assets/{add-cell-with-ai-2okCoA2d.js → add-cell-with-ai-DlgCM5eC.js} +1 -1
- package/dist/assets/{agent-panel-DS2YyDty.js → agent-panel-DPOcAmT2.js} +1 -1
- package/dist/assets/{cell-editor-1qg6DEg8.js → cell-editor-CPmMgQdQ.js} +1 -1
- package/dist/assets/{chat-display-Ba-bYFUU.js → chat-display-ZS_L6G-P.js} +1 -1
- package/dist/assets/{chat-panel-Biq3a7V5.js → chat-panel-DIrDEkHH.js} +1 -1
- package/dist/assets/{column-preview-oXDBchsB.js → column-preview-DtTAZWR2.js} +1 -1
- package/dist/assets/{command-palette-Dk8PKzC6.js → command-palette-YX-8TRpe.js} +1 -1
- package/dist/assets/{edit-page-qFmf6UNC.js → edit-page-DHDCnRCY.js} +3 -3
- package/dist/assets/{file-explorer-panel-BmTuxLH7.js → file-explorer-panel-DDuBM_bG.js} +1 -1
- package/dist/assets/{hooks-BKBouwbG.js → hooks-By_tTBOC.js} +1 -1
- package/dist/assets/{index-DSOUf4SJ.js → index-6Jn8SL0T.js} +3 -3
- package/dist/assets/{layout-wTVz6YE7.js → layout-DpOPQcqV.js} +1 -1
- package/dist/assets/markdown-renderer-DjqhqmES.js +4 -0
- package/dist/assets/{panels-CuOtdNMV.js → panels-BMs22LDk.js} +1 -1
- package/dist/assets/{run-page-BYrxd_KZ.js → run-page-BAEmnIJt.js} +1 -1
- package/dist/assets/{scratchpad-panel-B5-yknRc.js → scratchpad-panel-BNCSq768.js} +1 -1
- package/dist/assets/{session-panel-kCLI973D.js → session-panel-Cv4ZV7F6.js} +1 -1
- package/dist/assets/{useNotebookActions-sYRj2R7H.js → useNotebookActions-BGm4rxk7.js} +1 -1
- package/dist/assets/utilities.esm-XClsFrTX.js +3 -0
- package/dist/index.html +7 -7
- package/package.json +1 -1
- package/src/components/data-table/column-summary/legacy-chart-spec.ts +3 -4
- package/src/components/editor/actions/name-cell-input.tsx +2 -4
- package/src/utils/__tests__/data-views.test.ts +0 -45
- package/src/utils/data-views.ts +3 -19
- package/src/utils/json/__tests__/base64.test.ts +145 -69
- package/src/utils/json/base64.ts +59 -38
- package/dist/assets/markdown-renderer-60lTsu_X.js +0 -4
- package/dist/assets/utilities.esm-Dx7lHb2R.js +0 -3
|
@@ -2,99 +2,175 @@
|
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
type Base64String,
|
|
5
|
-
type ByteString,
|
|
6
5
|
base64ToDataURL,
|
|
7
|
-
|
|
6
|
+
base64ToDataView,
|
|
7
|
+
base64ToUint8Array,
|
|
8
8
|
type DataURLString,
|
|
9
|
-
|
|
9
|
+
dataViewToBase64,
|
|
10
|
+
deserializeJson,
|
|
10
11
|
extractBase64FromDataURL,
|
|
11
12
|
isDataURLString,
|
|
12
13
|
type JsonString,
|
|
13
|
-
|
|
14
|
-
typedBtoa,
|
|
14
|
+
uint8ArrayToBase64,
|
|
15
15
|
} from "../base64";
|
|
16
16
|
|
|
17
|
-
describe("
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
describe("base64", () => {
|
|
18
|
+
describe("deserializeJson", () => {
|
|
19
|
+
test("deserializes JSON string to object", () => {
|
|
20
|
+
const json = '{"name":"marimo","type":"notebook"}' as JsonString<{
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
}>;
|
|
24
|
+
const result = deserializeJson(json);
|
|
25
|
+
expect(result).toEqual({ name: "marimo", type: "notebook" });
|
|
26
|
+
});
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
test("serializeJsonToBase64 should correctly encode JSON to Base64", () => {
|
|
29
|
-
const base64Encoded = serializeJsonToBase64(testData);
|
|
30
|
-
expect(base64Encoded).toBe(expectedBase64);
|
|
28
|
+
test("deserializes JSON array", () => {
|
|
29
|
+
const json = "[1,2,3]" as JsonString<number[]>;
|
|
30
|
+
const result = deserializeJson(json);
|
|
31
|
+
expect(result).toEqual([1, 2, 3]);
|
|
32
|
+
});
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
describe("base64ToDataURL", () => {
|
|
36
|
+
test("creates proper data URL with mime type", () => {
|
|
37
|
+
const base64 = "SGVsbG8=" as Base64String;
|
|
38
|
+
const result = base64ToDataURL(base64, "text/plain");
|
|
39
|
+
expect(result).toBe("data:text/plain;base64,SGVsbG8=");
|
|
40
|
+
});
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
test("handles image mime types", () => {
|
|
43
|
+
const base64 = "iVBORw0KGgo=" as Base64String;
|
|
44
|
+
const result = base64ToDataURL(base64, "image/png");
|
|
45
|
+
expect(result).toBe("data:image/png;base64,iVBORw0KGgo=");
|
|
46
|
+
});
|
|
42
47
|
});
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
describe("isDataURLString", () => {
|
|
50
|
+
test.each([
|
|
51
|
+
["data:text/plain;base64,SGVsbG8=", true],
|
|
52
|
+
["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA", true],
|
|
53
|
+
["not-a-data-url", false],
|
|
54
|
+
["base64,SGVsbG8=", false],
|
|
55
|
+
["data:text/plain,hello", false],
|
|
56
|
+
["data:text/plain;charset=utf-8,hello", false],
|
|
57
|
+
])("isDataURLString(%s) returns %s", (input, expected) => {
|
|
58
|
+
expect(isDataURLString(input)).toBe(expected);
|
|
59
|
+
});
|
|
48
60
|
});
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
describe("extractBase64FromDataURL", () => {
|
|
63
|
+
test.each([
|
|
64
|
+
["data:text/plain;base64,SGVsbG8=", "SGVsbG8="],
|
|
65
|
+
[
|
|
66
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA",
|
|
67
|
+
"iVBORw0KGgoAAAANSUhEUgA",
|
|
68
|
+
],
|
|
69
|
+
["data:application/json;base64,", ""],
|
|
70
|
+
["data:text/html;charset=utf-8;base64,PGh0bWw+", "PGh0bWw+"],
|
|
71
|
+
])("extracts base64 from %s", (dataUrl, expected) => {
|
|
72
|
+
expect(extractBase64FromDataURL(dataUrl as DataURLString)).toBe(expected);
|
|
73
|
+
});
|
|
55
74
|
});
|
|
56
75
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
76
|
+
describe("base64ToUint8Array", () => {
|
|
77
|
+
test("converts base64 to Uint8Array", () => {
|
|
78
|
+
const base64 = "QUJD" as Base64String; // "ABC"
|
|
79
|
+
const result = base64ToUint8Array(base64);
|
|
80
|
+
expect(result).toEqual(new Uint8Array([65, 66, 67]));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("handles empty base64 string", () => {
|
|
84
|
+
const base64 = "" as Base64String;
|
|
85
|
+
const result = base64ToUint8Array(base64);
|
|
86
|
+
expect(result).toEqual(new Uint8Array([]));
|
|
87
|
+
});
|
|
64
88
|
});
|
|
65
89
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
describe("base64ToDataView", () => {
|
|
91
|
+
test("converts base64 to DataView", () => {
|
|
92
|
+
const base64 = "QUJD" as Base64String; // "ABC"
|
|
93
|
+
const result = base64ToDataView(base64);
|
|
94
|
+
expect(result.byteLength).toBe(3);
|
|
95
|
+
expect(result.getUint8(0)).toBe(65);
|
|
96
|
+
expect(result.getUint8(1)).toBe(66);
|
|
97
|
+
expect(result.getUint8(2)).toBe(67);
|
|
98
|
+
});
|
|
69
99
|
});
|
|
70
100
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
describe("uint8ArrayToBase64", () => {
|
|
102
|
+
test("converts Uint8Array to base64", () => {
|
|
103
|
+
const array = new Uint8Array([65, 66, 67]);
|
|
104
|
+
const result = uint8ArrayToBase64(array);
|
|
105
|
+
expect(result).toBe("QUJD");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("handles empty Uint8Array", () => {
|
|
109
|
+
const array = new Uint8Array([]);
|
|
110
|
+
const result = uint8ArrayToBase64(array);
|
|
111
|
+
expect(result).toBe("");
|
|
112
|
+
});
|
|
81
113
|
});
|
|
82
114
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
115
|
+
describe("dataViewToBase64", () => {
|
|
116
|
+
test("should convert a DataView to a base64 string", () => {
|
|
117
|
+
const encoder = new TextEncoder();
|
|
118
|
+
const bytes = encoder.encode("Hello, World!");
|
|
119
|
+
const dataView = new DataView(bytes.buffer);
|
|
120
|
+
const base64 = dataViewToBase64(dataView);
|
|
121
|
+
|
|
122
|
+
// Decode and verify
|
|
123
|
+
const decoded = atob(base64);
|
|
124
|
+
expect(decoded).toBe("Hello, World!");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("should handle empty DataView", () => {
|
|
128
|
+
const dataView = new DataView(new ArrayBuffer(0));
|
|
129
|
+
const base64 = dataViewToBase64(dataView);
|
|
130
|
+
expect(base64).toBe("");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("should handle DataView with offset and length", () => {
|
|
134
|
+
const encoder = new TextEncoder();
|
|
135
|
+
const bytes = encoder.encode("Hello, World!");
|
|
136
|
+
// Create a DataView that only looks at "World!"
|
|
137
|
+
const dataView = new DataView(bytes.buffer, 7, 6);
|
|
138
|
+
const base64 = dataViewToBase64(dataView);
|
|
139
|
+
|
|
140
|
+
const decoded = atob(base64);
|
|
141
|
+
expect(decoded).toBe("World!");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("should handle binary data", () => {
|
|
145
|
+
const bytes = new Uint8Array([0, 1, 2, 255, 254, 253]);
|
|
146
|
+
const dataView = new DataView(bytes.buffer);
|
|
147
|
+
const base64 = dataViewToBase64(dataView);
|
|
148
|
+
|
|
149
|
+
// Verify round-trip
|
|
150
|
+
const decoded = atob(base64);
|
|
151
|
+
const decodedBytes = new Uint8Array(decoded.length);
|
|
152
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
153
|
+
decodedBytes[i] = decoded.charCodeAt(i);
|
|
154
|
+
}
|
|
155
|
+
expect([...decodedBytes]).toEqual([0, 1, 2, 255, 254, 253]);
|
|
156
|
+
});
|
|
87
157
|
});
|
|
88
158
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
159
|
+
describe("round-trip conversions", () => {
|
|
160
|
+
test("Uint8Array to base64 and back", () => {
|
|
161
|
+
const original = new Uint8Array([1, 2, 3, 255, 128, 0]);
|
|
162
|
+
const base64 = uint8ArrayToBase64(original);
|
|
163
|
+
const result = base64ToUint8Array(base64);
|
|
164
|
+
expect(result).toEqual(original);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("DataView to base64 and back", () => {
|
|
168
|
+
const buffer = new ArrayBuffer(4);
|
|
169
|
+
const original = new DataView(buffer);
|
|
170
|
+
original.setUint32(0, 0x12_34_56_78);
|
|
171
|
+
const base64 = dataViewToBase64(original);
|
|
172
|
+
const result = base64ToDataView(base64);
|
|
173
|
+
expect(result.getUint32(0)).toBe(0x12_34_56_78);
|
|
174
|
+
});
|
|
93
175
|
});
|
|
94
176
|
});
|
|
95
|
-
|
|
96
|
-
// Serialization: JSON to Base64
|
|
97
|
-
function serializeJsonToBase64<T>(jsonObject: T) {
|
|
98
|
-
const jsonString = JSON.stringify(jsonObject);
|
|
99
|
-
return btoa(encodeURIComponent(jsonString)) as Base64String<JsonString<T>>;
|
|
100
|
-
}
|
package/src/utils/json/base64.ts
CHANGED
|
@@ -3,64 +3,88 @@
|
|
|
3
3
|
import type { NotificationMessageData } from "@/core/kernel/messages";
|
|
4
4
|
import type { TypedString } from "../typed";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A JSON string of a given type.
|
|
8
|
+
*/
|
|
6
9
|
export type JsonString<T = unknown> = TypedString<"Json"> & {
|
|
7
10
|
_of_: T;
|
|
8
11
|
};
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type ByteString<T = unknown> = TypedString<"ByteString"> & {
|
|
15
|
-
_of_: T;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type DataURLString = `data:${string};base64,${Base64String<string>}`;
|
|
13
|
+
/**
|
|
14
|
+
* A base64-encoded string.
|
|
15
|
+
*/
|
|
16
|
+
export type Base64String = TypedString<"Base64">;
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* A data URL string.
|
|
20
|
+
*/
|
|
21
|
+
export type DataURLString = `data:${string};base64,${Base64String}`;
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Typed JSON deserialization.
|
|
25
|
+
*/
|
|
27
26
|
export function deserializeJson<T>(jsonString: JsonString<T>): T {
|
|
28
27
|
return JSON.parse(jsonString) as T;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Convert a base64 string to a data URL string.
|
|
32
|
+
*/
|
|
33
|
+
export function base64ToDataURL(
|
|
34
|
+
base64: Base64String,
|
|
33
35
|
mimeType: string,
|
|
34
36
|
): DataURLString {
|
|
35
|
-
return `data:${mimeType};base64,${base64}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function typedAtob<T>(base64: Base64String<T>): ByteString<T> {
|
|
39
|
-
return window.atob(base64) as ByteString<T>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function typedBtoa<T>(bytes: ByteString<T>): Base64String<T> {
|
|
43
|
-
return window.btoa(bytes) as Base64String<T>;
|
|
37
|
+
return `data:${mimeType};base64,${base64}`;
|
|
44
38
|
}
|
|
45
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Check if a string is a data URL string.
|
|
42
|
+
*/
|
|
46
43
|
export function isDataURLString(str: string): str is DataURLString {
|
|
47
44
|
return str.startsWith("data:") && str.includes(";base64,");
|
|
48
45
|
}
|
|
49
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Extract the base64 string from a data URL string.
|
|
49
|
+
*/
|
|
50
50
|
export function extractBase64FromDataURL(str: DataURLString): Base64String {
|
|
51
51
|
return str.split(",")[1] as Base64String;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Convert a base64 string to a Uint8Array.
|
|
56
|
+
*/
|
|
57
|
+
export function base64ToUint8Array(bytes: Base64String): Uint8Array {
|
|
58
|
+
const binary = window.atob(bytes);
|
|
59
|
+
return Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Convert a base64 string to a DataView.
|
|
64
|
+
*/
|
|
65
|
+
export function base64ToDataView(bytes: Base64String): DataView {
|
|
66
|
+
const uint8Array = base64ToUint8Array(bytes);
|
|
67
|
+
return new DataView(uint8Array.buffer);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Convert a Uint8Array to a base64 string.
|
|
72
|
+
*/
|
|
73
|
+
export function uint8ArrayToBase64(binary: Uint8Array): Base64String {
|
|
74
|
+
const chars = Array.from(binary, (byte) => String.fromCharCode(byte));
|
|
75
|
+
return window.btoa(chars.join("")) as Base64String;
|
|
56
76
|
}
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Convert a DataView to a base64 string.
|
|
80
|
+
*/
|
|
81
|
+
export function dataViewToBase64(dataView: DataView): Base64String {
|
|
82
|
+
const uint8Array = new Uint8Array(
|
|
83
|
+
dataView.buffer,
|
|
84
|
+
dataView.byteOffset,
|
|
85
|
+
dataView.byteLength,
|
|
86
|
+
);
|
|
87
|
+
return uint8ArrayToBase64(uint8Array);
|
|
64
88
|
}
|
|
65
89
|
|
|
66
90
|
export function safeExtractSetUIElementMessageBuffers(
|
|
@@ -68,8 +92,5 @@ export function safeExtractSetUIElementMessageBuffers(
|
|
|
68
92
|
): readonly DataView[] {
|
|
69
93
|
// @ts-expect-error - TypeScript doesn't know that these strings are actually base64 strings
|
|
70
94
|
const strs: Base64String[] = notification.buffers ?? [];
|
|
71
|
-
return strs.map(
|
|
72
|
-
const bytes = byteStringToBinary(typedAtob(str));
|
|
73
|
-
return new DataView(bytes.buffer);
|
|
74
|
-
});
|
|
95
|
+
return strs.map(base64ToDataView);
|
|
75
96
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{s as y}from"./chunk-LvLJmgfZ.js";import{u as _}from"./useEvent-DlWF5OMa.js";import{t as S}from"./react-BGmjiNul.js";import{jt as $,w as A,wt as I}from"./cells-CmJW_FeD.js";import{t as j}from"./compiler-runtime-DeeZ7FnK.js";import{o as q}from"./utils-Czt8B2GX.js";import{t as z}from"./jsx-runtime-DN_bIXfG.js";import{t as v}from"./button-B8cGZzP5.js";import{at as M}from"./dist-CAcX026F.js";import{t as D}from"./createLucideIcon-CW2xpJ57.js";import{n as R,t as T}from"./LazyAnyLanguageCodeMirror-Dr2G5gxJ.js";import{r as V}from"./useTheme-BSVRc0kJ.js";import{t as W}from"./copy-DRhpWiOq.js";import{i as B}from"./chunk-OGVTOU66-DQphfHw1.js";import{r as E}from"./es-BJsT6vfZ.js";import{o as F}from"./focus-KGgBDCvb.js";var H=D("chevrons-up-down",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]),L=j(),g=y(S(),1),k={};function O(t){let e=(0,L.c)(5),[r,a]=(0,g.useState)(k[t]??!1),s;e[0]===t?s=e[1]:(s=o=>{a(o),k[t]=o},e[0]=t,e[1]=s);let n;return e[2]!==r||e[3]!==s?(n=[r,s],e[2]=r,e[3]=s,e[4]=n):n=e[4],n}function P(t){return t==null||t.data==null||t.data===""}function Q(t,e){return`data:${e};base64,${t}`}function C(t){return window.atob(t)}function U(t){return window.btoa(t)}function G(t){return t.startsWith("data:")&&t.includes(";base64,")}function J(t){return t.split(",")[1]}function b(t){return Uint8Array.from(t,e=>e.charCodeAt(0))}function K(t){let e="";for(let r of t)e+=String.fromCharCode(r);return e}function X(t){return(t.buffers??[]).map(e=>{let r=b(C(e));return new DataView(r.buffer)})}var w=j(),l=y(z(),1),Y=[M.lineWrapping],Z=new Set(["python","markdown","sql","json","yaml","toml","shell","javascript","typescript","jsx","tsx","css","html"]);function ee(t,e){return t?t==="python"?{language:t,code:e}:t==="sql"?{language:"python",code:I.fromQuery(e)}:t==="markdown"?{language:"python",code:$.fromMarkdown(e)}:t==="shell"||t==="bash"?{language:"python",code:`import subprocess
|
|
2
|
-
subprocess.run("${e}")`}:{language:"python",code:`_${t} = """
|
|
3
|
-
${e}
|
|
4
|
-
"""`}:{language:"python",code:e}}var te=t=>{let e=(0,w.c)(9),{code:r,language:a}=t,{createNewCell:s}=A(),n=F(),o=_(q),i;e[0]!==o||e[1]!==r||e[2]!==s||e[3]!==a||e[4]!==n?(i=()=>{let u=ee(a,r);a==="sql"&&E({autoInstantiate:o,createNewCell:s,fromCellId:n}),s({code:u.code,before:!1,cellId:n??"__end__"})},e[0]=o,e[1]=r,e[2]=s,e[3]=a,e[4]=n,e[5]=i):i=e[5];let c=i,m;e[6]===Symbol.for("react.memo_cache_sentinel")?(m=(0,l.jsx)(R,{className:"ml-2 h-4 w-4"}),e[6]=m):m=e[6];let d;return e[7]===c?d=e[8]:(d=(0,l.jsxs)(v,{size:"xs",variant:"outline",onClick:c,children:["Add to Notebook",m]}),e[7]=c,e[8]=d),d},re=t=>{let e=(0,w.c)(17),{code:r,language:a}=t,{theme:s}=V(),[n,o]=(0,g.useState)(r);n!==r&&o(r);let i;e[0]===n?i=e[1]:(i=async()=>{await W(n)},e[0]=n,e[1]=i);let c=i,m=s==="dark"?"dark":"light",d=a&&Z.has(a)?a:void 0,u;e[2]!==m||e[3]!==d||e[4]!==n?(u=(0,l.jsx)(g.Suspense,{children:(0,l.jsx)(T,{theme:m,language:d,className:"cm border rounded overflow-hidden",extensions:Y,value:n,onChange:o})}),e[2]=m,e[3]=d,e[4]=n,e[5]=u):u=e[5];let f;e[6]===c?f=e[7]:(f=(0,l.jsx)(ae,{size:"xs",variant:"outline",onClick:c,children:"Copy"}),e[6]=c,e[7]=f);let p;e[8]!==a||e[9]!==n?(p=(0,l.jsx)(te,{code:n,language:a}),e[8]=a,e[9]=n,e[10]=p):p=e[10];let h;e[11]!==f||e[12]!==p?(h=(0,l.jsxs)("div",{className:"flex justify-end mt-2 space-x-2",children:[f,p]}),e[11]=f,e[12]=p,e[13]=h):h=e[13];let x;return e[14]!==u||e[15]!==h?(x=(0,l.jsxs)("div",{className:"relative",children:[u,h]}),e[14]=u,e[15]=h,e[16]=x):x=e[16],x},ae=t=>{let e=(0,w.c)(9),r,a;e[0]===t?(r=e[1],a=e[2]):({onClick:r,...a}=t,e[0]=t,e[1]=r,e[2]=a);let[s,n]=(0,g.useState)(!1),o;e[3]===r?o=e[4]:(o=m=>{r==null||r(m),n(!0),setTimeout(()=>n(!1),1e3)},e[3]=r,e[4]=o);let i=s?"Copied":"Copy",c;return e[5]!==a||e[6]!==o||e[7]!==i?(c=(0,l.jsx)(v,{...a,onClick:o,children:i}),e[5]=a,e[6]=o,e[7]=i,e[8]=c):c=e[8],c},ne={code:({children:t,className:e})=>{let r=e==null?void 0:e.replace("language-","");if(r&&typeof t=="string"){let a=t.trim();return(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-xs text-muted-foreground pl-1",children:r}),(0,l.jsx)(re,{code:a,language:r})]})}return(0,l.jsx)("code",{className:e,children:t})}};const N=(0,g.memo)(t=>{let e=(0,w.c)(2),{content:r}=t,a;return e[0]===r?a=e[1]:(a=(0,l.jsx)(B,{components:ne,className:"mo-markdown-renderer",children:r}),e[0]=r,e[1]=a),a});N.displayName="MarkdownRenderer";export{J as a,C as c,O as d,H as f,b as i,U as l,Q as n,G as o,K as r,X as s,N as t,P as u};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var it=Object.defineProperty;var ot=(t,e,n)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>ot(t,typeof e!="symbol"?e+"":e,n);var M;import{s as ce}from"./chunk-LvLJmgfZ.js";import{i as Q,l as D,o as lt,p as q,u as ut}from"./useEvent-DlWF5OMa.js";import{t as ct}from"./react-BGmjiNul.js";import{Wr as dt,Xr as ft,b as mt,ni as z,ti as pt,y as ht}from"./cells-CmJW_FeD.js";import{B as gt,C as de,D as yt,I as bt,N as wt,P as O,R as fe,k as W,w as me}from"./zod-Cg4WLWh2.js";import{t as pe}from"./compiler-runtime-DeeZ7FnK.js";import{t as vt}from"./get-CyLJYAfP.js";import{r as xt}from"./useLifecycle-CmDXEyIC.js";import{t as Et}from"./debounce-BbFlGgjv.js";import{t as _t}from"./_baseSet-6FYvpjrm.js";import{d as E,p as y}from"./hotkeys-uKX61F1_.js";import{t as Ct}from"./invariant-C6yE60hi.js";import{S as kt}from"./utils-Czt8B2GX.js";import{j as Ft}from"./config-CENq_7Pd.js";import{a as Rt}from"./switch-C5jvDmuG.js";import{n as he}from"./globals-DPW2B3A9.js";import{t as ge}from"./ErrorBoundary-C7JBxSzd.js";import{t as Nt}from"./jsx-runtime-DN_bIXfG.js";import{t as St}from"./button-B8cGZzP5.js";import{t as qt}from"./cn-C1rgT0yh.js";import{Z as Pt}from"./JsonOutput-BJKlFcc0.js";import{t as jt}from"./createReducer-DDa-hVe3.js";import{t as ye}from"./requests-C0HaHO6a.js";import{t as be}from"./createLucideIcon-CW2xpJ57.js";import{h as Mt}from"./select-D9lTzMzP.js";import{c as At,i as Tt,l as It,r as Lt,u as Ut}from"./markdown-renderer-60lTsu_X.js";import{t as zt}from"./DeferredRequestRegistry-B3BENoUa.js";import{t as K}from"./Deferred-DzyBMRsy.js";import{t as we}from"./uuid-ClFZlR7U.js";import{t as Ot}from"./use-toast-Bzf3rpev.js";import{t as ve}from"./tooltip-CvjcEpZC.js";import{t as xe}from"./mode-CXc0VeQq.js";import{n as Wt,r as Dt,t as Ht}from"./share-CXQVxivL.js";import{r as Bt,t as Vt}from"./react-resizable-panels.browser.esm-B7ZqbY8M.js";import{t as Ee}from"./toggle-D-5M3JI_.js";function Xt(t,e,n){return t==null?t:_t(t,e,n)}var H=Xt,$t=be("crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]),Yt=be("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);function Gt(t){return{all:t||(t=new Map),on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(s){s(n)}),(r=t.get("*"))&&r.slice().map(function(s){s(e,n)})}}}var u=ce(ct(),1),Z=(0,u.createContext)(null),Qt=t=>{let{controller:e}=(0,u.useContext)(Z),n=u.useRef(Symbol("fill"));return(0,u.useEffect)(()=>(e.mount({name:t.name,ref:n.current,children:t.children}),()=>{e.unmount({name:t.name,ref:n.current})}),[]),(0,u.useEffect)(()=>{e.update({name:t.name,ref:n.current,children:t.children})}),null},Kt=Object.defineProperty,Zt=(t,e,n)=>e in t?Kt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,_e=(t,e,n)=>(Zt(t,typeof e=="symbol"?e:e+"",n),n),Ce=console,Jt=class{constructor(t){_e(this,"_bus"),_e(this,"_db"),this._bus=t,this.handleFillMount=this.handleFillMount.bind(this),this.handleFillUpdated=this.handleFillUpdated.bind(this),this.handleFillUnmount=this.handleFillUnmount.bind(this),this._db={byName:new Map,byFill:new Map}}mount(){this._bus.on("fill-mount",this.handleFillMount),this._bus.on("fill-updated",this.handleFillUpdated),this._bus.on("fill-unmount",this.handleFillUnmount)}unmount(){this._bus.off("fill-mount",this.handleFillMount),this._bus.off("fill-updated",this.handleFillUpdated),this._bus.off("fill-unmount",this.handleFillUnmount)}handleFillMount({fill:t}){let e=u.Children.toArray(t.children),n=t.name,r={fill:t,children:e,name:n},s=this._db.byName.get(n);s?(s.components.push(r),s.listeners.forEach(i=>i([...s.components]))):this._db.byName.set(n,{listeners:[],components:[r]}),this._db.byFill.set(t.ref,r)}handleFillUpdated({fill:t}){let e=this._db.byFill.get(t.ref),n=u.Children.toArray(t.children);if(e){e.children=n;let r=this._db.byName.get(e.name);if(r)r.listeners.forEach(s=>s([...r.components]));else throw Error("registration was expected to be defined")}else{Ce.error("[handleFillUpdated] component was expected to be defined");return}}handleFillUnmount({fill:t}){let e=this._db.byFill.get(t.ref);if(!e){Ce.error("[handleFillUnmount] component was expected to be defined");return}let n=e.name,r=this._db.byName.get(n);if(!r)throw Error("registration was expected to be defined");r.components=r.components.filter(s=>s!==e),this._db.byFill.delete(t.ref),r.listeners.length===0&&r.components.length===0?this._db.byName.delete(n):r.listeners.forEach(s=>s([...r.components]))}onComponentsChange(t,e){let n=this._db.byName.get(t);n?(n.listeners.push(e),e(n.components)):(this._db.byName.set(t,{listeners:[e],components:[]}),e([]))}getFillsByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.fill):[]}getChildrenByName(t){let e=this._db.byName.get(t);return e?e.components.map(n=>n.children).reduce((n,r)=>n.concat(r),[]):[]}removeOnComponentsChange(t,e){let n=this._db.byName.get(t);if(!n)throw Error("expected registration to be defined");let r=n.listeners;r.splice(r.indexOf(e),1)}},en=Object.defineProperty,tn=(t,e,n)=>e in t?en(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nn=(t,e,n)=>(tn(t,typeof e=="symbol"?e:e+"",n),n),ke=class{constructor(){nn(this,"bus",Gt())}mount(t){this.bus.emit("fill-mount",{fill:t})}unmount(t){this.bus.emit("fill-unmount",{fill:t})}update(t){this.bus.emit("fill-updated",{fill:t})}};function rn(t){let e=t||new ke;return{controller:e,manager:new Jt(e.bus)}}var sn=({controller:t,children:e})=>{let[n]=u.useState(()=>{let r=rn(t);return r.manager.mount(),r});return u.useEffect(()=>()=>{n.manager.unmount()},[]),u.createElement(Z.Provider,{value:n},e)};function J(t,e){let[n,r]=(0,u.useState)([]),{manager:s}=(0,u.useContext)(Z);return(0,u.useEffect)(()=>(s.onComponentsChange(t,r),()=>{s.removeOnComponentsChange(t,r)}),[t]),n.flatMap((i,d)=>{let{children:l}=i;return l.map((p,b)=>{if(typeof p=="number"||typeof p=="string")throw Error("Only element children will work here");return u.cloneElement(p,{key:d.toString()+b.toString(),...e})})})}var Fe=t=>{let e=J(t.name,t.childProps);if(typeof t.children=="function"){let n=t.children(e);if(u.isValidElement(n)||n===null)return n;throw Error("Slot rendered with function must return a valid React Element.")}return e};const an=q(null);var{valueAtom:on,useActions:ln}=jt(()=>({banners:[]}),{addBanner:(t,e)=>({...t,banners:[...t.banners,{...e,id:we()}]}),removeBanner:(t,e)=>({...t,banners:t.banners.filter(n=>n.id!==e)}),clearBanners:t=>({...t,banners:[]})});const un=()=>ut(on);function cn(){return ln()}const dn=new ke,B={SIDEBAR:"sidebar",CONTEXT_AWARE_PANEL:"context-aware-panel"};var fn=class{constructor(){a(this,"subscriptions",new Map)}addSubscription(t,e){var n;this.subscriptions.has(t)||this.subscriptions.set(t,new Set),(n=this.subscriptions.get(t))==null||n.add(e)}removeSubscription(t,e){var n;(n=this.subscriptions.get(t))==null||n.delete(e)}notify(t,e){for(let n of this.subscriptions.get(t)??[])n(e)}},Re=class ue{constructor(e){a(this,"subscriptions",new fn);this.producer=e}static withProducerCallback(e){return new ue(e)}static empty(){return new ue}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,n){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,n){this.subscriptions.addSubscription(e,n),e==="open"&&n(new Event("open")),e==="message"&&this.startProducer()}removeEventListener(e,n){this.subscriptions.removeSubscription(e,n)}},mn=1e10,pn=1e3;function V(t,e){let n=t.map(r=>`"${r}"`).join(", ");return Error(`This RPC instance cannot ${e} because the transport did not provide one or more of these methods: ${n}`)}function hn(t={}){let e={};function n(o){e=o}let r={};function s(o){var f;r.unregisterHandler&&r.unregisterHandler(),r=o,(f=r.registerHandler)==null||f.call(r,U)}let i;function d(o){if(typeof o=="function"){i=o;return}i=(f,g)=>{let c=o[f];if(c)return c(g);let h=o._;if(!h)throw Error(`The requested method has no handler: ${f}`);return h(f,g)}}let{maxRequestTime:l=pn}=t;t.transport&&s(t.transport),t.requestHandler&&d(t.requestHandler),t._debugHooks&&n(t._debugHooks);let p=0;function b(){return p<=mn?++p:p=0}let x=new Map,w=new Map;function _(o,...f){let g=f[0];return new Promise((c,h)=>{var T;if(!r.send)throw V(["send"],"make requests");let S=b(),j={type:"request",id:S,method:o,params:g};x.set(S,{resolve:c,reject:h}),l!==1/0&&w.set(S,setTimeout(()=>{w.delete(S),h(Error("RPC request timed out."))},l)),(T=e.onSend)==null||T.call(e,j),r.send(j)})}let R=new Proxy(_,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>_(f,c)}),C=R;function k(o,...f){var h;let g=f[0];if(!r.send)throw V(["send"],"send messages");let c={type:"message",id:o,payload:g};(h=e.onSend)==null||h.call(e,c),r.send(c)}let F=new Proxy(k,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>k(f,c)}),v=F,N=new Map,P=new Set;function A(o,f){var g;if(!r.registerHandler)throw V(["registerHandler"],"register message listeners");if(o==="*"){P.add(f);return}N.has(o)||N.set(o,new Set),(g=N.get(o))==null||g.add(f)}function L(o,f){var g,c;if(o==="*"){P.delete(f);return}(g=N.get(o))==null||g.delete(f),((c=N.get(o))==null?void 0:c.size)===0&&N.delete(o)}async function U(o){var f,g;if((f=e.onReceive)==null||f.call(e,o),!("type"in o))throw Error("Message does not contain a type.");if(o.type==="request"){if(!r.send||!i)throw V(["send","requestHandler"],"handle requests");let{id:c,method:h,params:S}=o,j;try{j={type:"response",id:c,success:!0,payload:await i(h,S)}}catch(T){if(!(T instanceof Error))throw T;j={type:"response",id:c,success:!1,error:T.message}}(g=e.onSend)==null||g.call(e,j),r.send(j);return}if(o.type==="response"){let c=w.get(o.id);c!=null&&clearTimeout(c);let{resolve:h,reject:S}=x.get(o.id)??{};o.success?h==null||h(o.payload):S==null||S(Error(o.error));return}if(o.type==="message"){for(let h of P)h(o.id,o.payload);let c=N.get(o.id);if(!c)return;for(let h of c)h(o.payload);return}throw Error(`Unexpected RPC message type: ${o.type}`)}return{setTransport:s,setRequestHandler:d,request:R,requestProxy:C,send:F,sendProxy:v,addMessageListener:A,removeMessageListener:L,proxy:{send:v,request:C},_setDebugHooks:n}}function gn(t){return hn(t)}var Ne="[transport-id]";function yn(t,e){let{transportId:n}=e;return n==null?t:{[Ne]:n,data:t}}function bn(t,e){let{transportId:n,filter:r}=e,s=r==null?void 0:r();if(n!=null&&s!=null)throw Error("Cannot use both `transportId` and `filter` at the same time");let i=t;if(n){if(t[Ne]!==n)return[!0];i=t.data}return s===!1?[!0]:[!1,i]}function wn(t,e={}){let{transportId:n,filter:r,remotePort:s}=e,i=t,d=s??t,l;return{send(p){d.postMessage(yn(p,{transportId:n}))},registerHandler(p){l=b=>{let x=b.data,[w,_]=bn(x,{transportId:n,filter:()=>r==null?void 0:r(b)});w||p(_)},i.addEventListener("message",l)},unregisterHandler(){l&&i.removeEventListener("message",l)}}}function vn(t,e){return wn(t,e)}function Se(t){return gn({transport:vn(t,{transportId:"marimo-transport"}),maxRequestTime:2e4,_debugHooks:{onSend:e=>{E.debug("[rpc] Parent -> Worker",e)},onReceive:e=>{E.debug("[rpc] Worker -> Parent",e)}}})}const qe=q("Initializing..."),xn=q(t=>{let e=t(ht),n=Object.values(e.cellRuntime);return n.some(r=>!Ut(r.output))?!0:n.every(r=>r.status==="idle")});var Pe=Wt(),je="marimo:file",Me=new dt(null);const En={saveFile(t){Me.set(je,t)},readFile(){return Me.get(je)}};var _n={saveFile(t){z.setCodeForHash((0,Pe.compressToEncodedURIComponent)(t))},readFile(){let t=z.getCodeFromHash()||z.getCodeFromSearchParam();return t?(0,Pe.decompressFromEncodedURIComponent)(t):null}};const Cn={saveFile(t){},readFile(){let t=document.querySelector("marimo-code");return t?decodeURIComponent(t.textContent||"").trim():null}};var kn={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)}},Fn={saveFile(t){},readFile(){return["import marimo","app = marimo.App()","","@app.cell","def __():"," return","",'if __name__ == "__main__":'," app.run()"].join(`
|
|
2
|
-
`)}},Ae=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}};const X=new Ae([Cn,_n]),ee=new Ae([En,kn,Fn]);var Te=class st{constructor(){a(this,"initialized",new K);a(this,"sendRename",async({filename:e})=>(e===null||(z.setFilename(e),await this.rpc.proxy.request.bridge({functionName:"rename_file",payload:e})),null));a(this,"sendSave",async e=>{if(!this.saveRpc)return E.warn("Save RPC not initialized"),null;await this.saveRpc.saveNotebook(e);let n=await this.readCode();return n.contents&&(X.saveFile(n.contents),ee.saveFile(n.contents)),this.rpc.proxy.request.saveNotebook(e).catch(r=>{E.error(r)}),null});a(this,"sendCopy",async()=>{y()});a(this,"sendStdin",async e=>(await this.rpc.proxy.request.bridge({functionName:"put_input",payload:e.text}),null));a(this,"sendPdb",async()=>{y()});a(this,"sendRun",async e=>(await this.rpc.proxy.request.loadPackages(e.codes.join(`
|
|
3
|
-
`)),await this.putControlRequest({type:"execute-cells",...e}),null));a(this,"sendRunScratchpad",async e=>(await this.rpc.proxy.request.loadPackages(e.code),await this.putControlRequest({type:"execute-scratchpad",...e}),null));a(this,"sendInterrupt",async()=>(this.interruptBuffer!==void 0&&(this.interruptBuffer[0]=2),null));a(this,"sendShutdown",async()=>(window.close(),null));a(this,"sendFormat",async e=>await this.rpc.proxy.request.bridge({functionName:"format",payload:e}));a(this,"sendDeleteCell",async e=>(await this.putControlRequest({type:"delete-cell",...e}),null));a(this,"sendInstallMissingPackages",async e=>(this.putControlRequest({type:"install-packages",...e}),null));a(this,"sendCodeCompletionRequest",async e=>(Q.get(mt)||await this.rpc.proxy.request.bridge({functionName:"code_complete",payload:e}),null));a(this,"saveUserConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_user_config",payload:e}),Rt.post("/kernel/save_user_config",e,{baseUrl:"/"}).catch(n=>(E.error(n),null))));a(this,"saveAppConfig",async e=>(await this.rpc.proxy.request.bridge({functionName:"save_app_config",payload:e}),null));a(this,"saveCellConfig",async e=>(await this.putControlRequest({type:"update-cell-config",...e}),null));a(this,"sendRestart",async()=>{let e=await this.readCode();return e.contents&&(X.saveFile(e.contents),ee.saveFile(e.contents)),Dt(),null});a(this,"readCode",async()=>this.saveRpc?{contents:await this.saveRpc.readNotebook()}:(E.warn("Save RPC not initialized"),{contents:""}));a(this,"readSnippets",async()=>await this.rpc.proxy.request.bridge({functionName:"read_snippets",payload:void 0}));a(this,"openFile",async({path:e})=>{let n=Ht({code:null,baseUrl:window.location.origin});return window.open(n,"_blank"),null});a(this,"sendListFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"list_files",payload:e}));a(this,"sendSearchFiles",async e=>await this.rpc.proxy.request.bridge({functionName:"search_files",payload:e}));a(this,"sendComponentValues",async e=>(await this.putControlRequest({type:"update-ui-element",...e,token:we()}),null));a(this,"sendInstantiate",async e=>null);a(this,"sendFunctionRequest",async e=>(await this.putControlRequest({type:"invoke-function",...e}),null));a(this,"sendCreateFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"create_file_or_directory",payload:e}));a(this,"sendDeleteFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"delete_file_or_directory",payload:e}));a(this,"sendRenameFileOrFolder",async e=>await this.rpc.proxy.request.bridge({functionName:"move_file_or_directory",payload:e}));a(this,"sendUpdateFile",async e=>await this.rpc.proxy.request.bridge({functionName:"update_file",payload:e}));a(this,"sendFileDetails",async e=>await this.rpc.proxy.request.bridge({functionName:"file_details",payload:e}));a(this,"exportAsHTML",async e=>await this.rpc.proxy.request.bridge({functionName:"export_html",payload:e}));a(this,"exportAsMarkdown",async e=>await this.rpc.proxy.request.bridge({functionName:"export_markdown",payload:e}));a(this,"previewDatasetColumn",async e=>(await this.putControlRequest({type:"preview-dataset-column",...e}),null));a(this,"previewSQLTable",async e=>(await this.putControlRequest({type:"preview-sql-table",...e}),null));a(this,"previewSQLTableList",async e=>(await this.putControlRequest({type:"list-sql-tables",...e}),null));a(this,"previewDataSourceConnection",async e=>(await this.putControlRequest({type:"list-data-source-connection",...e}),null));a(this,"validateSQL",async e=>(await this.putControlRequest({type:"validate-sql",...e}),null));a(this,"sendModelValue",async e=>(await this.putControlRequest({type:"update-widget-model",...e}),null));a(this,"syncCellIds",()=>Promise.resolve(null));a(this,"addPackage",async e=>this.rpc.proxy.request.addPackage(e));a(this,"removePackage",async e=>this.rpc.proxy.request.removePackage(e));a(this,"getPackageList",async()=>await this.rpc.proxy.request.listPackages());a(this,"getDependencyTree",async()=>({tree:{dependencies:[],name:"",tags:[],version:null}}));a(this,"listSecretKeys",async e=>(await this.putControlRequest({type:"list-secret-keys",...e}),null));a(this,"getUsageStats",y);a(this,"openTutorial",y);a(this,"getRecentFiles",y);a(this,"getWorkspaceFiles",y);a(this,"getRunningNotebooks",y);a(this,"shutdownSession",y);a(this,"exportAsPDF",y);a(this,"autoExportAsHTML",y);a(this,"autoExportAsMarkdown",y);a(this,"autoExportAsIPYNB",y);a(this,"updateCellOutputs",y);a(this,"writeSecret",y);a(this,"invokeAiTool",y);a(this,"clearCache",y);a(this,"getCacheInfo",y);Ft()&&(this.rpc=Se(new Worker(new URL(""+new URL("worker-CUL1lW-N.js",import.meta.url).href,""+import.meta.url),{type:"module",name:he()})),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})=>{Q.set(qe,e)}),this.rpc.addMessageListener("initializedError",({error:e})=>{this.initialized.status==="resolved"&&(E.error(e),Ot({title:"Error initializing",description:e,variant:"danger"})),this.initialized.reject(Error(e))}),this.rpc.addMessageListener("kernelMessage",({message:e})=>{var n;(n=this.messageConsumer)==null||n.call(this,new MessageEvent("message",{data:e}))}))}static get INSTANCE(){let e="_marimo_private_PyodideBridge";return window[e]||(window[e]=new st),window[e]}getSaveWorker(){return xe()==="read"?(E.debug("Skipping SaveWorker in read-mode"),{readFile:y,readNotebook:y,saveNotebook:y}):Se(new Worker(new URL(""+new URL("save-worker-DtF6B3PS.js",import.meta.url).href,""+import.meta.url),{type:"module",name:he()})).proxy.request}async startSession(){let e=await X.readFile(),n=await ee.readFile(),r=z.getFilename(),s=Q.get(kt),i={},d=new URLSearchParams(window.location.search);for(let l of d.keys()){let p=d.getAll(l);i[l]=p.length===1?p[0]:p}await this.rpc.proxy.request.startSession({queryParameters:i,code:e||n||"",filename:r,userConfig:{...s,runtime:{...s.runtime,auto_instantiate:xe()==="read"?!0:s.runtime.auto_instantiate}}})}setInterruptBuffer(){crossOriginIsolated?(this.interruptBuffer=new Uint8Array(new SharedArrayBuffer(1)),this.rpc.proxy.request.setInterruptBuffer(this.interruptBuffer)):E.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})}};function Rn(){return Re.withProducerCallback(t=>{Te.INSTANCE.attachMessageConsumer(t)})}const Ie=q({isInstantiated:!1,error:null});function Nn(){return lt(Ie,t=>t.isInstantiated)}function $(t){return()=>({TYPE:t,is(e){return e.type===t},create(e){return new CustomEvent(t,e)}})}const Le=$("marimo-value-input")(),Ue=$("marimo-value-update")(),ze=$("marimo-value-ready")(),Oe=$("marimo-incoming-message")();function Sn(t,e){return Le.create({bubbles:!0,composed:!0,detail:{value:t,element:e}})}var We=class at{static get INSTANCE(){let e="_marimo_private_UIElementRegistry";return window[e]||(window[e]=new at),window[e]}constructor(){this.entries=new Map}has(e){return this.entries.has(e)}set(e,n){if(this.entries.has(e))throw Error(`UIElement ${e} already registered`);this.entries.set(e,{objectId:e,value:n,elements:new Set})}registerInstance(e,n){let r=this.entries.get(e);r===void 0?this.entries.set(e,{objectId:e,value:pt(n,this),elements:new Set([n])}):r.elements.add(n)}removeInstance(e,n){let r=this.entries.get(e);r!=null&&r.elements.has(n)&&r.elements.delete(n)}removeElementsByCell(e){[...this.entries.keys()].filter(n=>n.startsWith(`${e}-`)).forEach(n=>{this.entries.delete(n)})}lookupValue(e){let n=this.entries.get(e);return n===void 0?void 0:n.value}broadcastMessage(e,n,r){let s=this.entries.get(e);s===void 0?E.warn("UIElementRegistry missing entry",e):s.elements.forEach(i=>{i.dispatchEvent(Oe.create({bubbles:!1,composed:!0,detail:{objectId:e,message:n,buffers:r}}))})}broadcastValueUpdate(e,n,r){let s=this.entries.get(n);s===void 0?E.warn("UIElementRegistry missing entry",n):(s.value=r,s.elements.forEach(i=>{i!==e&&i.dispatchEvent(Ue.create({bubbles:!1,composed:!0,detail:{value:r,element:i}}))}),document.dispatchEvent(ze.create({bubbles:!0,composed:!0,detail:{objectId:n}})))}};const qn=We.INSTANCE,Pn=new zt("function-call-result",async(t,e)=>{await ye().sendFunctionRequest({functionCallId:t,...e})}),jn="68px";var Mn="288px";const An=t=>t?/^\d+$/.test(t)?`${t}px`:t:Mn,Tn=ft({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}});function In(t){return It(Lt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)))}function te(t,e=[]){let n=[];if(t instanceof DataView)n.push(e);else if(Array.isArray(t))for(let[r,s]of t.entries())n.push(...te(s,[...e,r]));else if(typeof t=="object"&&t)for(let[r,s]of Object.entries(t))n.push(...te(s,[...e,r]));return n}function ne(t){let e=te(t);if(e.length===0)return{state:t,buffers:[],bufferPaths:[]};let n=structuredClone(t),r=[],s=[];for(let i of e){let d=vt(t,i);if(d instanceof DataView){let l=In(d);r.push(l),s.push(i),H(n,i,l)}}return{state:n,buffers:r,bufferPaths:s}}function Ln(t){return typeof t=="object"&&!!t&&"state"in t&&"bufferPaths"in t&&"buffers"in t}function Y(t){let{state:e,bufferPaths:n,buffers:r}=t;if(!n||n.length===0)return e;r&&Ct(r.length===n.length,"Buffers and buffer paths not the same length");let s=structuredClone(e);for(let[i,d]of n.entries()){let l=r==null?void 0:r[i];if(l==null){E.warn("[anywidget] Could not find buffer at path",d);continue}if(typeof l=="string"){let p=Tt(At(l));H(s,d,new DataView(p.buffer))}else H(s,d,l)}return s}const De=new class{constructor(t=1e4){a(this,"models",new Map);this.timeout=t}get(t){let e=this.models.get(t);return e||(e=new K,this.models.set(t,e),setTimeout(()=>{e.status==="pending"&&(e.reject(Error(`Model not found for key: ${t}`)),this.models.delete(t))},this.timeout)),e.promise}set(t,e){let n=this.models.get(t);n||(n=new K,this.models.set(t,n)),n.resolve(e)}delete(t){this.models.delete(t)}};var He=(M=class{constructor(e,n,r,s){a(this,"ANY_CHANGE_EVENT","change");a(this,"listeners",{});a(this,"widget_manager",{async get_model(e){let n=await M._modelManager.get(e);if(!n)throw Error(`Model not found with id: ${e}. This is likely because the model was not registered.`);return n}});a(this,"emitAnyChange",Et(()=>{var e;(e=this.listeners[this.ANY_CHANGE_EVENT])==null||e.forEach(n=>n())},0));this.data=e,this.onChange=n,this.sendToWidget=r,this.dirtyFields=new Map([...s].map(i=>[i,this.data[i]]))}off(e,n){var r;if(!e){this.listeners={};return}if(!n){this.listeners[e]=new Set;return}(r=this.listeners[e])==null||r.delete(n)}send(e,n,r){let{state:s,bufferPaths:i,buffers:d}=ne(e);this.sendToWidget({content:{state:s,bufferPaths:i},buffers:d}).then(n)}get(e){return this.data[e]}set(e,n){this.data={...this.data,[e]:n},this.dirtyFields.set(e,n),this.emit(`change:${e}`,n),this.emitAnyChange()}save_changes(){if(this.dirtyFields.size===0)return;let e=Object.fromEntries(this.dirtyFields.entries());this.dirtyFields.clear(),this.onChange(e)}updateAndEmitDiffs(e){e!=null&&Object.keys(e).forEach(n=>{let r=n;this.data[r]!==e[r]&&this.set(r,e[r])})}receiveCustomMessage(e,n=[]){var s;let r=Be.safeParse(e);if(r.success){let i=r.data;switch(i.method){case"update":this.updateAndEmitDiffs(Y({state:i.state,bufferPaths:i.buffer_paths??[],buffers:n}));break;case"custom":(s=this.listeners["msg:custom"])==null||s.forEach(d=>d(i.content,n));break;case"open":this.updateAndEmitDiffs(Y({state:i.state,bufferPaths:i.buffer_paths??[],buffers:n}));break;case"echo_update":break;default:E.error("[anywidget] Unknown message method",i.method);break}}else E.error("Failed to parse message",r.error),E.error("Message",e)}on(e,n){this.listeners[e]||(this.listeners[e]=new Set),this.listeners[e].add(n)}emit(e,n){this.listeners[e]&&this.listeners[e].forEach(r=>r(n))}},a(M,"_modelManager",De),M),re=me(me(gt([fe(),wt()]))),se=bt(fe(),de()),Be=yt("method",[O({method:W("open"),state:se,buffer_paths:re.optional()}),O({method:W("update"),state:se,buffer_paths:re.optional()}),O({method:W("custom"),content:de()}),O({method:W("echo_update"),buffer_paths:re,state:se}),O({method:W("close")})]);function Un(t){return t==null?!1:Be.safeParse(t).success}async function zn({modelId:t,msg:e,buffers:n,modelManager:r}){if(e.method==="echo_update")return;if(e.method==="custom"){(await r.get(t)).receiveCustomMessage(e,n);return}if(e.method==="close"){r.delete(t);return}let{method:s,state:i,buffer_paths:d=[]}=e,l=Y({state:i,bufferPaths:d,buffers:n});if(s==="open"){let p=new He(l,b=>{let{state:x,buffers:w,bufferPaths:_}=ne(b);ye().sendModelValue({modelId:t,message:{state:x,bufferPaths:_},buffers:w})},y,new Set);r.set(t,p);return}if(s==="update"){(await r.get(t)).updateAndEmitDiffs(l);return}xt(s)}const Ve=q(null),On=q(null),Xe=q(!1),Wn=q(!1),$e=q(!1);var Dn=pe();const Ye=t=>{let e=(0,Dn.c)(8),{onResize:n,startingWidth:r,minWidth:s,maxWidth:i}=t,d=(0,u.useRef)(null),l=(0,u.useRef)(null),p=(0,u.useRef)(null),b,x;e[0]!==i||e[1]!==s||e[2]!==n?(b=()=>{let C=d.current,k=l.current,F=p.current;if(!C||!k&&!F)return;let v=Number.parseInt(window.getComputedStyle(C).width,10),N=0,P=!1,A=null,L=c=>{if(!C||!P||!A)return;let h=c.clientX-N;N=c.clientX,v=A==="left"?v-h:v+h,s&&(v=Math.max(s,v)),i&&(v=Math.min(i,v)),C.style.width=`${v}px`},U=()=>{P&&(n==null||n(v),P=!1,A=null),document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",U)},o=(c,h)=>{c.preventDefault(),P=!0,A=h,N=c.clientX,document.addEventListener("mousemove",L),document.addEventListener("mouseup",U)},f=c=>o(c,"left"),g=c=>o(c,"right");return k&&k.addEventListener("mousedown",f),F&&F.addEventListener("mousedown",g),()=>{k&&k.removeEventListener("mousedown",f),F&&F.removeEventListener("mousedown",g),document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",U)}},x=[s,i,n],e[0]=i,e[1]=s,e[2]=n,e[3]=b,e[4]=x):(b=e[3],x=e[4]),(0,u.useEffect)(b,x);let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w={left:l,right:p},e[5]=w):w=e[5];let _=r==="contentWidth"?"var(--content-width-medium)":`${r}px`,R;return e[6]===_?R=e[7]:(R={resizableDivRef:d,handleRefs:w,style:{width:_}},e[6]=_,e[7]=R),R};function Ge(t){t||window.dispatchEvent(new Event("resize"))}var Qe=pe(),m=ce(Nt(),1);const Hn=()=>{let t=(0,Qe.c)(16),[e,n]=D(Ve),[r,s]=D(Xe),[i,d]=D(Wn),[l,p]=D($e),b;t[0]!==s||t[1]!==n?(b=()=>{n(null),s(!1)},t[0]=s,t[1]=n,t[2]=b):b=t[2];let x=b;if(J(B.CONTEXT_AWARE_PANEL).length===0||!e||!r)return null;let w;t[3]!==l||t[4]!==i||t[5]!==p||t[6]!==d?(w=()=>(0,m.jsxs)("div",{className:"flex flex-row items-center gap-3",children:[(0,m.jsx)(ve,{content:i?"Unpin panel":"Pin panel",children:(0,m.jsx)(Ee,{size:"xs",onPressedChange:()=>d(!i),pressed:i,"aria-label":i?"Unpin panel":"Pin panel",children:i?(0,m.jsx)(Yt,{className:"w-4 h-4"}):(0,m.jsx)(Pt,{className:"w-4 h-4"})})}),(0,m.jsx)(ve,{content:l?(0,m.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,m.jsx)("span",{children:"Follow focused table"}),(0,m.jsx)("span",{className:"text-xs text-muted-foreground w-64",children:"The panel updates as cells that output tables are focused. Click to fix to the current cell."})]}):(0,m.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,m.jsx)("span",{children:"Focus on current table"}),(0,m.jsx)("span",{className:"text-xs text-muted-foreground w-64",children:"The panel is focused on the current table. Click to update based on which cell is focused."})]}),children:(0,m.jsx)(Ee,{size:"xs",onPressedChange:()=>p(!l),pressed:l,"aria-label":l?"Follow focused cell":"Fixed",children:(0,m.jsx)($t,{className:qt("w-4 h-4",l&&"text-primary")})})})]}),t[3]=l,t[4]=i,t[5]=p,t[6]=d,t[7]=w):w=t[7];let _=w,R;t[8]!==x||t[9]!==_?(R=()=>(0,m.jsxs)("div",{className:"mt-2 pb-7 mb-4 h-full overflow-auto",children:[(0,m.jsxs)("div",{className:"flex flex-row justify-between items-center mx-2",children:[_(),(0,m.jsx)(St,{variant:"linkDestructive",size:"icon",onClick:x,"aria-label":"Close selection panel",children:(0,m.jsx)(Mt,{className:"w-4 h-4"})})]}),(0,m.jsx)(ge,{children:(0,m.jsx)(Fe,{name:B.CONTEXT_AWARE_PANEL})})]}),t[8]=x,t[9]=_,t[10]=R):R=t[10];let C=R;if(!i){let v;return t[11]===C?v=t[12]:(v=(0,m.jsx)(Vn,{children:C()}),t[11]=C,t[12]=v),v}let k;t[13]===Symbol.for("react.memo_cache_sentinel")?(k=(0,m.jsx)(Bt,{onDragging:Ge,className:"resize-handle border-border z-20 no-print border-l"}),t[13]=k):k=t[13];let F;return t[14]===C?F=t[15]:(F=(0,m.jsxs)(m.Fragment,{children:[k,(0,m.jsx)(Vt,{defaultSize:20,minSize:15,maxSize:80,children:C()})]}),t[14]=C,t[15]=F),F},Bn=t=>{let e=(0,Qe.c)(2),{children:n}=t,r;return e[0]===n?r=e[1]:(r=(0,m.jsx)(ge,{children:(0,m.jsx)(Qt,{name:B.CONTEXT_AWARE_PANEL,children:n})}),e[0]=n,e[1]=r),r};var Vn=({children:t})=>{let{resizableDivRef:e,handleRefs:n,style:r}=Ye({startingWidth:400,minWidth:300,maxWidth:1500});return(0,m.jsxs)("div",{className:"absolute z-40 right-0 h-full bg-background flex flex-row",children:[(0,m.jsx)("div",{ref:n.left,className:"w-1 h-full cursor-col-resize border-l"}),(0,m.jsx)("div",{ref:e,style:r,children:t})]})};function Xn(){var t=[...arguments];return(0,u.useMemo)(()=>e=>{t.forEach(n=>n(e))},t)}var Ke=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0;function G(t){let e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function ae(t){return"nodeType"in t}function I(t){var e;return t?G(t)?t:ae(t)?((e=t.ownerDocument)==null?void 0:e.defaultView)??window:window:window}function Ze(t){let{Document:e}=I(t);return t instanceof e}function Je(t){return G(t)?!1:t instanceof I(t).HTMLElement}function et(t){return t instanceof I(t).SVGElement}function $n(t){return t?G(t)?t.document:ae(t)?Ze(t)?t:Je(t)||et(t)?t.ownerDocument:document:document:document}var ie=Ke?u.useLayoutEffect:u.useEffect;function tt(t){let e=(0,u.useRef)(t);return ie(()=>{e.current=t}),(0,u.useCallback)(function(){var n=[...arguments];return e.current==null?void 0:e.current(...n)},[])}function Yn(){let t=(0,u.useRef)(null);return[(0,u.useCallback)((e,n)=>{t.current=setInterval(e,n)},[]),(0,u.useCallback)(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[])]}function Gn(t,e){e===void 0&&(e=[t]);let n=(0,u.useRef)(t);return ie(()=>{n.current!==t&&(n.current=t)},e),n}function Qn(t,e){let n=(0,u.useRef)();return(0,u.useMemo)(()=>{let r=t(n.current);return n.current=r,r},[...e])}function Kn(t){let e=tt(t),n=(0,u.useRef)(null);return[n,(0,u.useCallback)(r=>{r!==n.current&&(e==null||e(r,n.current)),n.current=r},[])]}function Zn(t){let e=(0,u.useRef)();return(0,u.useEffect)(()=>{e.current=t},[t]),e.current}var oe={};function Jn(t,e){return(0,u.useMemo)(()=>{if(e)return e;let n=oe[t]==null?0:oe[t]+1;return oe[t]=n,t+"-"+n},[t,e])}function nt(t){return function(e){return[...arguments].slice(1).reduce((n,r)=>{let s=Object.entries(r);for(let[i,d]of s){let l=n[i];l!=null&&(n[i]=l+t*d)}return n},{...e})}}var er=nt(1),tr=nt(-1);function nr(t){return"clientX"in t&&"clientY"in t}function rr(t){if(!t)return!1;let{KeyboardEvent:e}=I(t.target);return e&&t instanceof e}function sr(t){if(!t)return!1;let{TouchEvent:e}=I(t.target);return e&&t instanceof e}function ar(t){if(sr(t)){if(t.touches&&t.touches.length){let{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){let{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return nr(t)?{x:t.clientX,y:t.clientY}:null}var le=Object.freeze({Translate:{toString(t){if(!t)return;let{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;let{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[le.Translate.toString(t),le.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),rt="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function ir(t){return t.matches(rt)?t:t.querySelector(rt)}export{Rn as $,On as A,An as B,Jn as C,Ye as D,Ge as E,Un as F,Oe as G,Pn as H,Y as I,Ue as J,Le as K,Ln as L,De as M,He as N,Xe as O,zn as P,Te as Q,ne as R,Zn as S,Bn as T,We as U,Tn as V,qn as W,Ie as X,Sn as Y,Nn as Z,Yn as _,ar as a,dn as at,Qn as b,Ze as c,cn as ct,ae as d,J as dt,X as et,et as f,H as ft,tt as g,Xn as h,ir as i,B as it,$e as j,Ve as k,Je as l,sn as lt,tr as m,er as n,qe as nt,$n as o,an as ot,G as p,ze as q,Ke as r,Re as rt,I as s,un as st,le as t,xn as tt,rr as u,Fe as ut,ie as v,Hn as w,Kn as x,Gn as y,jn as z};
|