UNPKG

acud

Version:

acg react 组件库

47 lines • 1.43 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; /* * aiflow 流程图组件 * */ import AIFlow from 'aiflow'; import * as React from 'react'; export default /*#__PURE__*/React.forwardRef(function (props, ref) { var _props$width = props.width, width = _props$width === void 0 ? 400 : _props$width, _props$height = props.height, height = _props$height === void 0 ? 400 : _props$height, classname = props.classname, style = props.style, data = props.data, config = props.config, templates = props.templates; var domRef = React.useRef(); var _React$useState = React.useState(), _React$useState2 = _slicedToArray(_React$useState, 2), ins = _React$useState2[0], setIns = _React$useState2[1]; React.useEffect(function () { if (templates && templates.length) { templates.forEach(function (t) { AIFlow.registerTemplate(t.name, t.content); }); } var aiIns = new AIFlow(domRef.current, data, config); setIns(aiIns); // eslint-disable-next-line react-hooks/exhaustive-deps }, [templates]); React.useImperativeHandle(ref, function () { return { ins: ins }; }, [ins]); return /*#__PURE__*/React.createElement("div", { className: classname, ref: domRef, style: _extends({ width: width, height: height }, style) }); });