From 0133f8a94776a27ce06217b9681dd2a7376be3e7 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 11:42:24 +1100 Subject: [PATCH 01/18] feat(IDE): add open IDE to intellij --- .../src/ClickToComponent.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js index 4bc8404..bfa2741 100644 --- a/packages/click-to-react-component/src/ClickToComponent.js +++ b/packages/click-to-react-component/src/ClickToComponent.js @@ -41,11 +41,8 @@ export function ClickToComponent({ editor = 'vscode' }) { if (state === State.HOVER && target instanceof HTMLElement) { const source = getSourceForElement(target) const path = getPathToSource(source) - const url = `${editor}://file/${path}` - event.preventDefault() - window.open(url) - + openFileInIDE(path) setState(State.IDLE) } }, @@ -55,15 +52,26 @@ export function ClickToComponent({ editor = 'vscode' }) { const onClose = React.useCallback( function handleClose(returnValue) { if (returnValue) { - const url = `${editor}://file/${returnValue}` - window.open(url) + openFileInIDE(returnValue) } - setState(State.IDLE) }, [editor] ) + const openFileInIDE = (file) => { + if (editor === 'intellij') { + const url = `http://localhost:63342/api/file/${file}` + const cmd = window.open(url) + setTimeout(function() { + cmd.close(); + }, 100); + } else { + const url = `${editor}://file/${file}` + window.open(url) + } + } + const onContextMenu = React.useCallback( function handleContextMenu( /** From ede2875df50e185ca1a22b061f9cab66b9b774e6 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 12:54:30 +1100 Subject: [PATCH 02/18] feat(IDE): add open IDE to intellij --- .gitignore | 1 + package.json | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 30293be..28acec4 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ dist # TernJS port file .tern-port +/.idea/ diff --git a/package.json b/package.json index 71855e7..447cf87 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "private": true, "main": "index.js", "scripts": { "build": "turbo run build --filter=click-to-*-component", @@ -14,5 +13,18 @@ "eslint": "8.13.0", "turbo": "^1.2.5" }, - "packageManager": "pnpm@6.32.3" + "packageManager": "pnpm@6.32.3", + "name": "click-to-component-intellij", + "version": "1.0.0", + "description": "Component in the browser to instantly goto the source in your editor.", + "repository": { + "type": "git", + "url": "git+https://github.com/SkazyNC/click-to-component-intellij.git" + }, + "author": "abay", + "license": "ISC", + "bugs": { + "url": "https://github.com/SkazyNC/click-to-component-intellij/issues" + }, + "homepage": "https://github.com/SkazyNC/click-to-component-intellij#readme" } From c075aadf00d01bc4a7d81e5c47bdb56a5a8c779b Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:02:31 +1100 Subject: [PATCH 03/18] fix(readme): new cmd --- packages/click-to-react-component/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 4215219..adfd967 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -31,7 +31,7 @@ npm ```shell -npm install click-to-react-component +npm install click-to-component-intellij ``` @@ -40,7 +40,7 @@ npm install click-to-react-component pnpm ```shell -pnpm add click-to-react-component +pnpm add click-to-component-intellij ``` @@ -49,7 +49,7 @@ pnpm add click-to-react-component yarn ```shell -yarn add click-to-react-component +yarn add click-to-component-intellij ``` From 58f7a48dc8ed9739ac0aa2dd1fd91e6d06c39fb9 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:03:52 +1100 Subject: [PATCH 04/18] fix(readme): new cmd --- packages/click-to-react-component/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index adfd967..c275f7b 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -131,11 +131,11 @@ ReactDOM.createRoot(document.getElementById("root")!).render( By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). -If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: +If, like me, you use [`intellij`](https://code.visualstudio.com/insiders/), you can set `intellij` explicitly: ```diff - -+ ++ ``` ## Run Locally From 6cb4a6c4ef11aac540aee97000f2ab4351d87d3c Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:06:54 +1100 Subject: [PATCH 05/18] fix(readme): new cmd --- packages/click-to-react-component/README.md | 4 ++-- packages/click-to-react-component/src/ClickToComponent.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index c275f7b..2ff4748 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -129,9 +129,9 @@ ReactDOM.createRoot(document.getElementById("root")!).render( ### `editor` -By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). +By default, clicking will deafult `editor` to [`intellij`](https://code.visualstudio.com/). -If, like me, you use [`intellij`](https://code.visualstudio.com/insiders/), you can set `intellij` explicitly: +you can set `vscode` explicitly: ```diff - diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js index bfa2741..b4d06c0 100644 --- a/packages/click-to-react-component/src/ClickToComponent.js +++ b/packages/click-to-react-component/src/ClickToComponent.js @@ -20,7 +20,7 @@ export const State = /** @type {const} */ ({ /** * @param {Props} props */ -export function ClickToComponent({ editor = 'vscode' }) { +export function ClickToComponent({ editor = 'intellij' }) { const [state, setState] = React.useState( /** @type {State[keyof State]} */ (State.IDLE) From 1e851f3d29cc813dc9834c666b58dafd081968a9 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:07:28 +1100 Subject: [PATCH 06/18] fix(readme): new cmd --- packages/click-to-react-component/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 2ff4748..7d6df87 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -135,7 +135,7 @@ you can set `vscode` explicitly: ```diff - -+ ++ ``` ## Run Locally From e37bce70e95df569a5b292682580940c160c8299 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:07:43 +1100 Subject: [PATCH 07/18] fix(readme): new cmd --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 447cf87..46ca3f1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ }, "packageManager": "pnpm@6.32.3", "name": "click-to-component-intellij", - "version": "1.0.0", + "version": "1.0.1", "description": "Component in the browser to instantly goto the source in your editor.", "repository": { "type": "git", From b96e397c54b8340bdb78cc1f7d62fa0854cede30 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:29:36 +1100 Subject: [PATCH 08/18] Revert "Compare to React DevTools" This reverts commit 21c7791f29b34b19221856af03959a423794bd63. --- packages/click-to-react-component/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 7d6df87..8a4608e 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -21,9 +21,6 @@ - Supports `vscode` & `vscode-insiders`' [URL handling](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls) - Automatically **tree-shaken** from `production` builds - Keyboard navigation in context menu (e.g. , , ) -- More context & faster than using React DevTools: - - > ![React DevTools](devtools.png) ## Installation From 17548e46ac6d585a988b3718b03f93561d0ba719 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:32:27 +1100 Subject: [PATCH 09/18] fix(readme): new cmd --- package.json | 15 +------------- packages/click-to-react-component/README.md | 20 +++++++++++++------ .../src/ClickToComponent.js | 2 +- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 46ca3f1..906575c 100644 --- a/package.json +++ b/package.json @@ -13,18 +13,5 @@ "eslint": "8.13.0", "turbo": "^1.2.5" }, - "packageManager": "pnpm@6.32.3", - "name": "click-to-component-intellij", - "version": "1.0.1", - "description": "Component in the browser to instantly goto the source in your editor.", - "repository": { - "type": "git", - "url": "git+https://github.com/SkazyNC/click-to-component-intellij.git" - }, - "author": "abay", - "license": "ISC", - "bugs": { - "url": "https://github.com/SkazyNC/click-to-component-intellij/issues" - }, - "homepage": "https://github.com/SkazyNC/click-to-component-intellij#readme" + "packageManager": "pnpm@6.32.3" } diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 8a4608e..b1ec949 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -28,7 +28,7 @@ npm ```shell -npm install click-to-component-intellij +npm install click-to-react-component ``` @@ -37,7 +37,7 @@ npm install click-to-component-intellij pnpm ```shell -pnpm add click-to-component-intellij +pnpm add click-to-react-component ``` @@ -46,7 +46,7 @@ pnpm add click-to-component-intellij yarn ```shell -yarn add click-to-component-intellij +yarn add click-to-react-component ``` @@ -126,13 +126,21 @@ ReactDOM.createRoot(document.getElementById("root")!).render( ### `editor` -By default, clicking will deafult `editor` to [`intellij`](https://code.visualstudio.com/). +By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). -you can set `vscode` explicitly: + +If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: + +```diff +- ++ +``` + +If, you use [`intellij`], you can set `editor` explicitly: ```diff - -+ ++ ``` ## Run Locally diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js index b4d06c0..bfa2741 100644 --- a/packages/click-to-react-component/src/ClickToComponent.js +++ b/packages/click-to-react-component/src/ClickToComponent.js @@ -20,7 +20,7 @@ export const State = /** @type {const} */ ({ /** * @param {Props} props */ -export function ClickToComponent({ editor = 'intellij' }) { +export function ClickToComponent({ editor = 'vscode' }) { const [state, setState] = React.useState( /** @type {State[keyof State]} */ (State.IDLE) From da6758cd913636b78b1901070ceb17489b362e92 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:33:47 +1100 Subject: [PATCH 10/18] fix(readme): new cmd --- package.json | 1 + packages/click-to-react-component/README.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/package.json b/package.json index 906575c..71855e7 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "private": true, "main": "index.js", "scripts": { "build": "turbo run build --filter=click-to-*-component", diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index b1ec949..595585c 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -21,7 +21,10 @@ - Supports `vscode` & `vscode-insiders`' [URL handling](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls) - Automatically **tree-shaken** from `production` builds - Keyboard navigation in context menu (e.g. , , ) +- More context & faster than using React DevTools: + > ![React DevTools](devtools.png) + > ## Installation
From 2f4187351e9f3214130b85ee7509fb7c2d3bacb2 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:34:37 +1100 Subject: [PATCH 11/18] fix(readme): new cmd --- packages/click-to-react-component/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 595585c..3499a1c 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -24,7 +24,7 @@ - More context & faster than using React DevTools: > ![React DevTools](devtools.png) - > + ## Installation
@@ -131,7 +131,6 @@ ReactDOM.createRoot(document.getElementById("root")!).render( By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). - If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: ```diff From bf037100ab79704797a986dda5ee36120cb7f302 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 28 Apr 2022 13:40:17 +1100 Subject: [PATCH 12/18] Create soft-taxis-search.md --- .changeset/soft-taxis-search.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-taxis-search.md diff --git a/.changeset/soft-taxis-search.md b/.changeset/soft-taxis-search.md new file mode 100644 index 0000000..2236ab4 --- /dev/null +++ b/.changeset/soft-taxis-search.md @@ -0,0 +1,5 @@ +--- +"click-to-react-component": patch +--- + +Support for OpenFile to Intellij From 502fa5ee9cb575b231a47ccd44ef2edd9956bbde Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 28 Apr 2022 13:42:44 +1100 Subject: [PATCH 13/18] fix(readme): new cmd --- .changeset/{soft-taxis-search.md => open-file-intellij.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .changeset/{soft-taxis-search.md => open-file-intellij.md} (52%) diff --git a/.changeset/soft-taxis-search.md b/.changeset/open-file-intellij.md similarity index 52% rename from .changeset/soft-taxis-search.md rename to .changeset/open-file-intellij.md index 2236ab4..6d8973f 100644 --- a/.changeset/soft-taxis-search.md +++ b/.changeset/open-file-intellij.md @@ -2,4 +2,4 @@ "click-to-react-component": patch --- -Support for OpenFile to Intellij +Added Support for OpenFile to Intellij From 2522aff6f3c034dc637ad25e471cf4e6e5d869a5 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Tue, 3 May 2022 08:26:41 +1100 Subject: [PATCH 14/18] fix(type): add intellij to export type Editor --- packages/click-to-react-component/src/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/click-to-react-component/src/types.d.ts b/packages/click-to-react-component/src/types.d.ts index d48a719..6f10ee7 100644 --- a/packages/click-to-react-component/src/types.d.ts +++ b/packages/click-to-react-component/src/types.d.ts @@ -1,6 +1,6 @@ export { ClickToComponent } from './src/ClickToComponent' -export type Editor = 'vscode' | 'vscode-insiders' +export type Editor = 'vscode' | 'vscode-insiders' | 'intellij' export type ClickToComponentProps = { editor?: Editor From d9837db8ddd1c207cabfdc97e6eb3f9abf61c03a Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Thu, 5 May 2022 13:37:57 +1100 Subject: [PATCH 15/18] fix(IDE): add link to change default editor --- packages/click-to-react-component/README.md | 16 +++++----- .../src/ClickToComponent.js | 32 +++++++++++++------ .../src/ContextMenu.js | 23 +++++++++++-- .../click-to-react-component/src/types.d.ts | 2 ++ 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 3499a1c..2490839 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -129,20 +129,20 @@ ReactDOM.createRoot(document.getElementById("root")!).render( ### `editor` -By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). +By default, clicking will default `editor` to [`vscode`](https://code.visualstudio.com/). -If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: +You can change default `editor` in the context menu Option+Right-click -```diff -- -+ -``` +Possible values for the `editor` are [`vscode`] or [`vscode-insiders`] or [`intellij`] -If, you use [`intellij`], you can set `editor` explicitly: +If you use [`intellij`], the IDE need to be active to open the file + + +If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: ```diff - -+ ++ ``` ## Run Locally diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js index bfa2741..590a231 100644 --- a/packages/click-to-react-component/src/ClickToComponent.js +++ b/packages/click-to-react-component/src/ClickToComponent.js @@ -21,6 +21,8 @@ export const State = /** @type {const} */ ({ * @param {Props} props */ export function ClickToComponent({ editor = 'vscode' }) { + const localStorageKey = 'clickToComponentEditorUsed' + const [IDE, setIDE] = React.useState(localStorage.getItem(localStorageKey) || editor) const [state, setState] = React.useState( /** @type {State[keyof State]} */ (State.IDLE) @@ -40,13 +42,15 @@ export function ClickToComponent({ editor = 'vscode' }) { ) { if (state === State.HOVER && target instanceof HTMLElement) { const source = getSourceForElement(target) - const path = getPathToSource(source) - event.preventDefault() - openFileInIDE(path) - setState(State.IDLE) + if (source) { + const path = getPathToSource(source) + event.preventDefault() + openFileInIDE(path) + setState(State.IDLE) + } } }, - [editor, state, target] + [IDE, state, target] ) const onClose = React.useCallback( @@ -56,18 +60,24 @@ export function ClickToComponent({ editor = 'vscode' }) { } setState(State.IDLE) }, - [editor] + [IDE] ) + const onChangeIDE = () => { + const value = prompt("What editor do you use ? vscode | vscode-insiders | intellij\n\ninfo: intellij need to be open before", IDE) + localStorage.setItem(localStorageKey, value) + setIDE(value) + } + const openFileInIDE = (file) => { - if (editor === 'intellij') { + if (IDE === 'intellij') { const url = `http://localhost:63342/api/file/${file}` const cmd = window.open(url) setTimeout(function() { - cmd.close(); - }, 100); + cmd.close() + }, 100) } else { - const url = `${editor}://file/${file}` + const url = `${IDE}://file/${file}` window.open(url) } } @@ -213,7 +223,9 @@ export function ClickToComponent({ editor = 'vscode' }) { <${FloatingPortal} key="click-to-component-portal"> ${html`<${ContextMenu} key="click-to-component-contextmenu" + IDE=${IDE} onClose=${onClose} + onChangeIDE=${onChangeIDE} />`} { - const { onClose } = props + const { IDE, onClose, onChangeIDE } = props const [target, setTarget] = React.useState( /** @type {HTMLElement | null} */ @@ -296,6 +296,20 @@ export const ContextMenu = React.forwardRef( height: 8px; transform: rotate(45deg); } + + [data-click-to-component-contextmenu-change-editor] { + text-align: right; + font-size: 11px; + border-top: 1px solid #ccc; + padding-top: 5px; + margin-top: 5px; + font-weight: 600; + } + + [data-click-to-component-contextmenu-change-editor] a { + text-decoration: underline; + margin-left: 10px; + } ${open && @@ -363,7 +377,12 @@ export const ContextMenu = React.forwardRef( ` })} - +
+ default editor is ${IDE} + change +
void onClose?: () => void } From d08f8f7d21390ec79a065a7e5a609a2c08733884 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Wed, 11 May 2022 10:52:52 +1100 Subject: [PATCH 16/18] Revert "fix(type): add intellij to export type Editor" This reverts commit 2522aff6f3c034dc637ad25e471cf4e6e5d869a5. --- packages/click-to-react-component/src/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/click-to-react-component/src/types.d.ts b/packages/click-to-react-component/src/types.d.ts index 39d52e5..2832d8a 100644 --- a/packages/click-to-react-component/src/types.d.ts +++ b/packages/click-to-react-component/src/types.d.ts @@ -1,6 +1,6 @@ export { ClickToComponent } from './src/ClickToComponent' -export type Editor = 'vscode' | 'vscode-insiders' | 'intellij' +export type Editor = 'vscode' | 'vscode-insiders' export type ClickToComponentProps = { editor?: Editor From 92416ba22fd6fe693210f8aacb58e1afc3441bc0 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Wed, 11 May 2022 11:04:07 +1100 Subject: [PATCH 17/18] Revert "fix(IDE): add link to change default editor" This reverts commit d9837db8ddd1c207cabfdc97e6eb3f9abf61c03a. --- packages/click-to-react-component/README.md | 16 +++++----- .../src/ClickToComponent.js | 32 ++++++------------- .../src/ContextMenu.js | 23 ++----------- .../click-to-react-component/src/types.d.ts | 2 -- 4 files changed, 20 insertions(+), 53 deletions(-) diff --git a/packages/click-to-react-component/README.md b/packages/click-to-react-component/README.md index 2490839..3499a1c 100644 --- a/packages/click-to-react-component/README.md +++ b/packages/click-to-react-component/README.md @@ -129,14 +129,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render( ### `editor` -By default, clicking will default `editor` to [`vscode`](https://code.visualstudio.com/). - -You can change default `editor` in the context menu Option+Right-click - -Possible values for the `editor` are [`vscode`] or [`vscode-insiders`] or [`intellij`] - -If you use [`intellij`], the IDE need to be active to open the file - +By default, clicking will deafult `editor` to [`vscode`](https://code.visualstudio.com/). If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/), you can set `editor` explicitly: @@ -145,6 +138,13 @@ If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/ + ``` +If, you use [`intellij`], you can set `editor` explicitly: + +```diff +- ++ +``` + ## Run Locally Clone the project diff --git a/packages/click-to-react-component/src/ClickToComponent.js b/packages/click-to-react-component/src/ClickToComponent.js index 590a231..bfa2741 100644 --- a/packages/click-to-react-component/src/ClickToComponent.js +++ b/packages/click-to-react-component/src/ClickToComponent.js @@ -21,8 +21,6 @@ export const State = /** @type {const} */ ({ * @param {Props} props */ export function ClickToComponent({ editor = 'vscode' }) { - const localStorageKey = 'clickToComponentEditorUsed' - const [IDE, setIDE] = React.useState(localStorage.getItem(localStorageKey) || editor) const [state, setState] = React.useState( /** @type {State[keyof State]} */ (State.IDLE) @@ -42,15 +40,13 @@ export function ClickToComponent({ editor = 'vscode' }) { ) { if (state === State.HOVER && target instanceof HTMLElement) { const source = getSourceForElement(target) - if (source) { - const path = getPathToSource(source) - event.preventDefault() - openFileInIDE(path) - setState(State.IDLE) - } + const path = getPathToSource(source) + event.preventDefault() + openFileInIDE(path) + setState(State.IDLE) } }, - [IDE, state, target] + [editor, state, target] ) const onClose = React.useCallback( @@ -60,24 +56,18 @@ export function ClickToComponent({ editor = 'vscode' }) { } setState(State.IDLE) }, - [IDE] + [editor] ) - const onChangeIDE = () => { - const value = prompt("What editor do you use ? vscode | vscode-insiders | intellij\n\ninfo: intellij need to be open before", IDE) - localStorage.setItem(localStorageKey, value) - setIDE(value) - } - const openFileInIDE = (file) => { - if (IDE === 'intellij') { + if (editor === 'intellij') { const url = `http://localhost:63342/api/file/${file}` const cmd = window.open(url) setTimeout(function() { - cmd.close() - }, 100) + cmd.close(); + }, 100); } else { - const url = `${IDE}://file/${file}` + const url = `${editor}://file/${file}` window.open(url) } } @@ -223,9 +213,7 @@ export function ClickToComponent({ editor = 'vscode' }) { <${FloatingPortal} key="click-to-component-portal"> ${html`<${ContextMenu} key="click-to-component-contextmenu" - IDE=${IDE} onClose=${onClose} - onChangeIDE=${onChangeIDE} />`} { - const { IDE, onClose, onChangeIDE } = props + const { onClose } = props const [target, setTarget] = React.useState( /** @type {HTMLElement | null} */ @@ -300,20 +300,6 @@ export const ContextMenu = React.forwardRef( height: 8px; transform: rotate(45deg); } - - [data-click-to-component-contextmenu-change-editor] { - text-align: right; - font-size: 11px; - border-top: 1px solid #ccc; - padding-top: 5px; - margin-top: 5px; - font-weight: 600; - } - - [data-click-to-component-contextmenu-change-editor] a { - text-decoration: underline; - margin-left: 10px; - } ${open && @@ -381,12 +367,7 @@ export const ContextMenu = React.forwardRef( ` })} -
- default editor is ${IDE} - change -
+
void onClose?: () => void } From 75ed249a3ae0da3eeb04fe1a9845c415318500b0 Mon Sep 17 00:00:00 2001 From: Alexandre BAY Date: Wed, 11 May 2022 11:06:19 +1100 Subject: [PATCH 18/18] fix(type): add intellij to export type Editor --- packages/click-to-react-component/src/types.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/click-to-react-component/src/types.d.ts b/packages/click-to-react-component/src/types.d.ts index d48a719..6f10ee7 100644 --- a/packages/click-to-react-component/src/types.d.ts +++ b/packages/click-to-react-component/src/types.d.ts @@ -1,6 +1,6 @@ export { ClickToComponent } from './src/ClickToComponent' -export type Editor = 'vscode' | 'vscode-insiders' +export type Editor = 'vscode' | 'vscode-insiders' | 'intellij' export type ClickToComponentProps = { editor?: Editor