UNPKG

@rxflow/base

Version:

BaseFlow - 核心 Flow 组件库

69 lines (65 loc) 2.41 kB
/** * @author: yanxianliang * @date: 2025-10-16 19:35 * @modified:2025/10/16 19:35 by yanxianliang * @desc: Props 存储 * * Copyright (c) 2025 by yanxianliang, All Rights Reserved. */ import { NodeRoleType } from "../constants/NodeRoleType"; import { useDeepCompareEffect } from 'ahooks'; import React, { useEffect, useMemo, useRef } from "react"; import { v4 as uuid } from "uuid"; import { useGetState } from "./.."; import { useSetState } from "./.."; import { jsx as _jsx } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; export var PropsStore = function PropsStore(_ref) { var props = _ref.props, children = _ref.children; var setState = useSetState(); var getState = useGetState(); var defaultId = useMemo(function () { return uuid(); }, []); var nodeTypes = props.nodeTypes; var styleContentRef = useRef([]); // TODO 怎么支持内置的 nodeTypes??? var nodeTypeMap = useMemo(function () { var map = new Map(); styleContentRef.current = []; if (nodeTypes) { for (var i = 0; i < nodeTypes.length; i++) { var _definition$allowCont; var definition = nodeTypes[i]; map.set(definition.type, definition); // TODO 子工作流需要禁用内容区域的拖拽 if (definition.nodeRoleType === NodeRoleType.SubFlow && ((_definition$allowCont = definition.allowContentSelection) !== null && _definition$allowCont !== void 0 ? _definition$allowCont : true)) { // 子工作流,需要固定样式 var type = definition.type; styleContentRef.current.push(".react-flow__node-".concat(type, " {pointer-events: none!important;}")); } } } return map; }, [nodeTypes]); // TODO 更新属性怎么更好的区分 useDeepCompareEffect(function () { setState({ props: props, id: props.id || defaultId, nodeTypeMap: nodeTypeMap }); }, [props.edges, props.nodes, props.nodeTypes, props.loading]); useEffect(function () { // nodes 变化,需要重新进行初始化,清除当前初始化记录 getState().initialNodeIdSet.clear(); }, [props.nodes]); // 样式需要注入 return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx("style", { children: styleContentRef.current.join('') }), children] }); };