UNPKG

@ant-design/pro-flow

Version:
154 lines (151 loc) 7.54 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral"; var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { CaretDownFilled } from '@ant-design/icons'; import { ActionIcon } from '@ant-design/pro-editor'; import { ConfigProvider } from 'antd'; import { createStyles } from 'antd-style'; import { memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import { Handle, Position } from 'reactflow'; import useControlledState from 'use-merge-value'; import { CollapseProvider, useStore, useStoreApi } from "../EditNode/CollapseContext"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; var prefixCls = 'editor-field-item'; export var useNodeFieldStyles = createStyles(function (_ref) { var css = _ref.css, token = _ref.token, cx = _ref.cx; var handle = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 20px;\n height: 20px;\n background: ", ";\n border: 4px solid ", ";\n "])), token.colorBgElevated, token.colorPrimary); return { title: cx("".concat(prefixCls, "-title"), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n font-weight: bold;\n color: ", ";\n "])), token.colorText)), extra: cx(css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n "])))), value: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n padding: 12px 16px;\n background: ", ";\n border-radius: 8px;\n "])), token.colorBgLayout), handle: handle, handleRight: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n ", ";\n right: -35px;\n "])), handle), handleLeft: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n ", ";\n left: -35px;\n "])), handle) }; }); /** * 额外操作选项 */ /** * NodeField 组件的 props */ var NodeFieldContent = /*#__PURE__*/memo(function (_ref2) { var children = _ref2.children, title = _ref2.title, extra = _ref2.extra, collapsed = _ref2.collapsed, onCollapsedChange = _ref2.onCollapsedChange, valueContainer = _ref2.valueContainer, _ref2$classNames = _ref2.classNames, classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames, _ref2$handles = _ref2.handles, handles = _ref2$handles === void 0 ? {} : _ref2$handles, id = _ref2.id, className = _ref2.className, style = _ref2.style; var _useNodeFieldStyles = useNodeFieldStyles(), styles = _useNodeFieldStyles.styles, theme = _useNodeFieldStyles.theme, cx = _useNodeFieldStyles.cx; var _useStore = useStore(function (s) { return [s.collapsedKeys, s.toggleCollapsedKey]; }), _useStore2 = _slicedToArray(_useStore, 2), collapsedKeys = _useStore2[0], toggleCollapsedKey = _useStore2[1]; var _useControlledState = useControlledState(collapsedKeys.includes(id), { value: typeof collapsed === 'undefined' ? collapsedKeys.includes(id) : collapsed, onChange: function onChange(v) { toggleCollapsedKey(id); onCollapsedChange === null || onCollapsedChange === void 0 || onCollapsedChange(v); } }), _useControlledState2 = _slicedToArray(_useControlledState, 2), isCollapsed = _useControlledState2[0], setCollapsed = _useControlledState2[1]; return /*#__PURE__*/_jsxs(Flexbox, { gap: 12, className: cx("".concat(prefixCls, "-container"), className), style: style, children: [title && /*#__PURE__*/_jsxs(Flexbox, { horizontal: true, distribution: 'space-between', align: 'center', className: cx("".concat(prefixCls, "-header"), classNames === null || classNames === void 0 ? void 0 : classNames.header), children: [/*#__PURE__*/_jsxs(Flexbox, { className: cx(styles.title, classNames === null || classNames === void 0 ? void 0 : classNames.title), children: [!!(handles !== null && handles !== void 0 && handles.source) && /*#__PURE__*/_jsx(Handle, { id: typeof (handles === null || handles === void 0 ? void 0 : handles.source) === 'string' ? handles === null || handles === void 0 ? void 0 : handles.source : id, type: 'target', position: Position.Left, className: styles.handleLeft }), title] }), /*#__PURE__*/_jsxs(Flexbox, { horizontal: true, gap: 4, className: cx(styles.extra, "".concat(prefixCls, "-extra"), classNames === null || classNames === void 0 ? void 0 : classNames.extra, 'nodrag'), children: [/*#__PURE__*/_jsxs(ConfigProvider, { theme: { token: { colorText: theme.colorTextSecondary } }, children: [isCollapsed ? null : extra && extra.map(function (item, index) { return /*#__PURE__*/_jsx(ActionIcon, { icon: item.icon, title: item.title, onClick: item.onClick }, item.title || '' + index); }), /*#__PURE__*/_jsx(ActionIcon, { icon: /*#__PURE__*/_jsx(CaretDownFilled, { rotate: isCollapsed ? -90 : 0 }), title: isCollapsed ? '展开' : '折起', onClick: function onClick() { setCollapsed(!isCollapsed); } })] }), !!(handles !== null && handles !== void 0 && handles.target) && /*#__PURE__*/_jsx(Handle, { id: typeof (handles === null || handles === void 0 ? void 0 : handles.target) === 'string' ? handles === null || handles === void 0 ? void 0 : handles.target : id, type: 'source', position: Position.Right, className: styles.handleRight })] })] }), isCollapsed ? null : children && valueContainer === false ? children : /*#__PURE__*/_jsx("div", { className: cx(styles.value, classNames.value), children: children })] }); }); var Wrapper = function Wrapper(_ref3) { var children = _ref3.children; var isWrapped = true; var Content = /*#__PURE__*/_jsx(_Fragment, { children: children }); try { useStoreApi(); } catch (e) { isWrapped = false; } if (isWrapped) { return Content; } return /*#__PURE__*/_jsx(CollapseProvider, { children: children }); }; export var NodeField = /*#__PURE__*/memo(function (props) { return /*#__PURE__*/_jsx(Wrapper, { children: /*#__PURE__*/_jsx(NodeFieldContent, _objectSpread({}, props)) }); });