@marimo-team/islands 0.24.1-dev61 → 0.24.1-dev62

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.
@@ -3,12 +3,12 @@ import { c as n, g as r, h as i, t as a } from "./button-DOCIubLd.js";
3
3
  import { t as o } from "./react-DMWcHin-.js";
4
4
  import { t as s } from "./compiler-runtime-CAH9RLw2.js";
5
5
  import { r as c } from "./copy-DgAphl4k.js";
6
- import { Dn as l, F as u, Fn as d, Ft as f, G as p, Gn as m, Hn as h, In as g, Nt as _, Qt as v, Rt as y, Wn as b, Wt as x, Xn as S, Xt as C, Zt as w, _ as ee, a as T, c as E, cn as te, d as D, dn as ne, dt as re, en as ie, et as ae, f as oe, ft as se, g as ce, gn as le, h as ue, ht as de, kn as fe, kt as pe, l as me, ln as he, lt as ge, m as _e, n as ve, on as ye, p as be, qn as xe, r as Se, sn as Ce, t as we, v as Te, x as Ee, y as De, zt as Oe } from "./html-to-image-DnwkphJg.js";
6
+ import { Dn as l, F as u, Fn as d, Ft as f, G as p, Gn as m, Hn as h, In as g, Nt as _, Qt as v, Rt as y, Wn as b, Wt as x, Xn as S, Xt as C, Zt as w, _ as ee, a as T, c as E, cn as te, d as D, dn as ne, dt as re, en as ie, et as ae, f as oe, ft as se, g as ce, gn as le, h as ue, ht as de, kn as fe, kt as pe, l as me, ln as he, lt as ge, m as _e, n as ve, on as ye, p as be, qn as xe, r as Se, sn as Ce, t as we, v as Te, x as Ee, y as De, zt as Oe } from "./html-to-image-ChI8i0f-.js";
7
7
  import { u as ke } from "./dist-DTSuOdDc.js";
8
8
  import { C as Ae, I as je, R as Me, b as Ne } from "./select-Bakm9EUs.js";
9
9
  import { f as Pe, g as Fe, i as Ie, n as Le, t as Re, v as ze } from "./dropdown-menu-DrzAtluA.js";
10
10
  import { _ as Be, p as Ve } from "./toDate-Mzvy7JMZ.js";
11
- import { d as He, f as Ue, i as We, n as Ge, t as Ke, u as qe } from "./process-output-BkiZCdL9.js";
11
+ import { d as He, f as Ue, i as We, n as Ge, t as Ke, u as qe } from "./process-output-e5z-_0AB.js";
12
12
  import { t as Je } from "./jsx-runtime-CpoKNRgu.js";
13
13
  import { Cn as O, Cr as Ye, In as k, It as Xe, Jn as A, Sn as Ze, Tt as Qe, Yn as $e, bt as et, cn as tt, jn as nt, kt as j, ln as M, mr as rt, un as N, vt as it, wt as at, xt as ot, zt as st } from "./schemas-DeBAkn_c.js";
14
14
  import { n as ct } from "./error-banner-BT4uIIQ2.js";
