@marimo-team/islands 0.26.1-dev35 → 0.26.1-dev36
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/{ErrorBoundary-iyjiC9ML.js → ErrorBoundary-BmE2rNzY.js} +1 -1
- package/dist/{code-visibility-CxpKyHWF.js → code-visibility-BzRlyFnf.js} +1 -1
- package/dist/{common-Djc1JawL.js → common-CNYx3wi3.js} +1 -1
- package/dist/{data-grid-overlay-editor-Dmnpacp6.js → data-grid-overlay-editor-DcqdB__T.js} +1 -1
- package/dist/{feedback-button-C98GhNgD.js → feedback-button-2c5dWZX5.js} +2 -2
- package/dist/{glide-data-editor-BMVaUqLj.js → glide-data-editor-DkOZUghO.js} +3 -3
- package/dist/{globals-BMm0LbQt.js → globals-D0kZC9LO.js} +1 -1
- package/dist/main.js +6 -6
- package/dist/{number-overlay-editor-D56Dc7pp.js → number-overlay-editor-BABdat1B.js} +1 -1
- package/dist/{reveal-component-B3ad6vdK.js → reveal-component-C5O0UMiR.js} +2 -2
- package/package.json +1 -1
- package/src/components/editor/cell/code/cell-editor.tsx +3 -2
- package/src/core/ai/staged-cells.ts +6 -15
- package/src/core/cells/__tests__/pending-delete-service.test.tsx +117 -0
- package/src/core/cells/pending-delete-service.ts +97 -85
- package/src/core/codemirror/__tests__/use-lazy-editor-mount.test.tsx +7 -2
- package/src/core/codemirror/use-lazy-editor-mount.ts +7 -4
- package/src/core/state/__tests__/create-keyed-selector-hook.test.tsx +128 -0
- package/src/core/state/create-keyed-selector-hook.ts +26 -0
|
@@ -148,7 +148,7 @@ function L(e) {
|
|
|
148
148
|
}
|
|
149
149
|
//#endregion
|
|
150
150
|
//#region src/components/editor/boundary/ErrorBoundary.tsx
|
|
151
|
-
var R = (0, T.lazy)(() => import("./feedback-button-
|
|
151
|
+
var R = (0, T.lazy)(() => import("./feedback-button-2c5dWZX5.js").then((e) => ({ default: e.FeedbackModal }))), z = (e) => {
|
|
152
152
|
let t = (0, w.c)(2), n;
|
|
153
153
|
return t[0] === e.children ? n = t[1] : (n = /* @__PURE__ */ (0, N.jsx)(O, {
|
|
154
154
|
FallbackComponent: B,
|
|
@@ -14,7 +14,7 @@ function y() {
|
|
|
14
14
|
return e.warn("Failed to get version from mount config"), null;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
var b = y() || "0.26.1-
|
|
17
|
+
var b = y() || "0.26.1-dev36", x = s(b), S = s(!0);
|
|
18
18
|
s(null);
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/core/wasm/state.ts
|
|
@@ -33,7 +33,7 @@ import { a as ya, i as ba, n as xa, o as Sa, r as Ca, t as wa } from "./dialog-v
|
|
|
33
33
|
import { o as Ta } from "./dist-BG-7Qpaj.js";
|
|
34
34
|
import { t as Ea } from "./useAsyncData-P5-Oovhq.js";
|
|
35
35
|
import { n as W, t as G } from "./objectWithoutPropertiesLoose-BRDcTsfB.js";
|
|
36
|
-
import { n as Da, t as Oa } from "./ErrorBoundary-
|
|
36
|
+
import { n as Da, t as Oa } from "./ErrorBoundary-BmE2rNzY.js";
|
|
37
37
|
import { W as ka, n as Aa } from "./vega-loader.browser-Co9gYE8Z.js";
|
|
38
38
|
import { a as ja, n as Ma, r as Na, t as Pa } from "./loader-qPmiRXZd.js";
|
|
39
39
|
import { t as Fa } from "./useIframeCapabilities-_0KX0nu_.js";
|
|
@@ -2,7 +2,7 @@ import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
|
|
|
2
2
|
import { t } from "./react-Bgs_wQh3.js";
|
|
3
3
|
import { t as n } from "./react-dom-DdqGVp5N.js";
|
|
4
4
|
import { c as r, l as i, u as a } from "./data-grid-types-DBNnjiYJ.js";
|
|
5
|
-
import { a as o, i as s, n as c, r as l } from "./glide-data-editor-
|
|
5
|
+
import { a as o, i as s, n as c, r as l } from "./glide-data-editor-DkOZUghO.js";
|
|
6
6
|
//#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.18.1_marked@15.0.12_react-dom@19.3.1__a94b4518d090e84da26f3a68e82f2953/node_modules/@glideapps/glide-data-grid/dist/esm/internal/data-grid-overlay-editor/data-grid-overlay-editor-style.js
|
|
7
7
|
var u = /* @__PURE__ */ e(t(), 1), d = /* @__PURE__ */ e(n(), 1), f = /*#__PURE__*/ o("div")({
|
|
8
8
|
name: "DataGridOverlayEditorStyle",
|
|
@@ -4,13 +4,13 @@ import { t as r } from "./react-Bgs_wQh3.js";
|
|
|
4
4
|
import { t as i } from "./compiler-runtime-C5KHtL5D.js";
|
|
5
5
|
import { t as a } from "./copy-icon-rYV2znAe.js";
|
|
6
6
|
import { $t as o, A as s, L as c, Y as l, i as u, in as d, j as f, n as p, z as m } from "./error-entries-DFHEq_SO.js";
|
|
7
|
-
import { n as h, t as ee } from "./globals-
|
|
7
|
+
import { n as h, t as ee } from "./globals-D0kZC9LO.js";
|
|
8
8
|
import { r as g } from "./assertNever-BHnIohkX.js";
|
|
9
9
|
import { t as _ } from "./jsx-runtime-D8btoEHk.js";
|
|
10
10
|
import { Bt as v, Ct as te, m as y } from "./use-restore-focus-ocw7t85i.js";
|
|
11
11
|
import { a as ne, i as re, n as ie, r as ae } from "./dialog-vs6x3On9.js";
|
|
12
12
|
import { t as oe } from "./useAsyncData-P5-Oovhq.js";
|
|
13
|
-
import { t as se } from "./code-visibility-
|
|
13
|
+
import { t as se } from "./code-visibility-BzRlyFnf.js";
|
|
14
14
|
//#region src/components/ui/skeleton.tsx
|
|
15
15
|
var b = /* @__PURE__ */ e(r(), 1), x = i(), S = _(), ce = (e) => {
|
|
16
16
|
let n = (0, x.c)(8), r, i;
|
|
@@ -14,7 +14,7 @@ import { t as F } from "./jsx-runtime-D8btoEHk.js";
|
|
|
14
14
|
import { d as ae, r as I } from "./use-restore-focus-ocw7t85i.js";
|
|
15
15
|
import { t as oe } from "./useEvent-BoN7U38T.js";
|
|
16
16
|
import { n as L, t as se } from "./objectWithoutPropertiesLoose-BRDcTsfB.js";
|
|
17
|
-
import { t as ce } from "./ErrorBoundary-
|
|
17
|
+
import { t as ce } from "./ErrorBoundary-BmE2rNzY.js";
|
|
18
18
|
import { A as le, C as ue, D as de, E as fe, F as pe, I as me, L as he, M as ge, N as R, O as z, P as _e, R as ve, S as ye, T as be, _ as xe, a as Se, b as B, c as Ce, d as we, f as V, g as Te, h as Ee, i as De, j as H, k as Oe, l as ke, m as Ae, n as je, o as Me, p as Ne, r as U, s as Pe, t as Fe, u as Ie, v as Le, w as Re, x as ze, y as Be, z as Ve } from "./data-grid-types-DBNnjiYJ.js";
|
|
19
19
|
//#region ../node_modules/.pnpm/@emotion+memoize@0.9.0/node_modules/@emotion/memoize/dist/emotion-memoize.esm.js
|
|
20
20
|
function He(e) {
|
|
@@ -7061,7 +7061,7 @@ function ds(e, t, n, r, i) {
|
|
|
7061
7061
|
}
|
|
7062
7062
|
//#endregion
|
|
7063
7063
|
//#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.18.1_marked@15.0.12_react-dom@19.3.1__a94b4518d090e84da26f3a68e82f2953/node_modules/@glideapps/glide-data-grid/dist/esm/data-editor/data-editor.js
|
|
7064
|
-
var fs = /* @__PURE__ */ e(Tr(), 1), ps = /* @__PURE__ */ e(kr(), 1), ms = W.lazy(async () => await import("./data-grid-overlay-editor-
|
|
7064
|
+
var fs = /* @__PURE__ */ e(Tr(), 1), ps = /* @__PURE__ */ e(kr(), 1), ms = W.lazy(async () => await import("./data-grid-overlay-editor-DcqdB__T.js")), hs = 0;
|
|
7065
7065
|
function gs(e) {
|
|
7066
7066
|
return (0, fs.default)((0, ps.default)((0, ps.default)(e).filter((e) => e.span !== void 0).map((e) => (0, ao.default)((e.span?.[0] ?? 0) + 1, (e.span?.[1] ?? 0) + 1))));
|
|
7067
7067
|
}
|
|
@@ -9284,7 +9284,7 @@ function Ys(e, t, n, r, i) {
|
|
|
9284
9284
|
}
|
|
9285
9285
|
//#endregion
|
|
9286
9286
|
//#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.18.1_marked@15.0.12_react-dom@19.3.1__a94b4518d090e84da26f3a68e82f2953/node_modules/@glideapps/glide-data-grid/dist/esm/cells/number-cell.js
|
|
9287
|
-
var Xs = W.lazy(async () => await import("./number-overlay-editor-
|
|
9287
|
+
var Xs = W.lazy(async () => await import("./number-overlay-editor-BABdat1B.js")), Zs = {
|
|
9288
9288
|
getAccessibilityString: (e) => e.data?.toString() ?? "",
|
|
9289
9289
|
kind: U.Number,
|
|
9290
9290
|
needsHover: (e) => e.hoverEffect === !0,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h as e } from "./tooltip-DSWC_Td_.js";
|
|
2
2
|
import { Ct as t } from "./use-restore-focus-ocw7t85i.js";
|
|
3
|
-
import { r as n } from "./code-visibility-
|
|
3
|
+
import { r as n } from "./code-visibility-BzRlyFnf.js";
|
|
4
4
|
var r = e("triangle-alert", [
|
|
5
5
|
["path", {
|
|
6
6
|
d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import { i as x, n as S, r as C, t as w } from "./copy-icon-rYV2znAe.js";
|
|
|
6
6
|
import { B as T, Bt as E, Ct as D, E as O, F as k, Ft as A, I as j, It as M, J as N, L as P, Lt as F, M as I, Mt as L, O as R, Ot as z, P as B, R as ee, Rt as te, Ut as ne, Vt as re, Wt as ie, Y as ae, _ as oe, a as se, at as ce, b as le, bt as ue, c as de, ct as fe, ft as pe, ht as me, i as he, it as ge, j as _e, kt as ve, lt as ye, mt as be, n as xe, nt as Se, o as Ce, ot as we, pt as Te, tt as Ee, ut as De, vt as Oe, xt as ke, z as Ae, zt as je } from "./html-to-image-D6Gtk5ik.js";
|
|
7
7
|
import { a as Me, f as Ne, h as Pe, i as Fe, m as Ie, n as Le, o as Re, r as ze, t as Be } from "./tooltip-DSWC_Td_.js";
|
|
8
8
|
import { D as Ve, E as He, S as Ue, T as We, _ as Ge, a as Ke, c as qe, d as Je, f as Ye, g as Xe, h as Ze, i as Qe, l as $e, m as et, n as tt, o as nt, p as rt, r as it, s as at, t as ot, u as st, v as ct, w as lt, x as ut, y as dt } from "./spec-C4uOz0Em.js";
|
|
9
|
-
import { $ as ft, $t as pt, A as mt, An as ht, At as gt, B as _t, Bt as vt, C as yt, D as bt, Dn as xt, Dt as St, E as Ct, En as wt, Et as Tt, F as Et, Ft as Dt, G as Ot, Gt as kt, H as At, Ht as jt, I as Mt, It as Nt, J as Pt, Jt as Ft, K as It, Kt as Lt, L as Rt, Lt as zt, M as Bt, Mn as Vt, Mt as Ht, N as Ut, Nt as Wt, O as Gt, On as Kt, Ot as qt, P as Jt, Pt as Yt, Q as Xt, Qt as Zt, R as Qt, Rt as $t, S as en, Sn as tn, St as nn, T as rn, Tn as an, Tt as on, U as sn, Ut as cn, V as ln, Vt as un, W as dn, Wt as fn, X as pn, Xt as mn, Y as hn, Yt as gn, Z as _n, Zt as vn, _ as yn, _n as bn, _t as xn, an as Sn, at as Cn, b as wn, bn as Tn, bt as En, c as Dn, cn as On, ct as kn, d as An, dn as jn, dt as Mn, en as Nn, f as Pn, fn as Fn, ft as In, g as Ln, gn as Rn, gt as zn, h as Bn, hn as Vn, ht as Hn, in as Un, it as Wn, j as Gn, jn as Kn, jt as qn, k as Jn, kn as Yn, kt as Xn, ln as Zn, lt as Qn, m as $n, mn as er, mt as tr, nn as nr, on as rr, ot as ir, p as ar, pn as or, pt as sr, q as cr, qt as lr, r as ur, rn as dr, rt as fr, sn as pr, st as mr, t as hr, tn as gr, u as _r, un as vr, ut as yr, v as br, vn as xr, vt as Sr, w as Cr, wn as wr, x as Tr, xn as Er, xt as Dr, y as Or, yn as kr, yt as Ar, z as jr, zt as Mr } from "./common-
|
|
9
|
+
import { $ as ft, $t as pt, A as mt, An as ht, At as gt, B as _t, Bt as vt, C as yt, D as bt, Dn as xt, Dt as St, E as Ct, En as wt, Et as Tt, F as Et, Ft as Dt, G as Ot, Gt as kt, H as At, Ht as jt, I as Mt, It as Nt, J as Pt, Jt as Ft, K as It, Kt as Lt, L as Rt, Lt as zt, M as Bt, Mn as Vt, Mt as Ht, N as Ut, Nt as Wt, O as Gt, On as Kt, Ot as qt, P as Jt, Pt as Yt, Q as Xt, Qt as Zt, R as Qt, Rt as $t, S as en, Sn as tn, St as nn, T as rn, Tn as an, Tt as on, U as sn, Ut as cn, V as ln, Vt as un, W as dn, Wt as fn, X as pn, Xt as mn, Y as hn, Yt as gn, Z as _n, Zt as vn, _ as yn, _n as bn, _t as xn, an as Sn, at as Cn, b as wn, bn as Tn, bt as En, c as Dn, cn as On, ct as kn, d as An, dn as jn, dt as Mn, en as Nn, f as Pn, fn as Fn, ft as In, g as Ln, gn as Rn, gt as zn, h as Bn, hn as Vn, ht as Hn, in as Un, it as Wn, j as Gn, jn as Kn, jt as qn, k as Jn, kn as Yn, kt as Xn, ln as Zn, lt as Qn, m as $n, mn as er, mt as tr, nn as nr, on as rr, ot as ir, p as ar, pn as or, pt as sr, q as cr, qt as lr, r as ur, rn as dr, rt as fr, sn as pr, st as mr, t as hr, tn as gr, u as _r, un as vr, ut as yr, v as br, vn as xr, vt as Sr, w as Cr, wn as wr, x as Tr, xn as Er, xt as Dr, y as Or, yn as kr, yt as Ar, z as jr, zt as Mr } from "./common-CNYx3wi3.js";
|
|
10
10
|
import { a as Nr, n as Pr, s as Fr, t as Ir } from "./useLifecycle-CCV7yZ-v.js";
|
|
11
11
|
import { t as Lr } from "./check-LtjuWmNn.js";
|
|
12
12
|
import { A as Rr, C as zr, D as Br, M as Vr, O as Hr, a as Ur, c as Wr, d as Gr, i as Kr, k as qr, l as Jr, n as Yr, o as Xr, r as Zr, s as Qr, t as $r, w as ei, x as ti } from "./select-CKLRKIzB.js";
|
|
@@ -16,7 +16,7 @@ import { $t as Ui, A as Wi, At as Gi, C as Ki, Ct as qi, Dt as Ji, Ft as Yi, H a
|
|
|
16
16
|
import { a as Na, d as Pa, i as Fa, n as Ia, o as La, r as Ra, s as za, t as Ba, u as Va } from "./process-output-ZBdibqlG.js";
|
|
17
17
|
import { t as Ha } from "./pencil-AWgwbH4D.js";
|
|
18
18
|
import { a as Ua, c as Wa, d as Ga, f as Ka, i as qa, l as Ja, r as Ya } from "./glide-utils-CZ-O-CB_.js";
|
|
19
|
-
import { n as Xa, t as Za } from "./globals-
|
|
19
|
+
import { n as Xa, t as Za } from "./globals-D0kZC9LO.js";
|
|
20
20
|
import { a as Qa, i as $a, n as eo, r as to, s as no, t as ro } from "./assertNever-BHnIohkX.js";
|
|
21
21
|
import { t as io } from "./react-dom-DdqGVp5N.js";
|
|
22
22
|
import { t as ao } from "./jsx-runtime-D8btoEHk.js";
|
|
@@ -40,10 +40,10 @@ import { i as ic } from "./dist-BG-7Qpaj.js";
|
|
|
40
40
|
import { p as ac } from "./dist-BidYR5m4.js";
|
|
41
41
|
import { t as oc } from "./useAsyncData-P5-Oovhq.js";
|
|
42
42
|
import { n as sc, r as cc, t as lc } from "./useDeepCompareMemoize-BsaXfZ8C.js";
|
|
43
|
-
import { t as uc } from "./ErrorBoundary-
|
|
43
|
+
import { t as uc } from "./ErrorBoundary-BmE2rNzY.js";
|
|
44
44
|
import { G as dc, W as fc } from "./vega-loader.browser-Co9gYE8Z.js";
|
|
45
45
|
import { a as pc, n as mc } from "./loader-qPmiRXZd.js";
|
|
46
|
-
import { a as hc, c as gc, i as _c, l as vc, o as yc, s as bc, t as xc } from "./code-visibility-
|
|
46
|
+
import { a as hc, c as gc, i as _c, l as vc, o as yc, s as bc, t as xc } from "./code-visibility-BzRlyFnf.js";
|
|
47
47
|
import { t as Sc } from "./esm-DY8dGAjJ.js";
|
|
48
48
|
//#region ../node_modules/.pnpm/iconify-icon@2.3.0/node_modules/iconify-icon/dist/iconify-icon.mjs
|
|
49
49
|
var Cc = Object.freeze({
|
|
@@ -13027,7 +13027,7 @@ function BO(e, t) {
|
|
|
13027
13027
|
}
|
|
13028
13028
|
//#endregion
|
|
13029
13029
|
//#region src/plugins/impl/DataEditorPlugin.tsx
|
|
13030
|
-
var VO = J.lazy(() => import("./glide-data-editor-
|
|
13030
|
+
var VO = J.lazy(() => import("./glide-data-editor-DkOZUghO.js").then((e) => e.t)), HO = SD("marimo-data-editor", { cssStyles: [GD, KD] }).withData(G({
|
|
13031
13031
|
initialValue: G({ edits: V(G({
|
|
13032
13032
|
rowIdx: W(),
|
|
13033
13033
|
columnId: K(),
|
|
@@ -32750,7 +32750,7 @@ function UU(e) {
|
|
|
32750
32750
|
}
|
|
32751
32751
|
//#endregion
|
|
32752
32752
|
//#region src/components/editor/renderers/slides-layout/slides-layout.tsx
|
|
32753
|
-
var WU = J.lazy(() => import("./reveal-component-
|
|
32753
|
+
var WU = J.lazy(() => import("./reveal-component-C5O0UMiR.js")), GU = (e) => {
|
|
32754
32754
|
let t = (0, X.c)(33), { layout: n, setLayout: r, cells: i, mode: a } = e, o = uo(Gs), s = a === "read" || o, c = uo(wa) > 1, [l, u] = (0, J.useState)(null), d;
|
|
32755
32755
|
t[0] !== i || t[1] !== n ? (d = Vz(i, n), t[0] = i, t[1] = n, t[2] = d) : d = t[2];
|
|
32756
32756
|
let { slideCells: f, skippedIds: p, noOutputIds: m, slideTypes: h, startCellIndex: g } = d, _;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
|
|
2
2
|
import { t } from "./react-Bgs_wQh3.js";
|
|
3
|
-
import { a as n } from "./glide-data-editor-
|
|
3
|
+
import { a as n } from "./glide-data-editor-DkOZUghO.js";
|
|
4
4
|
//#region ../node_modules/.pnpm/@glideapps+glide-data-grid@6.0.4-alpha24_lodash@4.18.1_marked@15.0.12_react-dom@19.3.1__a94b4518d090e84da26f3a68e82f2953/node_modules/@glideapps/glide-data-grid/dist/esm/internal/data-grid-overlay-editor/private/number-overlay-editor-style.js
|
|
5
5
|
var r = /* @__PURE__ */ e(t()), i = /*#__PURE__*/ n("div")({
|
|
6
6
|
name: "NumberOverlayEditorStyle",
|
|
@@ -3,14 +3,14 @@ import { g as t, h as n, m as r, r as i, t as a } from "./button-Z2R2272J.js";
|
|
|
3
3
|
import { t as o } from "./react-Bgs_wQh3.js";
|
|
4
4
|
import { t as s } from "./compiler-runtime-C5KHtL5D.js";
|
|
5
5
|
import { h as c, t as l } from "./tooltip-DSWC_Td_.js";
|
|
6
|
-
import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-
|
|
6
|
+
import { Cn as u, En as d, Sn as f, dn as p, et as m, f as h, i as g, l as _, n as v, nt as y, r as b, t as x, tt as S, u as C } from "./common-CNYx3wi3.js";
|
|
7
7
|
import { M as w } from "./select-CKLRKIzB.js";
|
|
8
8
|
import { X as T } from "./dropdown-menu-D65ZUqka.js";
|
|
9
9
|
import { t as E } from "./jsx-runtime-D8btoEHk.js";
|
|
10
10
|
import { Bt as D, Ut as O, f as k, i as ee } from "./use-restore-focus-ocw7t85i.js";
|
|
11
11
|
import { t as A } from "./useEvent-BoN7U38T.js";
|
|
12
12
|
import { o as te } from "./static-state-DZ1nSa6e.js";
|
|
13
|
-
import { n as ne, t as re } from "./code-visibility-
|
|
13
|
+
import { n as ne, t as re } from "./code-visibility-BzRlyFnf.js";
|
|
14
14
|
/* empty css */
|
|
15
15
|
var j = c("sticky-note", [["path", {
|
|
16
16
|
d: "M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z",
|
package/package.json
CHANGED
|
@@ -348,6 +348,7 @@ const CellEditorInternal = ({
|
|
|
348
348
|
const {
|
|
349
349
|
elementRef: intersectionRef,
|
|
350
350
|
mounted: isEditorMounted,
|
|
351
|
+
mountedEditorView,
|
|
351
352
|
promote,
|
|
352
353
|
} = useLazyEditorMount({
|
|
353
354
|
cellId,
|
|
@@ -400,7 +401,7 @@ const CellEditorInternal = ({
|
|
|
400
401
|
<AiCompletionEditor
|
|
401
402
|
cellId={cellId}
|
|
402
403
|
aiCompletionCell={aiCompletionCell}
|
|
403
|
-
currentCode={
|
|
404
|
+
currentCode={mountedEditorView?.state.doc.toString() ?? code}
|
|
404
405
|
currentLanguageAdapter={languageAdapter}
|
|
405
406
|
declineChange={useEvent(() => {
|
|
406
407
|
setAiCompletionCell(null);
|
|
@@ -445,7 +446,7 @@ const CellEditorInternal = ({
|
|
|
445
446
|
{isEditorMounted ? (
|
|
446
447
|
<CellCodeMirrorEditor
|
|
447
448
|
className={editorClassName}
|
|
448
|
-
editorView={
|
|
449
|
+
editorView={mountedEditorView}
|
|
449
450
|
ref={editorViewParentRef}
|
|
450
451
|
/>
|
|
451
452
|
) : (
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { useAtomValue } from "jotai";
|
|
4
|
-
import { selectAtom } from "jotai/utils";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
3
|
import { useDeleteCellCallback } from "@/components/editor/cell/useDeleteCell";
|
|
7
4
|
import type { CellId } from "@/core/cells/ids";
|
|
5
|
+
import { createKeyedSelectorHook } from "@/core/state/create-keyed-selector-hook";
|
|
8
6
|
import { createReducerAndAtoms } from "@/utils/createReducer";
|
|
9
7
|
import { writeCellCode } from "../codemirror/cell-documents";
|
|
10
8
|
import type { EditType } from "./tools/edit-notebook-tool";
|
|
@@ -56,18 +54,11 @@ const {
|
|
|
56
54
|
|
|
57
55
|
export { useStagedAICellsActions };
|
|
58
56
|
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(cells) => (cellId === undefined ? undefined : cells.get(cellId)),
|
|
65
|
-
Object.is,
|
|
66
|
-
),
|
|
67
|
-
[cellId],
|
|
68
|
-
);
|
|
69
|
-
return useAtomValue(stagedCellAtom);
|
|
70
|
-
}
|
|
57
|
+
export const useStagedAICell = createKeyedSelectorHook(
|
|
58
|
+
stagedAICellsAtom,
|
|
59
|
+
(cells, cellId: CellId | undefined) =>
|
|
60
|
+
cellId === undefined ? undefined : cells.get(cellId),
|
|
61
|
+
);
|
|
71
62
|
|
|
72
63
|
/** Keep or discard staged cells, whichever AI workflow staged them. */
|
|
73
64
|
export function useStagedCells() {
|
|
@@ -11,6 +11,7 @@ import { CellId } from "@/core/cells/ids";
|
|
|
11
11
|
import {
|
|
12
12
|
usePendingDelete,
|
|
13
13
|
usePendingDeleteService,
|
|
14
|
+
visibleForTesting,
|
|
14
15
|
} from "../pending-delete-service";
|
|
15
16
|
|
|
16
17
|
const mockDeleteCell = vi.fn();
|
|
@@ -34,6 +35,107 @@ beforeEach(() => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
describe("pending-delete-service", () => {
|
|
38
|
+
it("preserves state identity when clearing an empty service", () => {
|
|
39
|
+
const { reducer, initialState } = visibleForTesting;
|
|
40
|
+
const state = initialState();
|
|
41
|
+
expect(reducer(state, { type: "clear", payload: undefined })).toBe(state);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it.each([25, 250, 500])(
|
|
45
|
+
"does not render %i subscribers on repeated empty clears",
|
|
46
|
+
(count) => {
|
|
47
|
+
const { wrapper } = createTestWrapper();
|
|
48
|
+
const renders = vi.fn();
|
|
49
|
+
const { result } = renderHook(() => usePendingDeleteService(), {
|
|
50
|
+
wrapper,
|
|
51
|
+
});
|
|
52
|
+
const subscribers = Array.from({ length: count }, () => {
|
|
53
|
+
const cellId = CellId.create();
|
|
54
|
+
return renderHook(
|
|
55
|
+
() => {
|
|
56
|
+
usePendingDeleteService();
|
|
57
|
+
usePendingDelete(cellId);
|
|
58
|
+
renders();
|
|
59
|
+
},
|
|
60
|
+
{ wrapper },
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
renders.mockClear();
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < 6; i++) {
|
|
66
|
+
act(() => result.current.clear());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
expect(renders).not.toHaveBeenCalled();
|
|
70
|
+
for (const subscriber of subscribers) {
|
|
71
|
+
subscriber.unmount();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
it("isolates same-count changes and follows a changed cell id", () => {
|
|
77
|
+
const { wrapper, store } = createTestWrapper();
|
|
78
|
+
const first = CellId.create();
|
|
79
|
+
const second = CellId.create();
|
|
80
|
+
const unrelated = CellId.create();
|
|
81
|
+
store.set(
|
|
82
|
+
notebookAtom,
|
|
83
|
+
MockNotebook.notebookState({
|
|
84
|
+
cellData: {
|
|
85
|
+
[first]: { code: "expensive1()" },
|
|
86
|
+
[second]: { code: "expensive2()" },
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
MockExecutions.seed(store, [
|
|
91
|
+
MockExecutions.took(first, 3000),
|
|
92
|
+
MockExecutions.took(second, 4000),
|
|
93
|
+
]);
|
|
94
|
+
const serviceRenders = vi.fn();
|
|
95
|
+
const { result: service } = renderHook(
|
|
96
|
+
() => {
|
|
97
|
+
serviceRenders();
|
|
98
|
+
return usePendingDeleteService();
|
|
99
|
+
},
|
|
100
|
+
{ wrapper },
|
|
101
|
+
);
|
|
102
|
+
const unrelatedRenders = vi.fn();
|
|
103
|
+
renderHook(
|
|
104
|
+
() => {
|
|
105
|
+
unrelatedRenders();
|
|
106
|
+
return usePendingDelete(unrelated);
|
|
107
|
+
},
|
|
108
|
+
{ wrapper },
|
|
109
|
+
);
|
|
110
|
+
const { result, rerender } = renderHook(
|
|
111
|
+
({ cellId }) => usePendingDelete(cellId),
|
|
112
|
+
{
|
|
113
|
+
wrapper,
|
|
114
|
+
initialProps: { cellId: first },
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
act(() => service.current.submit([first]));
|
|
118
|
+
expect(result.current.isPending).toBe(true);
|
|
119
|
+
serviceRenders.mockClear();
|
|
120
|
+
unrelatedRenders.mockClear();
|
|
121
|
+
|
|
122
|
+
act(() => service.current.submit([second]));
|
|
123
|
+
expect(result.current).toEqual({ isPending: false });
|
|
124
|
+
expect(serviceRenders).not.toHaveBeenCalled();
|
|
125
|
+
expect(unrelatedRenders).not.toHaveBeenCalled();
|
|
126
|
+
|
|
127
|
+
rerender({ cellId: second });
|
|
128
|
+
expect(result.current.isPending).toBe(true);
|
|
129
|
+
act(() => {
|
|
130
|
+
if (result.current.isPending && result.current.shouldConfirmDelete) {
|
|
131
|
+
result.current.cancel();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
expect(result.current).toEqual({ isPending: false });
|
|
135
|
+
expect(service.current.idle).toBe(true);
|
|
136
|
+
expect(mockDeleteManyCells).not.toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
|
|
37
139
|
it("auto-deletes simple cells (no dependencies, short execution time)", async () => {
|
|
38
140
|
const { wrapper, store } = createTestWrapper();
|
|
39
141
|
|
|
@@ -183,5 +285,20 @@ describe("pending-delete-service", () => {
|
|
|
183
285
|
}
|
|
184
286
|
expect(result.current.shouldConfirmDelete).toBe(false);
|
|
185
287
|
expect("confirm" in result.current).toBe(false);
|
|
288
|
+
|
|
289
|
+
expect(serviceResult.current.shouldConfirmDelete).toBe(true);
|
|
290
|
+
act(() => serviceResult.current.submit([cell1Id]));
|
|
291
|
+
expect(serviceResult.current.shouldConfirmDelete).toBe(false);
|
|
292
|
+
expect(result.current.shouldConfirmDelete).toBe(true);
|
|
293
|
+
act(() => {
|
|
294
|
+
if (result.current.isPending && result.current.shouldConfirmDelete) {
|
|
295
|
+
result.current.confirm();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
expect(mockDeleteManyCells).toHaveBeenCalledExactlyOnceWith({
|
|
299
|
+
cellIds: [cell1Id],
|
|
300
|
+
});
|
|
301
|
+
expect(result.current).toEqual({ isPending: false });
|
|
302
|
+
expect(serviceResult.current.idle).toBe(true);
|
|
186
303
|
});
|
|
187
304
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { useAtomValue, useStore } from "jotai";
|
|
4
|
+
import { selectAtom } from "jotai/utils";
|
|
4
5
|
import {
|
|
5
6
|
useDeleteCellCallback,
|
|
6
7
|
useDeleteManyCellsCallback,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
import { notebookAtom } from "@/core/cells/cells";
|
|
9
10
|
import type { CellId } from "@/core/cells/ids";
|
|
10
11
|
import { cellExecutionInputsAtom, cellExecutionView } from "@/core/executions";
|
|
12
|
+
import { createKeyedSelectorHook } from "@/core/state/create-keyed-selector-hook";
|
|
11
13
|
import type { JotaiStore } from "@/core/state/jotai";
|
|
12
14
|
import { variablesAtom } from "@/core/variables/state";
|
|
13
15
|
import type { VariableName } from "@/core/variables/types";
|
|
@@ -33,98 +35,102 @@ const initialState = (): PendingDeleteState => ({
|
|
|
33
35
|
entries: new Map(),
|
|
34
36
|
});
|
|
35
37
|
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Build defs map for this cell
|
|
68
|
-
const defs = new Map<VariableName, readonly CellId[]>();
|
|
69
|
-
for (const variable of Object.values(variables)) {
|
|
70
|
-
const declaredByThisCell = variable.declaredBy.includes(cellId);
|
|
71
|
-
const usedByNonEmptyCell = variable.usedBy.some(
|
|
72
|
-
(cellId) => !emptyCells.has(cellId),
|
|
73
|
-
);
|
|
74
|
-
if (declaredByThisCell && usedByNonEmptyCell) {
|
|
75
|
-
defs.set(variable.name, variable.usedBy);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
38
|
+
const {
|
|
39
|
+
valueAtom: pendingDeleteStateAtom,
|
|
40
|
+
useActions,
|
|
41
|
+
reducer,
|
|
42
|
+
} = createReducerAndAtoms(initialState, {
|
|
43
|
+
submit: (
|
|
44
|
+
state,
|
|
45
|
+
action: {
|
|
46
|
+
cellIds: CellId[];
|
|
47
|
+
deleteCell: (args: { cellId: CellId }) => void;
|
|
48
|
+
deleteManyCells: (args: { cellIds: CellId[] }) => void;
|
|
49
|
+
store: JotaiStore;
|
|
50
|
+
},
|
|
51
|
+
) => {
|
|
52
|
+
const { cellIds, deleteCell, deleteManyCells, store } = action;
|
|
53
|
+
const notebook = store.get(notebookAtom);
|
|
54
|
+
const executions = store.get(cellExecutionInputsAtom);
|
|
55
|
+
const variables = store.get(variablesAtom);
|
|
56
|
+
|
|
57
|
+
const emptyCells = new Set(
|
|
58
|
+
notebook.cellIds.filter((id) => notebook.cellData[id].code.trim() === ""),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const entries = new Map<CellId, PendingDeleteEntry>();
|
|
62
|
+
for (const cellId of cellIds) {
|
|
63
|
+
if (emptyCells.has(cellId)) {
|
|
64
|
+
// Empty cells indicate user intent to delete already
|
|
65
|
+
entries.set(cellId, { cellId, type: "simple" });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
78
68
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
// Build defs map for this cell
|
|
70
|
+
const defs = new Map<VariableName, readonly CellId[]>();
|
|
71
|
+
for (const variable of Object.values(variables)) {
|
|
72
|
+
const declaredByThisCell = variable.declaredBy.includes(cellId);
|
|
73
|
+
const usedByNonEmptyCell = variable.usedBy.some(
|
|
74
|
+
(cellId) => !emptyCells.has(cellId),
|
|
75
|
+
);
|
|
76
|
+
if (declaredByThisCell && usedByNonEmptyCell) {
|
|
77
|
+
defs.set(variable.name, variable.usedBy);
|
|
83
78
|
}
|
|
79
|
+
}
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
cellId,
|
|
90
|
-
type: "expensive",
|
|
91
|
-
executionDurationMs,
|
|
92
|
-
defs,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
81
|
+
let executionDurationMs: number | undefined;
|
|
82
|
+
const { duration } = cellExecutionView(executions, cellId);
|
|
83
|
+
if (duration !== null && duration > 2000) {
|
|
84
|
+
executionDurationMs = duration;
|
|
95
85
|
}
|
|
96
86
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
deleteManyCells({
|
|
107
|
-
cellIds: [...entries.values()].map((e) => e.cellId),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
// Return empty state since we auto-deleted
|
|
111
|
-
return initialState();
|
|
87
|
+
if (defs.size === 0 && executionDurationMs === undefined) {
|
|
88
|
+
entries.set(cellId, { cellId, type: "simple" });
|
|
89
|
+
} else {
|
|
90
|
+
entries.set(cellId, {
|
|
91
|
+
cellId,
|
|
92
|
+
type: "expensive",
|
|
93
|
+
executionDurationMs,
|
|
94
|
+
defs,
|
|
95
|
+
});
|
|
112
96
|
}
|
|
97
|
+
}
|
|
113
98
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
// Auto-delete if all are "simple" cells
|
|
100
|
+
const allSimple = [...entries.values()].every(
|
|
101
|
+
(entry) => entry.type === "simple",
|
|
102
|
+
);
|
|
103
|
+
if (entries.size > 0 && allSimple) {
|
|
104
|
+
// Perform the deletion immediately
|
|
105
|
+
if (entries.size === 1) {
|
|
106
|
+
deleteCell({ cellId: [...entries.values()][0].cellId });
|
|
107
|
+
} else {
|
|
108
|
+
deleteManyCells({
|
|
109
|
+
cellIds: [...entries.values()].map((e) => e.cellId),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// Return empty state since we auto-deleted
|
|
113
|
+
return initialState();
|
|
114
|
+
}
|
|
119
115
|
|
|
120
|
-
|
|
116
|
+
return {
|
|
117
|
+
...state,
|
|
118
|
+
entries,
|
|
119
|
+
};
|
|
121
120
|
},
|
|
121
|
+
|
|
122
|
+
clear: (state) => (state.entries.size === 0 ? state : initialState()),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const pendingDeleteCountAtom = selectAtom(
|
|
126
|
+
pendingDeleteStateAtom,
|
|
127
|
+
(state) => state.entries.size,
|
|
122
128
|
);
|
|
123
129
|
|
|
124
130
|
export function usePendingDeleteService() {
|
|
125
131
|
const store = useStore();
|
|
126
132
|
const { submit, clear } = useActions();
|
|
127
|
-
const
|
|
133
|
+
const count = useAtomValue(pendingDeleteCountAtom);
|
|
128
134
|
const deleteCell = useDeleteCellCallback();
|
|
129
135
|
const deleteManyCells = useDeleteManyCellsCallback();
|
|
130
136
|
return {
|
|
@@ -132,23 +138,27 @@ export function usePendingDeleteService() {
|
|
|
132
138
|
submit({ cellIds, deleteCell, deleteManyCells, store });
|
|
133
139
|
},
|
|
134
140
|
clear,
|
|
135
|
-
idle:
|
|
136
|
-
shouldConfirmDelete:
|
|
141
|
+
idle: count === 0,
|
|
142
|
+
shouldConfirmDelete: count > 1,
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
145
|
|
|
146
|
+
const usePendingDeleteEntry = createKeyedSelectorHook(
|
|
147
|
+
pendingDeleteStateAtom,
|
|
148
|
+
(state, cellId: CellId) => state.entries.get(cellId),
|
|
149
|
+
);
|
|
150
|
+
|
|
140
151
|
export function usePendingDelete(cellId: CellId) {
|
|
141
|
-
const
|
|
152
|
+
const entry = usePendingDeleteEntry(cellId);
|
|
153
|
+
const count = useAtomValue(pendingDeleteCountAtom);
|
|
142
154
|
const actions = useActions();
|
|
143
155
|
const deleteManyCells = useDeleteManyCellsCallback();
|
|
144
156
|
|
|
145
|
-
const entry = state.entries.get(cellId);
|
|
146
|
-
|
|
147
157
|
if (!entry) {
|
|
148
158
|
return { isPending: false as const };
|
|
149
159
|
}
|
|
150
160
|
|
|
151
|
-
const canConfirmDelete =
|
|
161
|
+
const canConfirmDelete = count === 1;
|
|
152
162
|
|
|
153
163
|
if (!canConfirmDelete) {
|
|
154
164
|
return {
|
|
@@ -164,10 +174,12 @@ export function usePendingDelete(cellId: CellId) {
|
|
|
164
174
|
shouldConfirmDelete: true as const,
|
|
165
175
|
confirm: () => {
|
|
166
176
|
deleteManyCells({
|
|
167
|
-
cellIds: [
|
|
177
|
+
cellIds: [entry.cellId],
|
|
168
178
|
});
|
|
169
179
|
actions.clear();
|
|
170
180
|
},
|
|
171
181
|
cancel: () => actions.clear(),
|
|
172
182
|
};
|
|
173
183
|
}
|
|
184
|
+
|
|
185
|
+
export const visibleForTesting = { reducer, initialState };
|
|
@@ -109,13 +109,15 @@ it("destroys and rebuilds with current code across Activity hide/show", () => {
|
|
|
109
109
|
editorViewRef.current = new EditorView({ doc: code });
|
|
110
110
|
});
|
|
111
111
|
function Cell({ code }: { code: string }) {
|
|
112
|
-
const { elementRef } = useLazyEditorMount({
|
|
112
|
+
const { elementRef, mountedEditorView } = useLazyEditorMount({
|
|
113
113
|
cellId: "activity",
|
|
114
114
|
editorViewRef,
|
|
115
115
|
build: () => build(code),
|
|
116
116
|
hidden: false,
|
|
117
117
|
});
|
|
118
|
-
return
|
|
118
|
+
return (
|
|
119
|
+
<div ref={elementRef}>{mountedEditorView?.state.doc.toString()}</div>
|
|
120
|
+
);
|
|
119
121
|
}
|
|
120
122
|
const screen = render(
|
|
121
123
|
<Activity mode="visible">
|
|
@@ -123,6 +125,7 @@ it("destroys and rebuilds with current code across Activity hide/show", () => {
|
|
|
123
125
|
</Activity>,
|
|
124
126
|
);
|
|
125
127
|
act(() => editorMountScheduler.promote("activity"));
|
|
128
|
+
expect(screen.container.textContent).toBe("first");
|
|
126
129
|
const first = editorViewRef.current!;
|
|
127
130
|
const destroy = vi.spyOn(first, "destroy");
|
|
128
131
|
screen.rerender(
|
|
@@ -139,7 +142,9 @@ it("destroys and rebuilds with current code across Activity hide/show", () => {
|
|
|
139
142
|
<Cell code="second" />
|
|
140
143
|
</Activity>,
|
|
141
144
|
);
|
|
145
|
+
expect(screen.container.textContent).toBe("");
|
|
142
146
|
act(() => editorMountScheduler.promote("activity"));
|
|
147
|
+
expect(screen.container.textContent).toBe("second");
|
|
143
148
|
expect(build.mock.calls).toEqual([["first"], ["second"]]);
|
|
144
149
|
expect(editorViewRef.current).not.toBe(first);
|
|
145
150
|
expect(editorViewRef.current?.state.doc.toString()).toBe("second");
|
|
@@ -27,14 +27,17 @@ export function useLazyEditorMount({
|
|
|
27
27
|
hidden: boolean;
|
|
28
28
|
}) {
|
|
29
29
|
const elementRef = useRef<HTMLDivElement>(null);
|
|
30
|
-
const [
|
|
30
|
+
const [mountedEditorView, setMountedEditorView] = useState<EditorView | null>(
|
|
31
|
+
null,
|
|
32
|
+
);
|
|
33
|
+
const mounted = mountedEditorView !== null;
|
|
31
34
|
const buildLatest = useEvent(() => {
|
|
32
35
|
build();
|
|
33
|
-
|
|
36
|
+
setMountedEditorView(editorViewRef.current);
|
|
34
37
|
});
|
|
35
38
|
|
|
36
39
|
useEffect(() => {
|
|
37
|
-
|
|
40
|
+
setMountedEditorView(null);
|
|
38
41
|
const cancel = editorMountScheduler.register(cellId, buildLatest);
|
|
39
42
|
return () => {
|
|
40
43
|
cancel();
|
|
@@ -63,5 +66,5 @@ export function useLazyEditorMount({
|
|
|
63
66
|
}, [cellId, awaitsVisibility]);
|
|
64
67
|
|
|
65
68
|
const promote = useEvent(() => editorMountScheduler.promote(cellId));
|
|
66
|
-
return { elementRef, mounted, promote };
|
|
69
|
+
return { elementRef, mounted, mountedEditorView, promote };
|
|
67
70
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { act, renderHook } from "@testing-library/react";
|
|
4
|
+
import { atom, createStore, Provider } from "jotai";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { createKeyedSelectorHook } from "../create-keyed-selector-hook";
|
|
8
|
+
|
|
9
|
+
function setup() {
|
|
10
|
+
const source = atom(
|
|
11
|
+
new Map([
|
|
12
|
+
["a", 1],
|
|
13
|
+
["b", 2],
|
|
14
|
+
]),
|
|
15
|
+
);
|
|
16
|
+
const store = createStore();
|
|
17
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
18
|
+
<Provider store={store}>{children}</Provider>
|
|
19
|
+
);
|
|
20
|
+
const select = vi.fn((state: Map<string, number>, key: string) =>
|
|
21
|
+
state.get(key),
|
|
22
|
+
);
|
|
23
|
+
const useEntry = createKeyedSelectorHook(source, select);
|
|
24
|
+
return { source, store, wrapper, select, useEntry };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("createKeyedSelectorHook", () => {
|
|
28
|
+
it("isolates renders while observing changes and removal of its own entry", () => {
|
|
29
|
+
const { source, store, wrapper, useEntry } = setup();
|
|
30
|
+
const renders = vi.fn();
|
|
31
|
+
const { result } = renderHook(
|
|
32
|
+
() => {
|
|
33
|
+
renders();
|
|
34
|
+
return useEntry("a");
|
|
35
|
+
},
|
|
36
|
+
{ wrapper },
|
|
37
|
+
);
|
|
38
|
+
renders.mockClear();
|
|
39
|
+
|
|
40
|
+
act(() =>
|
|
41
|
+
store.set(
|
|
42
|
+
source,
|
|
43
|
+
new Map([
|
|
44
|
+
["a", 1],
|
|
45
|
+
["b", 3],
|
|
46
|
+
]),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
expect(renders).not.toHaveBeenCalled();
|
|
50
|
+
expect(result.current).toBe(1);
|
|
51
|
+
|
|
52
|
+
act(() =>
|
|
53
|
+
store.set(
|
|
54
|
+
source,
|
|
55
|
+
new Map([
|
|
56
|
+
["a", 4],
|
|
57
|
+
["b", 3],
|
|
58
|
+
]),
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
expect(result.current).toBe(4);
|
|
62
|
+
expect(renders).toHaveBeenCalledTimes(1);
|
|
63
|
+
|
|
64
|
+
act(() => store.set(source, new Map([["b", 3]])));
|
|
65
|
+
expect(result.current).toBeUndefined();
|
|
66
|
+
expect(renders).toHaveBeenCalledTimes(2);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("keeps the selector stable on rerender and switches keys without stale reads", () => {
|
|
70
|
+
const { source, store, wrapper, select, useEntry } = setup();
|
|
71
|
+
const renders = vi.fn();
|
|
72
|
+
const { result, rerender } = renderHook(
|
|
73
|
+
({ id }) => {
|
|
74
|
+
renders();
|
|
75
|
+
return useEntry(id);
|
|
76
|
+
},
|
|
77
|
+
{ wrapper, initialProps: { id: "a" } },
|
|
78
|
+
);
|
|
79
|
+
select.mockClear();
|
|
80
|
+
rerender({ id: "a" });
|
|
81
|
+
expect(select).not.toHaveBeenCalled();
|
|
82
|
+
|
|
83
|
+
rerender({ id: "b" });
|
|
84
|
+
expect(result.current).toBe(2);
|
|
85
|
+
select.mockClear();
|
|
86
|
+
renders.mockClear();
|
|
87
|
+
act(() =>
|
|
88
|
+
store.set(
|
|
89
|
+
source,
|
|
90
|
+
new Map([
|
|
91
|
+
["a", 9],
|
|
92
|
+
["b", 2],
|
|
93
|
+
]),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
expect(renders).not.toHaveBeenCalled();
|
|
97
|
+
expect(select.mock.calls.map(([, key]) => key)).toEqual(["b"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("releases the source subscription and stops selecting after unmount", () => {
|
|
101
|
+
const { source, store, wrapper, select, useEntry } = setup();
|
|
102
|
+
const dispose = vi.fn();
|
|
103
|
+
source.onMount = () => dispose;
|
|
104
|
+
const { unmount } = renderHook(() => useEntry("a"), { wrapper });
|
|
105
|
+
select.mockClear();
|
|
106
|
+
unmount();
|
|
107
|
+
expect(dispose).toHaveBeenCalledTimes(1);
|
|
108
|
+
act(() => store.set(source, new Map([["a", 3]])));
|
|
109
|
+
expect(select).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("uses the current Provider store without sharing values between stores", () => {
|
|
113
|
+
const { source, store, wrapper, useEntry } = setup();
|
|
114
|
+
const otherStore = createStore();
|
|
115
|
+
otherStore.set(source, new Map([["a", 7]]));
|
|
116
|
+
const first = renderHook(() => useEntry("a"), { wrapper });
|
|
117
|
+
const second = renderHook(() => useEntry("a"), {
|
|
118
|
+
wrapper: ({ children }) => (
|
|
119
|
+
<Provider store={otherStore}>{children}</Provider>
|
|
120
|
+
),
|
|
121
|
+
});
|
|
122
|
+
expect(first.result.current).toBe(1);
|
|
123
|
+
expect(second.result.current).toBe(7);
|
|
124
|
+
act(() => store.set(source, new Map([["a", 9]])));
|
|
125
|
+
expect(first.result.current).toBe(9);
|
|
126
|
+
expect(second.result.current).toBe(7);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { type Atom, useAtomValue } from "jotai";
|
|
4
|
+
import { selectAtom } from "jotai/utils";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Define at module scope to subscribe to one keyed slice of immutable state.
|
|
9
|
+
*
|
|
10
|
+
* The selector should return a primitive or a structurally shared value.
|
|
11
|
+
* Each mounted hook owns its atom; no global key cache needs eviction.
|
|
12
|
+
* This isolates renders, but selectors still run when the source changes:
|
|
13
|
+
* reducers must preserve state identity for no-op actions.
|
|
14
|
+
*/
|
|
15
|
+
export function createKeyedSelectorHook<State, Key, Slice>(
|
|
16
|
+
source: Atom<State>,
|
|
17
|
+
select: (state: State, key: Key) => Slice,
|
|
18
|
+
) {
|
|
19
|
+
return function useKeyedSelector(key: Key): Slice {
|
|
20
|
+
const selected = useMemo(
|
|
21
|
+
() => selectAtom(source, (state) => select(state, key)),
|
|
22
|
+
[key],
|
|
23
|
+
);
|
|
24
|
+
return useAtomValue(selected);
|
|
25
|
+
};
|
|
26
|
+
}
|