@teamias/rex-design 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { ICustomNodeProps, INodeData } from '../types';
2
+ export declare const CustomNode: <T extends INodeData = INodeData>(props: ICustomNodeProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,261 @@
1
+ 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); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ 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; }
4
+ 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; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
11
+ import { Handle, NodeToolbar, Position, useReactFlow } from '@xyflow/react';
12
+ import { Button, Popconfirm, Space } from 'antd';
13
+ import { sleep } from 'radash';
14
+ import { autoLayoutTree, createEdge, createNode } from "./util";
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ import { Fragment as _Fragment } from "react/jsx-runtime";
18
+ export var CustomNode = function CustomNode(props) {
19
+ var _data$data;
20
+ var data = props.data,
21
+ id = props.id,
22
+ itemRender = props.itemRender,
23
+ toolbarRender = props.toolbarRender,
24
+ layoutOptions = props.layoutOptions,
25
+ actionChange = props.actionChange,
26
+ onAddItem = props.onAddItem,
27
+ onDelItem = props.onDelItem,
28
+ onEditItem = props.onEditItem;
29
+ var reactFlowInstance = useReactFlow();
30
+ var addItem = /*#__PURE__*/function () {
31
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
32
+ var node, _node$data$childIds, newNodeData, newNode, newEdge, nodes, edges;
33
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
34
+ while (1) switch (_context.prev = _context.next) {
35
+ case 0:
36
+ node = reactFlowInstance.getNode(id);
37
+ if (node) {
38
+ _context.next = 3;
39
+ break;
40
+ }
41
+ return _context.abrupt("return");
42
+ case 3:
43
+ _context.prev = 3;
44
+ _context.next = 6;
45
+ return onAddItem === null || onAddItem === void 0 ? void 0 : onAddItem(node.data);
46
+ case 6:
47
+ newNodeData = _context.sent;
48
+ newNode = createNode(newNodeData || {
49
+ id: "new-".concat(Date.now()),
50
+ parentIds: [node.id],
51
+ childIds: [],
52
+ data: {
53
+ label: '新节点'
54
+ }
55
+ }, layoutOptions);
56
+ newEdge = createEdge(node.id, newNode.id);
57
+ (_node$data$childIds = node.data.childIds) === null || _node$data$childIds === void 0 || _node$data$childIds.push(newNode.id);
58
+ reactFlowInstance.updateNodeData(node.id, _objectSpread({}, node.data));
59
+ reactFlowInstance.addNodes(newNode);
60
+ reactFlowInstance.addEdges(newEdge);
61
+ _context.next = 15;
62
+ return sleep(0);
63
+ case 15:
64
+ nodes = reactFlowInstance.getNodes();
65
+ edges = reactFlowInstance.getEdges();
66
+ reactFlowInstance.setNodes(autoLayoutTree(nodes, edges, layoutOptions));
67
+ actionChange === null || actionChange === void 0 || actionChange();
68
+ _context.next = 24;
69
+ break;
70
+ case 21:
71
+ _context.prev = 21;
72
+ _context.t0 = _context["catch"](3);
73
+ console.error('[CustomNode-addItem]', _context.t0);
74
+ case 24:
75
+ case "end":
76
+ return _context.stop();
77
+ }
78
+ }, _callee, null, [[3, 21]]);
79
+ }));
80
+ return function addItem() {
81
+ return _ref.apply(this, arguments);
82
+ };
83
+ }();
84
+ var delItem = /*#__PURE__*/function () {
85
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
86
+ var node, delIdsSet, eachFn, nodes, edges;
87
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
88
+ while (1) switch (_context2.prev = _context2.next) {
89
+ case 0:
90
+ node = reactFlowInstance.getNode(id);
91
+ if (node) {
92
+ _context2.next = 3;
93
+ break;
94
+ }
95
+ return _context2.abrupt("return");
96
+ case 3:
97
+ _context2.prev = 3;
98
+ _context2.next = 6;
99
+ return onDelItem === null || onDelItem === void 0 ? void 0 : onDelItem(node.data);
100
+ case 6:
101
+ delIdsSet = new Set([node.id]);
102
+ /**
103
+ * 递归删除节点及其子树
104
+ * @param currentId 当前处理的节点 ID
105
+ * @param parentId 触发删除的父节点 ID(undefined 表示是用户点击删除的根节点)
106
+ *
107
+ * 删除策略:
108
+ * - 子节点只有一个父节点:直接删除
109
+ * - 子节点有多个父节点:仅解除与被删除父节点的关联,保留节点本身
110
+ */
111
+ eachFn = function eachFn(currentId, parentId) {
112
+ var _currentNode$data$par, _currentNode$data$chi;
113
+ delIdsSet.add(currentId);
114
+ var isDelRoot = !parentId; // 是否为用户点击删除的根节点
115
+ var currentNode = reactFlowInstance.getNode(currentId);
116
+ if (!currentNode) return;
117
+ if ((_currentNode$data$par = currentNode.data.parentIds) !== null && _currentNode$data$par !== void 0 && _currentNode$data$par.length) {
118
+ // 多父节点场景:子节点有其他父节点,不删除,仅解除关联
119
+ if (!isDelRoot && currentNode.data.parentIds.length > 1) {
120
+ delIdsSet.delete(currentId);
121
+ currentNode.data.parentIds = currentNode.data.parentIds.filter(function (pid) {
122
+ return pid !== parentId;
123
+ });
124
+ reactFlowInstance.updateNodeData(currentId, _objectSpread({}, currentNode.data));
125
+ }
126
+
127
+ // 确认删除:清理所有父节点的 childIds 引用
128
+ if (delIdsSet.has(currentId)) {
129
+ currentNode.data.parentIds.forEach(function (parentId) {
130
+ var _parentNode$data$chil;
131
+ var parentNode = reactFlowInstance.getNode(parentId);
132
+ if (!parentNode) return;
133
+ parentNode.data.childIds = (_parentNode$data$chil = parentNode.data.childIds) === null || _parentNode$data$chil === void 0 ? void 0 : _parentNode$data$chil.filter(function (cid) {
134
+ return cid !== currentId;
135
+ });
136
+ reactFlowInstance.updateNodeData(parentId, _objectSpread({}, parentNode.data));
137
+ });
138
+ }
139
+ }
140
+
141
+ // 递归处理子节点
142
+ if ((_currentNode$data$chi = currentNode.data.childIds) !== null && _currentNode$data$chi !== void 0 && _currentNode$data$chi.length) {
143
+ currentNode.data.childIds.forEach(function (childId) {
144
+ eachFn(childId, currentId);
145
+ });
146
+ }
147
+ };
148
+ eachFn(node.id);
149
+ reactFlowInstance.deleteElements({
150
+ nodes: Array.from(delIdsSet).map(function (nid) {
151
+ return {
152
+ id: nid
153
+ };
154
+ })
155
+ });
156
+ _context2.next = 12;
157
+ return sleep(0);
158
+ case 12:
159
+ nodes = reactFlowInstance.getNodes();
160
+ edges = reactFlowInstance.getEdges();
161
+ reactFlowInstance.setNodes(autoLayoutTree(nodes, edges, layoutOptions));
162
+ actionChange === null || actionChange === void 0 || actionChange();
163
+ _context2.next = 21;
164
+ break;
165
+ case 18:
166
+ _context2.prev = 18;
167
+ _context2.t0 = _context2["catch"](3);
168
+ console.error('[CustomNode-delItem]', _context2.t0);
169
+ case 21:
170
+ case "end":
171
+ return _context2.stop();
172
+ }
173
+ }, _callee2, null, [[3, 18]]);
174
+ }));
175
+ return function delItem() {
176
+ return _ref2.apply(this, arguments);
177
+ };
178
+ }();
179
+ var editItem = /*#__PURE__*/function () {
180
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
181
+ var node, lastData;
182
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
183
+ while (1) switch (_context3.prev = _context3.next) {
184
+ case 0:
185
+ node = reactFlowInstance.getNode(id);
186
+ if (node) {
187
+ _context3.next = 3;
188
+ break;
189
+ }
190
+ return _context3.abrupt("return");
191
+ case 3:
192
+ _context3.prev = 3;
193
+ _context3.next = 6;
194
+ return onEditItem === null || onEditItem === void 0 ? void 0 : onEditItem(node.data);
195
+ case 6:
196
+ lastData = _context3.sent;
197
+ reactFlowInstance.updateNodeData(node.id, _objectSpread({}, lastData));
198
+ _context3.next = 13;
199
+ break;
200
+ case 10:
201
+ _context3.prev = 10;
202
+ _context3.t0 = _context3["catch"](3);
203
+ console.error('[CustomNode-editItem]', _context3.t0);
204
+ case 13:
205
+ case "end":
206
+ return _context3.stop();
207
+ }
208
+ }, _callee3, null, [[3, 10]]);
209
+ }));
210
+ return function editItem() {
211
+ return _ref3.apply(this, arguments);
212
+ };
213
+ }();
214
+ var actions = {
215
+ addItem: addItem,
216
+ delItem: delItem,
217
+ editItem: editItem
218
+ };
219
+ return /*#__PURE__*/_jsxs(_Fragment, {
220
+ children: [/*#__PURE__*/_jsx(NodeToolbar, {
221
+ isVisible: data.toolbarVisible,
222
+ position: Position.Top,
223
+ children: toolbarRender ? toolbarRender(data) : /*#__PURE__*/_jsxs(Space.Compact, {
224
+ size: "small",
225
+ children: [/*#__PURE__*/_jsx(Popconfirm, {
226
+ title: "\u786E\u5B9A\u5220\u9664\u5417?",
227
+ onConfirm: function onConfirm() {
228
+ return actions.delItem();
229
+ },
230
+ children: /*#__PURE__*/_jsx(Button, {
231
+ type: "primary",
232
+ danger: true,
233
+ icon: /*#__PURE__*/_jsx(DeleteOutlined, {})
234
+ })
235
+ }), /*#__PURE__*/_jsx(Button, {
236
+ icon: /*#__PURE__*/_jsx(EditOutlined, {}),
237
+ onClick: function onClick() {
238
+ return actions.editItem();
239
+ }
240
+ }), /*#__PURE__*/_jsx(Button, {
241
+ type: "primary",
242
+ icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
243
+ onClick: function onClick() {
244
+ return actions.addItem();
245
+ }
246
+ })]
247
+ })
248
+ }), itemRender ? itemRender(data) : /*#__PURE__*/_jsx("div", {
249
+ style: {
250
+ padding: 10
251
+ },
252
+ children: (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.label
253
+ }), /*#__PURE__*/_jsx(Handle, {
254
+ type: "target",
255
+ position: Position.Top
256
+ }), /*#__PURE__*/_jsx(Handle, {
257
+ type: "source",
258
+ position: Position.Bottom
259
+ })]
260
+ });
261
+ };
@@ -0,0 +1,3 @@
1
+ import '@xyflow/react/dist/style.css';
2
+ import { IFlowProps, INodeData } from '../types';
3
+ export declare const Flow: <T extends INodeData = INodeData>({ value, defaultValue, layoutOptions: outsideLayoutOptions, itemRender, toolbarRender, onChange, onAddItem, onDelItem, onEditItem, }: IFlowProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,136 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import { useStateData } from "../../..";
8
+ import { addEdge, applyEdgeChanges, applyNodeChanges, Background, BackgroundVariant, ConnectionLineType, Controls, ReactFlow } from '@xyflow/react';
9
+ import '@xyflow/react/dist/style.css';
10
+ import { useDebounceEffect, useDebounceFn } from 'ahooks';
11
+ import { cloneElement, useMemo } from 'react';
12
+ import { FlowDiv } from "../style";
13
+ import { CustomNode } from "./CustomNode";
14
+ import { toComponentData } from "./util";
15
+
16
+ // const initialNodes = [
17
+ // { id: 'n1', position: { x: 0, y: 0 }, type: 'textUpdater', data: { label: 'FlowNode 1' } },
18
+ // { id: 'n2', position: { x: 0, y: 100 }, type: 'textUpdater', data: { label: 'FlowNode 2' } },
19
+ // ];
20
+ // const initialEdges = [{ id: 'n1-n2', source: 'n1', target: 'n2', animated: true, type: ConnectionLineType.SmoothStep }];
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { jsxs as _jsxs } from "react/jsx-runtime";
23
+ export var Flow = function Flow(_ref) {
24
+ var value = _ref.value,
25
+ _ref$defaultValue = _ref.defaultValue,
26
+ defaultValue = _ref$defaultValue === void 0 ? [] : _ref$defaultValue,
27
+ outsideLayoutOptions = _ref.layoutOptions,
28
+ itemRender = _ref.itemRender,
29
+ toolbarRender = _ref.toolbarRender,
30
+ onChange = _ref.onChange,
31
+ onAddItem = _ref.onAddItem,
32
+ onDelItem = _ref.onDelItem,
33
+ onEditItem = _ref.onEditItem;
34
+ var layoutOptions = _objectSpread({
35
+ direction: 'TB',
36
+ nodeHeight: 100,
37
+ nodeWidth: 200
38
+ }, outsideLayoutOptions);
39
+ var _useStateData = useStateData(function () {
40
+ return {
41
+ nodes: [],
42
+ edges: []
43
+ };
44
+ }),
45
+ state = _useStateData.state,
46
+ update = _useStateData.update,
47
+ setState = _useStateData.setState;
48
+ var updateInlineData = useDebounceFn(function () {
49
+ var _toComponentData = toComponentData(value || defaultValue, layoutOptions),
50
+ nodes = _toComponentData.nodes,
51
+ edges = _toComponentData.edges;
52
+ state.nodes = nodes;
53
+ state.edges = edges;
54
+ update();
55
+ }, {
56
+ wait: 0
57
+ });
58
+ var change = useDebounceFn(function () {
59
+ onChange === null || onChange === void 0 || onChange(state.nodes.map(function (n) {
60
+ return n.data;
61
+ }));
62
+ }, {
63
+ wait: 300
64
+ });
65
+ useDebounceEffect(function () {
66
+ updateInlineData.run();
67
+ }, [], {
68
+ wait: 0,
69
+ trailing: true,
70
+ leading: false
71
+ });
72
+ useDebounceEffect(function () {
73
+ if (!value) return;
74
+ if (JSON.stringify(value) === JSON.stringify(state.nodes.map(function (n) {
75
+ return n.data;
76
+ }))) return;
77
+ updateInlineData.run();
78
+ }, [value], {
79
+ wait: 0,
80
+ trailing: true,
81
+ leading: false
82
+ });
83
+ return /*#__PURE__*/_jsx(FlowDiv, {
84
+ children: /*#__PURE__*/_jsxs(ReactFlow, {
85
+ nodes: state.nodes,
86
+ edges: state.edges,
87
+ connectionLineType: ConnectionLineType.SmoothStep,
88
+ fitView: true
89
+ // 禁用节点拖动
90
+ ,
91
+ nodesDraggable: false
92
+ // 禁用手动连接线
93
+ ,
94
+ nodesConnectable: false,
95
+ edgesReconnectable: false,
96
+ connectOnClick: false
97
+ // 禁用键盘快捷键
98
+ ,
99
+ deleteKeyCode: null,
100
+ selectionKeyCode: null,
101
+ multiSelectionKeyCode: null
102
+ // zoomActivationKeyCode={null}
103
+ // panActivationKeyCode={null}
104
+ // disableKeyboardA11y={true}
105
+ ,
106
+ nodeTypes: {
107
+ customNode: useMemo(function () {
108
+ return function (p) {
109
+ return /*#__PURE__*/cloneElement( /*#__PURE__*/_jsx(CustomNode, _objectSpread({}, p)), {
110
+ itemRender: itemRender,
111
+ toolbarRender: toolbarRender,
112
+ layoutOptions: layoutOptions,
113
+ actionChange: change.run,
114
+ onAddItem: onAddItem,
115
+ onDelItem: onDelItem,
116
+ onEditItem: onEditItem
117
+ });
118
+ };
119
+ }, [])
120
+ },
121
+ onNodesChange: function onNodesChange(changes) {
122
+ return setState('nodes', applyNodeChanges(changes, state.nodes));
123
+ },
124
+ onEdgesChange: function onEdgesChange(changes) {
125
+ return setState('edges', applyEdgeChanges(changes, state.edges));
126
+ },
127
+ onConnect: function onConnect(params) {
128
+ return setState('edges', addEdge(params, state.edges));
129
+ },
130
+ children: [/*#__PURE__*/_jsx(Controls, {}), /*#__PURE__*/_jsx(Background, {
131
+ color: "#ccc",
132
+ variant: BackgroundVariant.Dots
133
+ })]
134
+ })
135
+ });
136
+ };
@@ -0,0 +1,34 @@
1
+ import { ConnectionLineType, Edge } from '@xyflow/react';
2
+ import { FlowNode, ILayoutOptions, INodeData } from '../types';
3
+ /** 公共边样式 */
4
+ export declare const commonEdgeStyles: {
5
+ animated: boolean;
6
+ type: ConnectionLineType;
7
+ };
8
+ /** 数据转为组件可用数据 */
9
+ export declare const toComponentData: (eachData: INodeData[], layoutOptions: ILayoutOptions) => {
10
+ nodes: FlowNode[];
11
+ edges: Edge[];
12
+ };
13
+ /** 自动布局树形结构 */
14
+ export declare const autoLayoutTree: (nodes: FlowNode[], edges: Edge[], layoutOptions?: ILayoutOptions) => FlowNode[];
15
+ /** 创建节点 */
16
+ export declare const createNode: (data: INodeData, layoutOptions?: ILayoutOptions) => {
17
+ id: string;
18
+ data: INodeData;
19
+ type: string;
20
+ position: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ width: number | undefined;
25
+ height: number | undefined;
26
+ };
27
+ /** 创建边 */
28
+ export declare const createEdge: (sourceId: string, targetId: string) => {
29
+ animated: boolean;
30
+ type: ConnectionLineType;
31
+ id: string;
32
+ source: string;
33
+ target: string;
34
+ };
@@ -0,0 +1,102 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import dagre from '@dagrejs/dagre';
8
+ import { ConnectionLineType, Position } from '@xyflow/react';
9
+ /** 公共边样式 */
10
+ export var commonEdgeStyles = {
11
+ animated: true,
12
+ type: ConnectionLineType.SmoothStep
13
+ };
14
+
15
+ /** 数据转为组件可用数据 */
16
+ export var toComponentData = function toComponentData(eachData, layoutOptions) {
17
+ var nodes = [];
18
+ var edgesMap = {};
19
+ eachData.forEach(function (item) {
20
+ var _item$parentIds, _item$childIds;
21
+ nodes.push(createNode(item, layoutOptions));
22
+ if ((_item$parentIds = item.parentIds) !== null && _item$parentIds !== void 0 && _item$parentIds.length) {
23
+ item.parentIds.forEach(function (parentId) {
24
+ edgesMap["".concat(parentId, "-").concat(item.id)] = createEdge(parentId, item.id);
25
+ });
26
+ }
27
+ if ((_item$childIds = item.childIds) !== null && _item$childIds !== void 0 && _item$childIds.length) {
28
+ item.childIds.forEach(function (childId) {
29
+ edgesMap["".concat(item.id, "-").concat(childId)] = createEdge(item.id, childId);
30
+ });
31
+ }
32
+ });
33
+ return {
34
+ nodes: autoLayoutTree(nodes, Object.values(edgesMap), layoutOptions),
35
+ edges: Object.values(edgesMap)
36
+ };
37
+ };
38
+
39
+ /** 自动布局树形结构 */
40
+ export var autoLayoutTree = function autoLayoutTree(nodes, edges, layoutOptions) {
41
+ var dagreGraph = new dagre.graphlib.Graph().setDefaultEdgeLabel(function () {
42
+ return {};
43
+ });
44
+ var _ref = layoutOptions || {},
45
+ direction = _ref.direction,
46
+ _ref$nodeWidth = _ref.nodeWidth,
47
+ nodeWidth = _ref$nodeWidth === void 0 ? 0 : _ref$nodeWidth,
48
+ _ref$nodeHeight = _ref.nodeHeight,
49
+ nodeHeight = _ref$nodeHeight === void 0 ? 0 : _ref$nodeHeight;
50
+ var isHorizontal = direction === 'LR';
51
+ dagreGraph.setGraph({
52
+ rankdir: direction
53
+ });
54
+ nodes.forEach(function (node) {
55
+ dagreGraph.setNode(node.id, {
56
+ width: nodeWidth,
57
+ height: nodeHeight
58
+ });
59
+ });
60
+ edges.forEach(function (edge) {
61
+ dagreGraph.setEdge(edge.source, edge.target);
62
+ });
63
+ dagre.layout(dagreGraph);
64
+ return nodes.map(function (node) {
65
+ var nodeWithPosition = dagreGraph.node(node.id);
66
+ var newNode = _objectSpread(_objectSpread({}, node), {}, {
67
+ targetPosition: isHorizontal ? Position.Left : Position.Top,
68
+ sourcePosition: isHorizontal ? Position.Right : Position.Bottom,
69
+ // We are shifting the dagre node position (anchor=center center) to the top left
70
+ // so it matches the React Flow node anchor point (top left).
71
+ position: {
72
+ x: nodeWithPosition.x + nodeWidth * 2,
73
+ y: nodeWithPosition.y + nodeHeight * 2
74
+ }
75
+ });
76
+ return newNode;
77
+ });
78
+ };
79
+
80
+ /** 创建节点 */
81
+ export var createNode = function createNode(data, layoutOptions) {
82
+ return {
83
+ id: data.id,
84
+ data: data,
85
+ type: 'customNode',
86
+ position: {
87
+ x: 0,
88
+ y: 0
89
+ },
90
+ width: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.nodeWidth,
91
+ height: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.nodeHeight
92
+ };
93
+ };
94
+
95
+ /** 创建边 */
96
+ export var createEdge = function createEdge(sourceId, targetId) {
97
+ return _objectSpread({
98
+ id: "".concat(sourceId, "-").concat(targetId),
99
+ source: sourceId,
100
+ target: targetId
101
+ }, commonEdgeStyles);
102
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,200 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ import { Flow, useStateData } from "../../..";
17
+ import { Button, Input, Modal, message } from 'antd';
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { jsxs as _jsxs } from "react/jsx-runtime";
20
+ export default (function () {
21
+ var _Modal$useModal = Modal.useModal(),
22
+ _Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
23
+ modal = _Modal$useModal2[0],
24
+ contextHolder = _Modal$useModal2[1];
25
+ var _useStateData = useStateData(function () {
26
+ return {
27
+ value: [{
28
+ id: '1',
29
+ parentIds: [],
30
+ childIds: ['2', '3'],
31
+ data: {
32
+ label: '节点1',
33
+ w: 'wwwww'
34
+ }
35
+ }, {
36
+ id: '2',
37
+ parentIds: ['1'],
38
+ childIds: ['5'],
39
+ data: {
40
+ label: '节点2-1'
41
+ }
42
+ }, {
43
+ id: '3',
44
+ parentIds: ['1'],
45
+ childIds: ['4'],
46
+ data: {
47
+ label: '节点2-2'
48
+ }
49
+ }, {
50
+ id: '4',
51
+ parentIds: ['3'],
52
+ childIds: ['5'],
53
+ data: {
54
+ label: '节点3'
55
+ }
56
+ }, {
57
+ id: '5',
58
+ parentIds: ['2', '4'],
59
+ childIds: [],
60
+ data: {
61
+ label: '节点4'
62
+ }
63
+ } // 终点,无子节点
64
+ ]
65
+ };
66
+ }),
67
+ state = _useStateData.state,
68
+ update = _useStateData.update,
69
+ setState = _useStateData.setState;
70
+ var handleChange = function handleChange(data) {
71
+ console.log(data);
72
+ setState('value', data);
73
+ };
74
+ var promptConfirm = function promptConfirm(defaultValue) {
75
+ var text = defaultValue;
76
+ return new Promise(function (resolve, reject) {
77
+ modal.confirm({
78
+ title: 'Confirm',
79
+ content: /*#__PURE__*/_jsx(Input, {
80
+ autoFocus: true,
81
+ defaultValue: text,
82
+ onChange: function onChange(e) {
83
+ return text = e.target.value;
84
+ }
85
+ }),
86
+ okText: '确认',
87
+ cancelText: '取消',
88
+ onOk: function onOk() {
89
+ resolve(text || '未输入');
90
+ },
91
+ onCancel: function onCancel() {
92
+ return reject();
93
+ }
94
+ });
95
+ });
96
+ };
97
+ return /*#__PURE__*/_jsxs("div", {
98
+ style: {
99
+ width: '100vw',
100
+ height: '100vh'
101
+ },
102
+ children: [contextHolder, /*#__PURE__*/_jsx("div", {
103
+ style: {
104
+ position: 'fixed',
105
+ left: 0,
106
+ top: 0
107
+ },
108
+ children: /*#__PURE__*/_jsx(Button, {
109
+ children: "Click Me"
110
+ })
111
+ }), /*#__PURE__*/_jsx(Flow
112
+ // value={state.value}
113
+ , {
114
+ defaultValue: state.value
115
+ // defaultValue={[
116
+ // { id: '1', parentIds: [], childIds: ['2', '3'], data: { label: '节点1', w: 'wwwww' } },
117
+ // { id: '2', parentIds: ['1'], childIds: ['5'], data: { label: '节点2-1' } },
118
+ // { id: '3', parentIds: ['1'], childIds: ['4'], data: { label: '节点2-2' } },
119
+ // { id: '4', parentIds: ['3'], childIds: ['5'], data: { label: '节点3' } },
120
+ // { id: '5', parentIds: ['2', '4'], childIds: [], data: { label: '节点4' } }, // 终点,无子节点
121
+ // ]}
122
+ ,
123
+ itemRender: function itemRender(item) {
124
+ var _item$data;
125
+ return /*#__PURE__*/_jsxs("div", {
126
+ style: {
127
+ padding: 10
128
+ },
129
+ children: [(_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.label, "-", item.data.w, "-test"]
130
+ });
131
+ },
132
+ layoutOptions: {
133
+ nodeWidth: 100,
134
+ nodeHeight: 100
135
+ },
136
+ onChange: handleChange,
137
+ onAddItem: ( /*#__PURE__*/function () {
138
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(parentData) {
139
+ var text;
140
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
141
+ while (1) switch (_context.prev = _context.next) {
142
+ case 0:
143
+ _context.next = 2;
144
+ return promptConfirm();
145
+ case 2:
146
+ text = _context.sent;
147
+ return _context.abrupt("return", {
148
+ id: "new-".concat(Date.now()),
149
+ parentIds: [parentData.id],
150
+ childIds: [],
151
+ data: {
152
+ label: text
153
+ }
154
+ });
155
+ case 4:
156
+ case "end":
157
+ return _context.stop();
158
+ }
159
+ }, _callee);
160
+ }));
161
+ return function (_x) {
162
+ return _ref.apply(this, arguments);
163
+ };
164
+ }()),
165
+ onEditItem: ( /*#__PURE__*/function () {
166
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(currentData) {
167
+ var _currentData$data;
168
+ var text;
169
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
170
+ while (1) switch (_context2.prev = _context2.next) {
171
+ case 0:
172
+ _context2.next = 2;
173
+ return promptConfirm((_currentData$data = currentData.data) === null || _currentData$data === void 0 ? void 0 : _currentData$data.label);
174
+ case 2:
175
+ text = _context2.sent;
176
+ return _context2.abrupt("return", _objectSpread(_objectSpread({}, currentData), {}, {
177
+ data: _objectSpread(_objectSpread({}, currentData.data), {}, {
178
+ label: text
179
+ })
180
+ }));
181
+ case 4:
182
+ case "end":
183
+ return _context2.stop();
184
+ }
185
+ }, _callee2);
186
+ }));
187
+ return function (_x2) {
188
+ return _ref2.apply(this, arguments);
189
+ };
190
+ }()),
191
+ onDelItem: function onDelItem() {
192
+ if (Math.random() > 0.5) {
193
+ message.error('删除失败');
194
+ return Promise.reject();
195
+ }
196
+ return Promise.resolve();
197
+ }
198
+ })]
199
+ });
200
+ });
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ export * from "./core";
2
+ export * from "./types";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const FlowDiv: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
3
+ export declare const NodeDiv: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components';
2
+ export var FlowDiv = styled.div.withConfig({
3
+ displayName: "FlowDiv",
4
+ componentId: "rex-design-aaf4__sc-1odsg71-0"
5
+ })(["width:100%;height:100%;.react-flow{--xy-background-color:#f7f9fb;--xy-theme-selected:#f57dbd;--xy-theme-hover:#c5c5c5;--xy-theme-edge-hover:black;--xy-theme-color-focus:#e8e8e8;--xy-node-border-default:1px solid #ededed;--xy-node-boxshadow-default:0px 3.54px 4.55px 0px #00000005,0px 3.54px 4.55px 0px #0000000d,0px 0.51px 1.01px 0px #0000001a;--xy-node-border-radius-default:8px;--xy-handle-background-color-default:#ffffff;--xy-handle-border-color-default:#aaaaaa;--xy-edge-label-color-default:#505050;}.react-flow.dark{--xy-node-boxshadow-default:0px 3.54px 4.55px 0px rgba(255,255,255,0.05),0px 3.54px 4.55px 0px rgba(255,255,255,0.13),0px 0.51px 1.01px 0px rgba(255,255,255,0.2);--xy-theme-color-focus:#535353;}.react-flow__node{box-shadow:var(--xy-node-boxshadow-default);border-radius:var(--xy-node-border-radius-default);background-color:var(--xy-node-background-color-default);font-size:12px;flex-direction:column;border:var(--xy-node-border-default);color:var(--xy-node-color,var(--xy-node-color-default));}.react-flow__node.selectable:focus{box-shadow:0px 0px 0px 4px var(--xy-theme-color-focus);border-color:#d9d9d9;}.react-flow__node.selectable:focus:active{box-shadow:var(--xy-node-boxshadow-default);}.react-flow__node.selectable:hover,.react-flow__node.draggable:hover{border-color:var(--xy-theme-hover);}.react-flow__node.selectable.selected{border-color:var(--xy-theme-selected);box-shadow:var(--xy-node-boxshadow-default);}.react-flow__node-group{background-color:rgba(207,182,255,0.4);border-color:#9e86ed;}.react-flow__edge.selectable:hover .react-flow__edge-path,.react-flow__edge.selectable.selected .react-flow__edge-path{stroke:var(--xy-theme-edge-hover);}.react-flow__handle{background-color:var(--xy-handle-background-color-default);}.react-flow__handle.connectionindicator:hover{pointer-events:all;border-color:var(--xy-theme-edge-hover);background-color:white;}.react-flow__handle.connectionindicator:focus,.react-flow__handle.connectingfrom,.react-flow__handle.connectingto{border-color:var(--xy-theme-edge-hover);}.react-flow__node-resizer{border-radius:0;border:none;}.react-flow__resize-control.handle{background-color:#ffffff;border-color:#9e86ed;border-radius:0;width:5px;height:5px;}:root{--color-primary:#ff0073;--color-background:#fefefe;--color-hover-bg:#f6f6f6;--color-disabled:#76797e;}.xy-theme__button-group{display:flex;align-items:center;.xy-theme__button:first-child{border-radius:100px 0 0 100px;}.xy-theme__button:last-child{border-radius:0 100px 100px 0;margin:0;}}.xy-theme__button{display:inline-flex;align-items:center;justify-content:center;height:2.5rem;padding:0 1rem;border-radius:100px;border:1px solid var(--color-primary);background-color:var(--color-background);color:var(--color-primary);transition:background-color 0.2s ease,border-color 0.2s ease;box-shadow:var(--xy-node-boxshadow-default);cursor:pointer;}.xy-theme__button.active{background-color:var(--color-primary);color:white;border-color:var(--color-primary);}.xy-theme__button.active:hover,.xy-theme__button.active:active{background-color:var(--color-primary);opacity:0.9;}.xy-theme__button:hover{background-color:var(--xy-controls-button-background-color-hover-default);}.xy-theme__button:active{background-color:var(--color-hover-bg);}.xy-theme__button:disabled{color:var(--color-disabled);opacity:0.8;cursor:not-allowed;border:1px solid var(--color-disabled);}.xy-theme__button > span{margin-right:0.2rem;}.xy-theme__button + .xy-theme__button{margin-left:0.3rem;}.xy-theme__input{padding:0.5rem 0.75rem;border:1px solid var(--color-primary);border-radius:7px;background-color:var(--color-background);transition:background-color 0.2s ease,border-color 0.2s ease;font-size:1rem;color:inherit;}.xy-theme__input:focus{outline:none;border-color:var(--color-primary);box-shadow:0 0 0 2px rgba(255,0,115,0.3);}.xy-theme__checkbox{appearance:none;-webkit-appearance:none;width:1.25rem;height:1.25rem;border-radius:7px;border:2px solid var(--color-primary);background-color:var(--color-background);transition:background-color 0.2s ease,border-color 0.2s ease;cursor:pointer;display:inline-block;vertical-align:middle;margin-right:0.5rem;}.xy-theme__checkbox:checked{background-color:var(--color-primary);border-color:var(--color-primary);}.xy-theme__checkbox:focus{outline:none;box-shadow:0 0 0 2px rgba(255,0,115,0.3);}.xy-theme__select{padding:0.5rem 0.75rem;border:1px solid var(--color-primary);border-radius:50px;background-color:var(--color-background);transition:background-color 0.2s ease,border-color 0.2s ease;font-size:1rem;color:inherit;margin-right:0.5rem;box-shadow:var(--xy-node-boxshadow-default);}.xy-theme__select:focus{outline:none;border-color:var(--color-primary);box-shadow:0 0 0 2px rgba(255,0,115,0.3);}.xy-theme__label{margin-top:10px;margin-bottom:3px;display:inline-block;}"]);
6
+ export var NodeDiv = styled.div.withConfig({
7
+ displayName: "NodeDiv",
8
+ componentId: "rex-design-aaf4__sc-1odsg71-1"
9
+ })([""]);
@@ -0,0 +1,59 @@
1
+ /// <reference types="react" />
2
+ import { Node, NodeProps, ReactFlow } from '@xyflow/react';
3
+ import { GetProps } from 'antd';
4
+ export interface IFlowProps<T extends INodeData = INodeData> {
5
+ /** 节点数据 */
6
+ value?: T[];
7
+ /** 默认节点数据 */
8
+ defaultValue?: T[];
9
+ /** 节点数据变更回调 */
10
+ onChange?: (nodes: T[]) => void;
11
+ /** 自定义渲染节点 */
12
+ itemRender?: ICustomNodeProps<T>['itemRender'];
13
+ /** 自定义渲染节点 */
14
+ toolbarRender?: ICustomNodeProps<T>['toolbarRender'];
15
+ /** 布局选项 */
16
+ layoutOptions?: ICustomNodeProps<T>['layoutOptions'];
17
+ /** 添加 */
18
+ onAddItem?: ICustomNodeProps<T>['onAddItem'];
19
+ /** 删除 */
20
+ onDelItem?: ICustomNodeProps<T>['onDelItem'];
21
+ /** 编辑 */
22
+ onEditItem?: ICustomNodeProps<T>['onEditItem'];
23
+ }
24
+ /** 自定义节点组件props */
25
+ export type ICustomNodeProps<T extends INodeData = INodeData> = NodeProps<FlowNode<T>> & {
26
+ toolbarRender?: (node: T) => React.ReactNode;
27
+ itemRender?: (node: T) => React.ReactNode;
28
+ layoutOptions?: ILayoutOptions;
29
+ actionChange?: () => void;
30
+ onAddItem?: (parentNode: T) => Promise<T>;
31
+ onDelItem?: (currentNode: T) => Promise<void>;
32
+ onEditItem?: (currentNode: T) => Promise<T>;
33
+ };
34
+ export interface ILayoutOptions {
35
+ /** 节点宽度 */
36
+ nodeWidth?: number;
37
+ /** 节点高度 */
38
+ nodeHeight?: number;
39
+ /** 节点垂直间距 */
40
+ /** 节点水平间距 */
41
+ /** 布局方向 */
42
+ direction?: 'TB' | 'LR';
43
+ }
44
+ export interface INodeData {
45
+ /** 节点id */
46
+ id: string;
47
+ /** 父级 id */
48
+ parentIds?: string[];
49
+ /** 子级 id */
50
+ childIds?: string[];
51
+ /** 节点数据 */
52
+ data?: {
53
+ label?: string;
54
+ [key: string]: unknown;
55
+ };
56
+ [key: string]: unknown;
57
+ }
58
+ export type RawReactFlowProps = NonNullable<GetProps<typeof ReactFlow>>;
59
+ export type FlowNode<T extends Record<string, unknown> = Record<string, unknown>> = Node<T> & {};
@@ -0,0 +1 @@
1
+ export {};
@@ -6,6 +6,7 @@ export * from './base-table';
6
6
  export * from './big-input';