@@ -3,7 +3,7 @@ import { _ as n, f as r, g as i, h as a, m as o, n as s, p as c, r as l, t as u
3
3
  import { t as d } from "./react-DMWcHin-.js";
4
4
  import { t as f } from "./compiler-runtime-CAH9RLw2.js";
5
5
  import { n as p, r as m, t as h } from "./copy-DgAphl4k.js";
6
- import { $n as g, A as _, An as v, Bn as y, Bt as b, Cn as x, Ct as S, D as C, Dn as w, Dt as T, E, F as D, Fn as O, G as k, Gn as A, Hn as j, In as M, It as N, Jt as P, Kn as F, Kt as I, Lt as L, M as R, Mt as ee, N as z, Qn as te, Rn as ne, Rt as re, S as ie, T as ae, Tn as oe, Tt as se, V as ce, Vn as B, Wn as le, Wt as ue, X as de, Xn as fe, Y as pe, Z as me, _ as he, _n as ge, at as _e, dt as ve, en as ye, er as V, fn as be, ft as xe, g as Se, gn as Ce, ht as we, lt as Te, mt as Ee, n as De, nn as Oe, nt as ke, pt as Ae, qn as je, qt as Me, r as Ne, s as Pe, t as Fe, tt as Ie, u as Le, ut as Re, v as ze, w as Be, wn as Ve, wt as He, y as Ue, yt as We } from "./html-to-image-DnwkphJg.js";
6
+ import { $n as g, A as _, An as v, Bn as y, Bt as b, Cn as x, Ct as S, D as C, Dn as w, Dt as T, E, F as D, Fn as O, G as k, Gn as A, Hn as j, In as M, It as N, Jt as P, Kn as F, Kt as I, Lt as L, M as R, Mt as ee, N as z, Qn as te, Rn as ne, Rt as re, S as ie, T as ae, Tn as oe, Tt as se, V as ce, Vn as B, Wn as le, Wt as ue, X as de, Xn as fe, Y as pe, Z as me, _ as he, _n as ge, at as _e, dt as ve, en as ye, er as V, fn as be, ft as xe, g as Se, gn as Ce, ht as we, lt as Te, mt as Ee, n as De, nn as Oe, nt as ke, pt as Ae, qn as je, qt as Me, r as Ne, s as Pe, t as Fe, tt as Ie, u as Le, ut as Re, v as ze, w as Be, wn as Ve, wt as He, y as Ue, yt as We } from "./html-to-image-ChI8i0f-.js";
7
7
  import { o as Ge, u as H } from "./dist-DTSuOdDc.js";
8
8
  import { c as Ke, i as qe, r as Je } from "./useLifecycle-ClOphI_o.js";
9
9
  import { a as Ye, i as Xe, n as Ze, o as Qe, r as $e, t as et } from "./useDateFormatter-DjRKOAkR.js";
@@ -31786,7 +31786,7 @@ function ZG() {
31786
31786
  return i.warn("Failed to get version from mount config"), null;
31787
31787
  }
31788
31788
  }
31789
- var QG = ZG() || "0.24.1-dev61", $G = xi(QG), eK = xi(!0);
31789
+ var QG = ZG() || "0.24.1-dev62", $G = xi(QG), eK = xi(!0);
31790
31790
  xi(null);
31791
31791
  //#endregion
31792
31792
  //#region src/core/meta/code-visibility.ts
