@marimo-team/islands 0.25.3-dev40 → 0.25.3-dev42

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.
Files changed (35) hide show
  1. package/dist/{ErrorBoundary-C7__jAZL.js → ErrorBoundary-Bb_hjI-F.js} +1 -1
  2. package/dist/{chat-ui-DGpBSln7.js → chat-ui-DlUp75HS.js} +4 -4
  3. package/dist/{code-visibility-DO4MlViW.js → code-visibility-BseAT0Di.js} +3 -3
  4. package/dist/{common-Ci7TC3e0.js → common--apjoMvk.js} +5 -5
  5. package/dist/{data-grid-overlay-editor-DpH_AKdC.js → data-grid-overlay-editor-C2eZGIzb.js} +1 -1
  6. package/dist/{error-entries-D576fzV9.js → error-entries-D3ouOLDe.js} +1 -1
  7. package/dist/{feedback-button-BV5AJ3nl.js → feedback-button-Cy7x7fiM.js} +3 -3
  8. package/dist/{formats-DIVMVjeV.js → formats-C24TvExI.js} +1 -1
  9. package/dist/{glide-data-editor-CRK-O0KE.js → glide-data-editor-CYonCTY5.js} +3 -3
  10. package/dist/{globals-H_ILLmr7.js → globals-W7yeDcvx.js} +1 -1
  11. package/dist/{html-to-image-D3m5Ob5H.js → html-to-image-VZvb968z.js} +2 -2
  12. package/dist/main.js +13 -13
  13. package/dist/{number-overlay-editor-BQ2UqdED.js → number-overlay-editor-_5SNWHjp.js} +1 -1
  14. package/dist/{process-output-C6qc7hPS.js → process-output-CCPgTShO.js} +2 -2
  15. package/dist/{reveal-component-Cs-0GwxY.js → reveal-component-DV1u0Sl1.js} +4 -4
  16. package/dist/{toDate-CSY-j1Fi.js → toDate-C0jaysq2.js} +93 -94
  17. package/dist/{vega-component-Df45z17m.js → vega-component-CF9IzE2r.js} +2 -2
  18. package/package.json +2 -4
  19. package/src/__tests__/host-imports.test.ts +1 -0
  20. package/src/core/attachments/state.ts +2 -2
  21. package/src/core/host/AGENTS.md +6 -2
  22. package/src/core/host/__tests__/attachments.test.ts +9 -10
  23. package/src/core/host/__tests__/document.test.ts +18 -16
  24. package/src/core/host/__tests__/events.test.ts +5 -2
  25. package/src/core/host/__tests__/fixtures.ts +6 -4
  26. package/src/core/host/events.ts +18 -2
  27. package/src/core/host/notebook-client.ts +46 -13
  28. package/src/core/host/resources/attachments.ts +3 -3
  29. package/src/core/host/resources/document.ts +3 -3
  30. package/src/core/websocket/__tests__/useNotebookSession.hook.test.tsx +1 -1
  31. package/src/core/host/__tests__/protocol.test.ts +0 -229
  32. package/src/core/host/__tests__/stream.test.ts +0 -209
  33. package/src/core/host/protocol.ts +0 -1948
  34. package/src/core/host/resources/resource.ts +0 -47
  35. package/src/core/host/stream.ts +0 -211