7
7
  export * from './data-cell';
8
8
  export * from './file-viewer';
9
+ export * from './flow';
9
10
  export * from './icons';
10
11
  export * from './media-viewer';
11
12
  export * from './tiptap-editor';
@@ -6,6 +6,7 @@ export * from "./base-table";
6
6
  export * from "./big-input";
7
7
  export * from "./data-cell";
8
8
  export * from "./file-viewer";
9
+ export * from "./flow";
9
10
  export * from "./icons";
10
11
  export * from "./media-viewer";
11
12
  export * from "./tiptap-editor";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/rex-design",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -51,6 +51,7 @@
51
51
  "@ant-design/icons": "^6.0.0",
52
52
  "@ant-design/pro-components": "^2.8.10",
53
53
  "@ant-design/pro-form": "^2.32.0",
54
+ "@dagrejs/dagre": "^1.1.8",
54
55
  "@iconify/react": "^6.0.2",
55
56
  "@js-preview/pdf": "^2.0.10",
56
57
  "@tiptap/core": "^2.12.0",
@@ -68,6 +69,7 @@
68
69
  "@tiptap/pm": "^2.12.0",
69
70
  "@tiptap/react": "^2.12.0",
70
71
  "@tiptap/starter-kit": "^2.12.0",
72
+ "@xyflow/react": "^12.10.0",
71
73
  "ahooks": "^3.9.6",
72
74
  "antd": "^5.29.3",
73
75
  "classnames": "^2.5.1",
@@ -106,6 +108,8 @@
106
108
  "@ant-design/icons": ">=5.0.0",
107
109
  "@ant-design/pro-components": ">=2.0.0",
108
110
  "@ant-design/pro-form": ">=2.0.0",
111
+ "@dagrejs/dagre": ">=1.1.8",
112
+ "@xyflow/react": ">=12.10.0",
109
113
  "antd": ">=5.0.0",
110
114
  "react": ">=16.9.0",
111
115
  "react-dom": ">=16.9.0",