@@ -22865,8 +22865,8 @@ function Yg(e, t) {
22865
22865
  var Xg = P((e) => {
22866
22866
  let t = e($);
22867
22867
  return pn.fromEntries(t.cellIds.inOrderIds.map((e) => {
22868
- let n = t.cellHandles[e];
22869
- return [e, n?.current?.editorView ? cC(n.current.editorView) : ""];
22868
+ let n = t.cellHandles[e]?.current?.editorViewOrNull;
22869
+ return [e, n ? cC(n) : t.cellData[e]?.code ?? ""];
22870
22870
  }));
22871
22871
  }), Zg = P((e) => e($).cellIds.inOrderIds), Qg = P((e) => e_(e(Zg), e(Pm))), $g = P((e) => ({
22872
22872
  cellIds: e(Qg),
package/dist/main.js CHANGED
@@ -3,16 +3,16 @@ import { _ as a, c as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p,
3
3
  import { t as y } from "./react-DMWcHin-.js";
4
4
  import { t as b } from "./compiler-runtime-CAH9RLw2.js";
5
5
  import { n as x, r as S, t as C } from "./copy-DgAphl4k.js";
6
- import { $t as w, At as T, B as E, C as D, Cn as O, Ct as k, Dn as A, Dt as j, En as M, Et as N, F as P, Ft as F, G as I, Gn as L, Gt as ee, H as te, Hn as R, Ht as ne, I as z, In as re, J as ie, Jn as ae, K as oe, Kn as se, Kt as ce, L as le, Ln as ue, Mn as de, Nn as fe, On as pe, Ot as me, P as he, Pn as ge, Pt as _e, Q as ve, Qn as ye, R as be, Rt as xe, Sn as Se, St as Ce, Tt as we, U as Te, Un as Ee, Ut as De, Vt as Oe, W as ke, Wn as Ae, X as je, Y as Me, Yn as Ne, Yt as Pe, Zn as Fe, _ as Ie, _n as Le, _t as Re, a as ze, an as Be, b as Ve, bn as He, bt as Ue, ct as We, en as Ge, g as Ke, gt as qe, hn as Je, i as Ye, in as Xe, it as Ze, j as Qe, jn as $e, jt as et, k as tt, mn as nt, n as rt, nn as it, nt as at, o as ot, ot as st, pn as ct, q as lt, rn as ut, rt as dt, st as ft, tn as pt, un as mt, v as ht, vt as gt, xn as _t, xt as vt, y as yt, yn as bt, yt as xt, z as St, zn as Ct } from "./html-to-image-DnwkphJg.js";
6
+ import { $t as w, At as T, B as E, C as D, Cn as O, Ct as k, Dn as A, Dt as j, En as M, Et as N, F as P, Ft as F, G as I, Gn as L, Gt as ee, H as te, Hn as R, Ht as ne, I as z, In as re, J as ie, Jn as ae, K as oe, Kn as se, Kt as ce, L as le, Ln as ue, Mn as de, Nn as fe, On as pe, Ot as me, P as he, Pn as ge, Pt as _e, Q as ve, Qn as ye, R as be, Rt as xe, Sn as Se, St as Ce, Tt as we, U as Te, Un as Ee, Ut as De, Vt as Oe, W as ke, Wn as Ae, X as je, Y as Me, Yn as Ne, Yt as Pe, Zn as Fe, _ as Ie, _n as Le, _t as Re, a as ze, an as Be, b as Ve, bn as He, bt as Ue, ct as We, en as Ge, g as Ke, gt as qe, hn as Je, i as Ye, in as Xe, it as Ze, j as Qe, jn as $e, jt as et, k as tt, mn as nt, n as rt, nn as it, nt as at, o as ot, ot as st, pn as ct, q as lt, rn as ut, rt as dt, st as ft, tn as pt, un as mt, v as ht, vt as gt, xn as _t, xt as vt, y as yt, yn as bt, yt as xt, z as St, zn as Ct } from "./html-to-image-ChI8i0f-.js";
7
7
  import { o as wt, s as Tt, u as Et } from "./dist-DTSuOdDc.js";
8
8
  import { D as Dt, E as Ot, O as kt, S as At, T as jt, _ as Mt, a as Nt, c as Pt, d as Ft, f as It, g as Lt, h as Rt, i as zt, l as Bt, m as Vt, n as Ht, o as Ut, p as Wt, r as Gt, s as Kt, t as qt, u as Jt, v as Yt, w as Xt, x as Zt, y as Qt } from "./spec-iNjNWU_x.js";
9
- import { $ as $t, $t as en, A as tn, At as nn, B as rn, Bt as an, C as on, Ct as sn, D as cn, Dt as ln, E as un, Et as dn, F as fn, Ft as pn, G as mn, Gt as hn, H as gn, Ht as _n, I as vn, It as yn, Jt as bn, K as xn, Kt as Sn, L as Cn, Lt as wn, M as Tn, Mt as En, N as Dn, Nt as On, O as kn, Ot as An, P as jn, Pt as Mn, Q as Nn, Qt as Pn, R as Fn, Rt as In, S as Ln, St as Rn, T as zn, Tt as Bn, U as Vn, Ut as Hn, V as Un, Vt as Wn, W as Gn, Wt as Kn, Xt as qn, Yt as Jn, Z as Yn, Zt as Xn, _ as Zn, an as Qn, at as $n, b as er, bt as tr, c as nr, cn as rr, ct as ir, d as ar, dn as or, dt as sr, en as cr, et as lr, f as ur, fn as dr, ft as fr, g as pr, gt as mr, h as hr, ht as gr, i as _r, it as vr, j as yr, jt as br, k as xr, kt as Sr, ln as Cr, lt as wr, m as Tr, mt as Er, n as Dr, nn as Or, nt as kr, on as Ar, ot as jr, p as Mr, pn as Nr, pt as Pr, q as Fr, qt as Ir, r as Lr, rn as Rr, rt as zr, sn as Br, st as Vr, t as Hr, tn as Ur, tt as Wr, u as Gr, un as Kr, ut as qr, v as Jr, w as Yr, wt as Xr, x as Zr, xt as Qr, y as $r, yt as ei, z as ti, zt as ni } from "./common-B_E9_TZZ.js";
9
+ import { $ as $t, $t as en, A as tn, At as nn, B as rn, Bt as an, C as on, Ct as sn, D as cn, Dt as ln, E as un, Et as dn, F as fn, Ft as pn, G as mn, Gt as hn, H as gn, Ht as _n, I as vn, It as yn, Jt as bn, K as xn, Kt as Sn, L as Cn, Lt as wn, M as Tn, Mt as En, N as Dn, Nt as On, O as kn, Ot as An, P as jn, Pt as Mn, Q as Nn, Qt as Pn, R as Fn, Rt as In, S as Ln, St as Rn, T as zn, Tt as Bn, U as Vn, Ut as Hn, V as Un, Vt as Wn, W as Gn, Wt as Kn, Xt as qn, Yt as Jn, Z as Yn, Zt as Xn, _ as Zn, an as Qn, at as $n, b as er, bt as tr, c as nr, cn as rr, ct as ir, d as ar, dn as or, dt as sr, en as cr, et as lr, f as ur, fn as dr, ft as fr, g as pr, gt as mr, h as hr, ht as gr, i as _r, it as vr, j as yr, jt as br, k as xr, kt as Sr, ln as Cr, lt as wr, m as Tr, mt as Er, n as Dr, nn as Or, nt as kr, on as Ar, ot as jr, p as Mr, pn as Nr, pt as Pr, q as Fr, qt as Ir, r as Lr, rn as Rr, rt as zr, sn as Br, st as Vr, t as Hr, tn as Ur, tt as Wr, u as Gr, un as Kr, ut as qr, v as Jr, w as Yr, wt as Xr, x as Zr, xt as Qr, y as $r, yt as ei, z as ti, zt as ni } from "./common-Cnz6W9yD.js";
10
10
  import { c as ri, i as ii, n as ai, o as oi, t as si } from "./useLifecycle-ClOphI_o.js";
11
11
  import { t as ci } from "./check-DIJJHY-E.js";
12
12
  import { A as li, C as ui, D as di, E as fi, F as pi, I as mi, M as hi, N as gi, P as _i, R as vi, S as yi, a as bi, b as xi, c as Si, i as Ci, j as wi, l as Ti, n as Ei, o as Di, r as Oi, s as ki, t as Ai, w as ji, x as Mi } from "./select-Bakm9EUs.js";
13
13
  import { B as Ni, C as Pi, Ft as Fi, G as Ii, It as Li, S as Ri, V as zi, Wt as Bi, X as Vi, Y as Hi, _ as Ui, a as Wi, c as Gi, f as Ki, g as qi, gn as Ji, h as Yi, hn as Xi, i as Zi, m as Qi, n as $i, ot as ea, pt as ta, r as na, s as ra, st as ia, t as aa, v as oa, w as sa, xt as ca, y as la } from "./dropdown-menu-DrzAtluA.js";
14
14
  import { _ as ua, c as da, d as fa, f as pa, g as ma, h as ha, m as ga, u as _a } from "./toDate-Mzvy7JMZ.js";
15
- import { a as va, c as ya, d as ba, f as xa, i as Sa, l as Ca, n as wa, o as Ta, r as Ea, s as Da, t as Oa } from "./process-output-BkiZCdL9.js";
15
+ import { a as va, c as ya, d as ba, f as xa, i as Sa, l as Ca, n as wa, o as Ta, r as Ea, s as Da, t as Oa } from "./process-output-e5z-_0AB.js";
16
16
  import { i as ka, n as Aa, r as ja, t as Ma } from "./types-D8U7wKuc.js";
17
17
  import { n as Na, t as Pa } from "./ErrorBoundary-BF3QLrI_.js";
18
18
  import { t as Fa } from "./react-dom-C94wmq5w.js";
@@ -15397,7 +15397,7 @@ var uM = (e) => {
15397
15397
  output: t
15398
15398
  };
15399
15399
  } };
15400
- } }, gM = q.lazy(() => import("./chat-ui-DYcwIX9k.js").then((e) => ({ default: e.Chatbot }))), _M = U(B({
15400
+ } }, gM = q.lazy(() => import("./chat-ui-DZQth8T9.js").then((e) => ({ default: e.Chatbot }))), _M = U(B({
15401
15401
  id: V(),
15402
15402
  role: Pp([
15403
15403
  "system",
@@ -35256,7 +35256,7 @@ function Gq(e) {
35256
35256
  }
35257
35257
  //#endregion
35258
35258
  //#region src/components/editor/renderers/slides-layout/slides-layout.tsx
35259
- var Kq = q.lazy(() => import("./reveal-component-iJ-KAo0l.js")), qq = (e) => {
35259
+ var Kq = q.lazy(() => import("./reveal-component-AIH6_R6K.js")), qq = (e) => {
35260
35260
  let t = (0, Y.c)(33), { layout: n, setLayout: r, cells: i, mode: a } = e, o = Nm(k), s = a === "read" || o, c = Nm(lt) > 1, [l, u] = (0, q.useState)(null), d;
35261
35261
  t[0] !== i || t[1] !== n ? (d = UU(i, n), t[0] = i, t[1] = n, t[2] = d) : d = t[2];
35262
35262
  let { slideCells: f, skippedIds: p, noOutputIds: m, slideTypes: h, startCellIndex: g } = d, _;
@@ -1,4 +1,4 @@
1
- import { $ as e, O as t, et as n } from "./html-to-image-DnwkphJg.js";
1
+ import { $ as e, O as t, et as n } from "./html-to-image-ChI8i0f-.js";
2
2
  import { u as r } from "./dist-DTSuOdDc.js";
3
3
  import { b as i } from "./select-Bakm9EUs.js";
4
4
  import { n as a } from "./semaphore-89jsoHtS.js";
@@ -2,9 +2,9 @@ import { a as e } from "./rolldown-runtime-Cb76FRpK.js";
2
2
  import { c as t, g as n, h as r, m as i, t as a } from "./button-DOCIubLd.js";
3
3
  import { t as o } from "./react-DMWcHin-.js";
4
4
  import { t as s } from "./compiler-runtime-CAH9RLw2.js";
5
- import { Ct as c, rt as l } from "./html-to-image-DnwkphJg.js";
5
+ import { Ct as c, rt as l } from "./html-to-image-ChI8i0f-.js";
6
6
  import { u } from "./dist-DTSuOdDc.js";
7
- import { J as d, X as f, Y as p, in as m, l as h, n as g, rn as _, sn as v, t as y, u as b } from "./common-B_E9_TZZ.js";
7
+ import { J as d, X as f, Y as p, in as m, l as h, n as g, rn as _, sn as v, t as y, u as b } from "./common-Cnz6W9yD.js";
8
8
  import { R as x } from "./select-Bakm9EUs.js";
9
9
  import { X as S } from "./dropdown-menu-DrzAtluA.js";
10
10
  import { t as C } from "./jsx-runtime-CpoKNRgu.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.24.1-dev61",
3
+ "version": "0.24.1-dev62",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -5,13 +5,18 @@ import { EditorView } from "@codemirror/view";
5
5
  import { describe, expect, it } from "vitest";
6
6
  import { cellId, variableName } from "@/__tests__/branded";
7
7
  import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
8
+ import { createCell } from "@/core/cells/types";
8
9
  import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
9
10
  import { store } from "@/core/state/jotai";
10
11
  import { variablesAtom } from "@/core/variables/state";
11
12
  import { MultiColumn } from "@/utils/id-tree";
12
13
  import { cellConfigExtension } from "../../config/extension";
13
14
  import { adaptiveLanguageConfiguration } from "../../language/extension";
14
- import { getCodes, getTopologicalCellIds } from "../getCodes";
15
+ import {
16
+ getCodes,
17
+ getTopologicalCellIds,
18
+ topologicalCodesAtom,
19
+ } from "../getCodes";
15
20
 
16
21
  const Cells = {
17
22
  cell1: cellId("cell1"),
@@ -208,4 +213,64 @@ describe("getCodes", () => {
208
213
  const result = getCodes(otherCode);
209
214
  expect(result).toEqual("import os\nx = 1\ny = x + 1\nprint('Hello World')");
210
215
  });
216
+
217
+ it("should read code from the store when no editor is mounted", () => {
218
+ const otherCode = "print('Hello World')";
219
+ store.set(notebookAtom, {
220
+ ...initialNotebookState(),
221
+ cellIds: MultiColumn.from([[Cells.cell1, Cells.cell2]]),
222
+ cellData: {
223
+ [Cells.cell1]: createCell({ id: Cells.cell1, code: "import os" }),
224
+ [Cells.cell2]: createCell({ id: Cells.cell2, code: "x = 1" }),
225
+ },
226
+ });
227
+ const result = getCodes(otherCode);
228
+ expect(result).toEqual("import os\nx = 1\nprint('Hello World')");
229
+ });
230
+
231
+ it("should prefer the mounted editor code over the store code", () => {
232
+ const otherCode = "print('Hello World')";
233
+ store.set(notebookAtom, {
234
+ ...initialNotebookState(),
235
+ cellIds: MultiColumn.from([[Cells.cell1, Cells.cell2]]),
236
+ cellData: {
237
+ [Cells.cell1]: createCell({ id: Cells.cell1, code: "import os" }),
238
+ [Cells.cell2]: createCell({ id: Cells.cell2, code: "x = 1" }),
239
+ },
240
+ cellHandles: {
241
+ [Cells.cell2]: { current: createMockEditorView("x = 2") },
242
+ },
243
+ });
244
+ const result = getCodes(otherCode);
245
+ expect(result).toEqual("import os\nx = 2\nprint('Hello World')");
246
+ });
247
+ });
248
+
249
+ describe("topologicalCodesAtom", () => {
250
+ it("should include every cell when no editor is mounted", () => {
251
+ store.set(notebookAtom, {
252
+ ...initialNotebookState(),
253
+ cellIds: MultiColumn.from([[Cells.cell1, Cells.cell2, Cells.cell3]]),
254
+ cellData: {
255
+ [Cells.cell1]: createCell({ id: Cells.cell1, code: "import os" }),
256
+ [Cells.cell2]: createCell({ id: Cells.cell2, code: "x = 1" }),
257
+ [Cells.cell3]: createCell({ id: Cells.cell3, code: "y = x + 1" }),
258
+ },
259
+ });
260
+ store.set(variablesAtom, {
261
+ [Variables.var1]: {
262
+ name: Variables.var1,
263
+ declaredBy: [Cells.cell1],
264
+ usedBy: [Cells.cell2, Cells.cell3],
265
+ },
266
+ });
267
+
268
+ const { cellIds, codes } = store.get(topologicalCodesAtom);
269
+ expect(cellIds).toEqual([Cells.cell1, Cells.cell2, Cells.cell3]);
270
+ expect(codes).toEqual({
271
+ [Cells.cell1]: "import os",
272
+ [Cells.cell2]: "x = 1",
273
+ [Cells.cell3]: "y = x + 1",
274
+ });
275
+ });
211
276
  });
@@ -1,13 +1,32 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { atom } from "jotai";
4
- import { getAllEditorViews, notebookAtom } from "@/core/cells/cells";
4
+ import { notebookAtom } from "@/core/cells/cells";
5
5
  import type { CellId } from "@/core/cells/ids";
6
+ import { store } from "@/core/state/jotai";
6
7
  import { variablesAtom } from "@/core/variables/state";
7
8
  import type { Variables } from "@/core/variables/types";
8
9
  import { Objects } from "@/utils/objects";
9
10
  import { getEditorCodeAsPython } from "../language/utils";
10
11
 
12
+ const notebookCellCodes = atom((get) => {
13
+ const notebook = get(notebookAtom);
14
+ const codes = Objects.fromEntries(
15
+ notebook.cellIds.inOrderIds.map((id) => {
16
+ // A cell editor mounts progressively, so the notebook store is the only
17
+ // complete source of code until every editor is built.
18
+ const editorView = notebook.cellHandles[id]?.current?.editorViewOrNull;
19
+ return [
20
+ id,
21
+ editorView
22
+ ? getEditorCodeAsPython(editorView)
23
+ : (notebook.cellData[id]?.code ?? ""),
24
+ ];
25
+ }),
26
+ );
27
+ return codes;
28
+ });
29
+
11
30
  export function getCodes(otherCode: string) {
12
31
  const codes = getOtherCellsCode(otherCode);
13
32
 
@@ -18,15 +37,8 @@ export function getOtherCellsCode(otherCode: string) {
18
37
  // Get all other cells' code
19
38
  // Put `import` statements at the top, as it can help copilot give better suggestions
20
39
  // TODO: we should sort this topologically
21
- const codes = getAllEditorViews()
22
- .map((editorView) => {
23
- const code = getEditorCodeAsPython(editorView);
24
- if (code === otherCode) {
25
- return null;
26
- }
27
- return code;
28
- })
29
- .filter(Boolean)
40
+ const codes = Object.values(store.get(notebookCellCodes))
41
+ .filter((code) => code !== "" && code !== otherCode)
30
42
  .toSorted((a, b) => {
31
43
  if (a.startsWith("import") && !b.startsWith("import")) {
32
44
  return -1;
@@ -40,21 +52,6 @@ export function getOtherCellsCode(otherCode: string) {
40
52
  return codes;
41
53
  }
42
54
 
43
- const notebookCellCodes = atom((get) => {
44
- const notebook = get(notebookAtom);
45
- const codes = Objects.fromEntries(
46
- notebook.cellIds.inOrderIds.map((id) => {
47
- const handle = notebook.cellHandles[id];
48
- return [
49
- id,
50
- handle?.current?.editorView
51
- ? getEditorCodeAsPython(handle.current.editorView)
52
- : "",
53
- ];
54
- }),
55
- );
56
- return codes;
57
- });
58
55
  const inOrderCellIdsAtom = atom((get) => {
59
56
  const notebook = get(notebookAtom);
60
57
  return notebook.cellIds.inOrderIds;
@@ -8,7 +8,10 @@ import { beforeEach, describe, expect, it, type Mocked, vi } from "vitest";
8
8
  import * as LSP from "vscode-languageserver-protocol";
9
9
  import { cellId } from "@/__tests__/branded";
10
10
  import type { CellId } from "@/core/cells/ids";
11
+ import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
12
+ import { createCell } from "@/core/cells/types";
11
13
  import { store } from "@/core/state/jotai";
14
+ import { MultiColumn } from "@/utils/id-tree";
12
15
  import { topologicalCodesAtom } from "../../copilot/getCodes";
13
16
  import { lspWorkspaceAtom } from "@/core/saving/file-state";
14
17
  import { languageAdapterState } from "../../language/extension";
@@ -62,6 +65,28 @@ function isPublishDiagnosticsNotification(
62
65
  );
63
66
  }
64
67
 
68
+ describe("merged document with unmounted editors", () => {
69
+ it("should include the code of cells whose editors are not mounted", () => {
70
+ store.set(notebookAtom, {
71
+ ...initialNotebookState(),
72
+ cellIds: MultiColumn.from([[Cells.cell1, Cells.cell2]]),
73
+ cellData: {
74
+ [Cells.cell1]: createCell({ id: Cells.cell1, code: "import math" }),
75
+ [Cells.cell2]: createCell({
76
+ id: Cells.cell2,
77
+ code: "print(math.sqrt(4))",
78
+ }),
79
+ },
80
+ });
81
+
82
+ const { cellIds, codes } = store.get(topologicalCodesAtom);
83
+ const lens = createNotebookLens(cellIds, codes);
84
+
85
+ expect(lens.mergedText).toContain("import math");
86
+ expect(lens.mergedText).toContain("print(math.sqrt(4))");
87
+ });
88
+ });
89
+
65
90
  describe("createNotebookLens", () => {
66
91
  it("should produce correct lens for same inputs", () => {
67
92
  // Use unique content for this test