/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import React from 'react'; /** * 动态流编辑器(纯组件) * - 使用 Tabs 分隔多个 Flow * - 每个 Flow 下方显示:事件名输入框(编辑 flow.on)+ Steps 折叠面板 * - 每个 Step 面板内部:一个 JSON 文本框编辑 defaultParams * - 支持新增/删除 Flow 与 Step;所有改动直接作用于传入的响应式 value */ // export const DynamicFlowsEditor = observer( // (props: { value: FlowDefinitionOptions[]; model: FlowModel }) => { // const { value, model } = props; // const eventList = (model.constructor as any).meta?.eventList || []; // // 活动 tab // const [activeKey, setActiveKey] = React.useState(() => { // return value?.[0]?.key || 'flow-1'; // }); // // 工具:生成唯一 flow key(使用 uid(),如冲突则重试) // const getNextFlowKey = React.useCallback(() => { // const exists = (k: string) => value.some((f) => f.key === k); // let key = `flow-${uid()}`; // let guard = 10; // while (exists(key) && guard--) { // key = `flow-${uid()}`; // } // return key; // }, [value]); // const getNextStepKey = React.useCallback((flow: FlowDefinition) => { // const keys = Object.keys(flow.steps || {}); // let idx = keys.length + 1; // let k = `step-${idx}`; // while (keys.includes(k)) { // idx += 1; // k = `step-${idx}`; // } // return k; // }, []); // const addFlowWithTitle = React.useCallback( // (title?: string) => { // const key = getNextFlowKey(); // value.push({ key, title: title?.trim() || `Flow ${value.length + 1}`, steps: {} }); // setActiveKey(key); // }, // [getNextFlowKey, setActiveKey, value], // ); // const promptAddFlow = React.useCallback(() => { // let tempTitle = ''; // const modal = Modal.confirm({ // title: 'Flow title', // icon: null, // content: ( // (tempTitle = e.target.value)} // onPressEnter={() => { // modal.update({ okButtonProps: { loading: true } }); // // 模拟点击 OK // modal.destroy(); // addFlowWithTitle(tempTitle); // }} // /> // ), // okText: 'OK', // cancelText: 'Cancel', // onOk: () => addFlowWithTitle(tempTitle), // }); // }, [addFlowWithTitle]); // const updateFlowOn = React.useCallback((flow: FlowDefinition, onStr: string) => { // // 简化为字符串形式 // (flow as any).on = onStr || undefined; // }, []); // const addStep = React.useCallback( // (flow: FlowDefinition) => { // const key = getNextStepKey(flow); // // flow.steps = flow.steps || {}; // (flow.steps as any)[key] = { defaultParams: {} } as any; // }, // [getNextStepKey], // ); // const removeStep = React.useCallback((flow: FlowDefinition, stepKey: string) => { // if (!flow.steps) return; // delete (flow.steps as any)[stepKey]; // }, []); // const StepEditor: React.FC<{ flow: FlowDefinition; stepKey: string; form: FormInstance }> = ({ // flow, // stepKey, // form, // }) => { // return ( // <> // // { // const v = e?.target?.value; // (flow.steps as any)[stepKey] = (flow.steps as any)[stepKey] || ({} as any); // (flow.steps as any)[stepKey].defaultParams = (flow.steps as any)[stepKey].defaultParams || {}; // (flow.steps as any)[stepKey].defaultParams.targetUid = v; // }} // /> // // // e.stopPropagation()} // onChange={(e: any) => { // (flow.steps as any)[sk] = (flow.steps as any)[sk] || ({} as any); // (flow.steps as any)[sk].title = e.target.value; // }} // /> // // ); // const extraEl = ( // // ); // return ( // // // // ); // }); // return ( //
{ // if (Object.hasOwn(changed, 'eventName')) { // updateFlowOn(flow, all.eventName); // } // }} // > // //