@marimo-team/islands 0.25.3-dev82 → 0.25.3-dev86

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 (31) hide show
  1. package/dist/{ErrorBoundary-Dh-VaAao.js → ErrorBoundary-CWTKX5F9.js} +1 -1
  2. package/dist/{chat-ui-C0_lCzql.js → chat-ui-C9S_7vEJ.js} +4 -4
  3. package/dist/{code-visibility-BwTJAT1U.js → code-visibility-BYYTZhMX.js} +3 -3
  4. package/dist/{common-BTpcnvZO.js → common-D5MFwWU7.js} +5308 -5281
  5. package/dist/{data-grid-overlay-editor-C95q5QIf.js → data-grid-overlay-editor-0nyubmEm.js} +1 -1
  6. package/dist/{error-entries-CMNtA8NK.js → error-entries-Cmiq1RT-.js} +1 -1
  7. package/dist/{feedback-button-sOLkDWYm.js → feedback-button-BVXnmzuY.js} +3 -3
  8. package/dist/{formats-6pLWWrY2.js → formats-ZmooA-MD.js} +1 -1
  9. package/dist/{glide-data-editor-D6GkY0Z2.js → glide-data-editor-aaTq9XhK.js} +3 -3
  10. package/dist/{globals-rH_9s1xB.js → globals-CtT-eRE1.js} +1 -1
  11. package/dist/{html-to-image-6xcoTKhC.js → html-to-image-Dc3mTXAs.js} +2 -2
  12. package/dist/main.js +13 -13
  13. package/dist/{number-overlay-editor-BjJttHms.js → number-overlay-editor-DHSkZEYh.js} +1 -1
  14. package/dist/{process-output-BJRJFobf.js → process-output-C47Xs8_M.js} +2 -2
  15. package/dist/{reveal-component-Ckn4ABk3.js → reveal-component-CObsc45h.js} +4 -4
  16. package/dist/style.css +1 -1
  17. package/dist/{toDate-CjPuEPou.js → toDate-C6BRw8i5.js} +10 -13
  18. package/dist/{vega-component-DnfQeoyt.js → vega-component-B8IjMdad.js} +2 -2
  19. package/package.json +1 -1
  20. package/src/components/data-table/__tests__/columns.test.tsx +105 -0
  21. package/src/components/data-table/__tests__/search-highlight.test.tsx +109 -0
  22. package/src/components/data-table/__tests__/url-detector.test.tsx +74 -0
  23. package/src/components/data-table/columns.tsx +43 -45
  24. package/src/components/data-table/data-table.tsx +7 -1
  25. package/src/components/data-table/search-highlight.tsx +79 -0
  26. package/src/components/data-table/types.ts +1 -0
  27. package/src/components/data-table/url-detector.tsx +49 -9
  28. package/src/core/runtime/__tests__/createWsUrl.test.ts +77 -7
  29. package/src/core/runtime/__tests__/runtime.test.ts +13 -5
  30. package/src/core/runtime/runtime.ts +23 -27
  31. package/src/css/globals.css +2 -0
