"add block" shortcut update
This commit is contained in:
parent
5408e923e3
commit
18b61591b8
@ -239,8 +239,8 @@ const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
handleSelectionDrag,
|
handleSelectionDrag,
|
||||||
} = useSelectionInteractions()
|
} = useSelectionInteractions()
|
||||||
const {
|
const {
|
||||||
handlePaneContextMenu,
|
handlePanelContextMenu,
|
||||||
handlePaneContextmenuCancel,
|
handlePanelContextmenuCancel,
|
||||||
} = usePanelInteractions()
|
} = usePanelInteractions()
|
||||||
const {
|
const {
|
||||||
isValidConnection,
|
isValidConnection,
|
||||||
@ -304,7 +304,7 @@ const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
<UpdateDSLModal
|
<UpdateDSLModal
|
||||||
onCancel={() => setShowImportDSLModal(false)}
|
onCancel={() => setShowImportDSLModal(false)}
|
||||||
onBackup={exportCheck}
|
onBackup={exportCheck}
|
||||||
onImport={handlePaneContextmenuCancel}
|
onImport={handlePanelContextmenuCancel}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
onSelectionStart={handleSelectionStart}
|
onSelectionStart={handleSelectionStart}
|
||||||
onSelectionChange={handleSelectionChange}
|
onSelectionChange={handleSelectionChange}
|
||||||
onSelectionDrag={handleSelectionDrag}
|
onSelectionDrag={handleSelectionDrag}
|
||||||
onPaneContextMenu={handlePaneContextMenu}
|
onPaneContextMenu={handlePanelContextMenu}
|
||||||
connectionLineComponent={CustomConnectionLine}
|
connectionLineComponent={CustomConnectionLine}
|
||||||
connectionLineContainerStyle={{ zIndex: ITERATION_CHILDREN_Z_INDEX }}
|
connectionLineContainerStyle={{ zIndex: ITERATION_CHILDREN_Z_INDEX }}
|
||||||
defaultViewport={viewport}
|
defaultViewport={viewport}
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
import {
|
import React, { memo, useCallback, useEffect, useState } from 'react'
|
||||||
memo,
|
|
||||||
useCallback,
|
|
||||||
} from 'react'
|
|
||||||
import { RiAddCircleFill } from '@remixicon/react'
|
import { RiAddCircleFill } from '@remixicon/react'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { OffsetOptions } from '@floating-ui/react'
|
import type { OffsetOptions } from '@floating-ui/react'
|
||||||
import {
|
import { generateNewNode } from '../utils'
|
||||||
generateNewNode,
|
|
||||||
} from '../utils'
|
|
||||||
import {
|
import {
|
||||||
useAvailableBlocks,
|
useAvailableBlocks,
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
@ -19,20 +14,19 @@ import { useStore, useWorkflowStore } from '../store'
|
|||||||
import TipPopup from './tip-popup'
|
import TipPopup from './tip-popup'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import BlockSelector from '@/app/components/workflow/block-selector'
|
import BlockSelector from '@/app/components/workflow/block-selector'
|
||||||
import type {
|
import type { OnSelectBlock } from '@/app/components/workflow/types'
|
||||||
OnSelectBlock,
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
} from '@/app/components/workflow/types'
|
|
||||||
import {
|
|
||||||
BlockEnum,
|
|
||||||
} from '@/app/components/workflow/types'
|
|
||||||
|
|
||||||
type AddBlockProps = {
|
type AddBlockProps = {
|
||||||
renderTrigger?: (open: boolean) => React.ReactNode
|
renderTrigger?: (open: boolean) => React.ReactNode
|
||||||
offset?: OffsetOptions
|
offset?: OffsetOptions
|
||||||
|
useShortcut?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddBlock = ({
|
const AddBlock = ({
|
||||||
renderTrigger,
|
renderTrigger,
|
||||||
offset,
|
offset,
|
||||||
|
useShortcut = false,
|
||||||
}: AddBlockProps) => {
|
}: AddBlockProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const store = useStoreApi()
|
const store = useStoreApi()
|
||||||
@ -44,16 +38,24 @@ const AddBlock = ({
|
|||||||
const showAddBlock = useStore(state => state.showAddBlock)
|
const showAddBlock = useStore(state => state.showAddBlock)
|
||||||
const setShowAddBlock = useStore(state => state.setShowAddBlock)
|
const setShowAddBlock = useStore(state => state.setShowAddBlock)
|
||||||
|
|
||||||
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (useShortcut && showAddBlock)
|
||||||
|
setIsOpen(true)
|
||||||
|
}, [useShortcut, showAddBlock])
|
||||||
|
|
||||||
const handleOpenChange = useCallback((open: boolean) => {
|
const handleOpenChange = useCallback((open: boolean) => {
|
||||||
|
setIsOpen(open)
|
||||||
|
if (useShortcut)
|
||||||
setShowAddBlock(open)
|
setShowAddBlock(open)
|
||||||
|
|
||||||
if (!open)
|
if (!open)
|
||||||
handlePanelContextmenuCancel()
|
handlePanelContextmenuCancel()
|
||||||
}, [setShowAddBlock, handlePanelContextmenuCancel])
|
}, [useShortcut, setShowAddBlock, handlePanelContextmenuCancel])
|
||||||
|
|
||||||
const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => {
|
const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => {
|
||||||
const {
|
const { getNodes } = store.getState()
|
||||||
getNodes,
|
|
||||||
} = store.getState()
|
|
||||||
const nodes = getNodes()
|
const nodes = getNodes()
|
||||||
const nodesWithSameType = nodes.filter(node => node.data.type === type)
|
const nodesWithSameType = nodes.filter(node => node.data.type === type)
|
||||||
const newNode = generateNewNode({
|
const newNode = generateNewNode({
|
||||||
@ -68,16 +70,12 @@ const AddBlock = ({
|
|||||||
y: 0,
|
y: 0,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
workflowStore.setState({
|
workflowStore.setState({ candidateNode: newNode })
|
||||||
candidateNode: newNode,
|
|
||||||
})
|
|
||||||
}, [store, workflowStore, t])
|
}, [store, workflowStore, t])
|
||||||
|
|
||||||
const renderTriggerElement = useCallback((open: boolean) => {
|
const renderTriggerElement = useCallback((open: boolean) => {
|
||||||
return (
|
return (
|
||||||
<TipPopup
|
<TipPopup title={t('workflow.common.addBlock')}>
|
||||||
title={t('workflow.common.addBlock')}
|
|
||||||
>
|
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
'flex items-center justify-center w-8 h-8 rounded-lg hover:bg-black/5 hover:text-gray-700 cursor-pointer',
|
'flex items-center justify-center w-8 h-8 rounded-lg hover:bg-black/5 hover:text-gray-700 cursor-pointer',
|
||||||
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
`${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
|
||||||
@ -91,7 +89,7 @@ const AddBlock = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<BlockSelector
|
<BlockSelector
|
||||||
open={showAddBlock}
|
open={isOpen}
|
||||||
onOpenChange={handleOpenChange}
|
onOpenChange={handleOpenChange}
|
||||||
disabled={nodesReadOnly}
|
disabled={nodesReadOnly}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
|
@ -44,7 +44,9 @@ const Control = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center p-0.5 rounded-lg border-[0.5px] border-gray-100 bg-white shadow-lg text-gray-500'>
|
<div className='flex items-center p-0.5 rounded-lg border-[0.5px] border-gray-100 bg-white shadow-lg text-gray-500'>
|
||||||
<AddBlock />
|
<AddBlock
|
||||||
|
useShortcut={true}
|
||||||
|
/>
|
||||||
<TipPopup title={t('workflow.nodes.note.addNote')}>
|
<TipPopup title={t('workflow.nodes.note.addNote')}>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
|
@ -68,6 +68,7 @@ const PanelContextmenu = () => {
|
|||||||
mainAxis: -36,
|
mainAxis: -36,
|
||||||
crossAxis: -4,
|
crossAxis: -4,
|
||||||
}}
|
}}
|
||||||
|
useShortcut={false}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50'
|
className='flex items-center justify-between px-3 h-8 text-sm text-gray-700 rounded-lg cursor-pointer hover:bg-gray-50'
|
||||||
|
Loading…
Reference in New Issue
Block a user