@difizen/ai-flow
Version:
Scalable, out-of-the-box, agent-oriented flow
88 lines • 4.74 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { ConditionForm } from "../../ConditionForm";
import { useFlowStore } from "../../../stores/flowStore";
import { NodeWrapper } from "../NodeWrapper/index";
import React from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var IfElseNode = function IfElseNode(props) {
var _data$config;
var data = props.data;
var setNode = useFlowStore(function (state) {
return state.setNode;
});
var nodeLinkMap = useFlowStore(function (state) {
return state.nodeLinkMap;
});
var upstreamNodes = nodeLinkMap[data.id] || [];
var options = upstreamNodes.map(function (n) {
var _node$data;
var node = n;
return {
label: node.data.name,
value: node.data.id,
children: ((_node$data = node.data) === null || _node$data === void 0 || (_node$data = _node$data.config) === null || _node$data === void 0 || (_node$data = _node$data.outputs) === null || _node$data === void 0 ? void 0 : _node$data.map(function (output) {
return {
label: output.name,
value: output.name
};
})) || []
};
});
return /*#__PURE__*/_jsx(NodeWrapper, {
nodeProps: props,
className: "w-[610px]",
rightHandlerConfig: [{
id: 'branch-1',
style: {
top: 110
}
}, {
id: 'branch-default',
style: {
bottom: 34,
top: 'auto'
}
}],
children: /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx("div", {
className: "flex items-center gap-2 bg-gray-100 p-3 rounded-md mb-2",
children: /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("div", {
className: "ml-1 mb-2 font-medium",
children: "\u5982\u679C"
}), /*#__PURE__*/_jsx(ConditionForm, {
refOptions: options,
value: (_data$config = data.config) === null || _data$config === void 0 || (_data$config = _data$config.inputs) === null || _data$config === void 0 || (_data$config = _data$config.branches) === null || _data$config === void 0 ? void 0 : _data$config[0],
onChange: function onChange(val) {
setNode(data.id, function (old) {
return _objectSpread(_objectSpread({}, old), {}, {
data: _objectSpread(_objectSpread({}, old.data), {}, {
config: _objectSpread(_objectSpread({}, old.data['config']), {}, {
inputs: _objectSpread(_objectSpread({}, old.data['config']['inputs']), {}, {
branches: [val]
})
})
})
});
});
}
})]
})
}), /*#__PURE__*/_jsx("div", {
className: "bg-gray-100 p-3 rounded-md",
children: /*#__PURE__*/_jsx("div", {
className: "ml-1 font-medium",
children: "\u5426\u5219"
})
})]
})
});
};
export default IfElseNode;