@@ -1,209 +0,0 @@
1
- /* Copyright 2026 Marimo. All rights reserved. */
2
-
3
- import { describe, expect, it } from "vitest";
4
- import type { NotebookEvent } from "../events";
5
- import type { Resource } from "../resources/resource";
6
- import { createStream } from "../stream";
7
- import { fixtureEvents } from "./fixtures";
8
-
9
- interface CellIds {
10
- readonly ids: readonly string[];
11
- }
12
-
13
- /** A resource whose events are complete on their own. */
14
- const cells: Resource<CellIds> = {
15
- initial: { ids: [] },
16
- on: {
17
- cell: (state, event) =>
18
- state.ids.includes(event.data.cell.id)
19
- ? state
20
- : { ids: [...state.ids, event.data.cell.id] },
21
- "cell.removed": (state, event) =>
22
- state.ids.includes(event.data.id)
23
- ? { ids: state.ids.filter((id) => id !== event.data.id) }
24
- : state,
25
- },
26
- };
27
-
28
- interface Revisions {
29
- /** Cells changed since the last revision. */
30
- readonly pending: readonly string[];
31
- readonly published: readonly (readonly string[])[];
32
- }
33
-
34
- function publish(state: Revisions): Revisions {
35
- return { pending: [], published: [...state.published, state.pending] };
36
- }
37
-
38
- /** A resource assembled from groups of events, like a document from its cells. */
39
- const revisions: Resource<Revisions> = {
40
- initial: { pending: [], published: [] },
41
- on: {
42
- cell: (state, event) => ({
43
- ...state,
44
- pending: [...state.pending, event.data.cell.id],
45
- }),
46
- "cell.removed": (state, event) => ({
47
- ...state,
48
- pending: [...state.pending, event.data.id],
49
- }),
50
- // A live revision completes a group. A snapshot's revision waits for ready.
51
- document: (state, _event, { phase }) =>
52
- phase === "live" ? publish(state) : state,
53
- ready: publish,
54
- },
55
- };
56
-
57
- function createTestStream() {
58
- return createStream({ cells, revisions });
59
- }
60
-
61
- function replay(
62
- stream: ReturnType<typeof createTestStream>,
63
- events: readonly NotebookEvent[],
64
- from = stream.initial,
65
- ) {
66
- return events.reduce((state, event) => stream.reduce(state, event), from);
67
- }
68
-
69
- const snapshot = fixtureEvents("notebook-events.sse");
70
- const ready = snapshot.findIndex((event) => event.event === "ready");
71
- const cellEvent = snapshot.find((event) => event.event === "cell");
72
- if (cellEvent?.event !== "cell") {
73
- throw new Error("Fixture is missing a cell event");
74
- }
75
-
76
- describe("notebook stream", () => {
77
- it("reads the snapshot, goes live at ready, and rebuilds after reset", () => {
78
- const stream = createTestStream();
79
- const partial = replay(stream, snapshot.slice(0, ready));
80
- expect(partial).toMatchObject({
81
- phase: "snapshot",
82
- notebookId: "n1",
83
- cursor: null,
84
- });
85
- expect(partial.resources.cells.ids).toEqual(["c1", "c3", "k7f2"]);
86
- expect(partial.resources.revisions).toEqual({
87
- pending: ["c1", "c3", "k7f2"],
88
- published: [],
89
- });
90
-
91
- const live = replay(stream, snapshot.slice(ready), partial);
92
- expect(live).toMatchObject({ phase: "live", cursor: "97" });
93
- expect(live.resources.cells).toBe(partial.resources.cells);
94
- expect(live.resources.revisions).toEqual({
95
- pending: [],
96
- published: [["c1", "c3", "k7f2"]],
97
- });
98
-
99
- const resetEvents = fixtureEvents("events-reset.sse");
100
- const afterReset = stream.reduce(live, resetEvents[0]);
101
- expect(afterReset).toEqual({ ...stream.initial, notebookId: "n1" });
102
- expect(replay(stream, resetEvents, live).phase).toBe("live");
103
- });
104
-
105
- it("keeps resource state by reference when an event does not apply", () => {
106
- const stream = createTestStream();
107
- const state = replay(stream, snapshot);
108
- const runtime = snapshot.find((event) => event.event === "runtime");
109
- const unhandled = stream.reduce(state, { ...runtime!, id: "100" });
110
- expect(unhandled.resources).toBe(state.resources);
111
- expect(unhandled.cursor).toBe("100");
112
- expect(
113
- stream.reduce(state, { event: "unknown", name: "x", id: "101" })
114
- .resources,
115
- ).toBe(state.resources);
116
- expect(
117
- stream.reduce(state, { event: "marimo", data: { marimo: {} } }),
118
- ).toBe(state);
119
- });
120
-
121
- it("clears resources when its notebook is removed and ignores other notebooks", () => {
122
- const stream = createTestStream();
123
- const state = replay(stream, snapshot);
124
- const time = "2026-10-01T09:30:00Z";
125
- expect(
126
- stream.reduce(state, {
127
- event: "notebook.removed",
128
- id: "100",
129
- data: { id: "n2", time },
130
- }).resources,
131
- ).toBe(state.resources);
132
- const removed = stream.reduce(state, {
133
- event: "notebook.removed",
134
- id: "100",
135
- data: { id: "n1", time },
136
- });
137
- expect(removed).toMatchObject({ phase: "live", notebookId: "n1" });
138
- expect(removed.resources).toBe(stream.initial.resources);
139
- });
140
-
141
- it("rejects objects from another notebook", () => {
142
- const stream = createTestStream();
143
- const state = replay(stream, snapshot.slice(0, ready));
144
- const notebook = snapshot[0];
145
- if (notebook.event !== "notebook") {
146
- throw new Error("Fixture does not start with its notebook");
147
- }
148
- expect(() =>
149
- stream.reduce(state, {
150
- ...notebook,
151
- data: { notebook: { ...notebook.data.notebook, id: "n2" } },
152
- }),
153
- ).toThrow("changed identity");
154
- expect(() =>
155
- stream.reduce(state, {
156
- ...cellEvent,
157
- data: { cell: { ...cellEvent.data.cell, notebook_id: "n2" } },
158
- }),
159
- ).toThrow("changed identity");
160
- });
161
-
162
- it("records each live event's cursor and resumes in place", () => {
163
- const stream = createTestStream();
164
- const partial = replay(stream, snapshot.slice(0, ready));
165
- expect(stream.resume(partial)).toEqual({
166
- ...stream.initial,
167
- notebookId: "n1",
168
- });
169
-
170
- const live = replay(stream, snapshot.slice(ready), partial);
171
- const [cell, , removed, published, saved] = fixtureEvents("edits.sse");
172
- const editing = replay(stream, [cell], live);
173
- expect(editing.cursor).toBe("110");
174
- expect(editing.resources.revisions.pending).toEqual(["c2"]);
175
- expect(stream.resume(editing)).toBe(editing);
176
-
177
- const edited = replay(stream, [removed, published], editing);
178
- expect(edited.cursor).toBe("113");
179
- expect(edited.resources.revisions).toEqual({
180
- pending: [],
181
- published: [
182
- ["c1", "c3", "k7f2"],
183
- ["c2", "k7f2"],
184
- ],
185
- });
186
- expect(stream.reduce(edited, saved).cursor).toBe("114");
187
- expect(
188
- stream.reduce(edited, { event: "ready", id: "116", data: {} }).cursor,
189
- ).toBe("116");
190
- expect(stream.reduce(edited, { event: "reset", data: {} }).cursor).toBe(
191
- null,
192
- );
193
- });
194
-
195
- it("requires a cursor on live events other than reset and notifications", () => {
196
- const stream = createTestStream();
197
- const state = replay(stream, snapshot);
198
- expect(() => stream.reduce(state, cellEvent)).toThrow("cursor");
199
- expect(
200
- stream.reduce(state, { ...cellEvent, id: "100" }).resources.cells,
201
- ).toBe(state.resources.cells);
202
- expect(stream.reduce(state, { event: "reset", data: {} }).phase).toBe(
203
- "snapshot",
204
- );
205
- expect(
206
- stream.reduce(state, { event: "marimo", data: { marimo: null } }),
207
- ).toBe(state);
208
- });
209
- });