UNPKG

@xrenders/xflow

Version:

一款功能强大、易用灵活的流程编辑器框架,帮助你轻松构建复杂的工作流和流程产品

111 lines 5.65 kB
import "antd/es/space/style"; import _Space from "antd/es/space"; import classNames from 'classnames'; import React, { memo } from 'react'; import { shallow } from 'zustand/shallow'; import SourceHandle from '../../components/CustomNode/sourceHandle'; import TextEllipsis from '../../components/TextEllipsis'; import { useStore } from '../../hooks/useStore'; import { uuid } from '../../utils'; import "./index.css"; export default /*#__PURE__*/memo(function (props) { var _a, _b, _c, _d, _e; var data = props.data, position = props.position, isConnectable = props.isConnectable, selected = props.selected, isHovered = props.isHovered, _handleAddNode = props.handleAddNode, CustomNodeWidget = props.CustomNodeWidget, isSwitchBottom = props.isSwitchBottom, nodeSetting = props.nodeSetting, id = props.id; var switchExtra = nodeSetting.switchExtra; var _useStore = useStore(function (state) { return { nodes: state.nodes, edges: state.edges }; }, shallow), nodes = _useStore.nodes, edges = _useStore.edges; var renderTitle = function renderTitle(item, index) { var _a, _b, _c, _d; var defTitle = (item === null || item === void 0 ? void 0 : item.title) || "\u6761\u4EF6".concat(index); var title = (switchExtra === null || switchExtra === void 0 ? void 0 : switchExtra.titleKey) ? item[switchExtra === null || switchExtra === void 0 ? void 0 : switchExtra.titleKey] : defTitle; return /*#__PURE__*/React.createElement("div", { className: "item-header" }, /*#__PURE__*/React.createElement("div", { className: "item-title" }, title), /*#__PURE__*/React.createElement(SourceHandle, { position: position, isConnectable: ((_b = (_a = edges || []) === null || _a === void 0 ? void 0 : _a.filter(function (flow) { return (flow === null || flow === void 0 ? void 0 : flow.sourceHandle) === (item === null || item === void 0 ? void 0 : item._id); })) === null || _b === void 0 ? void 0 : _b.length) === 0, selected: selected, isHovered: isHovered, handleAddNode: function handleAddNode(data) { _handleAddNode(data, item === null || item === void 0 ? void 0 : item._id); }, id: item === null || item === void 0 ? void 0 : item._id, className: "item-handle", isConnected: ((_d = (_c = edges || []) === null || _c === void 0 ? void 0 : _c.filter(function (flow) { return (flow === null || flow === void 0 ? void 0 : flow.sourceHandle) === (item === null || item === void 0 ? void 0 : item._id); })) === null || _d === void 0 ? void 0 : _d.length) > 0 })); }; var renderContent = function renderContent(item, index) { var value = (switchExtra === null || switchExtra === void 0 ? void 0 : switchExtra.valueKey) ? item[switchExtra === null || switchExtra === void 0 ? void 0 : switchExtra.valueKey] : item === null || item === void 0 ? void 0 : item.value; return /*#__PURE__*/React.createElement("div", { className: "item-content" }, CustomNodeWidget ? (/*#__PURE__*/React.createElement(CustomNodeWidget, { data: item, index: index })) : (/*#__PURE__*/React.createElement("div", null, value && (/*#__PURE__*/React.createElement("div", { className: "item-content-in" }, /*#__PURE__*/React.createElement(TextEllipsis, { text: value, rows: 5, type: "paragraph" })))))); }; return /*#__PURE__*/React.createElement(_Space, { direction: isSwitchBottom ? 'horizontal' : 'vertical', className: classNames('node-switch-widget', { 'node-switch-widget-bottom': isSwitchBottom }), size: 5 }, (_a = (data === null || data === void 0 ? void 0 : data.list) || [{ _id: "id_".concat(uuid()) }]) === null || _a === void 0 ? void 0 : _a.map(function (item, index) { return /*#__PURE__*/React.createElement("div", { className: classNames('node-switch-widget-item', { 'node-switch-bottom-item': isSwitchBottom }), key: index }, isSwitchBottom ? (/*#__PURE__*/React.createElement(React.Fragment, null, renderContent(item, index), renderTitle(item, index))) : (/*#__PURE__*/React.createElement(React.Fragment, null, renderTitle(item, index), renderContent(item, index)))); }), !(switchExtra === null || switchExtra === void 0 ? void 0 : switchExtra.hideElse) && (/*#__PURE__*/React.createElement("div", { className: classNames('node-switch-widget-item', { 'node-switch-bottom-item': isSwitchBottom }) }, /*#__PURE__*/React.createElement("div", { className: "item-header" }, /*#__PURE__*/React.createElement("div", { className: "item-title" }, "\u9ED8\u8BA4"), /*#__PURE__*/React.createElement(SourceHandle, { position: position, isConnectable: ((_c = (_b = edges || []) === null || _b === void 0 ? void 0 : _b.filter(function (flow) { return (flow === null || flow === void 0 ? void 0 : flow.sourceHandle) === 'id_else' && (flow === null || flow === void 0 ? void 0 : flow.source) === id; })) === null || _c === void 0 ? void 0 : _c.length) === 0, selected: selected, isHovered: isHovered, handleAddNode: function handleAddNode(data) { _handleAddNode(data, 'id_else'); }, className: "item-handle", id: 'id_else', isConnected: ((_e = (_d = edges || []) === null || _d === void 0 ? void 0 : _d.filter(function (flow) { return (flow === null || flow === void 0 ? void 0 : flow.sourceHandle) === 'id_else' && (flow === null || flow === void 0 ? void 0 : flow.source) === id; })) === null || _e === void 0 ? void 0 : _e.length) > 0 }))))); });