@marimo-team/islands 0.21.1-dev94 → 0.21.2-dev0

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 (55) hide show
  1. package/dist/{Combination-Dk6JxauT.js → Combination-BBPQRrDo.js} +1 -1
  2. package/dist/{ConnectedDataExplorerComponent-Bh11efrC.js → ConnectedDataExplorerComponent-D0GoOd_c.js} +14 -13
  3. package/dist/{any-language-editor-BIj11a2e.js → any-language-editor-DlsjUw_l.js} +4 -4
  4. package/dist/{button-DQpBib29.js → button-BKkuUpZh.js} +8 -0
  5. package/dist/{check-DpqPQmzz.js → check-Diwc5emq.js} +1 -1
  6. package/dist/{copy-BkBF0Xgk.js → copy-DIK6DiIA.js} +2 -2
  7. package/dist/{dist-WIWVvdBh.js → dist-C0Rnbr-_.js} +2 -2
  8. package/dist/{error-banner-BctofTCP.js → error-banner-Dmi5ujan.js} +2 -2
  9. package/dist/{esm-BBkPJL8N.js → esm-BLobyqMs.js} +8 -7
  10. package/dist/{glide-data-editor-DqxJOnJk.js → glide-data-editor-pZyd9UJ_.js} +6 -6
  11. package/dist/{label-BLDcDYdI.js → label-BbpGrh4j.js} +4 -4
  12. package/dist/{loader-DsE3MiYo.js → loader-CABJs6GU.js} +12 -3
  13. package/dist/main.js +186 -127
  14. package/dist/{mermaid-DkdSmFY8.js → mermaid-CrKqsE2j.js} +5 -5
  15. package/dist/{slides-component-DwvL_HJi.js → slides-component-GkilRW21.js} +2 -2
  16. package/dist/{spec-CbYkiXG3.js → spec-Bfvf9Hre.js} +4 -4
  17. package/dist/style.css +1 -1
  18. package/dist/{tooltip-SPkubVH3.js → tooltip-CKG75XQa.js} +3 -3
  19. package/dist/{types-0FB-N7AA.js → types-CGc7peZV.js} +6 -6
  20. package/dist/{useAsyncData-D7-oahg5.js → useAsyncData-CEjJxwFB.js} +1 -1
  21. package/dist/{useDeepCompareMemoize-DLS-bHHT.js → useDeepCompareMemoize-BWUwfh37.js} +4 -4
  22. package/dist/{useIframeCapabilities-DFGZKWkO.js → useIframeCapabilities-OQaMKgZl.js} +1 -1
  23. package/dist/{useTheme-D0rdoMBF.js → useTheme-CPybHVFN.js} +2 -2
  24. package/dist/{vega-component-CnO3mkFC.js → vega-component-CuPTCRp5.js} +13 -10
  25. package/package.json +1 -1
  26. package/src/components/data-table/charts/lazy-chart.tsx +2 -0
  27. package/src/components/data-table/column-summary/column-summary.tsx +1 -0
  28. package/src/components/datasources/column-preview.tsx +1 -0
  29. package/src/components/editor/Output.tsx +2 -0
  30. package/src/components/editor/actions/useCellActionButton.tsx +38 -29
  31. package/src/components/editor/cell/code/cell-editor.tsx +9 -0
  32. package/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx +6 -0
  33. package/src/components/editor/chrome/wrapper/__tests__/utils.test.ts +35 -0
  34. package/src/components/editor/chrome/wrapper/app-chrome.tsx +12 -14
  35. package/src/components/editor/chrome/wrapper/utils.ts +5 -1
  36. package/src/components/editor/header/status.tsx +19 -11
  37. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +10 -3
  38. package/src/core/cells/cells.ts +6 -0
  39. package/src/core/cells/utils.ts +1 -0
  40. package/src/core/codemirror/__tests__/setup.test.ts +1 -0
  41. package/src/core/codemirror/cells/state.ts +1 -0
  42. package/src/core/codemirror/extensions.ts +20 -0
  43. package/src/core/codemirror/language/utils.ts +16 -1
  44. package/src/core/codemirror/reactive-references/__tests__/analyzer.test.ts +54 -0
  45. package/src/core/codemirror/reactive-references/analyzer.ts +14 -0
  46. package/src/core/dom/outline.ts +1 -1
  47. package/src/core/hotkeys/hotkeys.ts +8 -0
  48. package/src/css/md.css +4 -0
  49. package/src/plugins/core/sanitize-html.ts +50 -0
  50. package/src/plugins/core/sanitize.ts +3 -49
  51. package/src/plugins/impl/data-explorer/ConnectedDataExplorerComponent.tsx +6 -3
  52. package/src/plugins/impl/vega/__tests__/utils.test.ts +36 -0
  53. package/src/plugins/impl/vega/utils.ts +14 -0
  54. package/src/plugins/impl/vega/vega-component.tsx +6 -7
  55. package/src/plugins/impl/vega/vega.css +1 -1
