UNPKG

@xrenders/xflow

Version:

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

71 lines 3.87 kB
import { Position } from '@xyflow/react'; import classNames from 'classnames'; import React, { memo, useContext } from 'react'; import NodeContainer from '../../components/NodeContainer'; import { ConfigContext } from '../../models/context'; import SwitchBuildInNodeWidget from './SwitchBuildInNodeWidget'; import { getColorfulModeBackground } from '../../utils'; import "./index.css"; export default /*#__PURE__*/memo(function (props) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; var onClick = props.onClick, type = props.type, data = props.data, position = props.position, isConnectable = props.isConnectable, selected = props.selected, isHovered = props.isHovered, handleAddNode = props.handleAddNode, id = props.id; var _useContext = useContext(ConfigContext), settingMap = _useContext.settingMap, widgets = _useContext.widgets, iconFontUrl = _useContext.iconFontUrl, globalConfig = _useContext.globalConfig, openColorfulMode = _useContext.openColorfulMode; var nodeSetting = settingMap[type] || {}; var NodeWidget = widgets[nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.nodeWidget] || undefined; var nodeDescription = (nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.description) || ''; var hideDesc = (_d = (_b = (_a = nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.nodePanel) === null || _a === void 0 ? void 0 : _a.hideDesc) !== null && _b !== void 0 ? _b : (_c = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.nodePanel) === null || _c === void 0 ? void 0 : _c.hideDesc) !== null && _d !== void 0 ? _d : false; var hideTitleTips = (_f = (_e = globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.nodeView) === null || _e === void 0 ? void 0 : _e.hideTitleTips) !== null && _f !== void 0 ? _f : false; var isSwitchBottom = position === Position.Bottom; var SVGWidget = widgets[nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.iconSvg]; // 自定义面板配置组件 return /*#__PURE__*/React.createElement(NodeContainer, { className: classNames('custom-node-code', { 'switch-node-code-bottom': isSwitchBottom }), title: (data === null || data === void 0 ? void 0 : data.title) || (nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.title) || 'Switch', icon: { type: ((_g = nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.icon) === null || _g === void 0 ? void 0 : _g.type) || 'icon-switch', style: { fontSize: 14, color: '#fff' }, bgColor: ((_h = nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.icon) === null || _h === void 0 ? void 0 : _h.bgColor) || '#06AED4' }, onClick: onClick, hideDesc: hideDesc, desc: data === null || data === void 0 ? void 0 : data.desc, iconFontUrl: iconFontUrl, NodeWidget: /*#__PURE__*/React.createElement(SwitchBuildInNodeWidget, { data: data, position: position, isConnectable: isConnectable, selected: selected, isHovered: isHovered, handleAddNode: handleAddNode, CustomNodeWidget: NodeWidget, isSwitchBottom: isSwitchBottom, nodeSetting: nodeSetting, id: id }), description: nodeDescription, iconSvg: SVGWidget ? /*#__PURE__*/React.createElement(SVGWidget, { setting: nodeSetting }) : false, hideTitleTips: hideTitleTips, isSwitchBottom: isSwitchBottom, nodeSettingTitle: (nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.title) || 'Switch', style: Object.assign({}, getColorfulModeBackground((_j = nodeSetting === null || nodeSetting === void 0 ? void 0 : nodeSetting.icon) === null || _j === void 0 ? void 0 : _j.bgColor, openColorfulMode)) }); });