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

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 (38) hide show
  1. package/dist/{ErrorBoundary-C7__jAZL.js → ErrorBoundary-C0Oq0jHx.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-B1eNzkOg.js} +3 -3
  4. package/dist/{common-Ci7TC3e0.js → common-pqD_dOGD.js} +70 -71
  5. package/dist/{data-grid-overlay-editor-DpH_AKdC.js → data-grid-overlay-editor-pTWEP43w.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-dWEWzzD4.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-DBnOUonk.js} +3 -3
  10. package/dist/{globals-H_ILLmr7.js → globals-DYaD1Xz7.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-BURiB1Nu.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-s74n77kc.js} +4 -4
  16. package/dist/style.css +1 -1
  17. package/dist/{toDate-CSY-j1Fi.js → toDate-C0jaysq2.js} +93 -94
  18. package/dist/{vega-component-Df45z17m.js → vega-component-CF9IzE2r.js} +2 -2
  19. package/package.json +2 -4
  20. package/src/__tests__/host-imports.test.ts +1 -0
  21. package/src/components/data-table/__tests__/export-actions.test.tsx +88 -0
  22. package/src/components/data-table/export-actions.tsx +71 -45
  23. package/src/core/attachments/state.ts +2 -2
  24. package/src/core/host/AGENTS.md +6 -2
  25. package/src/core/host/__tests__/attachments.test.ts +9 -10
  26. package/src/core/host/__tests__/document.test.ts +18 -16
  27. package/src/core/host/__tests__/events.test.ts +5 -2
  28. package/src/core/host/__tests__/fixtures.ts +6 -4
  29. package/src/core/host/events.ts +18 -2
  30. package/src/core/host/notebook-client.ts +46 -13
  31. package/src/core/host/resources/attachments.ts +3 -3
  32. package/src/core/host/resources/document.ts +3 -3
  33. package/src/core/websocket/__tests__/useNotebookSession.hook.test.tsx +1 -1
  34. package/src/core/host/__tests__/protocol.test.ts +0 -229
  35. package/src/core/host/__tests__/stream.test.ts +0 -209
  36. package/src/core/host/protocol.ts +0 -1948
  37. package/src/core/host/resources/resource.ts +0 -47
  38. package/src/core/host/stream.ts +0 -211
