@marimo-team/islands 0.19.3-dev17 → 0.19.3-dev21

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.
package/dist/main.js CHANGED
@@ -38970,7 +38970,7 @@ ${c.sqlString}
38970
38970
  Logger.warn("scrollCellIntoView: editor not found", e);
38971
38971
  return;
38972
38972
  }
38973
- if (c2.hasFocus) return;
38973
+ if (c2.hasFocus || !document.hasFocus()) return;
38974
38974
  if (retryWithTimeout(() => (c2.focus(), c2.hasFocus), {
38975
38975
  retries: 5,
38976
38976
  delay: 20
@@ -101069,7 +101069,7 @@ Defaulting to \`null\`.`;
101069
101069
  return Logger.warn("Failed to get version from mount config"), null;
101070
101070
  }
101071
101071
  }
101072
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.3-dev17"), showCodeInRunModeAtom = atom(true);
101072
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.19.3-dev21"), showCodeInRunModeAtom = atom(true);
101073
101073
  atom(null);
101074
101074
  var VIRTUAL_FILE_REGEX = /\/@file\/([^\s"&'/]+)\.([\dA-Za-z]+)/g, VirtualFileTracker = class e {
101075
101075
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.19.3-dev17",
3
+ "version": "0.19.3-dev21",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -12,6 +12,8 @@ describe("useFocusFirstEditor", () => {
12
12
  cb(0);
13
13
  return 0;
14
14
  });
15
+ // Mock document.hasFocus() to return true so focus logic runs
16
+ vi.spyOn(document, "hasFocus").mockReturnValue(true);
15
17
  });
16
18
 
17
19
  afterEach(() => {
@@ -120,4 +122,29 @@ describe("useFocusFirstEditor", () => {
120
122
  writable: true,
121
123
  });
122
124
  });
125
+
126
+ it("should not focus when document does not have focus", () => {
127
+ // Mock document.hasFocus() to return false (e.g., when embedded in iframe)
128
+ vi.spyOn(document, "hasFocus").mockReturnValue(false);
129
+
130
+ const mockEditor = { focus: vi.fn() };
131
+ vi.spyOn(cellsModule, "getNotebook").mockReturnValue({
132
+ cellIds: { iterateTopLevelIds: ["cell-1"] },
133
+ cellData: {
134
+ "cell-1": { config: { hide_code: false } },
135
+ },
136
+ cellHandles: {
137
+ "cell-1": { current: { editorView: mockEditor } },
138
+ },
139
+ } as unknown as cellsModule.NotebookState);
140
+
141
+ renderHook(() => useFocusFirstEditor());
142
+
143
+ act(() => {
144
+ vi.advanceTimersByTime(100);
145
+ });
146
+
147
+ // Focus should NOT be called when document doesn't have focus
148
+ expect(mockEditor.focus).not.toHaveBeenCalled();
149
+ });
123
150
  });
@@ -19,6 +19,12 @@ export function useFocusFirstEditor() {
19
19
  const timeout = setTimeout(() => {
20
20
  // Let the DOM render
21
21
  requestAnimationFrame(() => {
22
+ // Skip auto-focus if the document doesn't have focus to avoid
23
+ // stealing focus from outside (e.g., when embedded in an iframe)
24
+ if (!document.hasFocus()) {
25
+ return;
26
+ }
27
+
22
28
  // Check if the URL contains a scrollTo parameter
23
29
  const hash = window.location.hash;
24
30
  const cellName = extractCellNameFromHash(hash);
@@ -53,8 +53,9 @@ export function focusAndScrollCellIntoView({
53
53
  Logger.warn("scrollCellIntoView: editor not found", cellId);
54
54
  return;
55
55
  }
56
- // If already focused, do nothing.
57
- if (editor.hasFocus) {
56
+ // Skip auto-focus if already focused, or if the document doesn't have
57
+ // focus to avoid stealing focus from outside (e.g., when embedded in an iframe)
58
+ if (editor.hasFocus || !document.hasFocus()) {
58
59
  return;
59
60
  }
60
61