@@ -1115,6 +1115,60 @@ class Foo:
1115
1115
  `);
1116
1116
  });
1117
1117
 
1118
+ test("should not highlight attribute access matching a for-loop variable", () => {
1119
+ // When `tool` is used as a for-loop variable, `mcp.tool` (attribute access)
1120
+ // should NOT have `tool` highlighted — it's a property, not a variable reference.
1121
+ expect(
1122
+ runHighlight(
1123
+ ["mcp", "client"],
1124
+ `
1125
+ @mcp.tool
1126
+ def roll_dice():
1127
+ pass
1128
+
1129
+ async with client:
1130
+ for tool in await client.list_tools():
1131
+ print(tool)
1132
+ `,
1133
+ ),
1134
+ ).toMatchInlineSnapshot(`
1135
+ "
1136
+ @mcp.tool
1137
+ ^^^
1138
+ def roll_dice():
1139
+ pass
1140
+
1141
+ async with client:
1142
+ ^^^^^^
1143
+ for tool in await client.list_tools():
1144
+ ^^^^^^
1145
+ print(tool)
1146
+ "
1147
+ `);
1148
+ });
1149
+
1150
+ test("should not highlight property name matching a global variable", () => {
1151
+ // `tool` is a global variable, but `mcp.tool` should not highlight `tool`
1152
+ // because it's a property access, not a variable reference.
1153
+ expect(
1154
+ runHighlight(
1155
+ ["mcp", "tool"],
1156
+ `
1157
+ @mcp.tool
1158
+ def roll_dice():
1159
+ pass
1160
+ `,
1161
+ ),
1162
+ ).toMatchInlineSnapshot(`
1163
+ "
1164
+ @mcp.tool
1165
+ ^^^
1166
+ def roll_dice():
1167
+ pass
1168
+ "
1169
+ `);
1170
+ });
1171
+
1118
1172
  test("class property self-reference", () => {
1119
1173
  expect(
1120
1174
  runHighlight(
@@ -462,6 +462,7 @@ export function findReactiveVariables(options: {
462
462
  ): boolean {
463
463
  return (
464
464
  allVariableNames.has(varName) &&
465
+ !isPropertyAccess(cursor) &&
465
466
  !isKeywordArgumentName(cursor) &&
466
467
  !isAssignmentTarget(cursor)
467
468
  );
@@ -529,6 +530,19 @@ function isAssignmentTarget(cursor: TreeCursor): boolean {
529
530
  return false;
530
531
  }
531
532
 
533
+ /** Checks whether a `VariableName` is a property access (e.g. `tool` in `mcp.tool`). */
534
+ function isPropertyAccess(cursor: TreeCursor): boolean {
535
+ // Check if the previous sibling is a "." node, which means this
536
+ // VariableName is a property access rather than a standalone variable.
537
+ // This handles both MemberExpression (e.g. `obj.attr`) and Decorator
538
+ // (e.g. `@mcp.tool`) where the parser emits flat sibling nodes.
539
+ const temp = cursor.node.cursor();
540
+ if (temp.prevSibling() && temp.name === ".") {
541
+ return true;
542
+ }
543
+ return false;
544
+ }
545
+
532
546
  /**
533
547
  * Checks if the syntax tree contains any syntax errors.
534
548
  * If there are errors, we shouldn't show reactive variable highlighting.
@@ -1,6 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
- import { sanitizeHtml } from "@/plugins/core/sanitize";
3
+ import { sanitizeHtml } from "@/plugins/core/sanitize-html";
4
4
  import { invariant } from "@/utils/invariant";
5
5
  import { Logger } from "@/utils/Logger";
6
6
  import type { Outline, OutlineItem } from "../cells/outline";
@@ -142,6 +142,14 @@ const DEFAULT_HOT_KEY = {
142
142
  group: "Editing",
143
143
  key: "Mod-Shift-m",
144
144
  },
145
+ "cell.viewAsSQL": {
146
+ name: "Toggle SQL",
147
+ group: "Editing",
148
+ key: {
149
+ windows: "Alt-Shift-l",
150
+ main: "Mod-Shift-l",
151
+ },
152
+ },
145
153
  "cell.complete": {
146
154
  name: "Code completion",
147
155
  group: "Editing",
package/src/css/md.css CHANGED
@@ -41,6 +41,10 @@
41
41
  font-family: var(--heading-font);
42
42
  }
43
43
 
44
+ .markdown hr {
45
+ margin-block: 0.5rem;
46
+ }
47
+
44
48
  .markdown a {
45
49
  cursor: pointer;
46
50
  text-decoration: inherit;
@@ -0,0 +1,50 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import DOMPurify, { type Config } from "dompurify";
3
+
4
+ // preserve target=_blank https://github.com/cure53/DOMPurify/issues/317#issuecomment-912474068
5
+ const TEMPORARY_ATTRIBUTE = "data-temp-href-target";
6
+ DOMPurify.addHook("beforeSanitizeAttributes", (node) => {
7
+ if (node.tagName === "A") {
8
+ if (!node.hasAttribute("target")) {
9
+ node.setAttribute("target", "_self");
10
+ }
11
+
12
+ if (node.hasAttribute("target")) {
13
+ node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute("target") || "");
14
+ }
15
+ }
16
+ });
17
+
18
+ DOMPurify.addHook("afterSanitizeAttributes", (node) => {
19
+ if (node.tagName === "A" && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
20
+ node.setAttribute("target", node.getAttribute(TEMPORARY_ATTRIBUTE) || "");
21
+ node.removeAttribute(TEMPORARY_ATTRIBUTE);
22
+ if (node.getAttribute("target") === "_blank") {
23
+ node.setAttribute("rel", "noopener noreferrer");
24
+ }
25
+ }
26
+ });
27
+
28
+ /**
29
+ * This removes script tags, form tags, iframe tags, and other potentially dangerous tags
30
+ */
31
+ export function sanitizeHtml(html: string) {
32
+ const sanitizationOptions: Config = {
33
+ // Default to permit HTML, SVG and MathML, this limits to HTML only
34
+ USE_PROFILES: { html: true, svg: true, mathMl: true },
35
+ // Allow SVG <use> elements and their href attributes, which are needed
36
+ // for SVGs that reference <defs> (e.g., Matplotlib SVG output).
37
+ ADD_TAGS: ["use"],
38
+ ADD_ATTR: ["href", "xlink:href"],
39
+ // glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases
40
+ FORCE_BODY: true,
41
+ CUSTOM_ELEMENT_HANDLING: {
42
+ tagNameCheck: /^(marimo-[A-Za-z][\w-]*|iconify-icon)$/,
43
+ attributeNameCheck: /^[A-Za-z][\w-]*$/,
44
+ },
45
+ // This flag means we should sanitize such that is it safe for XML,
46
+ // but this is only used for HTML content.
47
+ SAFE_FOR_XML: !html.includes("marimo-mermaid"),
48
+ };
49
+ return DOMPurify.sanitize(html, sanitizationOptions);
50
+ }
@@ -1,10 +1,12 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
- import DOMPurify, { type Config } from "dompurify";
3
2
  import { atom, useAtomValue } from "jotai";
4
3
  import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
5
4
  import { autoInstantiateAtom } from "@/core/config/config";
6
5
  import { getInitialAppMode } from "@/core/mode";
7
6
 
7
+ // Re-export so existing consumers don't break.
8
+ export { sanitizeHtml } from "./sanitize-html";
9
+
8
10
  /**
9
11
  * Whether to sanitize the html.
10
12
  * When running as an app or with auto_instantiate enabled
@@ -42,51 +44,3 @@ const sanitizeHtmlAtom = atom<boolean>((get) => {
42
44
  export function useSanitizeHtml() {
43
45
  return useAtomValue(sanitizeHtmlAtom);
44
46
  }
45
-
46
- // preserve target=_blank https://github.com/cure53/DOMPurify/issues/317#issuecomment-912474068
47
- const TEMPORARY_ATTRIBUTE = "data-temp-href-target";
48
- DOMPurify.addHook("beforeSanitizeAttributes", (node) => {
49
- if (node.tagName === "A") {
50
- if (!node.hasAttribute("target")) {
51
- node.setAttribute("target", "_self");
52
- }
53
-
54
- if (node.hasAttribute("target")) {
55
- node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute("target") || "");
56
- }
57
- }
58
- });
59
-
60
- DOMPurify.addHook("afterSanitizeAttributes", (node) => {
61
- if (node.tagName === "A" && node.hasAttribute(TEMPORARY_ATTRIBUTE)) {
62
- node.setAttribute("target", node.getAttribute(TEMPORARY_ATTRIBUTE) || "");
63
- node.removeAttribute(TEMPORARY_ATTRIBUTE);
64
- if (node.getAttribute("target") === "_blank") {
65
- node.setAttribute("rel", "noopener noreferrer");
66
- }
67
- }
68
- });
69
-
70
- /**
71
- * This removes script tags, form tags, iframe tags, and other potentially dangerous tags
72
- */
73
- export function sanitizeHtml(html: string) {
74
- const sanitizationOptions: Config = {
75
- // Default to permit HTML, SVG and MathML, this limits to HTML only
76
- USE_PROFILES: { html: true, svg: true, mathMl: true },
77
- // Allow SVG <use> elements and their href attributes, which are needed
78
- // for SVGs that reference <defs> (e.g., Matplotlib SVG output).
79
- ADD_TAGS: ["use"],
80
- ADD_ATTR: ["href", "xlink:href"],
81
- // glue elements like style, script or others to document.body and prevent unintuitive browser behavior in several edge-cases
82
- FORCE_BODY: true,
83
- CUSTOM_ELEMENT_HANDLING: {
84
- tagNameCheck: /^(marimo-[A-Za-z][\w-]*|iconify-icon)$/,
85
- attributeNameCheck: /^[A-Za-z][\w-]*$/,
86
- },
87
- // This flag means we should sanitize such that is it safe for XML,
88
- // but this is only used for HTML content.
89
- SAFE_FOR_XML: !html.includes("marimo-mermaid"),
90
- };
91
- return DOMPurify.sanitize(html, sanitizationOptions);
92
- }
@@ -17,6 +17,7 @@ import { cn } from "@/utils/cn";
17
17
  import { Objects } from "@/utils/objects";
18
18
  import { ErrorBanner } from "../common/error-banner";
19
19
  import { vegaLoadData } from "../vega/loader";
20
+ import { getContainerWidth } from "../vega/utils";
20
21
  import { ColumnSummary } from "./components/column-summary";
21
22
  import { QueryForm } from "./components/query-form";
22
23
  import type { SpecificEncoding } from "./encoding";
@@ -140,16 +141,18 @@ export const DataExplorerComponent = ({
140
141
  const responsiveSpec = makeResponsive(spec);
141
142
  // TODO: We can optimize by updating the data dynamically. https://github.com/vega/react-vega?tab=readme-ov-file#recipes
142
143
  const augmentedSpec = augmentSpecWithData(responsiveSpec, chartData);
143
- const isContainerWidth = responsiveSpec.width === "container";
144
144
 
145
145
  return (
146
146
  <div
147
147
  className={cn(
148
148
  "flex overflow-y-auto justify-center items-center flex-1 w-[90%]",
149
- isContainerWidth && "vega-container-width",
150
149
  )}
151
150
  >
152
- <VegaEmbed spec={augmentedSpec} options={chartOptions(theme)} />
151
+ <VegaEmbed
152
+ data-container-width={getContainerWidth(augmentedSpec)}
153
+ spec={augmentedSpec}
154
+ options={chartOptions(theme)}
155
+ />
153
156
  </div>
154
157
  );
155
158
  };
@@ -0,0 +1,36 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { describe, expect, it } from "vitest";
4
+ import { getContainerWidth } from "../utils";
5
+
6
+ describe("getContainerWidth", () => {
7
+ it('should return "container" when spec width is "container"', () => {
8
+ expect(getContainerWidth({ width: "container" })).toBe("container");
9
+ });
10
+
11
+ it("should return a numeric width", () => {
12
+ expect(getContainerWidth({ width: 500 })).toBe(500);
13
+ });
14
+
15
+ it("should return undefined when spec has no width", () => {
16
+ expect(getContainerWidth({ height: 300 })).toBeUndefined();
17
+ });
18
+
19
+ it("should return undefined for null", () => {
20
+ expect(getContainerWidth(null)).toBeUndefined();
21
+ });
22
+
23
+ it("should return undefined for undefined", () => {
24
+ expect(getContainerWidth(undefined)).toBeUndefined();
25
+ });
26
+
27
+ it("should return undefined for non-object values", () => {
28
+ expect(getContainerWidth("string")).toBeUndefined();
29
+ expect(getContainerWidth(42)).toBeUndefined();
30
+ expect(getContainerWidth(true)).toBeUndefined();
31
+ });
32
+
33
+ it("should return undefined when width is explicitly undefined", () => {
34
+ expect(getContainerWidth({ width: undefined })).toBeUndefined();
35
+ });
36
+ });
@@ -3,6 +3,20 @@
3
3
  import { Objects } from "@/utils/objects";
4
4
  import type { DataType, FieldTypes, VegaDataType } from "./vega-loader";
5
5
 
6
+ export type ContainerWidth = number | "container";
7
+
8
+ /**
9
+ * Get the container width from a VegaLite spec.
10
+ * @param spec - The VegaLite spec.
11
+ * @returns The container width.
12
+ */
13
+ export function getContainerWidth(spec: unknown): ContainerWidth | undefined {
14
+ if (typeof spec === "object" && spec !== null && "width" in spec) {
15
+ return spec.width as ContainerWidth | undefined;
16
+ }
17
+ return undefined;
18
+ }
19
+
6
20
  export function mergeAsArrays<T>(
7
21
  left: T | T[] | undefined,
8
22
  right: T | T[] | undefined,
@@ -27,6 +27,7 @@ import { makeSelectable } from "./make-selectable";
27
27
  import { getSelectionParamNames, ParamNames } from "./params";
28
28
  import { resolveVegaSpecData } from "./resolve-data";
29
29
  import type { VegaLiteSpec } from "./types";
30
+ import { getContainerWidth } from "./utils";
30
31
 
31
32
  // register arrow reader under type 'arrow'
32
33
  formats("arrow", arrow);
@@ -305,16 +306,14 @@ const LoadedVegaComponent = ({
305
306
  </Alert>
306
307
  )}
307
308
  <div
308
- className={cn(
309
- "relative",
310
- "width" in selectableSpec &&
311
- selectableSpec.width === "container" &&
312
- "vega-container-width",
313
- )}
309
+ className={cn("relative")}
314
310
  // Capture the pointer down event to prevent the parent from handling it
315
311
  onPointerDown={Events.stopPropagation()}
316
312
  >
317
- <div ref={vegaRef} />
313
+ <div
314
+ ref={vegaRef}
315
+ data-container-width={getContainerWidth(selectableSpec)}
316
+ />
318
317
  {renderHelpContent()}
319
318
  </div>
320
319
  </>
@@ -4,7 +4,7 @@
4
4
  max-width: 100%;
5
5
  }
6
6
 
7
- .vega-container-width .vega-embed {
7
+ .vega-embed[data-container-width="container"] {
8
8
  width: 100%;
9
9
  }
10
10