@marimo-team/islands 0.25.3-dev100 → 0.25.3-dev101

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.
@@ -0,0 +1,61 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type * as Protocol from "@marimo-team/client/protocol";
4
+ import type { createStore } from "jotai/vanilla";
5
+ import type { DocumentModel } from "../model";
6
+
7
+ /** Translate user actions and observations without keeping any expected state. */
8
+ export function createUser(
9
+ store: ReturnType<typeof createStore>,
10
+ model: DocumentModel,
11
+ ) {
12
+ function observe(promise: Promise<Protocol.Document>) {
13
+ // A failed assertion may end a scenario before it awaits sync; teardown
14
+ // should not obscure that failure with an unhandled abort rejection.
15
+ void promise.catch(() => undefined);
16
+ return promise;
17
+ }
18
+ return {
19
+ changeCode(id: Protocol.CellId, code: string) {
20
+ store.set(model.editAtom, (tx) => tx.setCode(id, code));
21
+ },
22
+ changeCells(
23
+ changes: Record<Protocol.CellId, Partial<Omit<Protocol.CellInput, "id">>>,
24
+ ) {
25
+ store.set(model.editAtom, (tx) => {
26
+ for (const [id, patch] of Object.entries(changes)) {
27
+ if (patch.code !== undefined) {
28
+ tx.setCode(id, patch.code);
29
+ }
30
+ if (patch.name !== undefined) {
31
+ tx.setName(id, patch.name);
32
+ }
33
+ if (patch.config !== undefined) {
34
+ tx.updateConfig(id, patch.config);
35
+ }
36
+ }
37
+ });
38
+ },
39
+ createCell(cell: Protocol.CellInput) {
40
+ store.set(model.editAtom, (tx) => tx.createCell(cell));
41
+ },
42
+ deleteCell(id: Protocol.CellId) {
43
+ store.set(model.editAtom, (tx) => tx.deleteCell(id));
44
+ },
45
+ cell(id: Protocol.CellId) {
46
+ const cell = store.get(model.cellAtom(id));
47
+ return cell === undefined
48
+ ? undefined
49
+ : {
50
+ id: cell.id,
51
+ code: cell.code,
52
+ name: cell.name,
53
+ config: cell.config,
54
+ };
55
+ },
56
+ order: () => store.get(model.orderAtom),
57
+ status: () => store.get(model.syncStateAtom),
58
+ sync: () => observe(model.flush()),
59
+ retry: () => observe(model.retry()),
60
+ };
61
+ }