@react-devtools-plus/kit 0.5.3 → 0.6.1

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/index.cjs CHANGED
@@ -2345,11 +2345,47 @@ function toggleInspector(enabled, options = {}) {
2345
2345
  //#endregion
2346
2346
  //#region src/core/open-in-editor/index.ts
2347
2347
  /**
2348
+ * JetBrains IDEs that use the `open?file=` URL format
2349
+ */
2350
+ const JETBRAINS_EDITORS = [
2351
+ "webstorm",
2352
+ "phpstorm",
2353
+ "idea",
2354
+ "intellij",
2355
+ "pycharm",
2356
+ "rubymine",
2357
+ "goland",
2358
+ "clion",
2359
+ "rider",
2360
+ "appcode",
2361
+ "datagrip",
2362
+ "dataspell"
2363
+ ];
2364
+ /**
2365
+ * Build URL protocol for opening file in editor
2366
+ */
2367
+ function buildEditorUrl(editor, fileName, line, column) {
2368
+ const editorLower = editor.toLowerCase();
2369
+ if (JETBRAINS_EDITORS.some((ide) => editorLower.includes(ide))) return `${editor}://open?file=${encodeURIComponent(fileName)}&line=${line}&column=${column}`;
2370
+ return `${editor}://file/${fileName}:${line}:${column}`;
2371
+ }
2372
+ /**
2373
+ * Get the configured editor
2374
+ * Priority: plugin config > localStorage > default 'vscode'
2375
+ */
2376
+ function getConfiguredEditor() {
2377
+ const config = window.__REACT_DEVTOOLS_CONFIG__;
2378
+ if (config === null || config === void 0 ? void 0 : config.launchEditor) return config.launchEditor;
2379
+ const localStorageEditor = localStorage.getItem("react_devtools_editor");
2380
+ if (localStorageEditor) return localStorageEditor;
2381
+ return "vscode";
2382
+ }
2383
+ /**
2348
2384
  * Try to open a file in the editor using URL protocol (fallback)
2349
2385
  */
2350
2386
  function tryOpenWithProtocol(fileName, line, column) {
2351
2387
  try {
2352
- const protocolUrl = `${localStorage.getItem("react_devtools_editor") || "vscode"}://file/${fileName}:${line}:${column}`;
2388
+ const protocolUrl = buildEditorUrl(getConfiguredEditor(), fileName, line, column);
2353
2389
  const link = document.createElement("a");
2354
2390
  link.href = protocolUrl;
2355
2391
  link.click();
@@ -2375,28 +2411,26 @@ function getDevToolsBasePath() {
2375
2411
  }
2376
2412
  return "/__react_devtools__";
2377
2413
  }
2378
- function openInEditor(fileName, line, column) {
2414
+ /**
2415
+ * Check if response is a valid API response (not HTML fallback from SPA)
2416
+ * SPA frameworks often return 200 + HTML for unknown routes due to fallback behavior
2417
+ */
2418
+ function isValidApiResponse(response) {
2419
+ if (!response.ok) return false;
2420
+ if ((response.headers.get("content-type") || "").includes("text/html")) return false;
2421
+ return true;
2422
+ }
2423
+ async function openInEditor(fileName, line, column) {
2379
2424
  const fileParam = encodeURIComponent(`${fileName}:${line}:${column}`);
2425
+ const editor = getConfiguredEditor();
2426
+ const editorParam = encodeURIComponent(editor);
2380
2427
  const basePath = getDevToolsBasePath();
2381
- const endpoints = [`/__open-in-editor?file=${fileParam}`, `${basePath}/api/open-in-editor?file=${fileParam}`];
2382
- async function tryEndpoints(index) {
2383
- if (index >= endpoints.length) {
2384
- console.warn("[React DevTools] All server endpoints failed, trying URL protocol fallback");
2385
- tryOpenWithProtocol(fileName, line, column);
2386
- return;
2387
- }
2388
- const url = endpoints[index];
2389
- try {
2390
- if ((await fetch(url)).ok) return;
2391
- await tryEndpoints(index + 1);
2392
- } catch (_unused2) {
2393
- await tryEndpoints(index + 1);
2394
- }
2395
- }
2396
- tryEndpoints(0).catch((e) => {
2397
- console.error("[React DevTools] Failed to open in editor:", e);
2398
- tryOpenWithProtocol(fileName, line, column);
2399
- });
2428
+ const endpoints = [`/__open-in-editor?file=${fileParam}&editor=${editorParam}`, `${basePath}/api/open-in-editor?file=${fileParam}&editor=${editorParam}`];
2429
+ for (const url of endpoints) try {
2430
+ if (isValidApiResponse(await fetch(url))) return;
2431
+ } catch (_unused2) {}
2432
+ console.warn("[React DevTools] All server endpoints failed, trying URL protocol fallback");
2433
+ tryOpenWithProtocol(fileName, line, column);
2400
2434
  }
2401
2435
 
2402
2436
  //#endregion
package/dist/index.d.cts CHANGED
@@ -364,7 +364,7 @@ interface ToggleInspectorOptions {
364
364
  declare function toggleInspector(enabled: boolean, options?: ToggleInspectorOptions): void;
365
365
  //#endregion
366
366
  //#region src/core/open-in-editor/index.d.ts
367
- declare function openInEditor(fileName: string, line: number, column: number): void;
367
+ declare function openInEditor(fileName: string, line: number, column: number): Promise<void>;
368
368
  //#endregion
369
369
  //#region src/core/router/index.d.ts
370
370
  interface RouteInfo {
package/dist/index.d.ts CHANGED
@@ -364,7 +364,7 @@ interface ToggleInspectorOptions {
364
364
  declare function toggleInspector(enabled: boolean, options?: ToggleInspectorOptions): void;
365
365
  //#endregion
366
366
  //#region src/core/open-in-editor/index.d.ts
367
- declare function openInEditor(fileName: string, line: number, column: number): void;
367
+ declare function openInEditor(fileName: string, line: number, column: number): Promise<void>;
368
368
  //#endregion
369
369
  //#region src/core/router/index.d.ts
370
370
  interface RouteInfo {
package/dist/index.js CHANGED
@@ -2321,11 +2321,47 @@ function toggleInspector(enabled, options = {}) {
2321
2321
  //#endregion
2322
2322
  //#region src/core/open-in-editor/index.ts
2323
2323
  /**
2324
+ * JetBrains IDEs that use the `open?file=` URL format
2325
+ */
2326
+ const JETBRAINS_EDITORS = [
2327
+ "webstorm",
2328
+ "phpstorm",
2329
+ "idea",
2330
+ "intellij",
2331
+ "pycharm",
2332
+ "rubymine",
2333
+ "goland",
2334
+ "clion",
2335
+ "rider",
2336
+ "appcode",
2337
+ "datagrip",
2338
+ "dataspell"
2339
+ ];
2340
+ /**
2341
+ * Build URL protocol for opening file in editor
2342
+ */
2343
+ function buildEditorUrl(editor, fileName, line, column) {
2344
+ const editorLower = editor.toLowerCase();
2345
+ if (JETBRAINS_EDITORS.some((ide) => editorLower.includes(ide))) return `${editor}://open?file=${encodeURIComponent(fileName)}&line=${line}&column=${column}`;
2346
+ return `${editor}://file/${fileName}:${line}:${column}`;
2347
+ }
2348
+ /**
2349
+ * Get the configured editor
2350
+ * Priority: plugin config > localStorage > default 'vscode'
2351
+ */
2352
+ function getConfiguredEditor() {
2353
+ const config = window.__REACT_DEVTOOLS_CONFIG__;
2354
+ if (config === null || config === void 0 ? void 0 : config.launchEditor) return config.launchEditor;
2355
+ const localStorageEditor = localStorage.getItem("react_devtools_editor");
2356
+ if (localStorageEditor) return localStorageEditor;
2357
+ return "vscode";
2358
+ }
2359
+ /**
2324
2360
  * Try to open a file in the editor using URL protocol (fallback)
2325
2361
  */
2326
2362
  function tryOpenWithProtocol(fileName, line, column) {
2327
2363
  try {
2328
- const protocolUrl = `${localStorage.getItem("react_devtools_editor") || "vscode"}://file/${fileName}:${line}:${column}`;
2364
+ const protocolUrl = buildEditorUrl(getConfiguredEditor(), fileName, line, column);
2329
2365
  const link = document.createElement("a");
2330
2366
  link.href = protocolUrl;
2331
2367
  link.click();
@@ -2351,28 +2387,26 @@ function getDevToolsBasePath() {
2351
2387
  }
2352
2388
  return "/__react_devtools__";
2353
2389
  }
2354
- function openInEditor(fileName, line, column) {
2390
+ /**
2391
+ * Check if response is a valid API response (not HTML fallback from SPA)
2392
+ * SPA frameworks often return 200 + HTML for unknown routes due to fallback behavior
2393
+ */
2394
+ function isValidApiResponse(response) {
2395
+ if (!response.ok) return false;
2396
+ if ((response.headers.get("content-type") || "").includes("text/html")) return false;
2397
+ return true;
2398
+ }
2399
+ async function openInEditor(fileName, line, column) {
2355
2400
  const fileParam = encodeURIComponent(`${fileName}:${line}:${column}`);
2401
+ const editor = getConfiguredEditor();
2402
+ const editorParam = encodeURIComponent(editor);
2356
2403
  const basePath = getDevToolsBasePath();
2357
- const endpoints = [`/__open-in-editor?file=${fileParam}`, `${basePath}/api/open-in-editor?file=${fileParam}`];
2358
- async function tryEndpoints(index) {
2359
- if (index >= endpoints.length) {
2360
- console.warn("[React DevTools] All server endpoints failed, trying URL protocol fallback");
2361
- tryOpenWithProtocol(fileName, line, column);
2362
- return;
2363
- }
2364
- const url = endpoints[index];
2365
- try {
2366
- if ((await fetch(url)).ok) return;
2367
- await tryEndpoints(index + 1);
2368
- } catch (_unused2) {
2369
- await tryEndpoints(index + 1);
2370
- }
2371
- }
2372
- tryEndpoints(0).catch((e) => {
2373
- console.error("[React DevTools] Failed to open in editor:", e);
2374
- tryOpenWithProtocol(fileName, line, column);
2375
- });
2404
+ const endpoints = [`/__open-in-editor?file=${fileParam}&editor=${editorParam}`, `${basePath}/api/open-in-editor?file=${fileParam}&editor=${editorParam}`];
2405
+ for (const url of endpoints) try {
2406
+ if (isValidApiResponse(await fetch(url))) return;
2407
+ } catch (_unused2) {}
2408
+ console.warn("[React DevTools] All server endpoints failed, trying URL protocol fallback");
2409
+ tryOpenWithProtocol(fileName, line, column);
2376
2410
  }
2377
2411
 
2378
2412
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-devtools-plus/kit",
3
3
  "type": "module",
4
- "version": "0.5.3",
4
+ "version": "0.6.1",
5
5
  "author": "wzc520pyfm",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "mitt": "^3.0.1",
28
28
  "perfect-debounce": "^2.0.0",
29
29
  "superjson": "^2.2.2",
30
- "@react-devtools-plus/shared": "^0.5.3"
30
+ "@react-devtools-plus/shared": "^0.6.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^24.7.2",