@@ -1,229 +0,0 @@
1
- /* Copyright 2026 Marimo. All rights reserved. */
2
-
3
- import NodeFs from "node:fs";
4
- import NodeUrl from "node:url";
5
- import { describe, expect, expectTypeOf, it } from "vitest";
6
- import * as Protocol from "../protocol";
7
-
8
- const fixtures = new NodeUrl.URL(
9
- "../../../../../protocols/host/fixtures/",
10
- import.meta.url,
11
- );
12
-
13
- function readFixture(name: string): unknown {
14
- return JSON.parse(
15
- NodeFs.readFileSync(new NodeUrl.URL(name, fixtures), "utf8"),
16
- );
17
- }
18
-
19
- const records = {
20
- "record.json": Protocol.HostRecord,
21
- "cell.json": Protocol.Cell,
22
- "cell-withheld.json": Protocol.Cell,
23
- "analysis.json": Protocol.Analysis,
24
- "diagnostic.json": Protocol.Error,
25
- "edit.json": Protocol.EditRequest,
26
- "edit-conflict-request.json": Protocol.EditRequest,
27
- "edit-response.json": Protocol.EditResponse,
28
- "execution-restored.json": Protocol.Execution,
29
- "run-cells-request.json": Protocol.RunRequest,
30
- };
31
-
32
- describe("host protocol fixtures", () => {
33
- it.each(Object.entries(records))("parses %s unchanged", (name, schema) => {
34
- const input = readFixture(name);
35
- const original = structuredClone(input);
36
- expect(schema.parse(input)).toEqual(original);
37
- expect(input).toEqual(original);
38
- });
39
-
40
- it.each(NodeFs.readdirSync(new NodeUrl.URL("problems/", fixtures)))(
41
- "parses problem %s",
42
- (name) => {
43
- const input = readFixture(`problems/${name}`);
44
- expect(Protocol.Problem.parse(input)).toEqual(input);
45
- },
46
- );
47
-
48
- it.each(NodeFs.readdirSync(fixtures).filter((name) => name.endsWith(".sse")))(
49
- "parses events in %s unchanged",
50
- (name) => {
51
- const stream = NodeFs.readFileSync(
52
- new NodeUrl.URL(name, fixtures),
53
- "utf8",
54
- );
55
- let count = 0;
56
- for (const frame of stream.split(/\r?\n\r?\n/)) {
57
- const event = /^event: (.+)$/m.exec(frame)?.[1];
58
- if (!event && !/^data:/m.test(frame)) {
59
- continue;
60
- }
61
- const data = frame
62
- .split(/\r?\n/)
63
- .filter((line) => line.startsWith("data:"))
64
- .map((line) => line.slice(5).trimStart())
65
- .join("\n");
66
- const id = /^id: (.+)$/m.exec(frame)?.[1];
67
- const payload: unknown = JSON.parse(data);
68
- const input = { event, data: payload, ...(id ? { id } : {}) };
69
- const original = structuredClone(input);
70
- expect(Protocol.Event.parse(input)).toEqual(original);
71
- expect(input).toEqual(original);
72
- count += 1;
73
- }
74
- expect(count).toBeGreaterThan(0);
75
- },
76
- );
77
- });
78
-
79
- describe("host protocol bindings", () => {
80
- it("preserves native marimo payloads without interpreting them", () => {
81
- expectTypeOf<Protocol.MarimoEvent["data"]["marimo"]>().toBeUnknown();
82
- const input = {
83
- event: "marimo",
84
- id: "42",
85
- data: {
86
- marimo: {
87
- future_payload: { value: Number.NaN },
88
- },
89
- },
90
- };
91
- expect(Protocol.Event.parse(input)).toEqual(input);
92
- });
93
-
94
- it("accepts additive fields and preserves arbitrary notebook settings", () => {
95
- const cell = Protocol.Cell.parse(readFixture("cell.json"));
96
- const input = {
97
- ...cell,
98
- future: { enabled: true },
99
- config: { ...cell.config, future: 42 },
100
- };
101
- const original = structuredClone(input);
102
- expect(Protocol.Cell.parse(input)).toEqual(cell);
103
- expect(input).toEqual(original);
104
-
105
- const { document } = Protocol.EditResponse.parse(
106
- readFixture("edit-response.json"),
107
- );
108
- const configured = {
109
- ...document,
110
- app_config: { extension: { values: [1, null, false] } },
111
- };
112
- expect(Protocol.Document.parse(configured)).toEqual(configured);
113
- });
114
-
115
- it("requires source in edits while allowing withheld source in records", () => {
116
- expectTypeOf<Protocol.Cell["code"]>().toEqualTypeOf<string | null>();
117
- expectTypeOf<Protocol.CellInput["code"]>().toEqualTypeOf<string>();
118
- const cell = Protocol.Cell.parse(readFixture("cell.json"));
119
- const { code, ...missing } = cell;
120
- expect(Protocol.Cell.safeParse(missing).success).toBe(false);
121
- expect(Protocol.Cell.parse({ ...cell, code: "" }).code).toBe("");
122
- for (const input of [{ id: cell.id }, { id: cell.id, code: null }]) {
123
- expect(Protocol.CellInput.safeParse(input).success).toBe(false);
124
- }
125
- expect(Protocol.CellInput.parse({ id: cell.id, code }).code).toBe(code);
126
- expect(Protocol.CellInput.parse({ id: cell.id, code: "" }).code).toBe("");
127
- });
128
-
129
- it("applies the defaults declared for cell inputs", () => {
130
- expect(
131
- Protocol.CellInput.parse({ id: "c3", code: "x = 1", config: {} }),
132
- ).toEqual({
133
- id: "c3",
134
- code: "x = 1",
135
- name: "_",
136
- config: {
137
- column: null,
138
- disabled: false,
139
- hide_code: false,
140
- expand_output: false,
141
- },
142
- });
143
- });
144
-
145
- it.each(["run_id", "runtime_id", "caused_by"] as const)(
146
- "requires the nullable execution field %s",
147
- (field) => {
148
- const execution = Protocol.Execution.parse(
149
- readFixture("execution-restored.json"),
150
- );
151
- const missing = Object.fromEntries(
152
- Object.entries(execution).filter(([key]) => key !== field),
153
- );
154
- expect(Protocol.Execution.safeParse(missing).success).toBe(false);
155
- expect(
156
- Protocol.Execution.safeParse({ ...execution, [field]: null }).success,
157
- ).toBe(true);
158
- },
159
- );
160
-
161
- it("preserves snapshot metadata omissions and validates live timestamps", () => {
162
- const cell = Protocol.Cell.parse(readFixture("cell.json"));
163
- expect(Protocol.CellMessage.parse({ cell })).toEqual({ cell });
164
- const message = { cell, time: "2026-01-01T12:00:00+05:30" };
165
- expect(Protocol.CellMessage.parse(message)).toEqual(message);
166
- for (const time of [
167
- null,
168
- "yesterday",
169
- "2026-02-30T12:00:00Z",
170
- "2026-01-01T12:00:00",
171
- ]) {
172
- expect(Protocol.CellMessage.safeParse({ cell, time }).success).toBe(
173
- false,
174
- );
175
- }
176
- });
177
-
178
- it("rejects invalid cell fields without coercing their values", () => {
179
- const cell = Protocol.Cell.parse(readFixture("cell.json"));
180
- for (const patch of [
181
- { id: "" },
182
- { code: 42 },
183
- { etag: 42 },
184
- { version: "2" },
185
- { version: 0 },
186
- { version: 1.5 },
187
- { config: { ...cell.config, disabled: "false" } },
188
- ]) {
189
- expect(Protocol.Cell.safeParse({ ...cell, ...patch }).success).toBe(
190
- false,
191
- );
192
- }
193
- const result = Protocol.Cell.safeParse({ ...cell, code: 42 });
194
- expect(result.success).toBe(false);
195
- if (result.success) {
196
- throw new Error("Expected an invalid cell");
197
- }
198
- expect(result.error.issues).toEqual([
199
- expect.objectContaining({ path: ["code"], code: "invalid_type" }),
200
- ]);
201
- });
202
-
203
- it("requires the fields of the selected change kind", () => {
204
- const change = { kind: "delete_cell", id: "c3", base_etag: "*" };
205
- expect(Protocol.Change.parse(change)).toEqual(change);
206
- expect(
207
- Protocol.Change.safeParse({ kind: "delete_cell", id: "c3" }).success,
208
- ).toBe(false);
209
- expect(
210
- Protocol.Change.safeParse({ ...change, kind: "unknown" }).success,
211
- ).toBe(false);
212
- });
213
-
214
- it("requires custom payloads while allowing any JSON value", () => {
215
- for (const data of [
216
- null,
217
- false,
218
- 42,
219
- "text",
220
- { nested: [1, null, false] },
221
- ]) {
222
- const custom = { type: "example.event", data };
223
- expect(Protocol.Custom.parse(custom)).toEqual(custom);
224
- }
225
- expect(Protocol.Custom.safeParse({ type: "example.event" }).success).toBe(
226
- false,
227
- );
228
- });
229
- });
@@ -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
- });