@marimo-team/islands 0.23.12-dev9 → 0.23.12

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 (36) hide show
  1. package/dist/{chat-ui-BEOvjkmJ.js → chat-ui-CsPewo4h.js} +2 -2
  2. package/dist/{code-visibility-w2yZTVwB.js → code-visibility-BFhOAQbo.js} +714 -707
  3. package/dist/{html-to-image-Di0mtt6O.js → html-to-image-DXwLcQ6l.js} +22 -15
  4. package/dist/main.js +1160 -1027
  5. package/dist/{process-output-BLd4KuwX.js → process-output-C6_e1pT_.js} +1 -1
  6. package/dist/{reveal-component-CuqTvwmg.js → reveal-component-ghVwQgXR.js} +13 -13
  7. package/dist/style.css +1 -1
  8. package/package.json +1 -1
  9. package/src/components/data-table/TableBottomBar.tsx +4 -1
  10. package/src/components/data-table/data-table.tsx +26 -17
  11. package/src/components/data-table/utils.ts +1 -4
  12. package/src/components/editor/ai/__tests__/completion-utils.test.ts +48 -2
  13. package/src/components/editor/ai/completion-utils.ts +54 -36
  14. package/src/components/editor/app-container.tsx +3 -1
  15. package/src/components/editor/output/ImageOutput.tsx +12 -3
  16. package/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx +2 -2
  17. package/src/core/codemirror/go-to-definition/__tests__/commands.test.ts +67 -0
  18. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +47 -0
  19. package/src/core/codemirror/go-to-definition/commands.ts +47 -30
  20. package/src/core/codemirror/go-to-definition/utils.ts +0 -1
  21. package/src/core/codemirror/reactive-references/__tests__/analyzer.test.ts +54 -0
  22. package/src/core/codemirror/reactive-references/analyzer.ts +44 -35
  23. package/src/core/islands/__tests__/bridge.test.ts +25 -0
  24. package/src/core/islands/__tests__/parse.test.ts +585 -1
  25. package/src/core/islands/__tests__/test-utils.tsx +10 -1
  26. package/src/core/islands/bridge.ts +6 -1
  27. package/src/core/islands/constants.ts +2 -0
  28. package/src/core/islands/parse.ts +290 -13
  29. package/src/plugins/impl/DataTablePlugin.tsx +20 -1
  30. package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +141 -1
  31. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +54 -4
  32. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +104 -1
  33. package/src/plugins/impl/anywidget/__tests__/model.test.ts +19 -0
  34. package/src/plugins/impl/anywidget/model.ts +15 -0
  35. package/src/utils/__tests__/records.test.ts +27 -0
  36. package/src/utils/records.ts +12 -0