@@ -0,0 +1,79 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type { ReactNode } from "react";
4
+
5
+ /** Half-open `[start, end)` offsets into a string. */
6
+ export type MatchRange = readonly [start: number, end: number];
7
+
8
+ /**
9
+ * Build the pattern that finds `query` in a display string. Returns
10
+ * `undefined` for an empty query. The query is matched as a literal,
11
+ * case-insensitive substring, which mirrors how the backend selects rows.
12
+ * The `u` flag selects Unicode simple case folding, the same folding the
13
+ * backend regex engines use.
14
+ */
15
+ export function buildHighlightPattern(query?: string): RegExp | undefined {
16
+ if (!query) {
17
+ return undefined;
18
+ }
19
+ const escaped = query.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&");
20
+ return new RegExp(escaped, "giu");
21
+ }
22
+
23
+ /** Offsets of every match of `pattern` in `text`. */
24
+ export function findMatchRanges(text: string, pattern?: RegExp): MatchRange[] {
25
+ if (!pattern) {
26
+ return [];
27
+ }
28
+ const ranges: MatchRange[] = [];
29
+ for (const match of text.matchAll(pattern)) {
30
+ ranges.push([match.index, match.index + match[0].length]);
31
+ }
32
+ return ranges;
33
+ }
34
+
35
+ /**
36
+ * Wrap the parts of `text` covered by `ranges` in `<mark>` elements.
37
+ * `ranges` are offsets into a larger string in which `text` starts at
38
+ * `offset`, so one set of ranges can be shared across adjacent segments.
39
+ * Returns `text` unchanged when no range overlaps it.
40
+ */
41
+ export function highlightRanges(
42
+ text: string,
43
+ ranges: readonly MatchRange[],
44
+ offset = 0,
45
+ ): ReactNode {
46
+ const segments: ReactNode[] = [];
47
+ let cursor = 0;
48
+ for (const [rangeStart, rangeEnd] of ranges) {
49
+ const start = Math.max(rangeStart - offset, cursor);
50
+ const end = Math.min(rangeEnd - offset, text.length);
51
+ if (end <= start) {
52
+ continue;
53
+ }
54
+ if (start > cursor) {
55
+ segments.push(text.slice(cursor, start));
56
+ }
57
+ segments.push(
58
+ <mark key={start} className="bg-search-highlight text-inherit">
59
+ {text.slice(start, end)}
60
+ </mark>,
61
+ );
62
+ cursor = end;
63
+ }
64
+ if (segments.length === 0) {
65
+ return text;
66
+ }
67
+ if (cursor < text.length) {
68
+ segments.push(text.slice(cursor));
69
+ }
70
+ return segments;
71
+ }
72
+
73
+ /**
74
+ * Wrap every match of `pattern` in `text` in a `<mark>` element. Returns
75
+ * `text` unchanged when `pattern` is absent or does not match.
76
+ */
77
+ export function highlightMatches(text: string, pattern?: RegExp): ReactNode {
78
+ return highlightRanges(text, findMatchRanges(text, pattern));
79
+ }
@@ -6,6 +6,7 @@ import type { DataType } from "@/core/kernel/messages";
6
6
  declare module "@tanstack/react-table" {
7
7
  interface TableMeta<TData extends RowData> {
8
8
  rawData?: TData[]; // raw data for filtering/copying (present only if format_mapping is provided)
9
+ highlightPattern?: RegExp; // built from the committed search query that produced the current rows
9
10
  }
10
11
  }
11
12
 
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { marked } from "marked";
4
- import { useState } from "react";
4
+ import { Fragment, type ReactNode, useState } from "react";
5
5
  import { MarkdownRenderer } from "@/components/markdown/markdown-renderer";
