UNPKG

@rxflow/base

Version:

BaseFlow - 核心 Flow 组件库

67 lines (63 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createFlow = createFlow; var _antd = require("antd"); var _react = _interopRequireDefault(require("react")); var _useProps = require("../hooks/props/useProps"); var _PropsStore = require("../store/PropsStore"); var _withFlowProvider = require("./withFlowProvider"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @author: yanxianliang * @date: 2025-10-15 15:25 * @modified:2025/10/15 15:25 by yanxianliang * @desc: 创建 Flow 组件 * * 提供公众能力封装 * * Copyright (c) 2025 by yanxianliang, All Rights Reserved. */ const RenderFlowWithProp = ({ FlowComponent, children }) => { const props = (0, _useProps.useProps)(); if (!props) { return null; } return /*#__PURE__*/(0, _jsxRuntime.jsx)(FlowComponent, { ...props, children: children }); }; // 不支持外部使用组件时自定义 Node类型,可以在使用 hooks 传入,hooks 会进行类型转换。 // TODO 还可以技进行优化, Flow 的 props 怎么进行传入??如何支持布局,布局前对 props 转换再传入??? 属性传递还是要考虑清楚,属性构建,存储需要存储外面传进来的 function createFlow(FlowComponent, usePropsTransform) { // 支持外部在使用时自定义 NodeType, return (0, _withFlowProvider.withFlowProvider)(props => { let _props = props; if (usePropsTransform) { // 外部传入了 hook _props = usePropsTransform(props); } const { children, ...others } = _props; // 外部的props,内置的,转换函数,转换之后的 props,支持转换函数 return /*#__PURE__*/(0, _jsxRuntime.jsx)(_antd.ConfigProvider, { prefixCls: 'rxflow', children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PropsStore.PropsStore, { props: others, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RenderFlowWithProp, { FlowComponent: FlowComponent, children: children }) }) }); }); // hooks 直接绑定在 Flow 上,是不是更好,可以直接和传入的 nodeType 进行绑定。 }