@rxflow/mind-map 0.0.1-alpha.0
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.
- package/README.md +41 -0
- package/cjs/constants.d.ts +14 -0
- package/cjs/constants.d.ts.map +1 -0
- package/cjs/constants.js +20 -0
- package/cjs/index.d.ts +7 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +90 -0
- package/cjs/nodes/Topic/index.d.ts +4 -0
- package/cjs/nodes/Topic/index.d.ts.map +1 -0
- package/cjs/nodes/Topic/index.js +24 -0
- package/cjs/nodes/TopicBranch/index.d.ts +4 -0
- package/cjs/nodes/TopicBranch/index.d.ts.map +1 -0
- package/cjs/nodes/TopicBranch/index.js +24 -0
- package/cjs/nodes/TopicChild/index.d.ts +5 -0
- package/cjs/nodes/TopicChild/index.d.ts.map +1 -0
- package/cjs/nodes/TopicChild/index.js +105 -0
- package/cjs/nodes/TopicChild/index.less +58 -0
- package/cjs/nodes/index.d.ts +6 -0
- package/cjs/nodes/index.d.ts.map +1 -0
- package/cjs/nodes/index.js +48 -0
- package/cjs/types.d.ts +77 -0
- package/cjs/types.d.ts.map +1 -0
- package/cjs/types.js +5 -0
- package/cjs/utils/getHandles.d.ts +4 -0
- package/cjs/utils/getHandles.d.ts.map +1 -0
- package/cjs/utils/getHandles.js +44 -0
- package/cjs/utils/getNodeBoundWidth.d.ts +4 -0
- package/cjs/utils/getNodeBoundWidth.d.ts.map +1 -0
- package/cjs/utils/getNodeBoundWidth.js +36 -0
- package/esm/constants.d.ts +14 -0
- package/esm/constants.d.ts.map +1 -0
- package/esm/constants.js +15 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +68 -0
- package/esm/nodes/Topic/index.d.ts +4 -0
- package/esm/nodes/Topic/index.d.ts.map +1 -0
- package/esm/nodes/Topic/index.js +20 -0
- package/esm/nodes/TopicBranch/index.d.ts +4 -0
- package/esm/nodes/TopicBranch/index.d.ts.map +1 -0
- package/esm/nodes/TopicBranch/index.js +20 -0
- package/esm/nodes/TopicChild/index.d.ts +5 -0
- package/esm/nodes/TopicChild/index.d.ts.map +1 -0
- package/esm/nodes/TopicChild/index.js +118 -0
- package/esm/nodes/TopicChild/index.less +58 -0
- package/esm/nodes/index.d.ts +6 -0
- package/esm/nodes/index.d.ts.map +1 -0
- package/esm/nodes/index.js +42 -0
- package/esm/types.d.ts +77 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +1 -0
- package/esm/utils/getHandles.d.ts +4 -0
- package/esm/utils/getHandles.d.ts.map +1 -0
- package/esm/utils/getHandles.js +37 -0
- package/esm/utils/getNodeBoundWidth.d.ts +4 -0
- package/esm/utils/getNodeBoundWidth.d.ts.map +1 -0
- package/esm/utils/getNodeBoundWidth.js +30 -0
- package/package.json +49 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getNodeBoundWidth = getNodeBoundWidth;
|
|
7
|
+
var _base = require("@rxflow/base");
|
|
8
|
+
/**
|
|
9
|
+
* @author: yanxianliang
|
|
10
|
+
* @date: 2025-07-02 20:29
|
|
11
|
+
* @desc: 计算节点宽度
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function calcAutoWidth(label, theme) {
|
|
17
|
+
const fontStyle = `${theme.fontSize}px ${theme.fontFamily}`;
|
|
18
|
+
const textWidth = (0, _base.measureTextWidth)(label, fontStyle);
|
|
19
|
+
return textWidth + 6 * 2; // margin 5px
|
|
20
|
+
}
|
|
21
|
+
function getNodeBoundWidth(defaultWidth, node, theme) {
|
|
22
|
+
const topicNode = node;
|
|
23
|
+
const {
|
|
24
|
+
width,
|
|
25
|
+
label = ''
|
|
26
|
+
} = topicNode;
|
|
27
|
+
if (width === 'auto') {
|
|
28
|
+
// 自动计算
|
|
29
|
+
|
|
30
|
+
const widthSize = calcAutoWidth(label, theme);
|
|
31
|
+
const minWidth = topicNode?.minWidth ?? widthSize;
|
|
32
|
+
const maxWidth = topicNode?.maxWidth ?? widthSize;
|
|
33
|
+
return Math.min(Math.max(widthSize, minWidth), maxWidth);
|
|
34
|
+
}
|
|
35
|
+
return defaultWidth; // 默认值
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-09-10 17:25
|
|
4
|
+
* @modified:2025/9/10 17:25 by yanxianliang
|
|
5
|
+
* @desc: 内置常量配置
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum MindMapNodeEnum {
|
|
10
|
+
Topic = "topic",
|
|
11
|
+
TopicBranch = "topic-branch",
|
|
12
|
+
TopicChild = "topic-child"
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,WAAW,iBAAgB;IAC3B,UAAU,gBAAgB;CAC3B"}
|
package/esm/constants.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-09-10 17:25
|
|
4
|
+
* @modified:2025/9/10 17:25 by yanxianliang
|
|
5
|
+
* @desc: 内置常量配置
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export var MindMapNodeEnum = /*#__PURE__*/function (MindMapNodeEnum) {
|
|
11
|
+
MindMapNodeEnum["Topic"] = "topic";
|
|
12
|
+
MindMapNodeEnum["TopicBranch"] = "topic-branch";
|
|
13
|
+
MindMapNodeEnum["TopicChild"] = "topic-child";
|
|
14
|
+
return MindMapNodeEnum;
|
|
15
|
+
}({});
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MindMapFlowProps } from "./";
|
|
3
|
+
declare const MindMapFlow: (props: import("react").PropsWithChildren<MindMapFlowProps>) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export default MindMapFlow;
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './constants';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAqB,gBAAgB,EAAC,WAAyB;AAoCtE,QAAA,MAAM,WAAW,yGAmBM,CAAA;AAEvB,eAAe,WAAW,CAAC;AAE3B,cAAc,SAAS,CAAC;AAExB,cAAc,aAAa,CAAC"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
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); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
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); }
|
|
13
|
+
/*
|
|
14
|
+
* @author: yanxianliang
|
|
15
|
+
* @date: 2025-06-01 18:36
|
|
16
|
+
* @desc: 资产树 / 脑图
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
19
|
+
*/
|
|
20
|
+
import { createFlow, Flow, mindMapLayout } from "@rxflow/base";
|
|
21
|
+
import { useMemo } from "react";
|
|
22
|
+
import { nodeTypes } from "./nodes";
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
var fitViewOptions = {
|
|
25
|
+
minZoom: 1,
|
|
26
|
+
maxZoom: 1
|
|
27
|
+
};
|
|
28
|
+
var omitProps = ['root', 'layoutType', 'showTooltip'];
|
|
29
|
+
var fn = function fn() {};
|
|
30
|
+
var usePropsTransformer = function usePropsTransformer(props) {
|
|
31
|
+
var _props$nodeTypes = props.nodeTypes,
|
|
32
|
+
customNodeTypes = _props$nodeTypes === void 0 ? [] : _props$nodeTypes,
|
|
33
|
+
root = props.root;
|
|
34
|
+
var nodes = useMemo(function () {
|
|
35
|
+
return root ? [root] : [];
|
|
36
|
+
}, [root]);
|
|
37
|
+
return _objectSpread(_objectSpread({
|
|
38
|
+
minZoom: 1,
|
|
39
|
+
maxZoom: 1,
|
|
40
|
+
onNodeClick: fn
|
|
41
|
+
}, props), {}, {
|
|
42
|
+
autoCenter: false,
|
|
43
|
+
fitViewOptions: fitViewOptions,
|
|
44
|
+
forceLayout: false,
|
|
45
|
+
nodes: nodes,
|
|
46
|
+
omitProps: omitProps,
|
|
47
|
+
readOnly: true,
|
|
48
|
+
nodeTypes: [].concat(_toConsumableArray(nodeTypes), _toConsumableArray(customNodeTypes))
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
var MindMapFlow = createFlow(function (props) {
|
|
52
|
+
var theme = props.theme,
|
|
53
|
+
children = props.children;
|
|
54
|
+
var layout = useMemo(function () {
|
|
55
|
+
return mindMapLayout.bind(null, {
|
|
56
|
+
hGap: theme === null || theme === void 0 ? void 0 : theme.hGap,
|
|
57
|
+
vGap: theme === null || theme === void 0 ? void 0 : theme.vGap,
|
|
58
|
+
markerType: theme === null || theme === void 0 ? void 0 : theme.markerType
|
|
59
|
+
});
|
|
60
|
+
}, []);
|
|
61
|
+
return /*#__PURE__*/_jsx(Flow, _objectSpread(_objectSpread({}, props), {}, {
|
|
62
|
+
layout: layout,
|
|
63
|
+
children: children
|
|
64
|
+
}));
|
|
65
|
+
}, usePropsTransformer);
|
|
66
|
+
export default MindMapFlow;
|
|
67
|
+
export * from "./types";
|
|
68
|
+
export * from "./constants";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AASA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAG/C,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,aAAa,CAItD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/*
|
|
8
|
+
* @author: yanxianliang
|
|
9
|
+
* @date: 2025-06-01 20:44
|
|
10
|
+
* @desc: Topic Node
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import React from "react";
|
|
16
|
+
import { TopicChildNode } from "../TopicChild";
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
export var TopicNode = function TopicNode(props) {
|
|
19
|
+
return /*#__PURE__*/_jsx(TopicChildNode, _objectSpread({}, props));
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,mBAAmB,CAIlE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/*
|
|
8
|
+
* @author: yanxianliang
|
|
9
|
+
* @date: 2025-06-01 20:44
|
|
10
|
+
* @desc: Topic Node
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import React from "react";
|
|
16
|
+
import { TopicChildNode } from "../TopicChild";
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
export var TopicBranchNode = function TopicBranchNode(props) {
|
|
19
|
+
return /*#__PURE__*/_jsx(TopicChildNode, _objectSpread({}, props));
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAC,aAAa,EAAwC,MAAM,aAAa,CAAC;AAEjF,OAAO,cAAc,CAAC;AAItB,OAAO,EAAoC,iBAAiB,EAAiD,MAAM,cAAc,CAAC;AAGlI,eAAO,MAAM,cAAc,kCAmEyF,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
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 _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; }
|
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
|
+
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); }
|
|
5
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
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."); }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
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; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
/*
|
|
16
|
+
* @author: yanxianliang
|
|
17
|
+
* @date: 2025-06-01 20:44
|
|
18
|
+
* @desc: Topic Node
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import React, { useMemo } from "react";
|
|
24
|
+
import { useInternalNode } from "@xyflow/react";
|
|
25
|
+
import { isEqual } from "lodash";
|
|
26
|
+
import "./index.less";
|
|
27
|
+
import cc from 'classcat';
|
|
28
|
+
import { useToken } from "antd/es/theme/internal";
|
|
29
|
+
import { useMemoizedFn } from "ahooks";
|
|
30
|
+
import { Tooltip, useTheme, CollapseButton, usePropsSelector, HiddenHandle, useForceUpdate } from "@rxflow/base";
|
|
31
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
32
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
33
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
34
|
+
export var TopicChildNode = /*#__PURE__*/React.memo(function (props) {
|
|
35
|
+
var _usePropsSelector, _internalNode$interna2;
|
|
36
|
+
var data = props.data,
|
|
37
|
+
height = props.height,
|
|
38
|
+
type = props.type,
|
|
39
|
+
id = props.id;
|
|
40
|
+
var _ref = data,
|
|
41
|
+
label = _ref.label,
|
|
42
|
+
level = _ref.level,
|
|
43
|
+
childCount = _ref.childCount,
|
|
44
|
+
collapsed = _ref.collapsed,
|
|
45
|
+
children = _ref.children,
|
|
46
|
+
ellipsis = _ref.ellipsis; // 主题配置
|
|
47
|
+
|
|
48
|
+
var theme = useTheme();
|
|
49
|
+
var showTooltip = (_usePropsSelector = usePropsSelector(function (state) {
|
|
50
|
+
return state.showTooltip;
|
|
51
|
+
})) !== null && _usePropsSelector !== void 0 ? _usePropsSelector : 'ellipsis';
|
|
52
|
+
var _useToken = useToken(),
|
|
53
|
+
_useToken2 = _slicedToArray(_useToken, 2),
|
|
54
|
+
_ = _useToken2[0],
|
|
55
|
+
token = _useToken2[1];
|
|
56
|
+
var triggerLayout = useForceUpdate();
|
|
57
|
+
var internalNode = useInternalNode(id);
|
|
58
|
+
var ellipsisRow = useMemo(function () {
|
|
59
|
+
if (typeof height === 'number' && token.lineHeight && ellipsis === 'multiLine' && theme.fontSize) {
|
|
60
|
+
return Math.floor(height / (theme.fontSize * token.lineHeight));
|
|
61
|
+
}
|
|
62
|
+
return 1;
|
|
63
|
+
}, [token.lineHeight, height, theme.fontSize]);
|
|
64
|
+
var childrenCounts = childCount !== null && childCount !== void 0 ? childCount : children === null || children === void 0 ? void 0 : children.length;
|
|
65
|
+
var onCollapsed = useMemoizedFn(function (collapsed) {
|
|
66
|
+
// 修改data 属性,触发relayout
|
|
67
|
+
data.collapsed = collapsed;
|
|
68
|
+
// 触发relayout
|
|
69
|
+
triggerLayout();
|
|
70
|
+
});
|
|
71
|
+
var canTooltipShow = useMemoizedFn(function (event) {
|
|
72
|
+
var target = event.currentTarget;
|
|
73
|
+
if (showTooltip) {
|
|
74
|
+
var textElement = target.firstElementChild;
|
|
75
|
+
return showTooltip === 'ellipsis' ? textElement && textElement.scrollHeight > textElement.clientHeight : true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
var handles = useMemo(function () {
|
|
80
|
+
var _internalNode$interna;
|
|
81
|
+
var _ref2 = (internalNode === null || internalNode === void 0 || (_internalNode$interna = internalNode.internals) === null || _internalNode$interna === void 0 ? void 0 : _internalNode$interna.handleBounds) || {},
|
|
82
|
+
_ref2$source = _ref2.source,
|
|
83
|
+
source = _ref2$source === void 0 ? [] : _ref2$source,
|
|
84
|
+
target = _ref2.target;
|
|
85
|
+
return [].concat(_toConsumableArray(source || []), _toConsumableArray(target || []));
|
|
86
|
+
}, [internalNode === null || internalNode === void 0 || (_internalNode$interna2 = internalNode.internals) === null || _internalNode$interna2 === void 0 ? void 0 : _internalNode$interna2.handleBounds]);
|
|
87
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
88
|
+
children: [handles === null || handles === void 0 ? void 0 : handles.map(function (handle) {
|
|
89
|
+
return /*#__PURE__*/_jsx(HiddenHandle, {
|
|
90
|
+
type: handle.type,
|
|
91
|
+
position: handle.position,
|
|
92
|
+
style: {
|
|
93
|
+
left: handle.x,
|
|
94
|
+
top: handle.y
|
|
95
|
+
}
|
|
96
|
+
}, "".concat(handle.id, "_").concat(handle.type));
|
|
97
|
+
}), /*#__PURE__*/_jsx(Tooltip, {
|
|
98
|
+
title: label,
|
|
99
|
+
canTooltipShow: canTooltipShow,
|
|
100
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
101
|
+
className: cc(['rxflow-topic-container', "rxflow-".concat(type)]),
|
|
102
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
103
|
+
className: cc(['rxflow-topic-text', _defineProperty({}, 'rxflow-topic-text-link', level === 'link')]),
|
|
104
|
+
style: {
|
|
105
|
+
WebkitLineClamp: ellipsisRow
|
|
106
|
+
},
|
|
107
|
+
children: label
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
}), childrenCounts ? /*#__PURE__*/_jsx(CollapseButton, {
|
|
111
|
+
count: childrenCounts,
|
|
112
|
+
collapsed: collapsed,
|
|
113
|
+
onCollapse: onCollapsed
|
|
114
|
+
}) : null]
|
|
115
|
+
});
|
|
116
|
+
}, function (prevProps, nextProps) {
|
|
117
|
+
return isEqual(prevProps.data, nextProps.data);
|
|
118
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.rxflow-topic {
|
|
2
|
+
&,&-branch{
|
|
3
|
+
align-items: center;
|
|
4
|
+
background-color: rgb(239, 244, 255);
|
|
5
|
+
border: 1px solid var(--primary-color);
|
|
6
|
+
border-radius: 6px;
|
|
7
|
+
|
|
8
|
+
&:hover {
|
|
9
|
+
box-shadow: 0 0 3px 2px var(--primary-color-lighten);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&-child {
|
|
14
|
+
align-items: end;
|
|
15
|
+
transform: translate(0, -50%) translate(0, 1px);
|
|
16
|
+
&:after {
|
|
17
|
+
content: '';
|
|
18
|
+
display: block;
|
|
19
|
+
position: absolute;
|
|
20
|
+
bottom: 0;
|
|
21
|
+
height: 2px;
|
|
22
|
+
background-color: var(--primary-color);
|
|
23
|
+
left: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:hover {
|
|
28
|
+
&:after {
|
|
29
|
+
box-shadow: 0 2px 1px 0 var(--primary-color-lighten);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&-container {
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
display: flex;
|
|
39
|
+
padding: 5px 5px 4px;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
position: relative;
|
|
42
|
+
box-sizing: border-box;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&-text {
|
|
46
|
+
font-family: var(--font-family);
|
|
47
|
+
font-size: var(--font-size);
|
|
48
|
+
color: var(--text-color);
|
|
49
|
+
display: -webkit-box;
|
|
50
|
+
-webkit-line-clamp: 1; /* 默认1行 */
|
|
51
|
+
-webkit-box-orient: vertical;
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
|
|
54
|
+
&&-link {
|
|
55
|
+
color: var(--link-text-color);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAI7C;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,EAwB1C,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-06-20 21:48
|
|
4
|
+
* @desc: nodeTypes register
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
+
*/
|
|
8
|
+
import { MindMapNodeEnum } from "../constants";
|
|
9
|
+
import { TopicNode } from "./Topic";
|
|
10
|
+
import { TopicBranchNode } from "./TopicBranch";
|
|
11
|
+
import { TopicChildNode } from "./TopicChild";
|
|
12
|
+
import { getNodeBoundWidth } from "../utils/getNodeBoundWidth";
|
|
13
|
+
import { getHandles } from "../utils/getHandles";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 内置的节点类型
|
|
17
|
+
*/
|
|
18
|
+
export var nodeTypes = [{
|
|
19
|
+
type: MindMapNodeEnum.Topic,
|
|
20
|
+
component: TopicNode,
|
|
21
|
+
defaultSize: {
|
|
22
|
+
width: getNodeBoundWidth.bind(this, 160),
|
|
23
|
+
height: 50
|
|
24
|
+
},
|
|
25
|
+
measureHandles: getHandles
|
|
26
|
+
}, {
|
|
27
|
+
type: MindMapNodeEnum.TopicBranch,
|
|
28
|
+
component: TopicBranchNode,
|
|
29
|
+
defaultSize: {
|
|
30
|
+
width: getNodeBoundWidth.bind(this, 100),
|
|
31
|
+
height: 40
|
|
32
|
+
},
|
|
33
|
+
measureHandles: getHandles
|
|
34
|
+
}, {
|
|
35
|
+
type: MindMapNodeEnum.TopicChild,
|
|
36
|
+
component: TopicChildNode,
|
|
37
|
+
defaultSize: {
|
|
38
|
+
width: getNodeBoundWidth.bind(this, 60),
|
|
39
|
+
height: 30
|
|
40
|
+
},
|
|
41
|
+
measureHandles: getHandles
|
|
42
|
+
}];
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BaseThemeConfig, IBaseFlowProps, MindMapLayoutConfig } from "@rxflow/base";
|
|
2
|
+
import { MindMapNodeEnum } from "./constants";
|
|
3
|
+
export interface MiniMapThemeConfig extends BaseThemeConfig, MindMapLayoutConfig {
|
|
4
|
+
/**
|
|
5
|
+
* @description 折叠按钮形状
|
|
6
|
+
* @default 'rect'
|
|
7
|
+
*/
|
|
8
|
+
collapseButtonShape?: 'rect' | 'circle';
|
|
9
|
+
}
|
|
10
|
+
export type LayoutType = 'compactBox' | 'mindmap';
|
|
11
|
+
export type NodeConfig = {
|
|
12
|
+
/**
|
|
13
|
+
* @description 节点默认宽度,当节点数据中未配置宽度时,使用全局默认宽度,不配置则使用对应节点类型内置的宽度
|
|
14
|
+
*/
|
|
15
|
+
width?: number | 'auto';
|
|
16
|
+
/**
|
|
17
|
+
* @description 节点高度,当节点数据中未配置宽度时,使用全局默认宽度,不配置则使用对应节点类型内置的宽度
|
|
18
|
+
*/
|
|
19
|
+
height?: number;
|
|
20
|
+
/**
|
|
21
|
+
* @description 最小宽度限制
|
|
22
|
+
*/
|
|
23
|
+
minWidth?: number;
|
|
24
|
+
/**
|
|
25
|
+
* @description 最大宽度限制
|
|
26
|
+
*/
|
|
27
|
+
maxWidth?: number;
|
|
28
|
+
};
|
|
29
|
+
export type MindMapExtendProps = {
|
|
30
|
+
/**
|
|
31
|
+
* @description 布局方式
|
|
32
|
+
* @default 'mindmap'
|
|
33
|
+
*/
|
|
34
|
+
layoutType?: LayoutType;
|
|
35
|
+
/**
|
|
36
|
+
* @description 主题配置
|
|
37
|
+
*/
|
|
38
|
+
theme?: MiniMapThemeConfig;
|
|
39
|
+
/**
|
|
40
|
+
* @description 树结构数据源
|
|
41
|
+
*/
|
|
42
|
+
root?: TopicNodeType | CustomNodeType;
|
|
43
|
+
/**
|
|
44
|
+
* @description tooltip 显示策略
|
|
45
|
+
* @default 'ellipsis'
|
|
46
|
+
*/
|
|
47
|
+
showTooltip?: 'always' | 'ellipsis' | false;
|
|
48
|
+
};
|
|
49
|
+
export type MindMapFlowProps = Omit<IBaseFlowProps, 'nodes' | 'edges' | 'defaultEdges' | 'defaultNodes' | 'markers' | 'readOnly' | 'forceLayout' | 'layout' | 'autoCenter' | 'showLegend'> & MindMapExtendProps & {};
|
|
50
|
+
export type DisplayLevel = 'link';
|
|
51
|
+
export type TopicChildNodeType = NodeConfig & {
|
|
52
|
+
id: string;
|
|
53
|
+
type: MindMapNodeEnum.TopicChild;
|
|
54
|
+
label: string;
|
|
55
|
+
level?: DisplayLevel;
|
|
56
|
+
ellipsis?: 'multiLine';
|
|
57
|
+
side?: 'left' | 'right';
|
|
58
|
+
};
|
|
59
|
+
export type TopicBranchNodeType = Omit<TopicChildNodeType, 'type'> & {
|
|
60
|
+
type: MindMapNodeEnum.TopicBranch;
|
|
61
|
+
collapsed?: boolean;
|
|
62
|
+
childCount?: number;
|
|
63
|
+
children?: Array<TopicBranchNodeType | TopicChildNodeType>;
|
|
64
|
+
};
|
|
65
|
+
export type TopicNodeType = Omit<TopicBranchNodeType, 'type'> & {
|
|
66
|
+
type: MindMapNodeEnum.Topic;
|
|
67
|
+
};
|
|
68
|
+
export type InnerNodeType = TopicNodeType | TopicBranchNodeType | TopicChildNodeType;
|
|
69
|
+
export type CustomNodeType = {
|
|
70
|
+
type: string;
|
|
71
|
+
id: string;
|
|
72
|
+
collapsed?: boolean;
|
|
73
|
+
childCount?: number;
|
|
74
|
+
children?: Array<CustomNodeType>;
|
|
75
|
+
side?: 'left' | 'right';
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAClF,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,kBAAmB,SAAQ,eAAe,EAAE,mBAAmB;IAC9E;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CACzC;AAED,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;AAGlD,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAExB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAA;AAGD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE,aAAa,GAAG,cAAc,CAAC;IAEtC;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,KAAK,CAAC;CAC7C,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,EAChD,OAAO,GACP,OAAO,GACP,cAAc,GACd,cAAc,GACd,SAAS,GACT,UAAU,GACV,aAAa,GACb,QAAQ,GACR,YAAY,GACZ,YAAY,CACb,GAAG,kBAAkB,GAAG,EAAE,CAAA;AAE3B,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,eAAe,CAAC,UAAU,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB,CAAA;AAGD,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,GAAG;IACnE,IAAI,EAAE,eAAe,CAAC,WAAW,CAAC;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,mBAAmB,GAAG,kBAAkB,CAAC,CAAC;CAC5D,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG;IAC9D,IAAI,EAAE,eAAe,CAAC,KAAK,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAGrF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB,CAAA"}
|
package/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHandles.d.ts","sourceRoot":"","sources":["getHandles.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAEhD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,gBAAgB,CAwBvD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-07-02 20:15
|
|
4
|
+
* @desc: 计算handles 信息
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
+
*/
|
|
8
|
+
import { Position } from "@xyflow/react";
|
|
9
|
+
export function getHandles(node) {
|
|
10
|
+
var id = node.id,
|
|
11
|
+
_node$width = node.width,
|
|
12
|
+
width = _node$width === void 0 ? 1 : _node$width,
|
|
13
|
+
_node$height = node.height,
|
|
14
|
+
height = _node$height === void 0 ? 1 : _node$height;
|
|
15
|
+
return {
|
|
16
|
+
source: [{
|
|
17
|
+
height: 0,
|
|
18
|
+
id: null,
|
|
19
|
+
nodeId: id,
|
|
20
|
+
position: Position.Right,
|
|
21
|
+
type: "source",
|
|
22
|
+
width: 0,
|
|
23
|
+
x: width,
|
|
24
|
+
y: height / 2
|
|
25
|
+
}],
|
|
26
|
+
target: [{
|
|
27
|
+
height: 0,
|
|
28
|
+
id: null,
|
|
29
|
+
nodeId: id,
|
|
30
|
+
position: Position.Left,
|
|
31
|
+
type: "target",
|
|
32
|
+
width: 0,
|
|
33
|
+
x: 0,
|
|
34
|
+
y: height / 2
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNodeBoundWidth.d.ts","sourceRoot":"","sources":["getNodeBoundWidth.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EAAmB,eAAe,EAAC,MAAM,cAAc,CAAC;AAQ/D,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,UAWzF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-07-02 20:29
|
|
4
|
+
* @desc: 计算节点宽度
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { measureTextWidth } from "@rxflow/base";
|
|
10
|
+
function calcAutoWidth(label, theme) {
|
|
11
|
+
var fontStyle = "".concat(theme.fontSize, "px ").concat(theme.fontFamily);
|
|
12
|
+
var textWidth = measureTextWidth(label, fontStyle);
|
|
13
|
+
return textWidth + 6 * 2; // margin 5px
|
|
14
|
+
}
|
|
15
|
+
export function getNodeBoundWidth(defaultWidth, node, theme) {
|
|
16
|
+
var topicNode = node;
|
|
17
|
+
var width = topicNode.width,
|
|
18
|
+
_topicNode$label = topicNode.label,
|
|
19
|
+
label = _topicNode$label === void 0 ? '' : _topicNode$label;
|
|
20
|
+
if (width === 'auto') {
|
|
21
|
+
var _topicNode$minWidth, _topicNode$maxWidth;
|
|
22
|
+
// 自动计算
|
|
23
|
+
|
|
24
|
+
var widthSize = calcAutoWidth(label, theme);
|
|
25
|
+
var minWidth = (_topicNode$minWidth = topicNode === null || topicNode === void 0 ? void 0 : topicNode.minWidth) !== null && _topicNode$minWidth !== void 0 ? _topicNode$minWidth : widthSize;
|
|
26
|
+
var maxWidth = (_topicNode$maxWidth = topicNode === null || topicNode === void 0 ? void 0 : topicNode.maxWidth) !== null && _topicNode$maxWidth !== void 0 ? _topicNode$maxWidth : widthSize;
|
|
27
|
+
return Math.min(Math.max(widthSize, minWidth), maxWidth);
|
|
28
|
+
}
|
|
29
|
+
return defaultWidth; // 默认值
|
|
30
|
+
}
|