6
6
  import {
7
7
  Popover,
@@ -10,13 +10,20 @@ import {
10
10
  } from "@/components/ui/popover";
11
11
  import { Events } from "@/utils/events";
12
12
  import type { ContentPart } from "@/utils/url-parser";
13
+ import { findMatchRanges, highlightRanges } from "./search-highlight";
13
14
 
14
- const ImageWithFallback = ({ url }: { url: string }) => {
15
+ const ImageWithFallback = ({
16
+ url,
17
+ fallbackLabel,
18
+ }: {
19
+ url: string;
20
+ fallbackLabel?: ReactNode;
21
+ }) => {
15
22
  const [error, setError] = useState(false);
16
23
  const [open, setOpen] = useState(false);
17
24
 
18
25
  if (error) {
19
- return <URLAnchor url={url} />;
26
+ return <URLAnchor url={url}>{fallbackLabel}</URLAnchor>;
20
27
  }
21
28
 
22
29
  return (
@@ -93,21 +100,54 @@ export const MarkdownUrlDetector = ({
93
100
  return <UrlDetector parts={parts} />;
94
101
  };
95
102
 
96
- export const UrlDetector = ({ parts }: { parts: ContentPart[] }) => {
103
+ export const UrlDetector = ({
104
+ parts,
105
+ highlightPattern,
106
+ }: {
107
+ parts: ContentPart[];
108
+ highlightPattern?: RegExp;
109
+ }) => {
110
+ // Match against the whole string so a query that spans a text part and
111
+ // a link is still marked. Each part then takes its slice of the ranges.
112
+ const ranges = highlightPattern
113
+ ? findMatchRanges(parts.map(partText).join(""), highlightPattern)
114
+ : [];
115
+
116
+ let offset = 0;
97
117
  const markup = parts.map((part, idx) => {
118
+ const text = partText(part);
119
+ const label = highlightRanges(text, ranges, offset);
120
+ offset += text.length;
121
+
98
122
  if (part.type === "url") {
99
- return <URLAnchor key={idx} url={part.url} />;
123
+ return (
124
+ <URLAnchor key={idx} url={part.url}>
125
+ {label}
126
+ </URLAnchor>
127
+ );
100
128
  }
101
129
  if (part.type === "image") {
102
- return <ImageWithFallback key={idx} url={part.url} />;
130
+ return (
131
+ <ImageWithFallback key={idx} url={part.url} fallbackLabel={label} />
132
+ );
103
133
  }
104
- return part.value;
134
+ return <Fragment key={idx}>{label}</Fragment>;
105
135
  });
106
136
 
107
137
  return markup;
108
138
  };
109
139
 
110
- const URLAnchor = ({ url }: { url: string }) => {
140
+ function partText(part: ContentPart): string {
141
+ return part.type === "text" ? part.value : part.url;
142
+ }
143
+
144
+ const URLAnchor = ({
145
+ url,
146
+ children,
147
+ }: {
148
+ url: string;
149
+ children?: ReactNode;
150
+ }) => {
111
151
  return (
112
152
  <a
113
153
  href={url}
@@ -116,7 +156,7 @@ const URLAnchor = ({ url }: { url: string }) => {
116
156
  onClick={Events.stopPropagation()}
117
157
  className="text-link hover:underline"
118
158
  >
119
- {url}
159
+ {children ?? url}
120
160
  </a>
121
161
  );
122
162
  };
@@ -13,7 +13,9 @@ describe("RuntimeManager.getWsURL", () => {
13
13
  });
14
14
  const sessionId = "1234" as SessionId;
15
15
  const url = runtime.getWsURL(sessionId);
16
- expect(url.toString()).toBe("wss://marimo.app/ws?session_id=1234");
16
+ expect(url.toString()).toBe(
17
+ "wss://marimo.app/ws?query_params=&session_id=1234",
18
+ );
17
19
  expect(url.searchParams.get(KnownQueryParams.sessionId)).toBe(sessionId);
18
20
  });
19
21
 
@@ -24,7 +26,9 @@ describe("RuntimeManager.getWsURL", () => {
24
26
  });
25
27
  const sessionId = "1234" as SessionId;
26
28
  const url = runtime.getWsURL(sessionId);
27
- expect(url.toString()).toBe("ws://marimo.app/ws?session_id=1234");
29
+ expect(url.toString()).toBe(
30
+ "ws://marimo.app/ws?query_params=&session_id=1234",
31
+ );
28
32
  expect(url.searchParams.get(KnownQueryParams.sessionId)).toBe(sessionId);
29
33
  });
30
34
 
@@ -35,7 +39,9 @@ describe("RuntimeManager.getWsURL", () => {
35
39
  });
36
40
  const sessionId = "1234" as SessionId;
37
41
  const url = runtime.getWsURL(sessionId);
38
- expect(url.toString()).toBe("ws://marimo.app/nested/ws?session_id=1234");
42
+ expect(url.toString()).toBe(
43
+ "ws://marimo.app/nested/ws?query_params=&session_id=1234",
44
+ );
39
45
  expect(url.searchParams.get(KnownQueryParams.sessionId)).toBe(sessionId);
40
46
  });
41
47
 
@@ -48,7 +54,7 @@ describe("RuntimeManager.getWsURL", () => {
48
54
  const sessionId = "1234" as SessionId;
49
55
  const url = runtime.getWsURL(sessionId);
50
56
  expect(url.toString()).toBe(
51
- "ws://marimo.app/nested/ws?foo=bar&file=test.py&session_id=1234",
57
+ "ws://marimo.app/nested/ws?foo=bar&file=test.py&query_params=foo%3Dbar%26file%3Dtest.py&session_id=1234",
52
58
  );
53
59
  expect(url.searchParams.get(KnownQueryParams.sessionId)).toBe(sessionId);
54
60
  });
@@ -62,11 +68,75 @@ describe("RuntimeManager.getWsURL", () => {
62
68
  const sessionId = "1234" as SessionId;
63
69
  const url = runtime.getWsURL(sessionId);
64
70
  expect(url.toString()).toBe(
65
- "ws://marimo.app/ws?file=test.py&search=test&other=last&session_id=1234",
71
+ "ws://marimo.app/ws?file=test.py&query_params=file%3Dtest.py%26search%3Dtest%26other%3Dlast&session_id=1234",
66
72
  );
67
73
  expect(url.searchParams.get("file")).toBe("test.py");
68
- expect(url.searchParams.get("search")).toBe("test");
69
- expect(url.searchParams.get("other")).toBe("last");
74
+ expect(url.searchParams.get("query_params")).toBe(
75
+ "file=test.py&search=test&other=last",
76
+ );
70
77
  expect(url.searchParams.get(KnownQueryParams.sessionId)).toBe(sessionId);
71
78
  });
72
79
  });
