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

Switch Event Handlers 2.0 #6469

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 21 additions & 21 deletions editor/src/components/canvas/design-panel-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const RightPane = React.memo<ResizableRightPaneProps>((props) => {
)
const dispatch = useDispatch()

const onClickTab = React.useCallback(
const onMouseDownTab = React.useCallback(
(menuTab: RightMenuTab) => {
const actions: Array<EditorAction> = [EditorActions.setRightMenuTab(menuTab)]
if (isCommentMode(editorModeRef.current) && menuTab !== RightMenuTab.Comments) {
Expand All @@ -147,25 +147,25 @@ export const RightPane = React.memo<ResizableRightPaneProps>((props) => {
[dispatch, editorModeRef],
)

const onClickInsertTab = React.useCallback(() => {
onClickTab(RightMenuTab.Insert)
}, [onClickTab])
const onMouseDownInsertTab = React.useCallback(() => {
onMouseDownTab(RightMenuTab.Insert)
}, [onMouseDownTab])

const onClickCommentsTab = React.useCallback(() => {
onClickTab(RightMenuTab.Comments)
}, [onClickTab])
const onMouseDownCommentsTab = React.useCallback(() => {
onMouseDownTab(RightMenuTab.Comments)
}, [onMouseDownTab])

const onClickInspectorTab = React.useCallback(() => {
onClickTab(RightMenuTab.Inspector)
}, [onClickTab])
const onMouseDownInspectorTab = React.useCallback(() => {
onMouseDownTab(RightMenuTab.Inspector)
}, [onMouseDownTab])

const onClickSettingsTab = React.useCallback(() => {
onClickTab(RightMenuTab.Settings)
}, [onClickTab])
const onMouseDownSettingsTab = React.useCallback(() => {
onMouseDownTab(RightMenuTab.Settings)
}, [onMouseDownTab])

const onClickRollYourOwnTab = React.useCallback(() => {
onClickTab(RightMenuTab.RollYourOwn)
}, [onClickTab])
const onMouseDownRollYourOwnTab = React.useCallback(() => {
onMouseDownTab(RightMenuTab.RollYourOwn)
}, [onMouseDownTab])

const canComment = useCanComment()

Expand Down Expand Up @@ -206,7 +206,7 @@ export const RightPane = React.memo<ResizableRightPaneProps>((props) => {
<MenuTab
label={'Inspector'}
selected={selectedTab === RightMenuTab.Inspector}
onClick={onClickInspectorTab}
onMouseDown={onMouseDownInspectorTab}
/>
{when(
allowedToEdit,
Expand All @@ -216,7 +216,7 @@ export const RightPane = React.memo<ResizableRightPaneProps>((props) => {
<MenuTab
label={'Insert'}
selected={selectedTab === RightMenuTab.Insert}
onClick={onClickInsertTab}
onMouseDown={onMouseDownInsertTab}
/>,
)}
</>,
Expand All @@ -227,20 +227,20 @@ export const RightPane = React.memo<ResizableRightPaneProps>((props) => {
testId='comments-tab'
label={'Comments'}
selected={selectedTab === RightMenuTab.Comments}
onClick={onClickCommentsTab}
onMouseDown={onMouseDownCommentsTab}
/>,
)}
<MenuTab
label={'Settings'}
selected={selectedTab === RightMenuTab.Settings}
onClick={onClickSettingsTab}
onMouseDown={onMouseDownSettingsTab}
/>
{when(
isFeatureEnabled('Roll Your Own'),
<MenuTab
label={'RYO'}
selected={selectedTab === RightMenuTab.RollYourOwn}
onClick={onClickRollYourOwnTab}
onMouseDown={onMouseDownRollYourOwnTab}
/>,
)}
</FlexRow>
Expand Down
12 changes: 11 additions & 1 deletion editor/src/components/context-menu-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,18 @@ export const ContextMenu = <T,>({ dispatch, getData, id, items }: ContextMenuPro
[getData, dispatch, isDisabled, isHidden],
)

const onMouseDown = React.useCallback((event: React.MouseEvent<HTMLDivElement>) => {
event.stopPropagation()
}, [])

return (
<Menu key={id} id={id} animation={false} onVisibilityChange={onVisibilityChange}>
<Menu
key={id}
id={id}
animation={false}
onVisibilityChange={onVisibilityChange}
onMouseDown={onMouseDown}
>
{splitItems.map((item, index) => {
if (item?.type === 'submenu') {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,12 @@ describe('inspector tests with real metadata', () => {

await act(async () => {
await screen.findByTestId('section-header-Advanced')
fireEvent.click(screen.getByTestId('section-header-Advanced'))
fireEvent.mouseDown(screen.getByTestId('section-header-Advanced'))
})

await act(async () => {
await screen.findByTestId('target-selector-style')
fireEvent.click(screen.getByTestId('target-selector'))
fireEvent.mouseDown(screen.getByTestId('target-selector'))
})
await act(async () => {
await screen.findByTestId('target-list-item-css')
Expand Down Expand Up @@ -1586,12 +1586,12 @@ describe('inspector tests with real metadata', () => {

await act(async () => {
await screen.findByTestId('section-header-Advanced')
fireEvent.click(screen.getByTestId('section-header-Advanced'))
fireEvent.mouseDown(screen.getByTestId('section-header-Advanced'))
})

await act(async () => {
await screen.findByTestId('target-selector-style')
fireEvent.click(screen.getByTestId('target-selector'))
fireEvent.mouseDown(screen.getByTestId('target-selector'))
})
await act(async () => {
await screen.findByTestId('target-list-item-css')
Expand Down
2 changes: 1 addition & 1 deletion editor/src/components/inspector/section-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function InspectorSectionHeader({
padding: 8,
cursor: 'pointer',
}}
onClick={toggle}
onMouseDown={toggle}
data-testid={`section-header-${title}`}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ interface ObjectIndicatorProps {
const ObjectIndicator = (props: ObjectIndicatorProps) => {
return (
<div
onClick={props.toggle}
onMouseDown={props.toggle}
style={{
border: `1px solid ${colorTheme.bg3.value}`,
paddingLeft: 2,
Expand Down Expand Up @@ -1579,7 +1579,7 @@ export const ComponentSectionInner = React.memo((props: ComponentSectionProps) =
<span onClick={openInstanceFile}>Component</span>
)}
</FlexRow>
<SquareButton highlight onClick={toggleSection}>
<SquareButton highlight onMouseDown={toggleSection}>
<ExpandableIndicator
testId='component-section-expand'
visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ const TargetListHeader = React.memo((props: TargetListHeaderProps) => {
Target
</H1>
<SectionActionSheet className='actionsheet'>
<SquareButton highlight disabled={isAdding} onClick={startAdding}>
<SquareButton highlight disabled={isAdding} onMouseDown={startAdding}>
<Icn category='semantic' type='cross' width={12} height={12} />
</SquareButton>
<SquareButton highlight onClick={togglePathPanel}>
<SquareButton highlight onMouseDown={togglePathPanel}>
<ExpandableIndicator
testId='target-selector'
visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ const MapListSourceCartoucheInner = React.memo(
const { popupIsOpen, DataPickerComponent, setReferenceElement, openPopup } =
useDataPickerButton(variableNamesInScope, onPickMappedElement, pathToMappedExpression, target)

const onClick = React.useCallback(() => {
if (openOn === 'single-click') {
openPopup()
}
}, [openOn, openPopup])
const onClick = React.useCallback(
(e: React.MouseEvent) => {
seanparsons marked this conversation as resolved.
Show resolved Hide resolved
if (openOn === 'single-click') {
openPopup()
}
},
[openOn, openPopup],
)

const onDoubleClick = React.useCallback(() => {
if (openOn === 'double-click') {
Expand Down
34 changes: 17 additions & 17 deletions editor/src/components/navigator/left-pane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const LeftPaneComponent = React.memo<LeftPaneComponentProps>((props) => {

const dispatch = useDispatch()

const onClickTab = React.useCallback(
const onMouseDownTab = React.useCallback(
(menuTab: LeftMenuTab) => {
let actions: Array<EditorAction> = []
actions.push(setLeftMenuTab(menuTab))
Expand All @@ -57,21 +57,21 @@ export const LeftPaneComponent = React.memo<LeftPaneComponentProps>((props) => {
[dispatch],
)

const onClickPagesTab = React.useCallback(() => {
onClickTab(LeftMenuTab.Pages)
}, [onClickTab])
const onMouseDownPagesTab = React.useCallback(() => {
onMouseDownTab(LeftMenuTab.Pages)
}, [onMouseDownTab])

const onClickProjectTab = React.useCallback(() => {
onClickTab(LeftMenuTab.Project)
}, [onClickTab])
const onMouseDownProjectTab = React.useCallback(() => {
onMouseDownTab(LeftMenuTab.Project)
}, [onMouseDownTab])

const onClickNavigatorTab = React.useCallback(() => {
onClickTab(LeftMenuTab.Navigator)
}, [onClickTab])
const onMouseDownNavigatorTab = React.useCallback(() => {
onMouseDownTab(LeftMenuTab.Navigator)
}, [onMouseDownTab])

const onClickGithubTab = React.useCallback(() => {
onClickTab(LeftMenuTab.Github)
}, [onClickTab])
const onMouseDownGithubTab = React.useCallback(() => {
onMouseDownTab(LeftMenuTab.Github)
}, [onMouseDownTab])

const isMyProject = useIsMyProject()

Expand Down Expand Up @@ -126,23 +126,23 @@ export const LeftPaneComponent = React.memo<LeftPaneComponentProps>((props) => {
<MenuTab
label={'Pages'}
selected={selectedTab === LeftMenuTab.Pages}
onClick={onClickPagesTab}
onMouseDown={onMouseDownPagesTab}
/>,
)}
<MenuTab
label={'Navigator'}
selected={selectedTab === LeftMenuTab.Navigator}
onClick={onClickNavigatorTab}
onMouseDown={onMouseDownNavigatorTab}
/>
<MenuTab
label={'Project'}
selected={selectedTab === LeftMenuTab.Project}
onClick={onClickProjectTab}
onMouseDown={onMouseDownProjectTab}
/>
<MenuTab
label={'Github'}
selected={selectedTab === LeftMenuTab.Github}
onClick={onClickGithubTab}
onMouseDown={onMouseDownGithubTab}
/>
</FlexRow>,
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LayoutIcon } from './layout-icon'
import { DataReferenceCartoucheControl } from '../../inspector/sections/component-section/data-reference-cartouche'
import {
NavigatorRowClickableWrapper,
useGetNavigatorClickActions,
useGetNavigatorMouseDownActions,
} from './navigator-item-clickable-wrapper'
import type { ThemeObject } from '../../../uuiui/styles/theme/theme-helpers'
import { useNavigatorSelectionBoundsForEntry } from './use-navigator-selection-bounds-for-entry'
Expand Down Expand Up @@ -341,18 +341,18 @@ const CondensedEntryItemContent = React.memo(
])
}, [props.entry, dispatch, highlightedViews])

const getClickActions = useGetNavigatorClickActions(
const getMouseDownActions = useGetNavigatorMouseDownActions(
props.entry.elementPath,
props.selected,
condensedNavigatorRow([props.entry], 'leaf', props.indentation),
)

const onClick = React.useCallback(
const onMouseDown = React.useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
dispatch(getClickActions(e))
dispatch(getMouseDownActions(e))
},
[dispatch, getClickActions],
[dispatch, getMouseDownActions],
)

return (
Expand All @@ -374,7 +374,7 @@ const CondensedEntryItemContent = React.memo(
}}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onClick={onClick}
onMouseDown={onMouseDown}
>
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,30 @@ export const NavigatorRowClickableWrapper = React.memo(
return selectedViews.current.some((view) => EP.pathsEqual(targetPath, view))
}, [selectedViews, targetPath])

const getActions = useGetNavigatorClickActions(targetPath, selected, props.row)
const getMouseDownActions = useGetNavigatorMouseDownActions(targetPath, selected, props.row)

const onClick = React.useCallback(
const onMouseDown = React.useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
e.preventDefault()

const actions = getActions(e)
const actions = getMouseDownActions(e)
dispatch(actions)
},
[dispatch, getActions],
[dispatch, getMouseDownActions],
)

return (
<div style={{ display: 'flex', alignItems: 'center', flex: 1 }} onClick={onClick}>
<div style={{ display: 'flex', alignItems: 'center', flex: 1 }} onMouseDown={onMouseDown}>
{props.children}
</div>
)
},
)
NavigatorRowClickableWrapper.displayName = 'NavigatorRowClickableWrapper'

export function useGetNavigatorClickActions(
export function useGetNavigatorMouseDownActions(
targetPath: ElementPath,
selected: boolean,
row: NavigatorRow,
) {
): (event: React.MouseEvent) => Array<EditorAction> {
const navigatorTargets = useRefEditorState(navigatorTargetsSelector)
const selectedViews = useRefEditorState((store) => store.editor.selectedViews)
const collapsedViews = useRefEditorState((store) => store.editor.navigator.collapsedViews)
Expand Down
Loading
Loading