@ichigo_san/graphing
Version:
A lightweight UML-style diagram editor built with React Flow and Tailwind CSS
54 lines (53 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactflow = require("reactflow");
var _floatingUtils = require("./floatingUtils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const FloatingEdge = _ref => {
let {
id,
source,
target,
style
} = _ref;
const {
sourceNode,
targetNode
} = (0, _reactflow.useStore)(s => {
const sourceNode = s.nodeLookup.get(source);
const targetNode = s.nodeLookup.get(target);
return {
sourceNode,
targetNode
};
});
if (!sourceNode || !targetNode) {
return null;
}
const {
sx,
sy,
tx,
ty,
sourcePos,
targetPos
} = (0, _floatingUtils.getEdgeParams)(sourceNode, targetNode);
const [path] = (0, _reactflow.getBezierPath)({
sourceX: sx,
sourceY: sy,
sourcePosition: sourcePos,
targetPosition: targetPos,
targetX: tx,
targetY: ty
});
return /*#__PURE__*/_react.default.createElement(_reactflow.BaseEdge, {
id: id,
path: path,
style: style
});
};
var _default = exports.default = FloatingEdge;