UNPKG

@ichigo_san/graphing

Version:

A lightweight UML-style diagram editor built with React Flow and Tailwind CSS

182 lines (181 loc) 6.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactflow = require("reactflow"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const handleStyle = { background: '#3b82f6', border: '2px solid #fff', width: 8, height: 8, borderRadius: '50%', zIndex: 10, cursor: 'crosshair', transition: 'all 0.15s ease' }; const ContainerNode = _ref => { let { data, id, selected, isConnectable } = _ref; const [isEditing, setIsEditing] = (0, _react.useState)(false); const [label, setLabel] = (0, _react.useState)(data.label || 'Container'); (0, _react.useEffect)(() => { setLabel(data.label || 'Container'); }, [data.label]); const inputRef = (0, _react.useRef)(null); const handleDoubleClick = (0, _react.useCallback)(e => { e.stopPropagation(); setIsEditing(true); }, []); const handleLabelSubmit = (0, _react.useCallback)(() => { setIsEditing(false); if (data.onLabelChange && label !== data.label) { data.onLabelChange(id, label); } }, [id, label, data]); const handleKeyDown = (0, _react.useCallback)(e => { if (e.key === 'Enter') { handleLabelSubmit(); } if (e.key === 'Escape') { setLabel(data.label); setIsEditing(false); } }, [handleLabelSubmit, data.label]); return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_reactflow.NodeResizer, { isVisible: selected, minWidth: 200, minHeight: 150, handleClassName: "w-2.5 h-2.5 bg-gray-500 rounded-full border-2 border-white shadow", lineClassName: "border-2 border-dashed border-indigo-500 opacity-60", nodeWidth: data.width, nodeHeight: data.height }), /*#__PURE__*/_react.default.createElement("div", { style: { background: data.color || '#f9f9f9', border: "2px solid ".concat(data.borderColor || '#ddd'), borderRadius: '8px', width: '100%', height: '100%', display: 'flex', flexDirection: 'column', cursor: 'move', transition: 'all 0.2s ease', boxShadow: selected ? '0 0 0 2px #2196F3' : '0 2px 4px rgba(0,0,0,0.1)', boxSizing: 'border-box', position: 'relative' } }, /*#__PURE__*/_react.default.createElement("div", { className: "px-2 py-1 border-b border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-800 dark:text-gray-100 rounded-t-lg flex items-center gap-2", onDoubleClick: handleDoubleClick }, data.icon && /*#__PURE__*/_react.default.createElement("span", { style: { fontSize: '14px' } }, data.icon), isEditing ? /*#__PURE__*/_react.default.createElement("input", { ref: inputRef, value: label, onChange: e => setLabel(e.target.value), onBlur: handleLabelSubmit, onKeyDown: handleKeyDown, autoFocus: true, style: { fontSize: '14px', border: 'none', borderBottom: '2px solid #2196F3', outline: 'none', background: 'transparent', padding: '4px', width: '100%' } }) : /*#__PURE__*/_react.default.createElement("span", { style: { fontSize: '14px', fontWeight: 'bold' } }, label)), /*#__PURE__*/_react.default.createElement("div", { style: { flex: 1, padding: '8px', overflow: 'hidden', position: 'relative' } }, data.description && /*#__PURE__*/_react.default.createElement("div", { style: { fontSize: '12px', color: '#666', marginBottom: '8px' } }, data.description)), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "source", position: _reactflow.Position.Top, id: "top", style: handleStyle, isConnectable: isConnectable, className: "container-handle" }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "source", position: _reactflow.Position.Right, id: "right", style: handleStyle, isConnectable: isConnectable, className: "container-handle" }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "source", position: _reactflow.Position.Bottom, id: "bottom", style: handleStyle, isConnectable: isConnectable, className: "container-handle" }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "source", position: _reactflow.Position.Left, id: "left", style: handleStyle, isConnectable: isConnectable, className: "container-handle" }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "target", position: _reactflow.Position.Top, id: "top-target", style: { opacity: 0, pointerEvents: 'none' }, isConnectable: isConnectable }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "target", position: _reactflow.Position.Right, id: "right-target", style: { opacity: 0, pointerEvents: 'none' }, isConnectable: isConnectable }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "target", position: _reactflow.Position.Bottom, id: "bottom-target", style: { opacity: 0, pointerEvents: 'none' }, isConnectable: isConnectable }), /*#__PURE__*/_react.default.createElement(_reactflow.Handle, { type: "target", position: _reactflow.Position.Left, id: "left-target", style: { opacity: 0, pointerEvents: 'none' }, isConnectable: isConnectable }))); }; var _default = exports.default = ContainerNode;