@@ -640,6 +640,60 @@ def run(polars):
640
640
  `);
641
641
  });
642
642
 
643
+ test("set comprehension target shadows outer global", () => {
644
+ // Regression: SCOPE_CREATING_NODES used "SetComprehension" instead of the
645
+ // grammar's "SetComprehensionExpression", so set comprehensions never
646
+ // created a scope and their for-target was treated as reactive.
647
+ expect(runHighlight(["x"], "result = {x for x in range(5)}"))
648
+ .toMatchInlineSnapshot(`
649
+ "
650
+ result = {x for x in range(5)}
651
+ "
652
+ `);
653
+ });
654
+
655
+ test("from-import module path stays reactive", () => {
656
+ // Regression: ImportStatement collected every VariableName child, so the
657
+ // module name in `from m import y` was wrongly treated as a local binding.
658
+ expect(
659
+ runHighlight(
660
+ ["math"],
661
+ `
662
+ def f():
663
+ from math import sin as my_sin
664
+ return math + my_sin(1)`,
665
+ ),
666
+ ).toMatchInlineSnapshot(`
667
+ "
668
+ def f():
669
+ from math import sin as my_sin
670
+ return math + my_sin(1)
671
+ ^^^^
672
+ "
673
+ `);
674
+ });
675
+
676
+ test("from-import: aliased imported name is not a binding", () => {
677
+ // Regression: `sin` in `from math import sin as my_sin` was incorrectly
678
+ // registered as a local binding, hiding genuine reactive uses of `sin`.
679
+ expect(
680
+ runHighlight(
681
+ ["sin"],
682
+ `
683
+ def f():
684
+ from math import sin as my_sin
685
+ return sin + my_sin(1)`,
686
+ ),
687
+ ).toMatchInlineSnapshot(`
688
+ "
689
+ def f():
690
+ from math import sin as my_sin
691
+ return sin + my_sin(1)
692
+ ^^^
693
+ "
694
+ `);
695
+ });
696
+
643
697
  test("lambda inside function with outer global", () => {
644
698
  expect(
645
699
  runHighlight(
@@ -16,7 +16,7 @@ const SCOPE_CREATING_NODES = new Set([
16
16
  "FunctionDefinition",
17
17
  "LambdaExpression",
18
18
  "ArrayComprehensionExpression",
19
- "SetComprehension",
19
+ "SetComprehensionExpression",
20
20
  "DictionaryComprehensionExpression",
21
21
  "ComprehensionExpression",
22
22
  "ClassDefinition",
@@ -152,7 +152,7 @@ export function findReactiveVariables(options: {
152
152
  }
153
153
  case "ArrayComprehensionExpression":
154
154
  case "DictionaryComprehensionExpression":
155
- case "SetComprehension":
155
+ case "SetComprehensionExpression":
156
156
  case "ComprehensionExpression": {
157
157
  // Domprehension variables - look for VariableName or TupleExpression after 'for'
158
158
  const subCursor = node.cursor();
@@ -276,49 +276,52 @@ export function findReactiveVariables(options: {
276
276
  break;
277
277
  }
278
278
  case "ImportStatement": {
279
- // Handle import x
279
+ // The grammar emits a single ImportStatement for both `import x [as y]`
280
+ // and `from m import x [as y], ...`. Direct children mix keywords,
281
+ // module-path names (before `import`), imported names, and aliases.
282
+ // Only post-`import` names that aren't shadowed by a following `as`
283
+ // (and the alias itself when `as` is present) bind in the current
284
+ // scope.
280
285
  const subCursor = node.cursor();
281
286
  subCursor.firstChild();
282
- do {
283
- if (subCursor.name === "VariableName") {
284
- const varName = options.state.doc.sliceString(
285
- subCursor.from,
286
- subCursor.to,
287
- );
288
-
289
- const currentScope =
290
- currentScopeStack[currentScopeStack.length - 1] ?? -1;
291
- if (!allDeclarations.has(currentScope)) {
292
- allDeclarations.set(currentScope, new Set());
293
- }
294
- allDeclarations.get(currentScope)?.add(varName);
287
+ const currentScope =
288
+ currentScopeStack[currentScopeStack.length - 1] ?? -1;
289
+ if (!allDeclarations.has(currentScope)) {
290
+ allDeclarations.set(currentScope, new Set());
291
+ }
292
+ const scope = allDeclarations.get(currentScope);
293
+ let pastImport = false;
294
+ let pending: string | null = null;
295
+ const commit = () => {
296
+ if (pending !== null) {
297
+ scope?.add(pending);
295
298
  }
296
- } while (subCursor.nextSibling());
297
-
298
- break;
299
- }
300
- case "ImportFromStatement": {
301
- // Handle from x import y as z
302
- const subCursor = node.cursor();
303
- subCursor.firstChild();
304
- let foundImport = false;
299
+ pending = null;
300
+ };
305
301
  do {
306
302
  if (subCursor.name === "import") {
307
- foundImport = true;
308
- } else if (foundImport && subCursor.name === "VariableName") {
309
- const varName = options.state.doc.sliceString(
303
+ pastImport = true;
304
+ continue;
305
+ }
306
+ if (!pastImport) {
307
+ continue;
308
+ }
309
+ if (subCursor.name === "as") {
310
+ // Drop the imported name; the next VariableName is the alias.
311
+ pending = null;
312
+ continue;
313
+ }
314
+ if (subCursor.name === "VariableName") {
315
+ commit();
316
+ pending = options.state.doc.sliceString(
310
317
  subCursor.from,
311
318
  subCursor.to,
312
319
  );
313
- // Add to the current innermost scope
314
- const currentScope =
315
- currentScopeStack[currentScopeStack.length - 1] ?? -1;
316
- if (!allDeclarations.has(currentScope)) {
317
- allDeclarations.set(currentScope, new Set());
318
- }
319
- allDeclarations.get(currentScope)?.add(varName);
320
+ } else if (subCursor.name === ",") {
321
+ commit();
320
322
  }
321
323
  } while (subCursor.nextSibling());
324
+ commit();
322
325
 
323
326
  break;
324
327
  }
@@ -424,6 +427,12 @@ export function findReactiveVariables(options: {
424
427
  const nodeName = cursor.name;
425
428
  const nodeStart = cursor.from;
426
429
 
430
+ // Names inside an import statement are module paths, imported names, or
431
+ // aliases — none of them are reactive *uses* of an outer-cell global.
432
+ if (nodeName === "ImportStatement") {
433
+ return;
434
+ }
435
+
427
436
  const isNewScope = SCOPE_CREATING_NODES.has(nodeName);
428
437
 
429
438
  let currentScopeStack = scopeStack;
@@ -12,6 +12,7 @@ import {
12
12
  type Base64String = components["schemas"]["Base64String"];
13
13
  interface TestIslandApp {
14
14
  id: string;
15
+ payloadBacked?: boolean;
15
16
  cells: { code: string; idx: number; output: string }[];
16
17
  }
17
18
  interface TestExportContext {
@@ -142,6 +143,30 @@ describe("IslandsPyodideBridge", () => {
142
143
  });
143
144
  });
144
145
 
146
+ it("should ignore trusted export notebook code for a payload-backed app", async () => {
147
+ const payloadApp = {
148
+ id: "app-1",
149
+ payloadBacked: true,
150
+ cells: [{ code: "x = 1", idx: 0, output: "<div>1</div>" }],
151
+ };
152
+ mockParseMarimoIslandApps.mockReturnValue([payloadApp]);
153
+ mockGetMarimoExportContext.mockReturnValue({
154
+ trusted: true,
155
+ notebookCode: "full notebook should be ignored",
156
+ });
157
+ mockCreateMarimoFile.mockReturnValue("generated payload app");
158
+
159
+ await (
160
+ bridge as unknown as { startSessionsForAllApps(): Promise<void> }
161
+ ).startSessionsForAllApps();
162
+
163
+ expect(mockCreateMarimoFile).toHaveBeenCalledWith(payloadApp);
164
+ expect(mockStartSessionRequest).toHaveBeenCalledWith({
165
+ appId: "app-1",
166
+ code: "generated payload app",
167
+ });
168
+ });
169
+
145
170
  it("should keep synthesized per-app files for multiple reactive apps even when export context exists", async () => {
146
171
  mockParseMarimoIslandApps.mockReturnValue([
147
172
  {