diff --git a/.changeset/four-geckos-suffer.md b/.changeset/four-geckos-suffer.md
new file mode 100644
index 0000000..bad7e02
--- /dev/null
+++ b/.changeset/four-geckos-suffer.md
@@ -0,0 +1,5 @@
+---
+'click-to-react-component': minor
+---
+
+support jb ide
diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md
index ea23514..9687519 100644
--- a/packages/click-to-react-component/README.md
+++ b/packages/click-to-react-component/README.md
@@ -18,7 +18,7 @@
[Create React App](https://create-react-app.dev/),
& [Vite](https://github.com/vitejs/vite/tree/main/packages/plugin-react)
that use [@babel/plugin-transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source)
-- Supports `vscode` & `vscode-insiders` & `cursor` [URL handling](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls)
+- Supports `vscode`, `vscode-insiders`, `cursor` [URL handling](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls), and JB IDEs like `WebStorm` (requires [IDE Remote Control](https://plugins.jetbrains.com/plugin/19991-ide-remote-control))
- Automatically **tree-shaken** from `production` builds
- Keyboard navigation in context menu (e.g. ←, →, ⏎)
- More context & faster than using React DevTools:
diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js
index 148a863..4ca930c 100644
--- a/packages/click-to-react-component/src/ClickToComponent.js
+++ b/packages/click-to-react-component/src/ClickToComponent.js
@@ -61,14 +61,17 @@ export function ClickToComponent({ editor = 'vscode', pathModifier }) {
)
}
const path = getPathToSource(source, pathModifier)
- const url = getUrl({
+ const [url, isURLScheme] = getUrl({
editor,
pathToSource: path,
})
event.preventDefault()
- window.location.assign(url)
-
+ if (isURLScheme) {
+ window.location.assign(url)
+ } else {
+ fetch(url);
+ }
setState(State.IDLE)
}
},
@@ -78,12 +81,16 @@ export function ClickToComponent({ editor = 'vscode', pathModifier }) {
const onClose = React.useCallback(
function handleClose(returnValue) {
if (returnValue) {
- const url = getUrl({
+ const [url,isURLScheme] = getUrl({
editor,
pathToSource: returnValue,
})
- window.location.assign(url)
+ if (isURLScheme) {
+ window.location.assign(url)
+ } else {
+ fetch(url);
+ }
}
setState(State.IDLE)
@@ -247,11 +254,12 @@ export function ClickToComponent({ editor = 'vscode', pathModifier }) {
<${FloatingPortal} key="click-to-component-portal">
- ${html`<${ContextMenu}
- key="click-to-component-contextmenu"
- onClose=${onClose}
- pathModifier=${pathModifier}
- />`}
+ ${html`
+ <${ContextMenu}
+ key="click-to-component-contextmenu"
+ onClose=${onClose}
+ pathModifier=${pathModifier}
+ />`}
${FloatingPortal}
`
}
diff --git a/packages/click-to-react-component/src/getUrl.js b/packages/click-to-react-component/src/getUrl.js
index 3b75cba..d012500 100644
--- a/packages/click-to-react-component/src/getUrl.js
+++ b/packages/click-to-react-component/src/getUrl.js
@@ -2,12 +2,20 @@
* @param {Object} param
* @param {string} param.editor
* @param {string} param.pathToSource
+ * @returns {[string, boolean]} bool isURLScheme
*/
export function getUrl({ editor, pathToSource }) {
+ if (JB_EDITORS.includes(editor)) {
+ // @see https://github.com/JetBrains/intellij-community/blob/a77365debaadcf00b888a977d89512f3f0f3cf9e/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt#L52-L59
+ return [`http://localhost:63342/api/file/${pathToSource}`, false]
+ }
// Fix https://github.com/microsoft/vscode/issues/197319
if (pathToSource[0] === '/') {
- return `${editor}://file${pathToSource}`
+ return [`${editor}://file${pathToSource}`, true]
}
- return `${editor}://file/${pathToSource}`
+ return [`${editor}://file/${pathToSource}`, true]
}
+
+export const JB_EDITORS = ['idea', 'appcode', 'clion', 'pycharm', 'phpstorm',
+ 'rubymine', 'webstorm', 'rider', 'goland', 'rustrover']
diff --git a/packages/click-to-react-component/src/types.d.ts b/packages/click-to-react-component/src/types.d.ts
index e0e6b1e..444389e 100644
--- a/packages/click-to-react-component/src/types.d.ts
+++ b/packages/click-to-react-component/src/types.d.ts
@@ -1,6 +1,9 @@
export { ClickToComponent } from './ClickToComponent'
-export type Editor = 'vscode' | 'vscode-insiders' | 'cursor' | string
+const JB_EDITORS = ['idea', 'appcode', 'clion', 'pycharm', 'phpstorm',
+ 'rubymine', 'webstorm', 'rider', 'goland', 'rustrover'] as const
+
+export type Editor = 'vscode' | 'vscode-insiders' | 'cursor' | typeof JB_EDITORS[number] | string
export type PathModifier = (path: string) => string