mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-12 04:16:54 +08:00
feat: code transform node editor support insert var by add slash or left brace (#3946)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect } from 'react'
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import produce from 'immer'
|
||||
import useVarList from '../_base/hooks/use-var-list'
|
||||
import type { Var } from '../../types'
|
||||
import type { Var, Variable } from '../../types'
|
||||
import { VarType } from '../../types'
|
||||
import { useStore } from '../../store'
|
||||
import type { TemplateTransformNodeType } from './types'
|
||||
@@ -15,12 +15,25 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||
const defaultConfig = useStore(s => s.nodesDefaultConfigs)[payload.type]
|
||||
|
||||
const { inputs, setInputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
||||
const { handleVarListChange, handleAddVariable } = useVarList<TemplateTransformNodeType>({
|
||||
const { inputs, setInputs: doSetInputs } = useNodeCrud<TemplateTransformNodeType>(id, payload)
|
||||
const inputsRef = useRef(inputs)
|
||||
const setInputs = useCallback((newPayload: TemplateTransformNodeType) => {
|
||||
doSetInputs(newPayload)
|
||||
inputsRef.current = newPayload
|
||||
}, [doSetInputs])
|
||||
|
||||
const { handleVarListChange, handleAddVariable: handleAddEmptyVariable } = useVarList<TemplateTransformNodeType>({
|
||||
inputs,
|
||||
setInputs,
|
||||
})
|
||||
|
||||
const handleAddVariable = useCallback((payload: Variable) => {
|
||||
const newInputs = produce(inputsRef.current, (draft: any) => {
|
||||
draft.variables.push(payload)
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [setInputs])
|
||||
|
||||
useEffect(() => {
|
||||
if (inputs.template)
|
||||
return
|
||||
@@ -36,11 +49,11 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
||||
}, [defaultConfig])
|
||||
|
||||
const handleCodeChange = useCallback((template: string) => {
|
||||
const newInputs = produce(inputs, (draft: any) => {
|
||||
const newInputs = produce(inputsRef.current, (draft: any) => {
|
||||
draft.template = template
|
||||
})
|
||||
setInputs(newInputs)
|
||||
}, [inputs, setInputs])
|
||||
}, [setInputs])
|
||||
|
||||
// single run
|
||||
const {
|
||||
@@ -82,6 +95,7 @@ const useConfig = (id: string, payload: TemplateTransformNodeType) => {
|
||||
inputs,
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
handleAddEmptyVariable,
|
||||
handleCodeChange,
|
||||
filterVar,
|
||||
// single run
|
||||
|
||||
Reference in New Issue
Block a user