@marimo-team/islands 0.21.2-dev6 → 0.21.2-dev61

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 (152) hide show
  1. package/dist/{ConnectedDataExplorerComponent-D0GoOd_c.js → ConnectedDataExplorerComponent-DrWDbHRV.js} +1 -1
  2. package/dist/{any-language-editor-DlsjUw_l.js → any-language-editor-BRpxklRq.js} +1 -1
  3. package/dist/{copy-DIK6DiIA.js → copy-BjkXCUxP.js} +12 -2
  4. package/dist/{esm-BLobyqMs.js → esm-No_6eSQS.js} +1 -1
  5. package/dist/{glide-data-editor-pZyd9UJ_.js → glide-data-editor-858wsVkd.js} +1 -1
  6. package/dist/main.js +821 -417
  7. package/dist/{spec-Bfvf9Hre.js → spec-oVDndBz4.js} +25 -16
  8. package/dist/style.css +1 -1
  9. package/package.json +1 -1
  10. package/src/__mocks__/notebook.ts +9 -9
  11. package/src/__mocks__/requests.ts +1 -0
  12. package/src/__tests__/branded.ts +20 -0
  13. package/src/components/app-config/user-config-form.tsx +5 -4
  14. package/src/components/data-table/__tests__/utils.test.ts +138 -1
  15. package/src/components/data-table/charts/__tests__/storage.test.ts +7 -7
  16. package/src/components/data-table/context-menu.tsx +9 -5
  17. package/src/components/data-table/data-table.tsx +3 -0
  18. package/src/components/data-table/range-focus/__tests__/atoms.test.ts +8 -2
  19. package/src/components/data-table/range-focus/__tests__/test-utils.ts +2 -0
  20. package/src/components/data-table/range-focus/__tests__/utils.test.ts +82 -8
  21. package/src/components/data-table/range-focus/atoms.ts +2 -2
  22. package/src/components/data-table/range-focus/utils.ts +50 -12
  23. package/src/components/data-table/types.ts +7 -0
  24. package/src/components/data-table/utils.ts +87 -0
  25. package/src/components/editor/__tests__/data-attributes.test.tsx +8 -8
  26. package/src/components/editor/ai/__tests__/completion-utils.test.ts +15 -15
  27. package/src/components/editor/connections/storage/__tests__/__snapshots__/as-code.test.ts.snap +2 -2
  28. package/src/components/editor/connections/storage/as-code.ts +2 -2
  29. package/src/components/editor/file-tree/file-explorer.tsx +16 -2
  30. package/src/components/editor/file-tree/file-viewer.tsx +17 -3
  31. package/src/components/editor/navigation/__tests__/clipboard.test.ts +2 -2
  32. package/src/components/editor/navigation/__tests__/selection.test.ts +7 -6
  33. package/src/components/editor/navigation/__tests__/state.test.ts +8 -7
  34. package/src/components/editor/output/MarimoErrorOutput.tsx +7 -7
  35. package/src/components/editor/output/__tests__/traceback.test.tsx +4 -4
  36. package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +4 -4
  37. package/src/components/editor/renderers/vertical-layout/useFocusFirstEditor.ts +8 -1
  38. package/src/components/storage/storage-file-viewer.tsx +35 -1
  39. package/src/components/storage/storage-inspector.tsx +9 -4
  40. package/src/components/storage/storage-snippets.ts +3 -3
  41. package/src/components/tracing/tracing.tsx +3 -1
  42. package/src/components/ui/range-slider.tsx +108 -1
  43. package/src/core/ai/__tests__/staged-cells.test.ts +9 -8
  44. package/src/core/ai/context/providers/__tests__/cell-output.test.ts +31 -31
  45. package/src/core/ai/context/providers/__tests__/datasource.test.ts +3 -3
  46. package/src/core/ai/context/providers/__tests__/tables.test.ts +3 -2
  47. package/src/core/ai/context/providers/__tests__/variable.test.ts +84 -63
  48. package/src/core/ai/tools/__tests__/edit-notebook-tool.test.ts +10 -9
  49. package/src/core/ai/tools/__tests__/run-cells-tool.test.ts +6 -6
  50. package/src/core/ai/tools/edit-notebook-tool.ts +3 -3
  51. package/src/core/cells/__tests__/add-missing-import.test.ts +3 -3
  52. package/src/core/cells/__tests__/apply-transaction.test.ts +279 -0
  53. package/src/core/cells/__tests__/cells.test.ts +198 -135
  54. package/src/core/cells/__tests__/document-changes.test.ts +575 -0
  55. package/src/core/cells/__tests__/document-roundtrip.test.ts +376 -0
  56. package/src/core/cells/__tests__/focus.test.ts +5 -4
  57. package/src/core/cells/__tests__/logs.test.ts +13 -12
  58. package/src/core/cells/__tests__/pending-delete-service.test.tsx +3 -3
  59. package/src/core/cells/__tests__/runs.test.ts +22 -21
  60. package/src/core/cells/__tests__/scrollCellIntoView.test.ts +8 -7
  61. package/src/core/cells/__tests__/session.test.ts +23 -22
  62. package/src/core/cells/cells.ts +29 -4
  63. package/src/core/cells/document-changes.ts +644 -0
  64. package/src/core/cells/ids.ts +5 -5
  65. package/src/core/cells/logs.ts +2 -2
  66. package/src/core/cells/runs.ts +6 -8
  67. package/src/core/codemirror/__tests__/format.test.ts +34 -36
  68. package/src/core/codemirror/__tests__/setup.test.ts +2 -2
  69. package/src/core/codemirror/cells/__tests__/extensions.test.ts +114 -0
  70. package/src/core/codemirror/cells/__tests__/traceback-decorations.test.ts +33 -32
  71. package/src/core/codemirror/cells/extensions.ts +66 -23
  72. package/src/core/codemirror/completion/__tests__/keymap.test.ts +15 -35
  73. package/src/core/codemirror/completion/keymap.ts +14 -4
  74. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +12 -13
  75. package/src/core/codemirror/language/__tests__/utils.test.ts +3 -3
  76. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +7 -8
  77. package/src/core/codemirror/language/languages/python.ts +4 -0
  78. package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +4 -3
  79. package/src/core/codemirror/lsp/notebook-lsp.ts +28 -2
  80. package/src/core/codemirror/reactive-references/__tests__/analyzer.test.ts +7 -6
  81. package/src/core/codemirror/reactive-references/analyzer.ts +2 -2
  82. package/src/core/codemirror/rtc/loro/__tests__/sync.test.ts +52 -0
  83. package/src/core/codemirror/rtc/loro/sync.ts +1 -0
  84. package/src/core/datasets/__tests__/data-source.test.ts +5 -6
  85. package/src/core/datasets/state.ts +1 -1
  86. package/src/core/errors/__tests__/errors.test.ts +2 -1
  87. package/src/core/export/__tests__/hooks.test.ts +37 -36
  88. package/src/core/islands/bridge.ts +1 -0
  89. package/src/core/islands/main.ts +4 -7
  90. package/src/core/kernel/__tests__/handlers.test.ts +5 -4
  91. package/src/core/kernel/handlers.ts +7 -4
  92. package/src/core/network/DeferredRequestRegistry.ts +2 -2
  93. package/src/core/network/__tests__/CachingRequestRegistry.test.ts +9 -10
  94. package/src/core/network/__tests__/DeferredRequestRegistry.test.ts +4 -6
  95. package/src/core/network/requests-lazy.ts +1 -0
  96. package/src/core/network/requests-network.ts +9 -0
  97. package/src/core/network/requests-static.ts +1 -0
  98. package/src/core/network/requests-toasting.tsx +1 -0
  99. package/src/core/network/types.ts +5 -0
  100. package/src/core/static/__tests__/virtual-file-tracker.test.ts +8 -8
  101. package/src/core/static/virtual-file-tracker.ts +1 -1
  102. package/src/core/storage/__tests__/state.test.ts +31 -21
  103. package/src/core/storage/state.ts +1 -1
  104. package/src/core/variables/__tests__/state.test.ts +6 -6
  105. package/src/core/variables/types.ts +2 -2
  106. package/src/core/wasm/__tests__/state.test.ts +8 -8
  107. package/src/core/wasm/bridge.ts +1 -0
  108. package/src/core/websocket/useMarimoKernelConnection.tsx +31 -16
  109. package/src/css/app/fonts.css +6 -6
  110. package/src/css/md-tooltip.css +4 -39
  111. package/src/css/md.css +7 -0
  112. package/src/fonts/Fira_Mono/FiraMono-Bold.woff2 +0 -0
  113. package/src/fonts/Fira_Mono/FiraMono-Medium.woff2 +0 -0
  114. package/src/fonts/Fira_Mono/FiraMono-Regular.woff2 +0 -0
  115. package/src/fonts/Lora/Lora-VariableFont_wght.woff2 +0 -0
  116. package/src/fonts/PT_Sans/PTSans-Bold.woff2 +0 -0
  117. package/src/fonts/PT_Sans/PTSans-Regular.woff2 +0 -0
  118. package/src/plugins/core/RenderHTML.tsx +17 -0
  119. package/src/plugins/core/__test__/RenderHTML.test.ts +45 -0
  120. package/src/plugins/core/sanitize-html.ts +25 -18
  121. package/src/plugins/impl/DataTablePlugin.tsx +23 -2
  122. package/src/plugins/impl/SliderPlugin.tsx +1 -3
  123. package/src/plugins/impl/__tests__/SliderPlugin.test.tsx +120 -0
  124. package/src/plugins/impl/anywidget/model.ts +1 -2
  125. package/src/stories/cell.stories.tsx +8 -8
  126. package/src/stories/layout/vertical/one-column.stories.tsx +9 -8
  127. package/src/stories/log-viewer.stories.tsx +8 -8
  128. package/src/stories/variables.stories.tsx +2 -2
  129. package/src/utils/__tests__/download.test.tsx +21 -20
  130. package/src/utils/copy.ts +18 -5
  131. package/src/utils/createReducer.ts +26 -11
  132. package/src/utils/download.ts +4 -3
  133. package/src/utils/html-to-image.ts +6 -0
  134. package/src/utils/json/base64.ts +3 -3
  135. package/src/utils/traceback.ts +5 -3
  136. package/src/fonts/Fira_Mono/FiraMono-Bold.ttf +0 -0
  137. package/src/fonts/Fira_Mono/FiraMono-Medium.ttf +0 -0
  138. package/src/fonts/Fira_Mono/FiraMono-Regular.ttf +0 -0
  139. package/src/fonts/Lora/Lora-Italic-VariableFont_wght.ttf +0 -0
  140. package/src/fonts/Lora/Lora-VariableFont_wght.ttf +0 -0
  141. package/src/fonts/Lora/static/Lora-Bold.ttf +0 -0
  142. package/src/fonts/Lora/static/Lora-BoldItalic.ttf +0 -0
  143. package/src/fonts/Lora/static/Lora-Italic.ttf +0 -0
  144. package/src/fonts/Lora/static/Lora-Medium.ttf +0 -0
  145. package/src/fonts/Lora/static/Lora-MediumItalic.ttf +0 -0
  146. package/src/fonts/Lora/static/Lora-Regular.ttf +0 -0
  147. package/src/fonts/Lora/static/Lora-SemiBold.ttf +0 -0
  148. package/src/fonts/Lora/static/Lora-SemiBoldItalic.ttf +0 -0
  149. package/src/fonts/PT_Sans/PTSans-Bold.ttf +0 -0
  150. package/src/fonts/PT_Sans/PTSans-BoldItalic.ttf +0 -0
  151. package/src/fonts/PT_Sans/PTSans-Italic.ttf +0 -0
  152. package/src/fonts/PT_Sans/PTSans-Regular.ttf +0 -0
