Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getPathToSource configurable as a prop #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/click-to-react-component/src/ClickToComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { html } from 'htm/react'
import * as React from 'react'

import { ContextMenu } from './ContextMenu.js'
import { getPathToSource } from './getPathToSource.js'
import { getPathToSource as defaultGetPathToSource } from './getPathToSource.js'
import { getSourceForElement } from './getSourceForElement.js'

export const State = /** @type {const} */ ({
Expand All @@ -20,7 +20,7 @@ export const State = /** @type {const} */ ({
/**
* @param {Props} props
*/
export function ClickToComponent({ editor = 'vscode' }) {
export function ClickToComponent({ editor = 'vscode', getPathToSource = defaultGetPathToSource }) {
const [state, setState] = React.useState(
/** @type {State[keyof State]} */
(State.IDLE)
Expand Down Expand Up @@ -49,7 +49,7 @@ export function ClickToComponent({ editor = 'vscode' }) {
setState(State.IDLE)
}
},
[editor, state, target]
[editor, state, target, getPathToSource]
)

const onClose = React.useCallback(
Expand Down Expand Up @@ -205,6 +205,7 @@ export function ClickToComponent({ editor = 'vscode' }) {
<${FloatingPortal} key="click-to-component-portal">
${html`<${ContextMenu}
key="click-to-component-contextmenu"
getPathToSource=${getPathToSource}
onClose=${onClose}
/>`}
</${FloatingPortal}
Expand Down
3 changes: 1 addition & 2 deletions packages/click-to-react-component/src/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import * as React from 'react'
import mergeRefs from 'react-merge-refs'

import { getDisplayNameForInstance } from './getDisplayNameFromReactInstance.js'
import { getPathToSource } from './getPathToSource.js'
import { getPropsForInstance } from './getPropsForInstance.js'
import { getReactInstancesForElement } from './getReactInstancesForElement.js'
import { getSourceForInstance } from './getSourceForInstance.js'
Expand All @@ -35,7 +34,7 @@ export const ContextMenu = React.forwardRef(
props,
ref
) => {
const { onClose } = props
const { getPathToSource, onClose } = props

const [target, setTarget] = React.useState(
/** @type {HTMLElement | null} */
Expand Down
3 changes: 3 additions & 0 deletions packages/click-to-react-component/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Source as ReactReconcilerSource } from 'react-reconciler'

export { ClickToComponent } from './src/ClickToComponent'

export type Editor = 'vscode' | 'vscode-insiders'

export type ClickToComponentProps = {
editor?: Editor
getPathToSource?: (source: ReactReconcilerSource) => string
}

export type Coords = [MouseEvent['pageX'], MouseEvent['pageY']]
Expand Down