ericclemmons / click-to-component

Option+Click React components in your browser to instantly open the source in VS Code
MIT License
1.82k stars 65 forks source link

Support for onOpenComponent callback #29

Closed frantic closed 10 months ago

frantic commented 2 years ago

This PR adds support for onOpenFile callback. When set, it will be called instead of opening the file with the default editor. This change will enable the support for the long tail of editors and will allow other products to build on top of click-to-component.

Usage

<ClickToComponent onOpenComponent={(source) => alert(source.fileName)} />

Fixes https://github.com/ericclemmons/click-to-component/issues/28

changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: 44a52e33d30923a3000b47850771ac767e10b4b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ------------------------ | ----- | | click-to-react-component | Minor | | remix-5961 | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

frantic commented 2 years ago

I've renamed onOpenFile to onOpenComponent and made the callback accept Source instead of path. The users who want an advanced control over what happens can provide their own implementation that formats it and calls external API (via window.open, postMessage, fetch, etc.)

frantic commented 2 years ago

@ericclemmons do you think we can move forward with this? Would you rather see a different approach?

zjffun commented 1 year ago

Great, as far as I know this method can support the following four situations: