Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.8 KB
Raw Blame
import type { FC } from 'react'
import { cn } from '@langgenius/dify-ui/cn'
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
import { useEffect } from 'react'
import { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
import { CurrentBlockNode, DELETE_CURRENT_BLOCK_COMMAND } from '.'
import { useSelectOrDelete } from '../../hooks'

type CurrentBlockComponentProps = {
  nodeKey: string
  generatorType: GeneratorType
}

const CurrentBlockComponent: FC<CurrentBlockComponentProps> = ({ nodeKey, generatorType }) => {
  const [editor] = useLexicalComposerContext()
  const [ref, isSelected] = useSelectOrDelete(nodeKey, DELETE_CURRENT_BLOCK_COMMAND)

  const iconClassName =
    generatorType === GeneratorType.prompt
      ? 'i-custom-vender-line-general-magic-edit'
      : 'i-custom-vender-line-general-code-assistant'
  useEffect(() => {
    if (!editor.hasNodes([CurrentBlockNode]))
      throw new Error('WorkflowVariableBlockPlugin: WorkflowVariableBlock not registered on editor')
  }, [editor])

  return (
    <div
      className={cn(
        'group/wrap relative mx-0.5 flex h-4.5 items-center rounded-[5px] border pr-0.75 pl-0.5 text-util-colors-violet-violet-600 select-none hover:border-state-accent-solid hover:bg-state-accent-hover',
        isSelected
          ? 'border-state-accent-solid bg-state-accent-hover'
          : 'border-components-panel-border-subtle bg-components-badge-white-to-dark',
      )}
      onClick={(e) => {
        e.stopPropagation()
      }}
      ref={ref}
    >
      <span aria-hidden className={cn(iconClassName, 'mr-0.5 size-3.5')} />
      <div className="text-xs font-medium">
        {generatorType === GeneratorType.prompt ? 'current_prompt' : 'current_code'}
      </div>
    </div>
  )
}

export default CurrentBlockComponent