@marimo-team/islands 0.23.15-dev2 → 0.23.15-dev20
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/{chat-ui-DinOvbWu.js → chat-ui-FiwuOgQU.js} +3094 -3094
- package/dist/{code-visibility-B-sydhvS.js → code-visibility-DNwczZr1.js} +925 -842
- package/dist/{html-to-image-_wGfk8V-.js → html-to-image-JXL8cvmt.js} +2218 -2205
- package/dist/main.js +1066 -1073
- package/dist/{process-output-Mh4UrjwM.js → process-output-CnDIXtM-.js} +1 -1
- package/dist/{reveal-component-MK2nUbwt.js → reveal-component-Cb5uzhCh.js} +614 -602
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/chat/__tests__/chat-utils.test.ts +244 -1
- package/src/components/chat/__tests__/message-queue.test.tsx +121 -0
- package/src/components/chat/chat-panel.tsx +196 -67
- package/src/components/chat/chat-utils.ts +111 -2
- package/src/components/editor/SortableCell.tsx +6 -2
- package/src/components/editor/__tests__/output-persistence.test.tsx +241 -0
- package/src/components/editor/cell/cell-context-menu.tsx +7 -0
- package/src/components/editor/chrome/panels/packages-panel.tsx +11 -1
- package/src/components/editor/columns/__tests__/cell-column.test.tsx +105 -0
- package/src/components/editor/columns/cell-column.tsx +34 -4
- package/src/components/editor/columns/sortable-column.tsx +24 -4
- package/src/components/editor/notebook-cell.tsx +203 -106
- package/src/components/editor/renderers/__tests__/cells-renderer.test.tsx +66 -0
- package/src/components/editor/renderers/cell-array.tsx +26 -13
- package/src/components/editor/renderers/cells-renderer.tsx +8 -2
- package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +29 -0
- package/src/components/editor/renderers/slides-layout/types.ts +4 -0
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +19 -19
- package/src/components/slides/reveal-component.tsx +33 -4
- package/src/components/slides/slide-form.tsx +72 -0
- package/src/core/cells/__tests__/utils.test.ts +59 -0
- package/src/core/cells/utils.ts +51 -0
- package/src/css/app/Cell.css +10 -0
- package/src/hooks/__tests__/useHotkey.test.tsx +88 -0
- package/src/hooks/useHotkey.ts +29 -4
- package/src/plugins/impl/anywidget/__tests__/host.test.ts +6 -9
- package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +22 -61
- package/src/plugins/impl/anywidget/model-proxy.ts +0 -13
- package/src/plugins/impl/anywidget/widget-binding.ts +4 -34
- package/src/plugins/impl/matplotlib/__tests__/matplotlib-renderer.test.ts +71 -3
- package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +1 -0
|
@@ -337,13 +337,12 @@ describe("WidgetBinding", () => {
|
|
|
337
337
|
{ el: document.createElement("div") },
|
|
338
338
|
{ signal: controller.signal },
|
|
339
339
|
);
|
|
340
|
-
// Called once by the hydration replay at mount, once by the set.
|
|
341
340
|
model.set("count", 1);
|
|
342
|
-
expect(onCount).toHaveBeenCalledTimes(
|
|
341
|
+
expect(onCount).toHaveBeenCalledTimes(1);
|
|
343
342
|
|
|
344
343
|
controller.abort();
|
|
345
344
|
model.set("count", 2);
|
|
346
|
-
expect(onCount).toHaveBeenCalledTimes(
|
|
345
|
+
expect(onCount).toHaveBeenCalledTimes(1);
|
|
347
346
|
});
|
|
348
347
|
|
|
349
348
|
it("should auto-clear initialize listeners on destroy", async () => {
|
|
@@ -366,92 +365,54 @@ describe("WidgetBinding", () => {
|
|
|
366
365
|
});
|
|
367
366
|
});
|
|
368
367
|
|
|
369
|
-
describe("WidgetBinding
|
|
370
|
-
it("
|
|
368
|
+
describe("WidgetBinding render listeners", () => {
|
|
369
|
+
it("fire only for changes after mount, never for pre-existing state", async () => {
|
|
371
370
|
const model = new Model<ModelState>({ count: 8 }, createMockComm());
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
render: vi.fn(({ model, el }) => {
|
|
375
|
-
// A widget view that starts with a local default and relies on
|
|
376
|
-
// change events for hydration.
|
|
377
|
-
el.textContent = "count is 5";
|
|
378
|
-
model.on("change:count", () => {
|
|
379
|
-
el.textContent = `count is ${model.get("count")}`;
|
|
380
|
-
});
|
|
381
|
-
}),
|
|
382
|
-
};
|
|
383
|
-
const binding = await createBinding(widgetDef, model);
|
|
384
|
-
|
|
385
|
-
const controller = new AbortController();
|
|
386
|
-
await binding.createView({ el }, { signal: controller.signal });
|
|
387
|
-
expect(el.textContent).toBe("count is 8");
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it("does not re-fire listeners of already-mounted views", async () => {
|
|
391
|
-
// Mounting view B must not double-paint view A: the replay is
|
|
392
|
-
// scoped to the listeners the new render attached.
|
|
393
|
-
const model = new Model<ModelState>({ count: 0 }, createMockComm());
|
|
394
|
-
const listeners: Array<ReturnType<typeof vi.fn>> = [];
|
|
371
|
+
const onCount = vi.fn();
|
|
372
|
+
const onAnyChange = vi.fn();
|
|
395
373
|
const widgetDef = {
|
|
396
374
|
render: vi.fn(({ model }) => {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
model.on("change:count", listener);
|
|
375
|
+
model.on("change:count", onCount);
|
|
376
|
+
model.on("change", onAnyChange);
|
|
400
377
|
}),
|
|
401
378
|
};
|
|
402
379
|
const binding = await createBinding(widgetDef, model);
|
|
403
380
|
const controller = new AbortController();
|
|
404
|
-
|
|
405
381
|
await binding.createView(
|
|
406
382
|
{ el: document.createElement("div") },
|
|
407
383
|
{ signal: controller.signal },
|
|
408
384
|
);
|
|
409
|
-
expect(
|
|
385
|
+
expect(onCount).not.toHaveBeenCalled();
|
|
386
|
+
expect(onAnyChange).not.toHaveBeenCalled();
|
|
410
387
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
);
|
|
415
|
-
// View B's listener hydrated once; view A's was left alone.
|
|
416
|
-
expect(listeners[1]).toHaveBeenCalledTimes(1);
|
|
417
|
-
expect(listeners[0]).toHaveBeenCalledTimes(1);
|
|
388
|
+
model.set("count", 9);
|
|
389
|
+
expect(onCount).toHaveBeenCalledTimes(1);
|
|
390
|
+
expect(onCount).toHaveBeenCalledWith(9);
|
|
418
391
|
});
|
|
419
392
|
|
|
420
|
-
it("
|
|
421
|
-
const model = new Model<ModelState>({ count:
|
|
422
|
-
const
|
|
393
|
+
it("mounting a second view does not fire the first view's listeners", async () => {
|
|
394
|
+
const model = new Model<ModelState>({ count: 0 }, createMockComm());
|
|
395
|
+
const listeners: Array<ReturnType<typeof vi.fn>> = [];
|
|
423
396
|
const widgetDef = {
|
|
424
397
|
render: vi.fn(({ model }) => {
|
|
425
|
-
|
|
398
|
+
const listener = vi.fn();
|
|
399
|
+
listeners.push(listener);
|
|
400
|
+
model.on("change:count", listener);
|
|
426
401
|
}),
|
|
427
402
|
};
|
|
428
403
|
const binding = await createBinding(widgetDef, model);
|
|
429
404
|
const controller = new AbortController();
|
|
405
|
+
|
|
430
406
|
await binding.createView(
|
|
431
407
|
{ el: document.createElement("div") },
|
|
432
408
|
{ signal: controller.signal },
|
|
433
409
|
);
|
|
434
|
-
expect(onAnyChange).toHaveBeenCalledTimes(1);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
it("does not replay initialize listeners", async () => {
|
|
438
|
-
// The guarantee is per-view: initialize listeners existed before
|
|
439
|
-
// any view, and replaying at them would fire once per mount.
|
|
440
|
-
const model = new Model<ModelState>({ count: 1 }, createMockComm());
|
|
441
|
-
const initListener = vi.fn();
|
|
442
|
-
const widgetDef = {
|
|
443
|
-
initialize: vi.fn(({ model }) => {
|
|
444
|
-
model.on("change:count", initListener);
|
|
445
|
-
}),
|
|
446
|
-
render: vi.fn(),
|
|
447
|
-
};
|
|
448
|
-
const binding = await createBinding(widgetDef, model);
|
|
449
|
-
const controller = new AbortController();
|
|
450
410
|
await binding.createView(
|
|
451
411
|
{ el: document.createElement("div") },
|
|
452
412
|
{ signal: controller.signal },
|
|
453
413
|
);
|
|
454
|
-
expect(
|
|
414
|
+
expect(listeners[0]).not.toHaveBeenCalled();
|
|
415
|
+
expect(listeners[1]).not.toHaveBeenCalled();
|
|
455
416
|
});
|
|
456
417
|
|
|
457
418
|
it("clears the element before rendering into it", async () => {
|
|
@@ -5,15 +5,6 @@ import type { ModelState } from "./types";
|
|
|
5
5
|
|
|
6
6
|
type ModelEventCallback = Parameters<AnyModel<ModelState>["on"]>[1];
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* A listener registered through a model proxy (see the hydration
|
|
10
|
-
* replay in `WidgetBinding.createView`).
|
|
11
|
-
*/
|
|
12
|
-
export interface ProxyRegistration {
|
|
13
|
-
event: string;
|
|
14
|
-
callback: ModelEventCallback;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
8
|
/**
|
|
18
9
|
* Wrap a model so every `on()` call from inside `initialize` or `render`
|
|
19
10
|
* is auto-tied to a lifetime `AbortSignal`. When the signal aborts,
|
|
@@ -27,14 +18,11 @@ export interface ProxyRegistration {
|
|
|
27
18
|
* The proxy is purely a host-side ergonomic helper. The widget author
|
|
28
19
|
* still writes `model.on("change:foo", handler)` exactly as before; the
|
|
29
20
|
* cleanup signal is supplied transparently.
|
|
30
|
-
*
|
|
31
|
-
* `onRegister`, when given, observes each `on()` registration.
|
|
32
21
|
*/
|
|
33
22
|
// oxlint-disable-next-line marimo/prefer-object-params -- concise internal helper used at protocol call sites
|
|
34
23
|
export function modelProxy<T extends ModelState>(
|
|
35
24
|
model: AnyModel<T>,
|
|
36
25
|
signal: AbortSignal,
|
|
37
|
-
onRegister?: (registration: ProxyRegistration) => void,
|
|
38
26
|
): AnyModel<T> {
|
|
39
27
|
return {
|
|
40
28
|
get(key) {
|
|
@@ -55,7 +43,6 @@ export function modelProxy<T extends ModelState>(
|
|
|
55
43
|
signal.addEventListener("abort", () => model.off(name, callback), {
|
|
56
44
|
once: true,
|
|
57
45
|
});
|
|
58
|
-
onRegister?.({ event: name, callback });
|
|
59
46
|
},
|
|
60
47
|
off(name?: string | null, callback?: ModelEventCallback | null): void {
|
|
61
48
|
model.off(name ?? null, callback ?? null);
|
|
@@ -12,7 +12,7 @@ import { isTrustedVirtualFileUrl } from "@/plugins/core/trusted-url";
|
|
|
12
12
|
import { Logger } from "@/utils/Logger";
|
|
13
13
|
import type { Host } from "./host";
|
|
14
14
|
import type { Model } from "./model";
|
|
15
|
-
import { modelProxy
|
|
15
|
+
import { modelProxy } from "./model-proxy";
|
|
16
16
|
import type { ModelState } from "./types";
|
|
17
17
|
|
|
18
18
|
export const experimental: Experimental = {
|
|
@@ -266,9 +266,8 @@ export class WidgetBinding<T extends ModelState = ModelState> {
|
|
|
266
266
|
* when the caller's `signal` fires or the binding is destroyed, and
|
|
267
267
|
* listeners registered inside `render` auto-clear on abort.
|
|
268
268
|
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* to this view's listeners; re-firing at other views double-paints.
|
|
269
|
+
* `render` reads current state via `model.get`; change listeners
|
|
270
|
+
* observe only subsequent changes, matching Jupyter semantics.
|
|
272
271
|
*/
|
|
273
272
|
async createView(
|
|
274
273
|
target: { el: HTMLElement },
|
|
@@ -305,11 +304,8 @@ export class WidgetBinding<T extends ModelState = ModelState> {
|
|
|
305
304
|
// Each view gets a host scoped to its own signal so child views tear
|
|
306
305
|
// down with this view.
|
|
307
306
|
const host = this.#createHost(renderSignal);
|
|
308
|
-
const registrations: ProxyRegistration[] = [];
|
|
309
307
|
const renderCleanup = await widget.render({
|
|
310
|
-
model: modelProxy(this.#model, renderSignal,
|
|
311
|
-
registrations.push(registration),
|
|
312
|
-
),
|
|
308
|
+
model: modelProxy(this.#model, renderSignal),
|
|
313
309
|
el: target.el,
|
|
314
310
|
experimental,
|
|
315
311
|
signal: renderSignal,
|
|
@@ -333,7 +329,6 @@ export class WidgetBinding<T extends ModelState = ModelState> {
|
|
|
333
329
|
once: true,
|
|
334
330
|
});
|
|
335
331
|
}
|
|
336
|
-
this.#replayState(registrations, renderSignal);
|
|
337
332
|
}
|
|
338
333
|
|
|
339
334
|
#trackCleanup(cleanup: Cleanup, reason: string): Promise<void> {
|
|
@@ -343,31 +338,6 @@ export class WidgetBinding<T extends ModelState = ModelState> {
|
|
|
343
338
|
return task;
|
|
344
339
|
}
|
|
345
340
|
|
|
346
|
-
/**
|
|
347
|
-
* The hydration guarantee documented on `createView`.
|
|
348
|
-
*/
|
|
349
|
-
#replayState(
|
|
350
|
-
registrations: readonly ProxyRegistration[],
|
|
351
|
-
renderSignal: AbortSignal,
|
|
352
|
-
): void {
|
|
353
|
-
const changePrefix = "change:";
|
|
354
|
-
for (const { event, callback } of registrations) {
|
|
355
|
-
if (renderSignal.aborted) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
try {
|
|
359
|
-
if (event.startsWith(changePrefix)) {
|
|
360
|
-
const key = event.slice(changePrefix.length);
|
|
361
|
-
callback(this.#model.get(key));
|
|
362
|
-
} else if (event === "change") {
|
|
363
|
-
callback();
|
|
364
|
-
}
|
|
365
|
-
} catch (error) {
|
|
366
|
-
Logger.error("[WidgetBinding] Error replaying state", error);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
341
|
/**
|
|
372
342
|
* Destroy this generation, running initialize/render cleanups and
|
|
373
343
|
* clearing listeners registered through its model proxies.
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
type Data,
|
|
5
|
+
MatplotlibRenderer,
|
|
6
|
+
type MatplotlibState,
|
|
7
|
+
visibleForTesting,
|
|
8
|
+
} from "../matplotlib-renderer";
|
|
5
9
|
|
|
6
10
|
const {
|
|
7
11
|
pixelToData,
|
|
@@ -185,3 +189,67 @@ describe("isInAxes", () => {
|
|
|
185
189
|
expect(isInAxes({ x: 300, y: 351 }, LINEAR_AXES)).toBe(false);
|
|
186
190
|
});
|
|
187
191
|
});
|
|
192
|
+
|
|
193
|
+
describe("MatplotlibRenderer", () => {
|
|
194
|
+
afterEach(() => {
|
|
195
|
+
vi.unstubAllGlobals();
|
|
196
|
+
vi.restoreAllMocks();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("restores a new selection when the chart changes", () => {
|
|
200
|
+
vi.stubGlobal(
|
|
201
|
+
"matchMedia",
|
|
202
|
+
vi.fn(() => ({ addEventListener: vi.fn() })),
|
|
203
|
+
);
|
|
204
|
+
vi.stubGlobal(
|
|
205
|
+
"requestAnimationFrame",
|
|
206
|
+
vi.fn(() => 1),
|
|
207
|
+
);
|
|
208
|
+
vi.stubGlobal("cancelAnimationFrame", vi.fn());
|
|
209
|
+
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);
|
|
210
|
+
|
|
211
|
+
const value = {
|
|
212
|
+
type: "box",
|
|
213
|
+
has_selection: true,
|
|
214
|
+
data: { x_min: 2, x_max: 4, y_min: 2, y_max: 4 },
|
|
215
|
+
} as const;
|
|
216
|
+
const state: MatplotlibState = {
|
|
217
|
+
...LINEAR_AXES,
|
|
218
|
+
axesPixelBounds: [0, 0, 100, 100],
|
|
219
|
+
yBounds: [0, 10],
|
|
220
|
+
chartBase64: "first",
|
|
221
|
+
width: 100,
|
|
222
|
+
height: 100,
|
|
223
|
+
selectionColor: "blue",
|
|
224
|
+
selectionOpacity: 0.15,
|
|
225
|
+
strokeWidth: 2,
|
|
226
|
+
debounce: false,
|
|
227
|
+
value: { has_selection: false },
|
|
228
|
+
setValue: vi.fn(),
|
|
229
|
+
};
|
|
230
|
+
const container = document.createElement("div");
|
|
231
|
+
const controller = new AbortController();
|
|
232
|
+
const renderer = new MatplotlibRenderer(container, {
|
|
233
|
+
state,
|
|
234
|
+
signal: controller.signal,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Cell reruns reuse the renderer, updating the chart and initial value together.
|
|
238
|
+
renderer.update({ ...state, chartBase64: "second", value });
|
|
239
|
+
|
|
240
|
+
const canvas = container.querySelector("canvas");
|
|
241
|
+
expect(canvas).not.toBeNull();
|
|
242
|
+
if (!canvas) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
vi.spyOn(canvas, "getBoundingClientRect").mockReturnValue(
|
|
246
|
+
DOMRect.fromRect({ width: 100, height: 100 }),
|
|
247
|
+
);
|
|
248
|
+
canvas.dispatchEvent(
|
|
249
|
+
new MouseEvent("pointermove", { clientX: 30, clientY: 70 }),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
expect(canvas.style.cursor).toBe("move");
|
|
253
|
+
controller.abort();
|
|
254
|
+
});
|
|
255
|
+
});
|