@rxflow/base
Version:
BaseFlow - 核心 Flow 组件库
66 lines (63 loc) • 4.6 kB
JavaScript
var _excluded = ["children"];
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
* @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.
*/
import { ConfigProvider } from "antd";
import React from "react";
import { useProps } from "../hooks/props/useProps";
import { PropsStore } from "../store/PropsStore";
import { withFlowProvider } from "./withFlowProvider";
import { jsx as _jsx } from "react/jsx-runtime";
var RenderFlowWithProp = function RenderFlowWithProp(_ref) {
var FlowComponent = _ref.FlowComponent,
children = _ref.children;
var props = useProps();
if (!props) {
return null;
}
return /*#__PURE__*/_jsx(FlowComponent, _objectSpread(_objectSpread({}, props), {}, {
children: children
}));
};
// 不支持外部使用组件时自定义 Node类型,可以在使用 hooks 传入,hooks 会进行类型转换。
// TODO 还可以技进行优化, Flow 的 props 怎么进行传入??如何支持布局,布局前对 props 转换再传入??? 属性传递还是要考虑清楚,属性构建,存储需要存储外面传进来的
export function createFlow(FlowComponent, usePropsTransform) {
// 支持外部在使用时自定义 NodeType,
return withFlowProvider(function (props) {
var _props = props;
if (usePropsTransform) {
// 外部传入了 hook
_props = usePropsTransform(props);
}
var _props2 = _props,
children = _props2.children,
others = _objectWithoutProperties(_props2, _excluded);
// 外部的props,内置的,转换函数,转换之后的 props,支持转换函数
return /*#__PURE__*/_jsx(ConfigProvider, {
prefixCls: 'rxflow',
children: /*#__PURE__*/_jsx(PropsStore, {
props: others,
children: /*#__PURE__*/_jsx(RenderFlowWithProp, {
FlowComponent: FlowComponent,
children: children
})
})
});
});
// hooks 直接绑定在 Flow 上,是不是更好,可以直接和传入的 nodeType 进行绑定。
}