@marimo-team/frontend 0.19.3-dev39 → 0.19.3-dev41
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/{CellStatus-C99xWY-n.js → CellStatus-b7Yo2X9j.js} +1 -1
- package/dist/assets/{JsonOutput-vgVa8Uqm.js → JsonOutput-C8Eo1zBR.js} +5 -5
- package/dist/assets/{MarimoErrorOutput-BheMLw1Y.js → MarimoErrorOutput-CXBGzjO2.js} +2 -2
- package/dist/assets/{RenderHTML-BE1SeEPf.js → RenderHTML-SoetmcW2.js} +1 -1
- package/dist/assets/{add-cell-with-ai-BQ3faBMp.js → add-cell-with-ai-Csh7GHT3.js} +8 -8
- package/dist/assets/{add-database-form-Cd6r_tKJ.js → add-database-form-BBkiGMZ_.js} +2 -2
- package/dist/assets/{agent-panel-B6jmJILp.js → agent-panel-C5C18dfm.js} +4 -4
- package/dist/assets/{ai-model-dropdown-Dv-MPaCU.js → ai-model-dropdown-CrMTCgo7.js} +1 -1
- package/dist/assets/{app-config-button-Dc-Pr3EG.js → app-config-button-9izWmQ0X.js} +1 -1
- package/dist/assets/{cell-editor-6RFkGM2j.js → cell-editor-gOJZyTG_.js} +13 -13
- package/dist/assets/cell-link-BP7_Ns0N.js +1 -0
- package/dist/assets/{cells-Ba_KE9BT.js → cells-Cv9PtwL9.js} +42 -42
- package/dist/assets/{chat-components-gFovWg-D.js → chat-components-Be6BPrbT.js} +1 -1
- package/dist/assets/{chat-display-DnPj1KhL.js → chat-display-BRKfnhbm.js} +1 -1
- package/dist/assets/{chat-panel-47KIpqX3.js → chat-panel-BwP6HOKA.js} +2 -2
- package/dist/assets/client-CGOlSEYr.js +4 -0
- package/dist/assets/{column-preview-DhROBSPD.js → column-preview-MC6VOHbd.js} +1 -1
- package/dist/assets/{command-D-UJxuGK.js → command-n_oMaKjl.js} +1 -1
- package/dist/assets/{command-palette-6sH9E7Dw.js → command-palette-DfZNcw7W.js} +1 -1
- package/dist/assets/common-MUZIZluQ.js +1 -0
- package/dist/assets/{datasource-D4Z8tdLQ.js → datasource-CEsMStKs.js} +2 -2
- package/dist/assets/{dependency-graph-panel-xSFZomKN.js → dependency-graph-panel-CNTGbfLZ.js} +4 -4
- package/dist/assets/{documentation-panel-Dm3ob6Ir.js → documentation-panel-Cb9AHO2C.js} +1 -1
- package/dist/assets/{download-BjwKjWNy.js → download-24bI2vH0.js} +1 -1
- package/dist/assets/{edit-page-CZh8JbX5.js → edit-page-KoYkiOm1.js} +6 -6
- package/dist/assets/{error-panel-DMBUp0y7.js → error-panel-CpYH0GfR.js} +1 -1
- package/dist/assets/{es-CHi7dcFm.js → es-BITbuY9w.js} +1 -1
- package/dist/assets/{file-explorer-panel-DjUhUpSF.js → file-explorer-panel-CdA81LHh.js} +1 -1
- package/dist/assets/{floating-outline-ftqqU4Np.js → floating-outline-BbJ4ldyu.js} +1 -1
- package/dist/assets/{focus-DZZOzpQD.js → focus-D1y1tXyC.js} +1 -1
- package/dist/assets/{form-CnZqs8Bn.js → form-BAtvsPJL.js} +2 -2
- package/dist/assets/{globals-Dh1hxKNk.js → globals-C6OH39EA.js} +1 -1
- package/dist/assets/{home-page-BMu2cQgR.js → home-page-B_YprqxM.js} +2 -2
- package/dist/assets/{index-DTpgS0Hi.js → index-Bq3Xa2YC.js} +9 -9
- package/dist/assets/{kiosk-mode-lfj9N4vd.js → kiosk-mode-DfyjlR7p.js} +1 -1
- package/dist/assets/{layout-0e9X02ON.js → layout-9uQoV-6h.js} +3 -3
- package/dist/assets/{logs-panel-pc8_rMGL.js → logs-panel-svcirwjp.js} +1 -1
- package/dist/assets/{markdown-renderer-DOsqiCxS.js → markdown-renderer-DlVqlHOL.js} +2 -2
- package/dist/assets/mode-PeuS_Lp-.js +1 -0
- package/dist/assets/{name-cell-input-DwI5DL4H.js → name-cell-input-YMoA0SQj.js} +1 -1
- package/dist/assets/{outline-panel-BkVymtAn.js → outline-panel-RKJ5Mqrt.js} +1 -1
- package/dist/assets/{packages-panel-C2AcLZfz.js → packages-panel-BuiAGEBw.js} +1 -1
- package/dist/assets/{panels-Bw1r9qwY.js → panels-BKsZUDjc.js} +1 -1
- package/dist/assets/{process-output-C46Mdai2.js → process-output-KJWsSvCT.js} +1 -1
- package/dist/assets/{readonly-python-code-C5OixNOu.js → readonly-python-code-HPlG_YPX.js} +1 -1
- package/dist/assets/{run-page-gAREGgIk.js → run-page-CBDzVDX3.js} +1 -1
- package/dist/assets/scratchpad-panel-BcE_ovEU.js +1 -0
- package/dist/assets/{session-panel-BuxKOamF.js → session-panel-Cv14Ehfm.js} +1 -1
- package/dist/assets/{snippets-panel-B6_Edpel.js → snippets-panel-OAdQXQ93.js} +1 -1
- package/dist/assets/{state-CSQYiEJY.js → state-DYG6kYly.js} +1 -1
- package/dist/assets/state-xh6GqNrp.js +1 -0
- package/dist/assets/{switch-eOpIZoDX.js → switch-DPeh0R76.js} +1 -1
- package/dist/assets/{textarea-niGA0rfg.js → textarea-wbzgrXvB.js} +1 -1
- package/dist/assets/{tracing-DkpVk4o4.js → tracing-Bh3EJxAS.js} +1 -1
- package/dist/assets/{tracing-panel-BIncP1rT.js → tracing-panel-BzSQ7qvB.js} +2 -2
- package/dist/assets/{types-VIX1OCSW.js → types-B8Qb1FfB.js} +1 -1
- package/dist/assets/{useAddCell-B_xjsTBs.js → useAddCell-DBGvrN8K.js} +1 -1
- package/dist/assets/{useCellActionButton-Ds3zG2vC.js → useCellActionButton-BlS_HKk-.js} +1 -1
- package/dist/assets/useDeleteCell-BvQIJfpI.js +1 -0
- package/dist/assets/{useDependencyPanelTab-D-cjUX7M.js → useDependencyPanelTab-BqEhbPr2.js} +1 -1
- package/dist/assets/useInterval-BGPIviJp.js +1 -0
- package/dist/assets/{useNotebookActions-BR0qaiDG.js → useNotebookActions-D1Woz3AV.js} +1 -1
- package/dist/assets/useRunCells-B9Xr4tcH.js +1 -0
- package/dist/assets/useSplitCell-7xBW3b8-.js +1 -0
- package/dist/assets/utilities.esm-xahhGpny.js +3 -0
- package/dist/index.html +31 -31
- package/package.json +1 -1
- package/src/__mocks__/requests.ts +1 -0
- package/src/core/cells/cells.ts +2 -0
- package/src/core/export/__tests__/hooks.test.ts +504 -0
- package/src/core/export/hooks.ts +93 -4
- 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 +2 -0
- package/src/core/wasm/bridge.ts +1 -0
- package/src/hooks/__tests__/useInterval.test.tsx +104 -0
- package/src/hooks/useInterval.ts +32 -6
- package/dist/assets/cell-link--tfL3CA1.js +0 -1
- package/dist/assets/client-ptbakt_D.js +0 -4
- package/dist/assets/common-CTqesfI3.js +0 -1
- package/dist/assets/mode-BCyUhVQM.js +0 -1
- package/dist/assets/scratchpad-panel-CCfSlzxc.js +0 -1
- package/dist/assets/state-CW2XRi_v.js +0 -1
- package/dist/assets/useDeleteCell-BHcO82VK.js +0 -1
- package/dist/assets/useInterval-DpipYmgs.js +0 -1
- package/dist/assets/useRunCells-DNyvw4YU.js +0 -1
- package/dist/assets/useSplitCell-PfU2seYs.js +0 -1
- package/dist/assets/utilities.esm-B52GCDdx.js +0 -3
|
@@ -67,4 +67,108 @@ describe("useInterval", () => {
|
|
|
67
67
|
vi.advanceTimersByTime(1000);
|
|
68
68
|
expect(callback).not.toHaveBeenCalled();
|
|
69
69
|
});
|
|
70
|
+
|
|
71
|
+
describe("skipIfRunning", () => {
|
|
72
|
+
it("should allow overlapping async calls by default", async () => {
|
|
73
|
+
let concurrentCalls = 0;
|
|
74
|
+
let maxConcurrentCalls = 0;
|
|
75
|
+
|
|
76
|
+
const callback = vi.fn(async () => {
|
|
77
|
+
concurrentCalls++;
|
|
78
|
+
maxConcurrentCalls = Math.max(maxConcurrentCalls, concurrentCalls);
|
|
79
|
+
// Simulate slow async work
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
81
|
+
concurrentCalls--;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
renderHook(() =>
|
|
85
|
+
useInterval(callback, { delayMs: 500, whenVisible: false }),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// First call at 500ms
|
|
89
|
+
vi.advanceTimersByTime(500);
|
|
90
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
91
|
+
|
|
92
|
+
// Second call at 1000ms (while first is still running)
|
|
93
|
+
vi.advanceTimersByTime(500);
|
|
94
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
95
|
+
|
|
96
|
+
// Third call at 1500ms
|
|
97
|
+
vi.advanceTimersByTime(500);
|
|
98
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
99
|
+
|
|
100
|
+
// Multiple concurrent calls should have occurred
|
|
101
|
+
expect(maxConcurrentCalls).toBeGreaterThan(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should skip calls when skipIfRunning is true", async () => {
|
|
105
|
+
let concurrentCalls = 0;
|
|
106
|
+
let maxConcurrentCalls = 0;
|
|
107
|
+
|
|
108
|
+
const callback = vi.fn(async () => {
|
|
109
|
+
concurrentCalls++;
|
|
110
|
+
maxConcurrentCalls = Math.max(maxConcurrentCalls, concurrentCalls);
|
|
111
|
+
// Simulate slow async work (3 seconds)
|
|
112
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 3000));
|
|
113
|
+
concurrentCalls--;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
renderHook(() =>
|
|
117
|
+
useInterval(callback, {
|
|
118
|
+
delayMs: 500,
|
|
119
|
+
whenVisible: false,
|
|
120
|
+
skipIfRunning: true,
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// First call at 500ms
|
|
125
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
126
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
127
|
+
|
|
128
|
+
// Second interval tick at 1000ms - should be skipped since first is still running
|
|
129
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
130
|
+
expect(callback).toHaveBeenCalledTimes(1); // Still 1, not 2
|
|
131
|
+
|
|
132
|
+
// Third interval tick at 1500ms - should still be skipped
|
|
133
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
134
|
+
expect(callback).toHaveBeenCalledTimes(1); // Still 1
|
|
135
|
+
|
|
136
|
+
// Only one concurrent call should have occurred
|
|
137
|
+
expect(maxConcurrentCalls).toBe(1);
|
|
138
|
+
|
|
139
|
+
// Advance past the 3 second timeout to complete first callback
|
|
140
|
+
await vi.advanceTimersByTimeAsync(2000);
|
|
141
|
+
|
|
142
|
+
// Next interval tick should now be able to run
|
|
143
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
144
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should allow next call after previous async call completes with skipIfRunning true", async () => {
|
|
148
|
+
const callback = vi.fn(async () => {
|
|
149
|
+
// Quick async operation
|
|
150
|
+
await Promise.resolve();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
renderHook(() =>
|
|
154
|
+
useInterval(callback, {
|
|
155
|
+
delayMs: 1000,
|
|
156
|
+
whenVisible: false,
|
|
157
|
+
skipIfRunning: true,
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// First call
|
|
162
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
163
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
164
|
+
|
|
165
|
+
// Second call - should proceed since first completed
|
|
166
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
167
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
168
|
+
|
|
169
|
+
// Third call
|
|
170
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
171
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
70
174
|
});
|
package/src/hooks/useInterval.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
3
|
import { useEventListener } from "./useEventListener";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates an interval that runs a callback every `delayMs` milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* @param callback - The callback to run.
|
|
9
|
+
* @param opts - The options for the interval.
|
|
10
|
+
* @param opts.delayMs - The delay in milliseconds between runs.
|
|
11
|
+
* @param opts.whenVisible - Whether to run the callback when the document is visible.
|
|
12
|
+
* @param opts.disabled - Whether to disable the interval.
|
|
13
|
+
* @param opts.skipIfRunning - Whether to skip the callback if it is already running.
|
|
7
14
|
*/
|
|
8
15
|
export function useInterval(
|
|
9
16
|
callback: () => void,
|
|
@@ -11,16 +18,35 @@ export function useInterval(
|
|
|
11
18
|
delayMs: number | null;
|
|
12
19
|
whenVisible: boolean;
|
|
13
20
|
disabled?: boolean;
|
|
21
|
+
skipIfRunning?: boolean;
|
|
14
22
|
},
|
|
15
23
|
) {
|
|
16
|
-
const {
|
|
17
|
-
|
|
24
|
+
const {
|
|
25
|
+
delayMs,
|
|
26
|
+
whenVisible,
|
|
27
|
+
disabled = false,
|
|
28
|
+
skipIfRunning = false,
|
|
29
|
+
} = opts;
|
|
30
|
+
const savedCallback = useRef<() => void | Promise<void>>(undefined);
|
|
31
|
+
const isRunning = useRef(false);
|
|
18
32
|
|
|
19
33
|
// Store the callback
|
|
20
34
|
useEffect(() => {
|
|
21
35
|
savedCallback.current = callback;
|
|
22
36
|
}, [callback]);
|
|
23
37
|
|
|
38
|
+
const runCallback = useCallback(async () => {
|
|
39
|
+
if (isRunning.current && skipIfRunning) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
isRunning.current = true;
|
|
43
|
+
try {
|
|
44
|
+
await savedCallback.current?.();
|
|
45
|
+
} finally {
|
|
46
|
+
isRunning.current = false;
|
|
47
|
+
}
|
|
48
|
+
}, [skipIfRunning]);
|
|
49
|
+
|
|
24
50
|
// Run the interval
|
|
25
51
|
useEffect(() => {
|
|
26
52
|
if (delayMs === null || disabled) {
|
|
@@ -32,16 +58,16 @@ export function useInterval(
|
|
|
32
58
|
return;
|
|
33
59
|
}
|
|
34
60
|
|
|
35
|
-
|
|
61
|
+
runCallback();
|
|
36
62
|
}, delayMs);
|
|
37
63
|
|
|
38
64
|
return () => clearInterval(id);
|
|
39
|
-
}, [delayMs, whenVisible, disabled]);
|
|
65
|
+
}, [delayMs, whenVisible, disabled, runCallback]);
|
|
40
66
|
|
|
41
67
|
// When the document becomes visible, run the callback
|
|
42
68
|
useEventListener(document, "visibilitychange", () => {
|
|
43
69
|
if (document.visibilityState === "visible" && whenVisible && !disabled) {
|
|
44
|
-
|
|
70
|
+
runCallback();
|
|
45
71
|
}
|
|
46
72
|
});
|
|
47
73
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as P}from"./chunk-LvLJmgfZ.js";import{d as A,l as O,n as j,u as w}from"./useEvent-DlWF5OMa.js";import{A as y,C as L,Gt as E,O as S,Pt as T,Ur as _,ei as $,pt as D}from"./cells-Ba_KE9BT.js";import{t as b}from"./compiler-runtime-DeeZ7FnK.js";import{d as F}from"./hotkeys-uKX61F1_.js";import{u as U}from"./utils-CJJIceVn.js";import{r as C}from"./constants-Bkp4R3bQ.js";import{A as q,p as B,w as G}from"./config-DFDEcYvy.js";import{t as H}from"./jsx-runtime-DN_bIXfG.js";import{t as M}from"./cn-C1rgT0yh.js";import{r as R}from"./requests-C0HaHO6a.js";import{n as V}from"./ImperativeModal-DVhvP4lH.js";var z=b();function I(){return w(_)}function J(){let r=(0,z.c)(5),[t]=O(G),e=A(_),{openAlert:a}=V(),{sendRename:o}=R(),s;return r[0]!==t.state||r[1]!==a||r[2]!==o||r[3]!==e?(s=async l=>{let n=U();return t.state===q.OPEN?(B(i=>{l===null?i.delete(C.filePath):i.set(C.filePath,l)}),o({filename:l}).then(()=>(e(l),document.title=n.app_title||T.basename(l)||"Untitled Notebook",l)).catch(i=>(a(i.message),null))):(a("Failed to save notebook: not connected to a kernel."),null)},r[0]=t.state,r[1]=a,r[2]=o,r[3]=e,r[4]=s):s=r[4],j(s)}var p=b(),v=P(H(),1);const k=r=>{let t=(0,p.c)(12),{className:e,cellId:a,variant:o,onClick:s,formatCellName:l,skipScroll:n}=r,i=y()[a]??"",x=S().inOrderIds.indexOf(a),{showCellIfHidden:d}=L(),g=l??W,c;t[0]===e?c=t[1]:(c=M("inline-block cursor-pointer text-link hover:underline",e),t[0]=e,t[1]=c);let m;t[2]!==a||t[3]!==s||t[4]!==d||t[5]!==n||t[6]!==o?(m=h=>{if(a==="__scratch__")return!1;d({cellId:a}),h.stopPropagation(),h.preventDefault(),requestAnimationFrame(()=>{N(a,o,n)&&(s==null||s())})},t[2]=a,t[3]=s,t[4]=d,t[5]=n,t[6]=o,t[7]=m):m=t[7];let f=g(D(i,x)),u;return t[8]!==c||t[9]!==m||t[10]!==f?(u=(0,v.jsx)("div",{className:c,role:"link",tabIndex:-1,onClick:m,children:f}),t[8]=c,t[9]=m,t[10]=f,t[11]=u):u=t[11],u},K=r=>{let t=(0,p.c)(2),e;return t[0]===r?e=t[1]:(e=(0,v.jsx)(k,{...r,variant:"destructive"}),t[0]=r,t[1]=e),e},Q=r=>{let t=(0,p.c)(10),{cellId:e,lineNumber:a}=r,o=I(),s;t[0]!==e||t[1]!==a?(s=()=>E(e,a),t[0]=e,t[1]=a,t[2]=s):s=t[2];let l;t[3]!==e||t[4]!==o?(l=i=>e==="__scratch__"?"scratch":`marimo://${o||"untitled"}#cell=${i}`,t[3]=e,t[4]=o,t[5]=l):l=t[5];let n;return t[6]!==e||t[7]!==s||t[8]!==l?(n=(0,v.jsx)(k,{cellId:e,onClick:s,skipScroll:!0,variant:"destructive",className:"traceback-cell-link",formatCellName:l}),t[6]=e,t[7]=s,t[8]=l,t[9]=n):n=t[9],n};function N(r,t,e){let a=$.create(r),o=document.getElementById(a);return o===null?(F.error(`Cell ${a} not found on page.`),!1):(e||o.scrollIntoView({behavior:"smooth",block:"center"}),t==="destructive"&&(o.classList.add("error-outline"),setTimeout(()=>{o.classList.remove("error-outline")},2e3)),t==="focus"&&(o.classList.add("focus-outline"),setTimeout(()=>{o.classList.remove("focus-outline")},2e3)),!0)}function W(r){return r}export{I as a,N as i,K as n,J as o,Q as r,k as t};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var z=Object.defineProperty;var L=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>L(n,typeof e!="symbol"?e+"":e,t);var g;import{i as p,o as W,p as b}from"./useEvent-DlWF5OMa.js";import{Ar as P,Dr as R,Ht as a,It as B,Kr as K,Lt as j,Or as J,Tt as Q,Ut as w,V as X,Vr as Y,Wt as Z,fn as ee,fr as v,kr as te,pr as D,qt as ne,wr as ie,zt as S}from"./cells-Ba_KE9BT.js";import{x as re}from"./_Uint8Array-BGESiCQL.js";import{i as se}from"./useLifecycle-CmDXEyIC.js";import{t as oe}from"./debounce-BbFlGgjv.js";import{d as o}from"./hotkeys-uKX61F1_.js";import{t as x}from"./invariant-C6yE60hi.js";import{d as ae,g as I}from"./utils-CJJIceVn.js";import{O as le,r as ce}from"./config-DFDEcYvy.js";import{St as m,Ut as E,at as ue,ct as M}from"./dist-CAcX026F.js";import{O as T,g as de,k as F,w as me}from"./dist-CI6_zMIl.js";import{n as h}from"./once-CTiSlR1m.js";import{t as pe}from"./requests-C0HaHO6a.js";import{t as ge}from"./use-toast-Bzf3rpev.js";import{a as he}from"./error-banner-DvT0IGDZ.js";var fe="Expected a function";function we(n,e,t){var r=!0,s=!0;if(typeof n!="function")throw TypeError(fe);return re(t)&&(r="leading"in t?!!t.leading:r,s="trailing"in t?!!t.trailing:s),oe(n,e,{leading:r,maxWait:e,trailing:s})}var ve=we;function ye(n){"scheduler"in window?window.scheduler.postTask(n,{priority:"background"}):"requestIdleCallback"in window?requestIdleCallback(n):setTimeout(n,0)}var y=null,Ce=class{constructor(n){c(this,"abortController",new AbortController);this.view=n.view,this.view.dom.addEventListener("focus",()=>{y=new WeakRef(this.view)},{signal:this.abortController.signal,capture:!0}),this.update()}update(){let n=this.view.dom.querySelector(".cm-vimCursorLayer");if(n instanceof HTMLElement)if(X())n.style.display="none";else{let e=(y==null?void 0:y.deref())===this.view;n.style.display=e?"":"none"}}destroy(){this.abortController.abort()}};const O={map:{args:["lhs","rhs"]},nmap:{mode:"normal",args:["lhs","rhs"]},vmap:{mode:"visual",args:["lhs","rhs"]},imap:{mode:"insert",args:["lhs","rhs"]},noremap:{args:["lhs","rhs"]},nnoremap:{mode:"normal",args:["lhs","rhs"]},vnoremap:{mode:"visual",args:["lhs","rhs"]},inoremap:{mode:"insert",args:["lhs","rhs"]},unmap:{args:["lhs"]},nunmap:{mode:"normal",args:["lhs"]},vunmap:{mode:"visual",args:["lhs"]},iunmap:{mode:"insert",args:["lhs"]},mapclear:{},nmapclear:{mode:"normal"},vmapclear:{mode:"visual"},imapclear:{mode:"insert"}};function be(n,e){let t=[];for(let r of n.split(`
|
|
2
|
-
`)){if(r.startsWith('"')||r.trim()==="")continue;let s=xe(r,e);s&&t.push(s)}return t}function xe(n,e){let t=n.split(/\s+/),r=t[0],s=0;if(r in O){let i=O[r],u={};for(let f of i.args||[])if(s+=1,s<t.length)u[f]=t[s];else{e&&e(`Not enough arguments for "${r}" command: "${n}"`);return}let d={name:r};return"args"in i&&(d.args=u),"mode"in i&&(d.mode=i.mode),d}e&&e(`Unknown vimrc command: "${n}"`)}function Ie(){return ke(),De(),[m.of([{key:"j",run:n=>{if(B(n,!0)&&S(n)){let e=n.state.facet(v),t=n.state.facet(D);return e.moveToNextCell({cellId:t,before:!1,noCreate:!0}),!0}return!1}}]),m.of([{key:"k",run:n=>{if(j(n)&&S(n)){let e=n.state.facet(v),t=n.state.facet(D);return e.moveToNextCell({cellId:t,before:!0,noCreate:!0}),!0}return!1}}]),m.of([{linux:"Ctrl-[",win:"Ctrl-[",run:n=>{let e=w(n);return e?$(e)?e.state.vim.insertMode?(a.exitInsertMode(e,!0),!0):!1:(o.warn("Expected CodeMirror instance to have Vim state"),!1):(o.warn("Expected CodeMirror instance to have CodeMirror instance state"),!1)}}]),M.define(n=>(requestAnimationFrame(()=>{H.INSTANCES.addInstance(n)}),{destroy(){H.INSTANCES.removeInstance(n)}})),M.define(n=>new Ce({view:n})),ue.domEventHandlers({keydown(n,e){return n.ctrlKey&&n.key==="Escape"?(e.dom.dispatchEvent(new KeyboardEvent(n.type,n)),!0):!1}})]}var ke=h(()=>{a.defineAction("goToDefinition",n=>{let e=n.cm6;return ne(e)}),a.mapCommand("gd","action","goToDefinition",{},{context:"normal"}),a.defineEx("write","w",n=>{let e=n.cm6;e&&e.state.facet(v).saveNotebook()})}),De=h(async()=>{var e;let n=(e=p.get(I).keymap)==null?void 0:e.vimrc;if(n)try{o.log(`Loading vimrc from ${n}`);let t=(await pe().sendFileDetails({path:n})).contents;if(!t){o.error(`Failed to load vimrc from ${n}`);return}Se(be(t,o.warn))}catch(t){o.error("Failed to load vimrc:",t)}});function Se(n){function e(i){if(!i.args){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}if(!i.args.lhs||!i.args.rhs){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}i.mode?a.map(i.args.lhs,i.args.rhs,i.mode):a.map(i.args.lhs,i.args.rhs)}function t(i){if(!i.args){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}if(!i.args.lhs||!i.args.rhs){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}i.mode?a.noremap(i.args.lhs,i.args.rhs,i.mode):a.noremap(i.args.lhs,i.args.rhs)}function r(i){if(!i.args){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}if(!i.args.lhs){o.warn(`Could not execute vimrc command "${i.name}: expected arguments"`);return}i.mode?a.unmap(i.args.lhs,i.mode):a.unmap(i.args.lhs)}function s(i){i.mode?a.mapclear(i.mode):a.mapclear()}for(let i of n)"map|nmap|vmap|imap".split("|").includes(i.name)?e(i):"noremap|nnoremap|vnoremap|inoremap".split("|").includes(i.name)?t(i):"unmap|nunmap|vunmap|iunmap".split("|").includes(i.name)?r(i):"mapclear|nmapclear|vmapclear|imapclear".split("|").includes(i.name)?s(i):o.warn(`Could not execute vimrc command "${i.name}: unknown command"`)}var H=(g=class{constructor(){c(this,"instances",new Set);c(this,"isBroadcasting",!1)}addInstance(e){this.instances.add(e);let t=w(e);if(!t){o.warn("Expected CodeMirror instance to have CodeMirror instance state");return}t.on("vim-mode-change",r=>{this.isBroadcasting||(x("mode"in r,'Expected event to have a "mode" property'),this.isBroadcasting=!0,ye(()=>{this.broadcastModeChange(e,r.mode,r.subMode),this.isBroadcasting=!1}))})}removeInstance(e){this.instances.delete(e)}broadcastModeChange(e,t,r){x("exitInsertMode"in a,"Vim does not have an exitInsertMode method"),x("exitVisualMode"in a,"Vim does not have an exitVisualMode method");for(let s of this.instances)if(s!==e){let i=w(s);if(!i){o.warn("Expected CodeMirror instance to have CodeMirror instance state");continue}let u=i.setSelections.bind(i);if(i.setSelections=()=>[],!$(i)){o.warn("Expected CodeMirror instance to have Vim state");continue}let d=i.state.vim;switch(t){case"normal":d.insertMode&&a.exitInsertMode(i,!0),d.visualMode&&a.exitVisualMode(i,!0);break;case"insert":d.insertMode||a.handleKey(i,"i","");break;case"visual":break}i.setSelections=u}}},c(g,"INSTANCES",new g),g);function $(n){return n.state.vim!==void 0}const Ee=["default","vim"];function Me(n,e){switch(n.preset){case"default":return[m.of(V()),m.of(q(e))];case"vim":return[m.of(Fe()),m.of(q(e)),m.of([{key:"Enter",run:t=>{var r,s;return(s=(r=w(t))==null?void 0:r.state.vim)!=null&&s.insertMode?me(t):!1}}]),E.high(Oe("d",t=>t.state.doc.toString()==="",t=>t.state.doc.toString()===""?(t.state.facet(v).deleteCell(),!0):!1)),Z({status:!1}),E.high(Ie())];default:return se(n.preset),[]}}var Te=new Set([F,T]),V=h(()=>de.filter(n=>!Te.has(n.run))),q=n=>[{key:n.getHotkey("cell.toggleComment").key,run:F},{key:n.getHotkey("cell.toggleBlockComment").key,run:T}],Fe=h(()=>{let n=new Set(["Enter","Ctrl-v"]);return V().filter(e=>!n.has(e.key||e.mac||e.linux||e.win||""))});function Oe(n,e,t){let r="",s=0;return m.of([{any:(i,u)=>{let d=u.key,f=u.timeStamp;return d!==n||!e(i)?(r="",s=0,!1):r===n&&f-s<500&&t(i)?(r="",s=0,!0):(r=d,s=f,!1)}}])}var N="marimo:copilot:signedIn";const He=K(N,null,ee,{getOnInit:!0}),$e=b(null),C=b(null),k=b({busy:!1,kind:null,message:null});function Ve(n){p.set(C,n)}function qe(n){p.get(C)===n&&p.set(C,null)}function Ne(){return Y.getItem(N)==="true"}function _(){let n=Ne(),e=ae();return n&&e.completion.copilot==="github"}function _e(){return W(I,n=>n.completion.copilot==="github")}var Ue=J(),l=o.get("@github/copilot-language-server"),Ae=class extends R{constructor(e){super(e);c(this,"documentVersion",0);c(this,"hasOpenedDocument",!1);c(this,"copilotSettings",{});c(this,"getCompletionInternal",async(e,t)=>await this._request("textDocument/inlineCompletion",{...e,textDocument:{...e.textDocument,version:t}}));c(this,"throttledGetCompletionInternal",ve(this.getCompletionInternal,200));c(this,"handleNotification",e=>{if(!e.params)return;let t=e;if(t.method==="statusNotification"&&p.set(k,t.params),t.method==="didChangeStatus"&&p.set(k,t.params),t.method==="window/logMessage"){let{type:r,message:s}=t.params;switch(r){case 1:l.error("[GitHub Copilot]",s);break;case 2:l.warn("[GitHub Copilot]",s);break;case 3:l.debug("[GitHub Copilot]",s);break;default:l.log("[GitHub Copilot]",s);break}}});this.copilotSettings=e.copilotSettings??{},this.onNotification(this.handleNotification),this.attachInitializeListener()}attachInitializeListener(){this.initializePromise.then(()=>{this.sendConfiguration()})}async sendConfiguration(){let e=this.copilotSettings;!e||Object.keys(e).length===0||(await this.notify("workspace/didChangeConfiguration",{settings:e}),l.debug("#sendConfiguration: Configuration sent",e))}async _request(e,t){return await this.request(e,t)}async notify(e,t){return l.debug("#notify",e,t),super.notify(e,t)}getInitializationOptions(){let e={name:"marimo",version:"0.1.0"};return{...super.getInitializationOptions(),workspaceFolders:[],capabilities:{workspace:{workspaceFolders:!1}},initializationOptions:{editorInfo:e,editorPluginInfo:e}}}isDisabled(){return!_()}async textDocumentDidOpen(e){return this.isDisabled()?e:(this.hasOpenedDocument=!0,super.textDocumentDidOpen(e))}async textDocumentCompletion(e){return[]}async textDocumentDidChange(e){if(this.isDisabled())return e;this.hasOpenedDocument||await this.textDocumentDidOpen({textDocument:{uri:e.textDocument.uri,languageId:"python",version:e.textDocument.version,text:e.contentChanges[0].text}});let t=e.contentChanges;t.length!==1&&l.warn("#textDocumentDidChange: Multiple changes detected. This is not supported.",t);let r=t[0];"range"in r&&l.warn("#textDocumentDidChange: Copilot doesn't support range changes.",r);let s=Q(r.text);return super.textDocumentDidChange({...e,contentChanges:[{text:s}],textDocument:Ue.VersionedTextDocumentIdentifier.create(e.textDocument.uri,++this.documentVersion)})}textDocumentHover(e){return Promise.resolve({contents:[]})}signOut(){return this._request("signOut",{})}async signInInitiate(){l.log("#signInInitiate: Starting sign-in flow");try{let e=await this._request("signIn",{});return l.log("#signInInitiate: Sign-in flow started successfully"),e}catch(e){throw l.warn("#signInInitiate: Failed to start sign-in flow",e),e}}async signInConfirm(e){l.log("#signInConfirm: Confirming sign-in");try{let t=await this._request("signInConfirm",e);return l.log("#signInConfirm: Sign-in confirmed successfully"),t}catch(t){throw l.warn("#signInConfirm: Failed to confirm sign-in",t),t}}async signedIn(){try{let{status:e}=await this._request("checkStatus",{});return l.log("#checkStatus: Status check completed",{status:e}),e==="SignedIn"||e==="AlreadySignedIn"||e==="OK"}catch(e){throw l.warn("#signedIn: Failed to check sign-in status",e),e}}async getCompletion(e){if(this.isDisabled())return null;let t=this.documentVersion;if(e.textDocument.version=t,t===0)return null;Ve(t);let r=await this.throttledGetCompletionInternal(e,t);return qe(t),t===this.documentVersion?r??null:null}},Ge=te(),ze=P(),Le=class extends ze.Transport{constructor(e){super();c(this,"pendingSubscriptions",[]);this.delegate=void 0,this.pendingSubscriptions=[],this.options={retries:e.retries??3,retryDelayMs:e.retryDelayMs??1e3,maxTimeoutMs:e.maxTimeoutMs??5e3,getWsUrl:e.getWsUrl,waitForReady:e.waitForReady,showError:e.showError}}subscribe(...e){super.subscribe(...e);let[t,r]=e;this.pendingSubscriptions.push({event:t,handler:r}),this.delegate&&this.delegate.subscribe(t,r)}unsubscribe(...e){let t=super.unsubscribe(...e),[r,s]=e;if(this.delegate&&this.delegate.unsubscribe(r,s),s)if(r){let i=this.pendingSubscriptions.findIndex(u=>u.event===r&&u.handler===s);i>-1&&this.pendingSubscriptions.splice(i,1)}else this.pendingSubscriptions=this.pendingSubscriptions.filter(i=>i.handler!==s);else r?this.pendingSubscriptions=this.pendingSubscriptions.filter(i=>i.event!==r):this.pendingSubscriptions=[];return t}createDelegate(){let e=new Ge.WebSocketTransport(this.options.getWsUrl());for(let{event:t,handler:r}of this.pendingSubscriptions)e.subscribe(t,r);return e}async tryConnect(){for(let e=1;e<=this.options.retries;e++)try{this.delegate||(this.delegate=this.createDelegate()),await this.delegate.connect(),o.log("Copilot#connect: Connected successfully");return}catch(t){if(o.warn(`Copilot#connect: Connection attempt ${e}/${this.options.retries} failed`,t),e===this.options.retries)throw this.delegate=void 0,this.options.showError("GitHub Copilot Connection Error",`Failed to connect to GitHub Copilot. Please check your settings and try again.
|
|
3
|
-
|
|
4
|
-
`+he(t)),t;await new Promise(r=>setTimeout(r,this.options.retryDelayMs))}}async connect(){return await this.options.waitForReady(),this.tryConnect()}close(){var e;(e=this.delegate)==null||e.close(),this.delegate=void 0}async sendData(e,t){if(!this.delegate){o.log("Copilot#sendData: Delegate not initialized, reconnecting...");try{await this.options.waitForReady(),await this.tryConnect()}catch(r){throw o.error("Copilot#sendData: Failed to reconnect transport",r),Error("Unable to connect to GitHub Copilot. Please check your settings and try again.")}}if(!this.delegate)throw Error("Failed to initialize GitHub Copilot connection. Please try again.");return t=Math.min(t??this.options.maxTimeoutMs,this.options.maxTimeoutMs),this.delegate.sendData(e,t)}};const U="/__marimo_copilot__.py";var A=`file://${U}`;const We=h(()=>{let n=ce();return new Le({getWsUrl:()=>n.getLSPURL("copilot").toString(),waitForReady:async()=>{await _e(),await le()},showError:(e,t)=>{ge({variant:"danger",title:e,description:t})}})}),G=h(()=>{var e,t;let n=((t=(e=p.get(I).ai)==null?void 0:e.github)==null?void 0:t.copilot_settings)??{};return new Ae({rootUri:A,workspaceFolders:null,transport:We(),copilotSettings:n})});function Pe(){return ie({documentUri:A,client:G(),languageId:"copilot",hoverEnabled:!1,completionEnabled:!1,definitionEnabled:!1,renameEnabled:!1,codeActionsEnabled:!1,signatureHelpEnabled:!1,diagnosticsEnabled:!1,sendIncrementalChanges:!1})}export{k as a,He as c,$e as i,Ee as l,Pe as n,C as o,G as r,_ as s,U as t,Me as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as j}from"./chunk-LvLJmgfZ.js";import{t as w}from"./react-BGmjiNul.js";import{O as k}from"./cells-Ba_KE9BT.js";import{t as g}from"./compiler-runtime-DeeZ7FnK.js";import{t as N}from"./jsx-runtime-DN_bIXfG.js";import{t as y}from"./badge-DAnNhy3O.js";import{t as C}from"./use-toast-Bzf3rpev.js";import{i as _,r as b,t as I}from"./popover-DtnzNVk-.js";import{t as O}from"./copy-DRhpWiOq.js";import{t as v}from"./cell-link--tfL3CA1.js";var S=g(),i=j(N(),1);const B=p=>{let e=(0,S.c)(18),{maxCount:n,cellIds:r,onClick:t,skipScroll:o}=p,m=k(),l,a,c;if(e[0]!==r||e[1]!==m||e[2]!==n||e[3]!==t||e[4]!==o){c=Symbol.for("react.early_return_sentinel");e:{let f;e[8]===m?f=e[9]:(f=(s,x)=>m.inOrderIds.indexOf(s)-m.inOrderIds.indexOf(x),e[8]=m,e[9]=f);let u=[...r].sort(f);if(r.length===0){let s;e[10]===Symbol.for("react.memo_cache_sentinel")?(s=(0,i.jsx)("div",{className:"text-muted-foreground",children:"--"}),e[10]=s):s=e[10],c=s;break e}let h;e[11]!==r.length||e[12]!==t||e[13]!==o?(h=(s,x)=>(0,i.jsxs)("span",{className:"truncate",children:[(0,i.jsx)(v,{variant:"focus",cellId:s,skipScroll:o,className:"whitespace-nowrap",onClick:t?()=>t(s):void 0},s),x<r.length-1&&", "]},s),e[11]=r.length,e[12]=t,e[13]=o,e[14]=h):h=e[14],l=u.slice(0,n).map(h),a=r.length>n&&(0,i.jsxs)(I,{children:[(0,i.jsx)(_,{asChild:!0,children:(0,i.jsxs)("span",{className:"whitespace-nowrap text-muted-foreground text-xs hover:underline cursor-pointer",children:["+",r.length-n," more"]})}),(0,i.jsx)(b,{className:"w-auto",children:(0,i.jsx)("div",{className:"flex flex-col gap-1 py-1",children:u.slice(n).map(s=>(0,i.jsx)(v,{variant:"focus",cellId:s,className:"whitespace-nowrap",onClick:t?()=>t(s):void 0},s))})})]})}e[0]=r,e[1]=m,e[2]=n,e[3]=t,e[4]=o,e[5]=l,e[6]=a,e[7]=c}else l=e[5],a=e[6],c=e[7];if(c!==Symbol.for("react.early_return_sentinel"))return c;let d;return e[15]!==l||e[16]!==a?(d=(0,i.jsxs)(i.Fragment,{children:[l,a]}),e[15]=l,e[16]=a,e[17]=d):d=e[17],d};var F=g();w();const q=p=>{let e=(0,F.c)(15),n,r,t,o;e[0]===p?(n=e[1],r=e[2],t=e[3],o=e[4]):({name:r,declaredBy:n,onClick:t,...o}=p,e[0]=p,e[1]=n,e[2]=r,e[3]=t,e[4]=o);let m=n.length>1?"destructive":"outline",l;e[5]!==r||e[6]!==t?(l=async d=>{if(t){t(d);return}await O(r),C({title:"Copied to clipboard"})},e[5]=r,e[6]=t,e[7]=l):l=e[7];let a;e[8]!==r||e[9]!==m||e[10]!==l?(a=(0,i.jsx)(y,{title:r,variant:m,className:"rounded-sm text-ellipsis block overflow-hidden max-w-fit cursor-pointer font-medium",onClick:l,children:r}),e[8]=r,e[9]=m,e[10]=l,e[11]=a):a=e[11];let c;return e[12]!==o||e[13]!==a?(c=(0,i.jsx)("div",{className:"max-w-[130px]",...o,children:a}),e[12]=o,e[13]=a,e[14]=c):c=e[14],c};export{B as n,q as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as n,p as t}from"./useEvent-DlWF5OMa.js";import{ci as o}from"./cells-Ba_KE9BT.js";import{t as i}from"./invariant-C6yE60hi.js";import{t as a}from"./utils-CJJIceVn.js";function s(){let r=n.get(e);return o(r,"internal-error: initial mode not found"),i(r!=="present","internal-error: initial mode cannot be 'present'"),r}function m(r){return r==="read"?"read":r==="edit"?"present":"edit"}const d=t({mode:a()?"read":"not-set",cellAnchor:null}),e=t(void 0),l=t(!1);export{d as a,m as i,e as n,l as r,s as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as oe}from"./chunk-LvLJmgfZ.js";import{d as be,l as ye,n as V,p as ae,u as we}from"./useEvent-DlWF5OMa.js";import{t as Ne}from"./react-BGmjiNul.js";import{C as ke,Kr as ze,M as Ce,ei as Se,fn as Oe,ti as n,__tla as Ae}from"./cells-Ba_KE9BT.js";import"./react-dom-C9fstfnp.js";import{t as se}from"./compiler-runtime-DeeZ7FnK.js";import"./tooltip-CrRUCOBw.js";import{f as ie}from"./hotkeys-uKX61F1_.js";import{v as Ie}from"./utils-CJJIceVn.js";import{t as Me}from"./constants-Bkp4R3bQ.js";import"./config-DFDEcYvy.js";import{t as Le}from"./jsx-runtime-DN_bIXfG.js";import{t as z}from"./button-B8cGZzP5.js";import{t as le}from"./cn-C1rgT0yh.js";import"./dist-CAcX026F.js";import{n as Pe,__tla as Ee}from"./JsonOutput-vgVa8Uqm.js";import"./cjs-Bj40p_Np.js";import"./main-CwSdzVhm.js";import"./useNonce-EAuSVK-5.js";import{r as Re}from"./requests-C0HaHO6a.js";import{t as me}from"./createLucideIcon-CW2xpJ57.js";import{d as De,__tla as He}from"./layout-0e9X02ON.js";import{n as Ve,t as qe,__tla as Te}from"./LazyAnyLanguageCodeMirror-Cp2punaU.js";import"./download-BjwKjWNy.js";import"./markdown-renderer-DOsqiCxS.js";import{u as Ge}from"./toDate-5JckKRQn.js";import{t as Ke,__tla as Ue}from"./cell-editor-6RFkGM2j.js";import{t as Be}from"./play-BJDBXApx.js";import{t as Fe}from"./spinner-C1czjtp7.js";import"./dist-HGZzCB0y.js";import"./dist-CVj-_Iiz.js";import"./dist-BVf1IY4_.js";import"./dist-Cq_4nPfh.js";import"./dist-RKnr9SNh.js";import{r as Je}from"./useTheme-DfP1CWaW.js";import"./Combination-D1TsGrBC.js";import{t as C}from"./tooltip-CvjcEpZC.js";import"./dates-CdsE1R40.js";import"./popover-DtnzNVk-.js";import"./vega-loader.browser-C8wT63Va.js";import"./defaultLocale-BLUna9fQ.js";import"./defaultLocale-DzliDDTm.js";import"./purify.es-N-2faAGj.js";import{__tla as Qe}from"./chunk-OGVTOU66-CjNLT2C3.js";import"./katex-AwOI3EvM.js";import"./marked.esm-CHnOtnr3.js";import"./es-CHi7dcFm.js";import{o as We}from"./focus-DZZOzpQD.js";import{a as Xe}from"./renderShortcut-D0Pei-OA.js";import"./esm-B3JckBtM.js";import{n as Ye,r as Ze,t as ne}from"./react-resizable-panels.browser.esm-BqxQegSf.js";import"./name-cell-input-DwI5DL4H.js";import"./Inputs-DmoeP8nh.js";import{__tla as $e}from"./loro_wasm_bg-CghhyG7y.js";import"./ws-itdlXHqs.js";import"./dist-BRZzJw_5.js";import"./dist-P7JHert4.js";import"./dist-CoiWxjLF.js";import"./dist-cVYW_wBR.js";import"./dist-BAmo7Mv9.js";import"./dist-3oAtECdQ.js";import"./dist-D6Pwf0VF.js";import"./dist-D9HMoxdZ.js";import"./dist-JtCdI6tY.js";import"./esm-CCqLcax5.js";import{a as et,i as tt,t as rt}from"./kiosk-mode-lfj9N4vd.js";let ce,ot=Promise.all([(()=>{try{return Ae}catch{}})(),(()=>{try{return Ee}catch{}})(),(()=>{try{return He}catch{}})(),(()=>{try{return Te}catch{}})(),(()=>{try{return Ue}catch{}})(),(()=>{try{return Qe}catch{}})(),(()=>{try{return $e}catch{}})()]).then(async()=>{var de=me("eraser",[["path",{d:"M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21",key:"g5wo59"}],["path",{d:"m5.082 11.09 8.828 8.828",key:"1wx5vj"}]]),pe=me("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),he=se(),q=oe(Ne(),1),fe=15;const T=ze("marimo:scratchpadHistory:v1",[],Oe),ue=ae(!1),xe=ae(null,(e,s,i)=>{if(i=i.trim(),!i)return;let m=e(T);s(T,[i,...m.filter(c=>c!==i)].slice(0,fe))});var t=oe(Le(),1),_e={hide_code:!1,disabled:!1};const ve=()=>{var re;let e=(0,he.c)(60),s=Ce(),[i]=Ie(),{theme:m}=Je(),c=(0,q.useRef)(null),G=We(),{createNewCell:K,updateCellCode:d}=ke(),{sendRunScratchpad:p}=Re(),S=tt(),U=et(),l=s.cellRuntime[n],B=l==null?void 0:l.output,O=l==null?void 0:l.status,F=l==null?void 0:l.consoleOutputs,r=((re=s.cellData.__scratch__)==null?void 0:re.code)??"",J=be(xe),[a,h]=ye(ue),f=we(T),A;e[0]!==J||e[1]!==r||e[2]!==p?(A=()=>{p({code:r}),J(r)},e[0]=J,e[1]=r,e[2]=p,e[3]=A):A=e[3];let u=V(A),I;e[4]!==r||e[5]!==K||e[6]!==G?(I=()=>{r.trim()&&K({code:r,before:!1,cellId:G??"__end__"})},e[4]=r,e[5]=K,e[6]=G,e[7]=I):I=e[7];let Q=V(I),M;e[8]!==p||e[9]!==d?(M=()=>{d({cellId:n,code:"",formattingChange:!1}),p({code:""});let o=c.current;o&&o.dispatch({changes:{from:0,to:o.state.doc.length,insert:""}})},e[8]=p,e[9]=d,e[10]=M):M=e[10];let W=V(M),L;e[11]!==h||e[12]!==d?(L=o=>{h(!1),d({cellId:n,code:o,formattingChange:!1});let k=c.current;k&&k.dispatch({changes:{from:0,to:k.state.doc.length,insert:o}})},e[11]=h,e[12]=d,e[13]=L):L=e[13];let X=V(L),[Y,ge]=(0,q.useState)(),P;e[14]!==X||e[15]!==f||e[16]!==a||e[17]!==m?(P=()=>a?(0,t.jsx)("div",{className:"absolute inset-0 z-100 bg-background p-3 border-none overflow-auto",children:(0,t.jsx)("div",{className:"overflow-auto flex flex-col gap-3",children:f.map((o,k)=>(0,t.jsx)("div",{className:"border rounded-md hover:shadow-sm cursor-pointer hover:border-input overflow-hidden",onClick:()=>X(o),children:(0,t.jsx)(q.Suspense,{children:(0,t.jsx)(qe,{language:"python",theme:m,basicSetup:{highlightActiveLine:!1,highlightActiveLineGutter:!1},value:o.trim(),editable:!1,readOnly:!0})})},k))})}):null,e[14]=X,e[15]=f,e[16]=a,e[17]=m,e[18]=P):P=e[18];let Z=P,E;e[19]!==W||e[20]!==Q||e[21]!==u||e[22]!==f.length||e[23]!==a||e[24]!==h||e[25]!==O?(E=()=>(0,t.jsxs)("div",{className:"flex items-center shrink-0 border-b",children:[(0,t.jsx)(C,{content:Xe("cell.run"),children:(0,t.jsx)(z,{"data-testid":"scratchpad-run-button",onClick:u,disabled:a,variant:"text",size:"xs",children:(0,t.jsx)(Be,{color:"var(--grass-11)",size:16})})}),(0,t.jsx)(C,{content:"Clear code and outputs",children:(0,t.jsx)(z,{disabled:a,size:"xs",variant:"text",onClick:W,children:(0,t.jsx)(de,{size:16})})}),(0,t.jsx)(rt,{children:(0,t.jsx)(C,{content:"Insert code",children:(0,t.jsx)(z,{disabled:a,size:"xs",variant:"text",onClick:Q,children:(0,t.jsx)(Ve,{size:16})})})}),(O==="running"||O==="queued")&&(0,t.jsx)(Fe,{className:"inline",size:"small"}),(0,t.jsx)("div",{className:"flex-1"}),(0,t.jsx)(C,{content:"Toggle history",children:(0,t.jsx)(z,{size:"xs",variant:"text",className:le(a&&"bg-(--sky-3) rounded-none"),onClick:()=>h(!a),disabled:f.length===0,children:(0,t.jsx)(pe,{size:16})})}),(0,t.jsx)(C,{content:(0,t.jsx)("span",{className:"block max-w-prose",children:"Use this scratchpad to experiment with code without restrictions on variable names. Variables defined here aren't saved to notebook memory, and the code is not saved in the notebook file."}),children:(0,t.jsx)(z,{size:"xs",variant:"text",children:(0,t.jsx)(Ge,{size:16})})})]}),e[19]=W,e[20]=Q,e[21]=u,e[22]=f.length,e[23]=a,e[24]=h,e[25]=O,e[26]=E):E=e[26];let $=E,je=S==="vertical",R;e[27]===Symbol.for("react.memo_cache_sentinel")?(R=Se.create(n),e[27]=R):R=e[27];let x;e[28]===$?x=e[29]:(x=$(),e[28]=$,e[29]=x);let D;e[30]===Symbol.for("react.memo_cache_sentinel")?(D=o=>{c.current=o},e[30]=D):D=e[30];let _;e[31]!==r||e[32]!==u||e[33]!==Y||e[34]!==m||e[35]!==i?(_=(0,t.jsx)("div",{className:"flex-1 overflow-auto",children:(0,t.jsx)(Ke,{theme:m,showPlaceholder:!1,id:n,code:r,config:_e,status:"idle",serializedEditorState:null,runCell:u,userConfig:i,editorViewRef:c,setEditorView:D,hidden:!1,showHiddenCode:ie.NOOP,languageAdapter:Y,setLanguageAdapter:ge})}),e[31]=r,e[32]=u,e[33]=Y,e[34]=m,e[35]=i,e[36]=_):_=e[36];let v;e[37]===Z?v=e[38]:(v=Z(),e[37]=Z,e[38]=v);let g;e[39]!==v||e[40]!==x||e[41]!==_?(g=(0,t.jsx)(ne,{defaultSize:40,minSize:20,maxSize:70,children:(0,t.jsxs)("div",{className:"h-full flex flex-col overflow-hidden relative",children:[x,_,v]})}),e[39]=v,e[40]=x,e[41]=_,e[42]=g):g=e[42];let ee=je?"h-1":"w-1",j;e[43]===ee?j=e[44]:(j=le("bg-border hover:bg-primary/50 transition-colors",ee),e[43]=ee,e[44]=j);let b;e[45]===j?b=e[46]:(b=(0,t.jsx)(Ze,{className:j}),e[45]=j,e[46]=b);let y;e[47]===B?y=e[48]:(y=(0,t.jsx)("div",{className:"flex-1 overflow-auto",children:(0,t.jsx)(Pe,{allowExpand:!1,output:B,className:Me.outputArea,cellId:n,stale:!1,loading:!1})}),e[47]=B,e[48]=y);let w;e[49]===F?w=e[50]:(w=(0,t.jsx)("div",{className:"overflow-auto shrink-0 max-h-[50%]",children:(0,t.jsx)(De,{consoleOutputs:F,className:"overflow-auto",stale:!1,cellName:"_",onSubmitDebugger:ie.NOOP,cellId:n,debuggerActive:!1})}),e[49]=F,e[50]=w);let N;e[51]!==y||e[52]!==w?(N=(0,t.jsx)(ne,{defaultSize:60,minSize:20,children:(0,t.jsxs)("div",{className:"h-full flex flex-col divide-y overflow-hidden",children:[y,w]})}),e[51]=y,e[52]=w,e[53]=N):N=e[53];let H;return e[54]!==S||e[55]!==U||e[56]!==g||e[57]!==b||e[58]!==N?(H=(0,t.jsx)("div",{className:"flex flex-col h-full overflow-hidden",id:R,children:(0,t.jsxs)(Ye,{direction:S,className:"h-full",children:[g,b,N]},U)}),e[54]=S,e[55]=U,e[56]=g,e[57]=b,e[58]=N,e[59]=H):H=e[59],H};let te;te=se(),ce=()=>{let e=(0,te.c)(1),s;return e[0]===Symbol.for("react.memo_cache_sentinel")?(s=(0,t.jsx)(ve,{}),e[0]=s):s=e[0],s}});export{ot as __tla,ce as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{p as i}from"./useEvent-DlWF5OMa.js";import{Kr as l,dn as o,fn as h}from"./cells-Ba_KE9BT.js";import{d}from"./once-CTiSlR1m.js";import{t as m}from"./createLucideIcon-CW2xpJ57.js";var p=m("sparkles",[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]]),f="marimo:ai:chatState:v5";const v=i(null),u=l("marimo:ai:includeOtherCells",!0,h);function C(a){let t=new Map;for(let[s,e]of a.entries()){if(e.messages.length===0)continue;let c=d(e.messages,n=>n.id);t.set(s,{...e,messages:c})}return t}const r=l(f,{chats:new Map,activeChatId:null},o({toSerializable:a=>({chats:[...C(a.chats).entries()],activeChatId:a.activeChatId}),fromSerializable:a=>({chats:new Map(a.chats),activeChatId:a.activeChatId})})),I=i(a=>{let t=a(r);return t.activeChatId?t.chats.get(t.activeChatId):null},(a,t,s)=>{t(r,e=>({...e,activeChatId:s}))});export{p as a,u as i,v as n,r,I as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as v}from"./chunk-LvLJmgfZ.js";import{i as m,n as u}from"./useEvent-DlWF5OMa.js";import{C as p,g as C,v as D}from"./cells-Ba_KE9BT.js";import{t as h}from"./compiler-runtime-DeeZ7FnK.js";import{t as I}from"./useEventListener-COkmyg1v.js";import{t as x}from"./jsx-runtime-DN_bIXfG.js";import{t as _}from"./button-B8cGZzP5.js";import{r as g}from"./requests-C0HaHO6a.js";import{t as b}from"./use-toast-Bzf3rpev.js";import{n as j}from"./renderShortcut-D0Pei-OA.js";var w=h(),d=v(x(),1);const f=e=>{let t=(0,w.c)(7),l;t[0]===e?l=t[1]:(l=a=>{var s;(a.ctrlKey||a.metaKey)&&a.key==="z"&&(a.preventDefault(),a.stopPropagation(),(s=e.onClick)==null||s.call(e,a))},t[0]=e,t[1]=l);let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r={capture:!0},t[2]=r):r=t[2],I(window,"keydown",l,r);let o=e.children??"Undo",i;t[3]===Symbol.for("react.memo_cache_sentinel")?(i=(0,d.jsx)(j,{className:"ml-2",shortcut:"cmd-z"}),t[3]=i):i=t[3];let n;return t[4]!==o||t[5]!==e?(n=(0,d.jsxs)(_,{"data-testid":"undo-button",size:"sm",variant:"outline",...e,children:[o," ",i]}),t[4]=o,t[5]=e,t[6]=n):n=t[6],n};var y=h();function z(){let e=(0,y.c)(4),{deleteCell:t,undoDeleteCell:l}=p(),{sendDeleteCell:r}=g(),o;return e[0]!==t||e[1]!==r||e[2]!==l?(o=i=>{var s;if(m.get(C))return;let{cellId:n}=i,a=(((s=m.get(D).cellData[n])==null?void 0:s.code)??"").trim()==="";if(t({cellId:n}),r({cellId:n}).catch(()=>{l()}),!a){let{dismiss:c}=b({title:"Cell deleted",description:"You can bring it back by clicking undo or through the command palette.",action:(0,d.jsx)(f,{"data-testid":"undo-delete-button",onClick:()=>{l(),k()}})}),k=c}},e[0]=t,e[1]=r,e[2]=l,e[3]=o):o=e[3],u(o)}function K(){let e=(0,y.c)(4),{deleteCell:t,undoDeleteCell:l}=p(),{sendDeleteCell:r}=g(),o;return e[0]!==t||e[1]!==r||e[2]!==l?(o=async i=>{if(m.get(C))return;let{cellIds:n}=i;for(let c of n)await r({cellId:c}).then(()=>{t({cellId:c})});let{dismiss:a}=b({title:"Cells deleted",action:(0,d.jsx)(f,{"data-testid":"undo-delete-button",onClick:()=>{for(let c of n)l();s()}})}),s=a},e[0]=t,e[1]=r,e[2]=l,e[3]=o):o=e[3],u(o)}export{K as n,f as r,z as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as p}from"./chunk-LvLJmgfZ.js";import{t as y}from"./react-BGmjiNul.js";import{t as h}from"./compiler-runtime-DeeZ7FnK.js";import{t as E}from"./useEventListener-COkmyg1v.js";var I=h(),u=p(y(),1);function S(n,b){let t=(0,I.c)(11),{delayMs:l,whenVisible:e,disabled:v}=b,i=v===void 0?!1:v,r=(0,u.useRef)(void 0),s,o;t[0]===n?(s=t[1],o=t[2]):(s=()=>{r.current=n},o=[n],t[0]=n,t[1]=s,t[2]=o),(0,u.useEffect)(s,o);let a,c;t[3]!==l||t[4]!==i||t[5]!==e?(a=()=>{if(l===null||i)return;let m=setInterval(()=>{var d;e&&document.visibilityState!=="visible"||((d=r.current)==null||d.call(r))},l);return()=>clearInterval(m)},c=[l,e,i],t[3]=l,t[4]=i,t[5]=e,t[6]=a,t[7]=c):(a=t[6],c=t[7]),(0,u.useEffect)(a,c);let f;return t[8]!==i||t[9]!==e?(f=()=>{var m;document.visibilityState==="visible"&&e&&!i&&((m=r.current)==null||m.call(r))},t[8]=i,t[9]=e,t[10]=f):f=t[10],E(document,"visibilitychange",f),null}export{S as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as g,n as i,p as k}from"./useEvent-DlWF5OMa.js";import{C as v,_n as w,hr as F,p as f,rt as b,yr as _}from"./cells-Ba_KE9BT.js";import{t as x}from"./compiler-runtime-DeeZ7FnK.js";import{d as C}from"./hotkeys-uKX61F1_.js";import{o as D}from"./dist-DKNOF5xd.js";import{r as H}from"./requests-C0HaHO6a.js";var u=x();const y=k(!1);function V(){let r=(0,u.c)(2),n=p(),t;return r[0]===n?t=r[1]:(t=()=>n(_(f())),r[0]=n,r[1]=t),i(t)}function j(r){let n=(0,u.c)(3),t=p(),e;return n[0]!==r||n[1]!==t?(e=()=>{r!==void 0&&t([r])},n[0]=r,n[1]=t,n[2]=e):e=n[2],i(e)}function q(){let r=(0,u.c)(2),n=p(),t;return r[0]===n?t=r[1]:(t=()=>n(F(f())),r[0]=n,r[1]=t),i(t)}function p(){let r=(0,u.c)(4),{prepareForRun:n}=v(),{sendRun:t}=H(),e=g(y),o;return r[0]!==n||r[1]!==t||r[2]!==e?(o=async s=>{if(s.length===0)return;let c=f();return e(!0),I({cellIds:s,sendRun:t,prepareForRun:n,notebook:c})},r[0]=n,r[1]=t,r[2]=e,r[3]=o):o=r[3],i(o)}async function I({cellIds:r,sendRun:n,prepareForRun:t,notebook:e}){var m,h,R;if(r.length===0)return;let{cellHandles:o,cellData:s}=e,c=[];for(let a of r){let l=(h=(m=o[a])==null?void 0:m.current)==null?void 0:h.editorView,d;l?(w(l)!=="markdown"&&D(l),d=b(l)):d=((R=s[a])==null?void 0:R.code)||"",c.push(d),t({cellId:a})}await n({cellIds:r,codes:c}).catch(a=>{C.error(a)})}export{p as a,j as i,I as n,V as o,q as r,y as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as m}from"./chunk-LvLJmgfZ.js";import{n as p}from"./useEvent-DlWF5OMa.js";import{C as d,d as f,rt as u}from"./cells-Ba_KE9BT.js";import{t as c}from"./compiler-runtime-DeeZ7FnK.js";import{t as C}from"./jsx-runtime-DN_bIXfG.js";import{t as h}from"./use-toast-Bzf3rpev.js";import{r as v}from"./useDeleteCell-BHcO82VK.js";var x=c(),b=m(C(),1);function j(){let t=(0,x.c)(3),{splitCell:r,undoSplitCell:i}=d(),o;return t[0]!==r||t[1]!==i?(o=s=>{let l=f(s.cellId);if(!l)return;let a=u(l);r(s);let{dismiss:n}=h({title:"Cell split",action:(0,b.jsx)(v,{"data-testid":"undo-split-button",size:"sm",variant:"outline",onClick:()=>{i({...s,snapshot:a}),e()},children:"Undo"})}),e=n},t[0]=r,t[1]=i,t[2]=o):o=t[2],p(o)}export{j as t};
|
|
@@ -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{Gr as dt,Xr as ft,Zr as z,v as mt,y as pt,zr as ht}from"./cells-Ba_KE9BT.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{x as kt}from"./utils-CJJIceVn.js";import{j as Rt}from"./config-DFDEcYvy.js";import{a as Ft}from"./switch-eOpIZoDX.js";import{n as he}from"./globals-Dh1hxKNk.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-vgVa8Uqm.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-DOsqiCxS.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-BCyUhVQM.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-BqxQegSf.js";import{t as Ee}from"./toggle-G1t0cQyf.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 Re=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)}},Fe=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 F=new Proxy(_,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>_(f,c)}),C=F;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 R=new Proxy(k,{get:(o,f,g)=>f in o?Reflect.get(o,f,g):c=>k(f,c)}),v=R,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:F,requestProxy:C,send:R,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(mt),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 ht(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)}},Rn={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,Rn]);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(pt)||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}),Ft.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,"autoExportAsHTML",y);a(this,"autoExportAsMarkdown",y);a(this,"autoExportAsIPYNB",y);a(this,"writeSecret",y);a(this,"invokeAiTool",y);a(this,"clearCache",y);a(this,"getCacheInfo",y);Rt()&&(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 Fn(){return Fe.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:ft(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=dt({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,R=p.current;if(!C||!k&&!R)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),R&&R.addEventListener("mousedown",g),()=>{k&&k.removeEventListener("mousedown",f),R&&R.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`,F;return e[6]===_?F=e[7]:(F={resizableDivRef:d,handleRefs:w,style:{width:_}},e[6]=_,e[7]=F),F};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,F;t[8]!==x||t[9]!==_?(F=()=>(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)(Re,{name:B.CONTEXT_AWARE_PANEL})})]}),t[8]=x,t[9]=_,t[10]=F):F=t[10];let C=F;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 R;return t[14]===C?R=t[15]:(R=(0,m.jsxs)(m.Fragment,{children:[k,(0,m.jsx)(Vt,{defaultSize:20,minSize:15,maxSize:80,children:C()})]}),t[14]=C,t[15]=R),R},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{Fn 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,Fe as rt,I as s,un as st,le as t,xn as tt,rr as u,Re as ut,ie as v,Hn as w,Kn as x,Gn as y,jn as z};
|