@@ -0,0 +1,279 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ /**
4
+ * Tests for fromDocumentChanges / applyTransactionChanges in isolation.
5
+ *
6
+ * These test the change→action mapping for edge cases and error paths that
7
+ * can't be exercised via the round-trip tests (since toDocumentChanges would
8
+ * never produce malformed or conflicting changes). Basic correctness is
9
+ * covered by document-roundtrip.test.ts. This file focuses on:
10
+ *
11
+ * - Multi-change transactions (create+move, create+set-code, set-code+delete)
12
+ * - Cancelled changes (create+delete same cell)
13
+ * - Missing/nonexistent anchors and cells
14
+ * - Config propagation on create-cell (disabled, column)
15
+ */
16
+
17
+ import { python } from "@codemirror/lang-python";
18
+ import { EditorState } from "@codemirror/state";
19
+ import { EditorView } from "@codemirror/view";
20
+ import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
21
+ import type { CellHandle } from "@/components/editor/notebook-cell";
22
+ import { adaptiveLanguageConfiguration } from "@/core/codemirror/language/extension";
23
+ import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
24
+ import { MultiColumn } from "@/utils/id-tree";
25
+ import { exportedForTesting, type NotebookState } from "../cells";
26
+ import {
27
+ applyTransactionChanges,
28
+ exportedForTesting as middlewareExports,
29
+ } from "../document-changes";
30
+ import { CellId } from "../ids";
31
+
32
+ const { initialNotebookState, reducer, createActions } = exportedForTesting;
33
+
34
+ function createEditor(code: string) {
35
+ const state = EditorState.create({
36
+ doc: code,
37
+ extensions: [
38
+ python(),
39
+ adaptiveLanguageConfiguration({
40
+ cellId: "cell1" as CellId,
41
+ completionConfig: {
42
+ activate_on_typing: true,
43
+ signature_hint_on_typing: false,
44
+ copilot: false,
45
+ codeium_api_key: null,
46
+ },
47
+ hotkeys: new OverridingHotkeyProvider({}),
48
+ placeholderType: "marimo-import",
49
+ lspConfig: {},
50
+ }),
51
+ ],
52
+ });
53
+ return new EditorView({ state, parent: document.body });
54
+ }
55
+
56
+ let state: NotebookState;
57
+ let actions: ReturnType<typeof createActions>;
58
+
59
+ function setup(...codes: string[]) {
60
+ state = initialNotebookState();
61
+ state.cellIds = MultiColumn.from([]);
62
+ actions = createActions((action) => {
63
+ state = reducer(state, action);
64
+ for (const [cellId, handle] of Object.entries(state.cellHandles)) {
65
+ if (!handle.current) {
66
+ const view = createEditor(state.cellData[cellId as CellId].code);
67
+ const h: CellHandle = { editorView: view, editorViewOrNull: view };
68
+ state.cellHandles[cellId as CellId] = { current: h };
69
+ }
70
+ }
71
+ });
72
+ for (const code of codes) {
73
+ actions.createNewCell({ cellId: "__end__", before: false, code });
74
+ }
75
+ }
76
+
77
+ afterEach(() => {
78
+ middlewareExports.cancelPendingChanges();
79
+ });
80
+
81
+ function apply(changes: Parameters<typeof applyTransactionChanges>[0]) {
82
+ applyTransactionChanges(changes, actions, () => state.cellIds.inOrderIds);
83
+ }
84
+
85
+ /** Snapshot of document state: ordering, code, name, config. */
86
+ function pretty(s: NotebookState): string {
87
+ const lines = s.cellIds.inOrderIds.map((id) => {
88
+ const cell = s.cellData[id];
89
+ const flags: string[] = [];
90
+ if (cell.name && cell.name !== "_") {
91
+ flags.push(`name=${cell.name}`);
92
+ }
93
+ if (cell.config.hide_code) {
94
+ flags.push("hide_code");
95
+ }
96
+ if (cell.config.disabled) {
97
+ flags.push("disabled");
98
+ }
99
+ if (cell.config.column != null) {
100
+ flags.push(`col=${cell.config.column}`);
101
+ }
102
+ const suffix = flags.length > 0 ? ` [${flags.join(", ")}]` : "";
103
+ return `${id}: '${cell.code}'${suffix}`;
104
+ });
105
+ return `\n${lines.join("\n")}\n`;
106
+ }
107
+
108
+ let i = 0;
109
+
110
+ beforeAll(() => {
111
+ CellId.create = () => `${i++}` as CellId;
112
+ });
113
+
114
+ beforeEach(() => {
115
+ i = 0;
116
+ });
117
+
118
+ describe("applyTransactionChanges edge cases", () => {
119
+ it("create-cell applies disabled and column config", () => {
120
+ setup("a");
121
+ apply([
122
+ {
123
+ type: "create-cell",
124
+ cellId: "new-cell",
125
+ code: "configured",
126
+ name: "",
127
+ config: { hide_code: true, disabled: true, column: 1 },
128
+ },
129
+ ]);
130
+ expect(pretty(state)).toMatchInlineSnapshot(`
131
+ "
132
+ 0: 'a'
133
+ new-cell: 'configured' [hide_code, disabled, col=1]
134
+ "
135
+ `);
136
+ });
137
+
138
+ it("create-cell then move-cell in same transaction", () => {
139
+ setup("a", "b");
140
+ const [a] = state.cellIds.inOrderIds;
141
+ apply([
142
+ {
143
+ type: "create-cell",
144
+ cellId: "new-cell",
145
+ code: "new",
146
+ name: "",
147
+ config: {},
148
+ },
149
+ { type: "move-cell", cellId: "new-cell", before: a },
150
+ ]);
151
+ expect(pretty(state)).toMatchInlineSnapshot(`
152
+ "
153
+ new-cell: 'new'
154
+ 0: 'a'
155
+ 1: 'b'
156
+ "
157
+ `);
158
+ });
159
+
160
+ it("create-cell then set-code in same transaction", () => {
161
+ setup("a");
162
+ apply([
163
+ {
164
+ type: "create-cell",
165
+ cellId: "new-cell",
166
+ code: "initial",
167
+ name: "",
168
+ config: {},
169
+ },
170
+ { type: "set-code", cellId: "new-cell", code: "updated" },
171
+ ]);
172
+ expect(pretty(state)).toMatchInlineSnapshot(`
173
+ "
174
+ 0: 'a'
175
+ new-cell: 'updated'
176
+ "
177
+ `);
178
+ });
179
+
180
+ it("create-cell then delete-cell same cell cancels out", () => {
181
+ setup("a");
182
+ apply([
183
+ {
184
+ type: "create-cell",
185
+ cellId: "ephemeral",
186
+ code: "tmp",
187
+ name: "",
188
+ config: {},
189
+ },
190
+ { type: "delete-cell", cellId: "ephemeral" },
191
+ ]);
192
+ expect(pretty(state)).toMatchInlineSnapshot(`
193
+ "
194
+ 0: 'a'
195
+ "
196
+ `);
197
+ });
198
+
199
+ it("multiple changes in one transaction", () => {
200
+ setup("a", "b", "c");
201
+ const [a, b, c] = state.cellIds.inOrderIds;
202
+ apply([
203
+ { type: "set-code", cellId: a, code: "x = 1" },
204
+ { type: "set-name", cellId: b, name: "middle" },
205
+ { type: "delete-cell", cellId: c },
206
+ ]);
207
+ expect(pretty(state)).toMatchInlineSnapshot(`
208
+ "
209
+ 0: 'x = 1'
210
+ 1: 'b' [name=middle]
211
+ "
212
+ `);
213
+ });
214
+
215
+ it("move-cell with no anchor appends to end", () => {
216
+ setup("a", "b", "c");
217
+ const [a] = state.cellIds.inOrderIds;
218
+ apply([{ type: "move-cell", cellId: a }]);
219
+ expect(pretty(state)).toMatchInlineSnapshot(`
220
+ "
221
+ 1: 'b'
222
+ 2: 'c'
223
+ 0: 'a'
224
+ "
225
+ `);
226
+ });
227
+
228
+ it("move-cell with missing after anchor falls back to end", () => {
229
+ setup("a", "b");
230
+ const [a] = state.cellIds.inOrderIds;
231
+ apply([{ type: "move-cell", cellId: a, after: "nonexistent" as CellId }]);
232
+ expect(pretty(state)).toMatchInlineSnapshot(`
233
+ "
234
+ 1: 'b'
235
+ 0: 'a'
236
+ "
237
+ `);
238
+ });
239
+
240
+ it("move-cell with missing before anchor falls back to start", () => {
241
+ setup("a", "b");
242
+ const [, b] = state.cellIds.inOrderIds;
243
+ apply([{ type: "move-cell", cellId: b, before: "nonexistent" as CellId }]);
244
+ expect(pretty(state)).toMatchInlineSnapshot(`
245
+ "
246
+ 1: 'b'
247
+ 0: 'a'
248
+ "
249
+ `);
250
+ });
251
+
252
+ it("move-cell on nonexistent cell is a no-op", () => {
253
+ setup("a", "b");
254
+ apply([
255
+ {
256
+ type: "move-cell",
257
+ cellId: "nonexistent" as CellId,
258
+ after: "0" as CellId,
259
+ },
260
+ ]);
261
+ expect(pretty(state)).toMatchInlineSnapshot(`
262
+ "
263
+ 0: 'a'
264
+ 1: 'b'
265
+ "
266
+ `);
267
+ });
268
+
269
+ it("empty changes is a no-op", () => {
270
+ setup("a", "b");
271
+ apply([]);
272
+ expect(pretty(state)).toMatchInlineSnapshot(`
273
+ "
274
+ 0: 'a'
275
+ 1: 'b'
276
+ "
277
+ `);
278
+ });
279
+ });