| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 | 
							- import type { FC } from 'react'
 - import React from 'react'
 - import { useTranslation } from 'react-i18next'
 - import RemoveEffectVarConfirm from '../_base/components/remove-effect-var-confirm'
 - import useConfig from './use-config'
 - import type { CodeNodeType } from './types'
 - import { CodeLanguage } from './types'
 - import { extractFunctionParams, extractReturnType } from './code-parser'
 - import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
 - import OutputVarList from '@/app/components/workflow/nodes/_base/components/variable/output-var-list'
 - import AddButton from '@/app/components/base/button/add-button'
 - import Field from '@/app/components/workflow/nodes/_base/components/field'
 - import Split from '@/app/components/workflow/nodes/_base/components/split'
 - import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
 - import TypeSelector from '@/app/components/workflow/nodes/_base/components/selector'
 - import type { NodePanelProps } from '@/app/components/workflow/types'
 - import SyncButton from '@/app/components/base/button/sync-button'
 - const i18nPrefix = 'workflow.nodes.code'
 - 
 - const codeLanguages = [
 -   {
 -     label: 'Python3',
 -     value: CodeLanguage.python3,
 -   },
 -   {
 -     label: 'JavaScript',
 -     value: CodeLanguage.javascript,
 -   },
 - ]
 - const Panel: FC<NodePanelProps<CodeNodeType>> = ({
 -   id,
 -   data,
 - }) => {
 -   const { t } = useTranslation()
 - 
 -   const {
 -     readOnly,
 -     inputs,
 -     outputKeyOrders,
 -     handleCodeAndVarsChange,
 -     handleVarListChange,
 -     handleAddVariable,
 -     handleRemoveVariable,
 -     handleSyncFunctionSignature,
 -     handleCodeChange,
 -     handleCodeLanguageChange,
 -     handleVarsChange,
 -     handleAddOutputVariable,
 -     filterVar,
 -     isShowRemoveVarConfirm,
 -     hideRemoveVarConfirm,
 -     onRemoveVarConfirm,
 -   } = useConfig(id, data)
 - 
 -   const handleGeneratedCode = (value: string) => {
 -     const params = extractFunctionParams(value, inputs.code_language)
 -     const codeNewInput = params.map((p) => {
 -       return {
 -         variable: p,
 -         value_selector: [],
 -       }
 -     })
 -     const returnTypes = extractReturnType(value, inputs.code_language)
 -     handleCodeAndVarsChange(value, codeNewInput, returnTypes)
 -   }
 - 
 -   return (
 -     <div className='mt-2'>
 -       <div className='space-y-4 px-4 pb-4'>
 -         <Field
 -           title={t(`${i18nPrefix}.inputVars`)}
 -           operations={
 -             !readOnly ? (
 -               <div className="flex gap-2">
 -                 <SyncButton popupContent={t(`${i18nPrefix}.syncFunctionSignature`)} onClick={handleSyncFunctionSignature} />
 -                 <AddButton onClick={handleAddVariable} />
 -               </div>
 -             ) : undefined
 -           }
 -         >
 -           <VarList
 -             readonly={readOnly}
 -             nodeId={id}
 -             list={inputs.variables}
 -             onChange={handleVarListChange}
 -             filterVar={filterVar}
 -             isSupportFileVar={false}
 -           />
 -         </Field>
 -         <Split />
 -         <CodeEditor
 -           nodeId={id}
 -           isInNode
 -           readOnly={readOnly}
 -           title={
 -             <TypeSelector
 -               options={codeLanguages}
 -               value={inputs.code_language}
 -               onChange={handleCodeLanguageChange}
 -             />
 -           }
 -           language={inputs.code_language}
 -           value={inputs.code}
 -           onChange={handleCodeChange}
 -           onGenerated={handleGeneratedCode}
 -           showCodeGenerator={true}
 -         />
 -       </div>
 -       <Split />
 -       <div className='px-4 pb-2 pt-4'>
 -         <Field
 -           title={t(`${i18nPrefix}.outputVars`)}
 -           operations={
 -             <AddButton onClick={handleAddOutputVariable} />
 -           }
 -           required
 -         >
 -           <OutputVarList
 -             readonly={readOnly}
 -             outputs={inputs.outputs}
 -             outputKeyOrders={outputKeyOrders}
 -             onChange={handleVarsChange}
 -             onRemove={handleRemoveVariable}
 -           />
 -         </Field>
 -       </div>
 -       <RemoveEffectVarConfirm
 -         isShow={isShowRemoveVarConfirm}
 -         onCancel={hideRemoveVarConfirm}
 -         onConfirm={onRemoveVarConfirm}
 -       />
 -     </div >
 -   )
 - }
 - 
 - export default React.memo(Panel)
 
 
  |