@rxflow/base
Version:
BaseFlow - 核心 Flow 组件库
72 lines (69 loc) • 2.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Legend = void 0;
require("./index.less");
var _react = require("@xyflow/react");
var _antd = require("antd");
var _react2 = _interopRequireWildcard(require("react"));
var _hooks = require("../../hooks");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/*
* @author: yanxianliang
* @date: 2025-06-03 19:33
* @desc: 图例标准组件。按照节点类型进行分类展示。
*
* 遍历当前的nodes 列表,根据类型定义解析出图例列表。
*
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
*/
const Legend = ({
showLegend
}) => {
const nodes = (0, _react.useNodes)();
const showAll = typeof showLegend === "boolean" ? true : showLegend?.showAll ?? true; // 默认值为 true
// 节点定义列表
const nodeTypeList = (0, _hooks.usePropsSelector)(state => state.nodeTypes);
const legendList = (0, _react2.useMemo)(() => {
const showTypeList = [];
const nodeTypeSet = new Set();
if (!showAll) {
nodes.forEach(node => {
const type = node.type;
nodeTypeSet.add(type);
});
}
nodeTypeList?.forEach(nodeType => {
if (!nodeType.hideInLegend && (showAll || nodeTypeSet.has(nodeType.type))) {
showTypeList.push(nodeType);
}
});
return showTypeList;
}, [nodes, nodeTypeList]);
if (legendList.length === 0) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: 'rxflow-legend-container',
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.Space, {
size: 10,
children: legendList.map(legend => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
className: 'rxflow-legend-item',
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: 'rxflow-legend-tag',
style: {
backgroundColor: legend.color
},
children: legend.icon
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: 'rxflow-legend-label',
children: legend.label
})]
}, legend.label))
})
});
};
exports.Legend = Legend;