80
+
81
+ describe.each(["getWsURL", "getSseURL"] as const)(
82
+ "RuntimeManager.%s",
83
+ (method) => {
84
+ it("preserves runtime parameters and repeated page values", () => {
85
+ window.history.pushState({}, "", "/?tag=page-one&tag=page-two");
86
+ const runtime = new RuntimeManager(
87
+ {
88
+ url: `${window.location.origin}/nested?proxy_token=secret&tag=base&base=one&base=two`,
89
+ lazy: true,
90
+ },
91
+ true,
92
+ );
93
+ const url = runtime[method]("session" as SessionId);
94
+ expect([...url.searchParams]).toEqual([
95
+ ["proxy_token", "secret"],
96
+ ["tag", "base"],
97
+ ["base", "one"],
98
+ ["base", "two"],
99
+ [
100
+ "query_params",
101
+ "proxy_token=secret&base=one&base=two&tag=page-one&tag=page-two",
102
+ ],
103
+ ["session_id", "session"],
104
+ ]);
105
+ });
106
+
107
+ it("keeps notebook parameters out of the stream options", () => {
108
+ const notebookParams = new URLSearchParams([
109
+ ["types", "scatter"],
110
+ ["cursor", "page-2"],
111
+ ["run_id", "experiment"],
112
+ ["query_params", "nested=value&other=1"],
113
+ ["tag", "one"],
114
+ ["tag", "two"],
115
+ ["empty", ""],
116
+ ["text", "a+b & café"],
117
+ ["file", "test.py"],
118
+ ["kiosk", "true"],
119
+ ]);
120
+ window.history.pushState(
121
+ {},
122
+ "",
123
+ `/?${notebookParams}&session_id=page-session`,
124
+ );
125
+ const runtime = new RuntimeManager(
126
+ { url: window.location.origin, lazy: true },
127
+ true,
128
+ );
129
+ const url = runtime[method]("actual-session" as SessionId);
130
+
131
+ expect(Object.fromEntries(url.searchParams)).toEqual({
132
+ file: "test.py",
133
+ kiosk: "true",
134
+ session_id: "actual-session",
135
+ query_params: notebookParams.toString(),
136
+ });
137
+ expect([
138
+ ...new URLSearchParams(url.searchParams.get("query_params") ?? ""),
139
+ ]).toEqual([...notebookParams]);
140
+ });
141
+ },
142
+ );
@@ -249,7 +249,8 @@ describe("RuntimeManager", () => {
249
249
  const url = runtime.getSseURL("s_123" as SessionId);
250
250
 
251
251
  expect(url.searchParams.get("access_token")).toBeNull();
252
- expect(url.searchParams.get("foo")).toBe("bar");
252
+ expect(url.searchParams.get("query_params")).toBe("foo=bar");
253
+ expect(url.toString()).not.toContain("page-token");
253
254
  } finally {
254
255
  window.history.pushState({}, "", original);
255
256
  }
@@ -669,9 +670,16 @@ describe("RuntimeManager", () => {
669
670
  expect(httpUrl.searchParams.get("base_param")).toBe("existing");
670
671
 
671
672
  // Should preserve all window-level query params (including custom ones)
672
- expect(wsUrl.searchParams.get("custom_param")).toBe("value123");
673
- expect(wsUrl.searchParams.get("user_token")).toBe("abc");
674
- expect(wsUrl.searchParams.get("theme")).toBe("dark");
673
+ expect(
674
+ Object.fromEntries(
675
+ new URLSearchParams(wsUrl.searchParams.get("query_params") ?? ""),
676
+ ),
677
+ ).toEqual({
678
+ base_param: "existing",
679
+ custom_param: "value123",
680
+ user_token: "abc",
681
+ theme: "dark",
682
+ });
675
683
  expect(httpUrl.searchParams.get("custom_param")).toBe("value123");
676
684
  expect(httpUrl.searchParams.get("user_token")).toBe("abc");
677
685
  expect(httpUrl.searchParams.get("theme")).toBe("dark");
@@ -738,7 +746,7 @@ describe("RuntimeManager", () => {
738
746
  const sessionId = "test" as SessionId;
739
747
 
740
748
  expect(runtime.getWsURL(sessionId).toString()).toMatchInlineSnapshot(
741
- `"blob:https://example.com/12345678-1234-1234-1234-123456789abc?session_id=test"`,
749
+ `"blob:https://example.com/12345678-1234-1234-1234-123456789abc?query_params=&session_id=test"`,
742
750
  );
743
751
  expect(Logger.warn).toHaveBeenCalledOnce();
744
752
  });
@@ -128,33 +128,32 @@ export class RuntimeManager {
128
128
  return asWsUrl(this.appendCrossOriginAuth(url).toString());
129
129
  }
130
130
 
131
- /**
132
- * Search params for a session connection: the base URL's params, merged
133
- * with the current page's, plus the session id.
134
- */
135
- private getSessionSearchParams(sessionId: SessionId): URLSearchParams {
136
- const baseUrl = new URL(this.config.url);
137
- const searchParams = new URLSearchParams(baseUrl.search);
138
-
139
- // Merge in current page's query parameters
140
- const currentParams = new URLSearchParams(window.location.search);
141
- currentParams.forEach((value, key) => {
142
- // Don't override base URL params
143
- if (!searchParams.has(key)) {
144
- searchParams.set(key, value);
145
- }
146
- });
147
-
148
- searchParams.set(KnownQueryParams.sessionId, sessionId);
149
- return searchParams;
131
+ /** Keep notebook page parameters separate from connection options. */
132
+ private getSessionURL(path: string, sessionId: SessionId): URL {
133
+ const url = this.formatHttpURL({ path });
134
+ const notebookParams = new URLSearchParams(this.httpURL.search);
135
+ const pageParams = new URLSearchParams(window.location.search);
136
+ for (const key of pageParams.keys()) {
137
+ notebookParams.delete(key);
138
+ }
139
+ for (const [key, value] of pageParams) {
140
+ notebookParams.append(key, value);
141
+ }
142
+ // These parameters are internal and are not exposed by mo.query_params().
143
+ notebookParams.delete(KnownQueryParams.accessToken);
144
+ notebookParams.delete("refresh_token");
145
+ notebookParams.delete(KnownQueryParams.sessionId);
146
+ url.searchParams.set("query_params", notebookParams.toString());
147
+ url.searchParams.set(KnownQueryParams.sessionId, sessionId);
148
+ return url;
150
149
  }
151
150
 
152
151
  /**
153
152
  * The WebSocket URL of the runtime.
154
153
  */
155
154
  public getWsURL(sessionId: SessionId): URL {
156
- const searchParams = this.getSessionSearchParams(sessionId);
157
- return this.formatWsURL("/ws", searchParams);
155
+ const url = this.getSessionURL("/ws", sessionId);
156
+ return asWsUrl(this.appendCrossOriginAuth(url).toString());
158
157
  }
159
158
 
160
159
  /**
@@ -164,11 +163,7 @@ export class RuntimeManager {
164
163
  * (see `headers()`) instead of the URL.
165
164
  */
166
165
  public getSseURL(sessionId: SessionId): URL {
167
- const url = this.formatHttpURL({
168
- path: "/sse",
169
- searchParams: this.getSessionSearchParams(sessionId),
170
- restrictToKnownQueryParams: false,
171
- });
166
+ const url = this.getSessionURL("/sse", sessionId);
172
167
  // The page URL can still carry access_token (merged in from the
173
168
  // current page's params, before auth cleanup strips it); never
174
169
  // forward it — a token in the URL leaks into proxy/server logs.
@@ -180,7 +175,8 @@ export class RuntimeManager {
180
175
  * The WebSocket Sync URL of the runtime, for real-time updates.
181
176
  */
182
177
  public getWsSyncURL(sessionId: SessionId): URL {
183
- return this.formatWsURL("/ws_sync", this.getSessionSearchParams(sessionId));
178
+ const url = this.getSessionURL("/ws_sync", sessionId);
179
+ return asWsUrl(this.appendCrossOriginAuth(url).toString());
184
180
  }
185
181
 
186
182
  /**
@@ -92,6 +92,7 @@
92
92
  --action-hover: var(--yellow-10, #ffdc00);
93
93
  --action-border: var(--yellow-11, #9e6c00);
94
94
  --action-foreground: var(--yellow-12, #473b1f);
95
+ --search-highlight: var(--yellow-4, #fff394);
95
96
  --link: light-dark(hsl(211deg 90% 42%), hsl(211deg 90% 62%));
96
97
  --link-visited: light-dark(hsl(272deg 51% 54%), hsl(272deg 51% 74%));
97
98
  --stale: hsl(42deg 56% 44% / 25%);
@@ -140,6 +141,7 @@
140
141
  --action-hover: var(--yellow-7, #665417);
141
142
  --action-border: var(--yellow-11, #f5e147);
142
143
  --action-foreground: var(--yellow-12, #f6eeb4);
144
+ --search-highlight: var(--yellow-6, #524202);
143
145
  --stale: hsl(54deg 100% 86.7% / 25%);
144
146
  }
145
147
  }