'use client'; import React, { useEffect, useMemo, useState } from 'react' import Agent from './NodeType/Agent'; import Form from './NodeType/Form'; import Unsupport from './NodeType/Unsupport'; import * as R from 'ramda' import { curNodeAtom, curStepAtom, arrowStateAtom, cardInstantAtomFamily, cardInstantAtomsAtom, instantDataAtom, stepsNodesAtom } from '../store'; import { useAtom, useAtomValue } from 'jotai'; import { exportFlowToDocx } from '../export'; import PreviewModal from './PreviewModal'; const NodeRender = () => { const [curStep, setCurStep] = useAtom(curStepAtom) const node = useAtomValue(curNodeAtom) const arrowState = useAtomValue(arrowStateAtom) const Comp = useMemo(() => { return R.cond([ [R.propEq('form_card', 'type'), R.always(Form)], [R.propEq('UserTask', 'type'), R.always(Agent)], [R.T, R.always(Unsupport)], ])(node) }, [node, node?.id]) const nodeName = useMemo(() => { return R.cond([ [R.propEq('form_card', 'type'), R.always('表单填写')], [R.propEq('UserTask', 'type'), R.pathOr('Unknown Agent', ['properties', 'item', 'assistantName'])], [R.T, R.always('Unknown')], ])(node) }, [node, node?.id]) // 动态注册当前节点的Atom,并将其放进一个atom集合的atom,方便后续格式化所有节点实例 const cardInstantAtom = cardInstantAtomFamily(node) const [, dispatchCardInstantAtoms] = useAtom(cardInstantAtomsAtom) useEffect(() => { if (node?.id) { dispatchCardInstantAtoms({ [node.id]: cardInstantAtom }) } }, [cardInstantAtom]) const onNextStep = () => { setCurStep(prev => prev + 1) } const onPrevStep = () => { setCurStep(prev => prev - 1) } const [isPreviewModalOpen, setPreviewModalOpen] = useState(false) const onPreview = () => { setPreviewModalOpen(true) } return (

{curStep + 1}: {nodeName}

{arrowState.prev && } {arrowState.next ? : }
setPreviewModalOpen(false)} />
) } export default React.memo(React.forwardRef(NodeRender))