@hkyhy/marsun-components-core 0.1.66 → 0.1.67
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.
|
@@ -13,6 +13,13 @@ export type OrgTreeProps = {
|
|
|
13
13
|
/** 展示节点内增删改操作 */
|
|
14
14
|
editable?: boolean;
|
|
15
15
|
className?: string;
|
|
16
|
+
/**
|
|
17
|
+
* 初始展开深度:0=全部折叠;1=展开根(露出一级子,默认);
|
|
18
|
+
* 传很大的数或 Infinity ≈ 全展开(仅小树建议)。
|
|
19
|
+
*/
|
|
20
|
+
defaultExpandDepth?: number;
|
|
21
|
+
/** 虚拟列表可视高度(px);节点多时默认开启 */
|
|
22
|
+
virtualHeight?: number | false;
|
|
16
23
|
/** 受控选中(点选节点,如右侧岗位面板) */
|
|
17
24
|
selectedKeys?: Key[];
|
|
18
25
|
onSelect?: (node: {
|
|
@@ -38,8 +45,8 @@ export type OrgTreeProps = {
|
|
|
38
45
|
deleteOkType?: 'primary' | 'danger';
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
41
|
-
* 组织树(对齐 Assets
|
|
42
|
-
* 纯 UI,无业务 API
|
|
48
|
+
* 组织树(对齐 Assets 组织架构行为):可配置展开深度、节点 hover 增删改。
|
|
49
|
+
* 纯 UI,无业务 API。大树勿默认全展开(会卡死 DOM)。
|
|
43
50
|
*/
|
|
44
51
|
declare const OrgTree: React.FC<OrgTreeProps>;
|
|
45
52
|
export default OrgTree;
|
|
@@ -1,154 +1,171 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Spin as
|
|
3
|
-
import
|
|
4
|
-
import { useMemo as
|
|
1
|
+
import { jsx as l, jsxs as p, Fragment as F } from "react/jsx-runtime";
|
|
2
|
+
import { Spin as L, Tree as M, Tooltip as V, Space as q, Button as N, Popconfirm as G } from "antd";
|
|
3
|
+
import c from "classnames";
|
|
4
|
+
import { useMemo as y, useState as H, useEffect as J } from "react";
|
|
5
5
|
import m from "./style.module.scss.js";
|
|
6
|
-
import { Plus as
|
|
7
|
-
import { Pencil as
|
|
8
|
-
import { Trash2 as
|
|
9
|
-
function
|
|
10
|
-
var
|
|
6
|
+
import { Plus as Q } from "../Icons/Plus.js";
|
|
7
|
+
import { Pencil as R } from "../Icons/Pencil.js";
|
|
8
|
+
import { Trash2 as U } from "../Icons/Trash2.js";
|
|
9
|
+
function I(n, a) {
|
|
10
|
+
var t;
|
|
11
|
+
if (a <= 0 || !n.length) return [];
|
|
11
12
|
const i = [];
|
|
12
|
-
for (const
|
|
13
|
-
|
|
13
|
+
for (const s of n)
|
|
14
|
+
(t = s.children) != null && t.length && (i.push(s.id), a > 1 && i.push(...I(s.children, a - 1)));
|
|
14
15
|
return i;
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
function S(n) {
|
|
18
|
+
var i;
|
|
19
|
+
let a = 0;
|
|
20
|
+
for (const t of n)
|
|
21
|
+
a += 1, (i = t.children) != null && i.length && (a += S(t.children));
|
|
22
|
+
return a;
|
|
23
|
+
}
|
|
24
|
+
function T(n, a) {
|
|
25
|
+
var i;
|
|
26
|
+
for (const t of n) {
|
|
27
|
+
if (t.id === a)
|
|
28
|
+
return { id: t.id, name: t.name, parentId: t.parentId ?? null };
|
|
29
|
+
if ((i = t.children) != null && i.length) {
|
|
30
|
+
const s = T(t.children, a);
|
|
31
|
+
if (s) return s;
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
return null;
|
|
27
35
|
}
|
|
28
|
-
const
|
|
29
|
-
nodes:
|
|
30
|
-
loading:
|
|
31
|
-
editable:
|
|
32
|
-
className:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const D = ({
|
|
37
|
+
nodes: n,
|
|
38
|
+
loading: a = !1,
|
|
39
|
+
editable: i = !1,
|
|
40
|
+
className: t,
|
|
41
|
+
defaultExpandDepth: s = 1,
|
|
42
|
+
virtualHeight: P,
|
|
43
|
+
selectedKeys: w,
|
|
44
|
+
onSelect: z,
|
|
45
|
+
onAdd: f,
|
|
46
|
+
onEdit: g,
|
|
47
|
+
onDelete: h,
|
|
38
48
|
deleteConfirmTitle: E = "确认删除该节点?",
|
|
39
|
-
deleteOkText:
|
|
40
|
-
deleteOkType:
|
|
49
|
+
deleteOkText: d = "删除",
|
|
50
|
+
deleteOkType: v = "danger"
|
|
41
51
|
}) => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
),
|
|
70
|
-
l ? /* @__PURE__ */ u(
|
|
71
|
-
v,
|
|
72
|
-
{
|
|
73
|
-
size: 0,
|
|
74
|
-
className: o("marsun-org-tree-actions", m["marsun-org-tree-actions"]),
|
|
75
|
-
children: [
|
|
76
|
-
g ? /* @__PURE__ */ t(
|
|
77
|
-
p,
|
|
78
|
-
{
|
|
79
|
-
type: "text",
|
|
80
|
-
size: "small",
|
|
81
|
-
"aria-label": "添加子节点",
|
|
82
|
-
icon: /* @__PURE__ */ t(O, { size: 14 }),
|
|
83
|
-
onClick: (e) => {
|
|
84
|
-
e.stopPropagation(), g(r.id);
|
|
52
|
+
const K = y(() => S(n), [n]), x = y(
|
|
53
|
+
() => I(n, s),
|
|
54
|
+
[n, s]
|
|
55
|
+
), [j, C] = H(x);
|
|
56
|
+
J(() => {
|
|
57
|
+
C(x);
|
|
58
|
+
}, [x]);
|
|
59
|
+
const B = y(() => {
|
|
60
|
+
const o = (u) => u.map((r) => {
|
|
61
|
+
var k;
|
|
62
|
+
return {
|
|
63
|
+
key: r.id,
|
|
64
|
+
title: /* @__PURE__ */ p("div", { className: c("marsun-org-tree-row", m["marsun-org-tree-row"]), children: [
|
|
65
|
+
/* @__PURE__ */ l(
|
|
66
|
+
V,
|
|
67
|
+
{
|
|
68
|
+
title: r.nameExtra ? /* @__PURE__ */ p(F, { children: [
|
|
69
|
+
r.name,
|
|
70
|
+
r.nameExtra
|
|
71
|
+
] }) : r.name,
|
|
72
|
+
children: /* @__PURE__ */ p("span", { className: c("marsun-org-tree-name", m["marsun-org-tree-name"]), children: [
|
|
73
|
+
r.name,
|
|
74
|
+
r.nameExtra ? /* @__PURE__ */ l(
|
|
75
|
+
"span",
|
|
76
|
+
{
|
|
77
|
+
className: c("marsun-org-tree-extra", m["marsun-org-tree-extra"]),
|
|
78
|
+
children: r.nameExtra
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
) : null
|
|
81
|
+
] })
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
i ? /* @__PURE__ */ p(
|
|
85
|
+
q,
|
|
86
|
+
{
|
|
87
|
+
size: 0,
|
|
88
|
+
className: c("marsun-org-tree-actions", m["marsun-org-tree-actions"]),
|
|
89
|
+
children: [
|
|
90
|
+
f ? /* @__PURE__ */ l(
|
|
91
|
+
N,
|
|
92
|
+
{
|
|
93
|
+
type: "text",
|
|
94
|
+
size: "small",
|
|
95
|
+
"aria-label": "添加子节点",
|
|
96
|
+
icon: /* @__PURE__ */ l(Q, { size: 14 }),
|
|
97
|
+
onClick: (e) => {
|
|
98
|
+
e.stopPropagation(), f(r.id);
|
|
99
|
+
}
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
type: "text",
|
|
117
|
-
size: "small",
|
|
118
|
-
danger: !0,
|
|
119
|
-
"aria-label": x,
|
|
120
|
-
icon: /* @__PURE__ */ t(A, { size: 14 }),
|
|
121
|
-
onClick: (e) => e.stopPropagation()
|
|
101
|
+
) : null,
|
|
102
|
+
g ? /* @__PURE__ */ l(
|
|
103
|
+
N,
|
|
104
|
+
{
|
|
105
|
+
type: "text",
|
|
106
|
+
size: "small",
|
|
107
|
+
"aria-label": "编辑",
|
|
108
|
+
icon: /* @__PURE__ */ l(R, { size: 14 }),
|
|
109
|
+
onClick: (e) => {
|
|
110
|
+
e.stopPropagation(), g({
|
|
111
|
+
id: r.id,
|
|
112
|
+
name: r.name,
|
|
113
|
+
parentId: r.parentId ?? null
|
|
114
|
+
});
|
|
122
115
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
}
|
|
117
|
+
) : null,
|
|
118
|
+
h ? /* @__PURE__ */ l(
|
|
119
|
+
G,
|
|
120
|
+
{
|
|
121
|
+
title: E,
|
|
122
|
+
okText: d,
|
|
123
|
+
okType: v,
|
|
124
|
+
cancelText: "取消",
|
|
125
|
+
onConfirm: (e) => (e == null || e.stopPropagation(), h({ id: r.id, name: r.name })),
|
|
126
|
+
onCancel: (e) => e == null ? void 0 : e.stopPropagation(),
|
|
127
|
+
children: /* @__PURE__ */ l(
|
|
128
|
+
N,
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
size: "small",
|
|
132
|
+
danger: !0,
|
|
133
|
+
"aria-label": d,
|
|
134
|
+
icon: /* @__PURE__ */ l(U, { size: 14 }),
|
|
135
|
+
onClick: (e) => e.stopPropagation()
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
) : null
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
) : null
|
|
143
|
+
] }),
|
|
144
|
+
children: (k = r.children) != null && k.length ? o(r.children) : void 0
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
return o(n);
|
|
148
|
+
}, [n, i, f, g, h, E, d, v]), b = P === !1 ? void 0 : P ?? (K > 80 ? 520 : void 0);
|
|
149
|
+
return /* @__PURE__ */ l(L, { spinning: a, children: /* @__PURE__ */ l(
|
|
150
|
+
M,
|
|
135
151
|
{
|
|
136
|
-
className:
|
|
137
|
-
treeData:
|
|
138
|
-
expandedKeys:
|
|
139
|
-
onExpand: (
|
|
140
|
-
selectedKeys:
|
|
141
|
-
onSelect: (
|
|
142
|
-
if (!
|
|
143
|
-
const
|
|
144
|
-
|
|
152
|
+
className: c("marsun-org-tree", m["marsun-org-tree"], t),
|
|
153
|
+
treeData: B,
|
|
154
|
+
expandedKeys: j,
|
|
155
|
+
onExpand: (o) => C(o),
|
|
156
|
+
selectedKeys: w,
|
|
157
|
+
onSelect: (o) => {
|
|
158
|
+
if (!z) return;
|
|
159
|
+
const u = o[0] != null ? String(o[0]) : "";
|
|
160
|
+
z(u ? T(n, u) : null);
|
|
145
161
|
},
|
|
146
162
|
showLine: !0,
|
|
147
|
-
blockNode: !0
|
|
163
|
+
blockNode: !0,
|
|
164
|
+
...b ? { virtual: !0, height: b } : {}
|
|
148
165
|
}
|
|
149
166
|
) });
|
|
150
167
|
};
|
|
151
168
|
export {
|
|
152
|
-
|
|
169
|
+
D as default
|
|
153
170
|
};
|
|
154
171
|
//# sourceMappingURL=OrgTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrgTree.js","sources":["../../../src/components/OrgTree/OrgTree.tsx"],"sourcesContent":["import { Pencil, Plus, Trash2 } from '../Icons';\nimport { Button, Popconfirm, Space, Spin, Tooltip, Tree } from 'antd';\nimport type { DataNode } from 'antd/es/tree';\nimport classNames from 'classnames';\nimport React, { useEffect, useMemo, useState, type Key, type ReactNode } from 'react';\nimport styles from './style.module.scss';\n\nexport type OrgTreeNode = {\n id: string;\n name: string;\n parentId?: string | null;\n children?: OrgTreeNode[];\n /** 名称旁附加文案(如 mapped) */\n nameExtra?: ReactNode;\n};\n\nexport type OrgTreeProps = {\n nodes: OrgTreeNode[];\n loading?: boolean;\n /** 展示节点内增删改操作 */\n editable?: boolean;\n className?: string;\n /** 受控选中(点选节点,如右侧岗位面板) */\n selectedKeys?: Key[];\n onSelect?: (node: { id: string; name: string; parentId: string | null } | null) => void;\n onAdd?: (parentId: string) => void;\n onEdit?: (node: { id: string; name: string; parentId: string | null }) => void;\n /** 确认删除后回调;由业务执行 API */\n onDelete?: (node: { id: string; name: string }) => void | Promise<void>;\n /** 删除确认文案 */\n deleteConfirmTitle?: string;\n /** 确认钮文案(软禁用场景可传「禁用」) */\n deleteOkText?: string;\n deleteOkType?: 'primary' | 'danger';\n};\n\nfunction collectAllKeys(nodes: OrgTreeNode[]): string[] {\n const keys: string[] = [];\n for (const n of nodes) {\n keys.push(n.id);\n if (n.children?.length) keys.push(...collectAllKeys(n.children));\n }\n return keys;\n}\n\nfunction findOrgNode(\n list: OrgTreeNode[],\n id: string,\n): { id: string; name: string; parentId: string | null } | null {\n for (const n of list) {\n if (n.id === id) {\n return { id: n.id, name: n.name, parentId: n.parentId ?? null };\n }\n if (n.children?.length) {\n const hit = findOrgNode(n.children, id);\n if (hit) return hit;\n }\n }\n return null;\n}\n\n/**\n * 组织树(对齐 Assets 组织架构行为):默认展开、节点 hover 增删改。\n * 纯 UI,无业务 API。\n */\nconst OrgTree: React.FC<OrgTreeProps> = ({\n nodes,\n loading = false,\n editable = false,\n className,\n selectedKeys,\n onSelect,\n onAdd,\n onEdit,\n onDelete,\n deleteConfirmTitle = '确认删除该节点?',\n deleteOkText = '删除',\n deleteOkType = 'danger',\n}) => {\n const allKeys = useMemo(() => collectAllKeys(nodes), [nodes]);\n const [expandedKeys, setExpandedKeys] = useState<Key[]>([]);\n\n useEffect(() => {\n setExpandedKeys(allKeys);\n }, [allKeys]);\n\n const buildTreeNodes = (list: OrgTreeNode[]): DataNode[] =>\n list.map((node) => ({\n key: node.id,\n title: (\n <div className={classNames('marsun-org-tree-row', styles['marsun-org-tree-row'])}>\n <Tooltip\n title={\n node.nameExtra ? (\n <>\n {node.name}\n {node.nameExtra}\n </>\n ) : (\n node.name\n )\n }\n >\n <span className={classNames('marsun-org-tree-name', styles['marsun-org-tree-name'])}>\n {node.name}\n {node.nameExtra ? (\n <span\n className={classNames('marsun-org-tree-extra', styles['marsun-org-tree-extra'])}\n >\n {node.nameExtra}\n </span>\n ) : null}\n </span>\n </Tooltip>\n {editable ? (\n <Space\n size={0}\n className={classNames('marsun-org-tree-actions', styles['marsun-org-tree-actions'])}\n >\n {onAdd ? (\n <Button\n type=\"text\"\n size=\"small\"\n aria-label=\"添加子节点\"\n icon={<Plus size={14} />}\n onClick={(e) => {\n e.stopPropagation();\n onAdd(node.id);\n }}\n />\n ) : null}\n {onEdit ? (\n <Button\n type=\"text\"\n size=\"small\"\n aria-label=\"编辑\"\n icon={<Pencil size={14} />}\n onClick={(e) => {\n e.stopPropagation();\n onEdit({\n id: node.id,\n name: node.name,\n parentId: node.parentId ?? null,\n });\n }}\n />\n ) : null}\n {onDelete ? (\n <Popconfirm\n title={deleteConfirmTitle}\n okText={deleteOkText}\n okType={deleteOkType}\n cancelText=\"取消\"\n onConfirm={(e) => {\n e?.stopPropagation();\n return onDelete({ id: node.id, name: node.name });\n }}\n onCancel={(e) => e?.stopPropagation()}\n >\n <Button\n type=\"text\"\n size=\"small\"\n danger\n aria-label={deleteOkText}\n icon={<Trash2 size={14} />}\n onClick={(e) => e.stopPropagation()}\n />\n </Popconfirm>\n ) : null}\n </Space>\n ) : null}\n </div>\n ),\n children: node.children?.length ? buildTreeNodes(node.children) : undefined,\n }));\n\n const treeData = buildTreeNodes(nodes);\n\n return (\n <Spin spinning={loading}>\n <Tree\n className={classNames('marsun-org-tree', styles['marsun-org-tree'], className)}\n treeData={treeData}\n expandedKeys={expandedKeys}\n onExpand={(keys) => setExpandedKeys(keys)}\n selectedKeys={selectedKeys}\n onSelect={(keys) => {\n if (!onSelect) return;\n const id = keys[0] != null ? String(keys[0]) : '';\n onSelect(id ? findOrgNode(nodes, id) : null);\n }}\n showLine\n blockNode\n />\n </Spin>\n );\n};\n\nexport default OrgTree;\n"],"names":["collectAllKeys","nodes","keys","_a","findOrgNode","list","id","hit","OrgTree","loading","editable","className","selectedKeys","onSelect","onAdd","onEdit","onDelete","deleteConfirmTitle","deleteOkText","deleteOkType","allKeys","useMemo","expandedKeys","setExpandedKeys","useState","useEffect","buildTreeNodes","node","classNames","styles","jsx","Tooltip","jsxs","Fragment","Space","Button","Plus","Pencil","Popconfirm","Trash2","treeData","Spin","Tree"],"mappings":";;;;;;;;AAoCA,SAASA,EAAeC,GAAgC;;AACtD,QAAMC,IAAiB,CAAA;AACvB,aAAW,KAAKD;AACd,IAAAC,EAAK,KAAK,EAAE,EAAE,IACVC,IAAA,EAAE,aAAF,QAAAA,EAAY,UAAQD,EAAK,KAAK,GAAGF,EAAe,EAAE,QAAQ,CAAC;AAEjE,SAAOE;AACT;AAEA,SAASE,EACPC,GACAC,GAC8D;;AAC9D,aAAW,KAAKD,GAAM;AACpB,QAAI,EAAE,OAAOC;AACX,aAAO,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,MAAM,UAAU,EAAE,YAAY,KAAA;AAE3D,SAAIH,IAAA,EAAE,aAAF,QAAAA,EAAY,QAAQ;AACtB,YAAMI,IAAMH,EAAY,EAAE,UAAUE,CAAE;AACtC,UAAIC,EAAK,QAAOA;AAAA,IAClB;AAAA,EACF;AACA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AAM,GAAA,CAAI;AAAA,sBACxB,SAAS,CAAC,MAAM,EAAE,gBAAA;AAAA,oBAAgB;AAAA,kBAAA;AAAA,gBACpC;AAAA,cAAA,IAEA;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA,IAEJ;AAAA,MAAA,GACN;AAAA,MAEF,WAAUpC,IAAAwB,EAAK,aAAL,QAAAxB,EAAe,SAASuB,EAAeC,EAAK,QAAQ,IAAI;AAAA,IAAA;AAAA,GAClE,GAEEa,IAAWd,EAAezB,CAAK;AAErC,SACE,gBAAA6B,EAACW,GAAA,EAAK,UAAUhC,GACd,UAAA,gBAAAqB;AAAA,IAACY;AAAA,IAAA;AAAA,MACC,WAAWd,EAAW,mBAAmBC,EAAO,iBAAiB,GAAGlB,CAAS;AAAA,MAC7E,UAAA6B;AAAA,MACA,cAAAlB;AAAA,MACA,UAAU,CAACpB,MAASqB,EAAgBrB,CAAI;AAAA,MACxC,cAAAU;AAAA,MACA,UAAU,CAACV,MAAS;AAClB,YAAI,CAACW,EAAU;AACf,cAAMP,IAAKJ,EAAK,CAAC,KAAK,OAAO,OAAOA,EAAK,CAAC,CAAC,IAAI;AAC/C,QAAAW,EAASP,IAAKF,EAAYH,GAAOK,CAAE,IAAI,IAAI;AAAA,MAC7C;AAAA,MACA,UAAQ;AAAA,MACR,WAAS;AAAA,IAAA;AAAA,EAAA,GAEb;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"OrgTree.js","sources":["../../../src/components/OrgTree/OrgTree.tsx"],"sourcesContent":["import { Pencil, Plus, Trash2 } from '../Icons';\nimport { Button, Popconfirm, Space, Spin, Tooltip, Tree } from 'antd';\nimport type { DataNode } from 'antd/es/tree';\nimport classNames from 'classnames';\nimport React, { useEffect, useMemo, useState, type Key, type ReactNode } from 'react';\nimport styles from './style.module.scss';\n\nexport type OrgTreeNode = {\n id: string;\n name: string;\n parentId?: string | null;\n children?: OrgTreeNode[];\n /** 名称旁附加文案(如 mapped) */\n nameExtra?: ReactNode;\n};\n\nexport type OrgTreeProps = {\n nodes: OrgTreeNode[];\n loading?: boolean;\n /** 展示节点内增删改操作 */\n editable?: boolean;\n className?: string;\n /**\n * 初始展开深度:0=全部折叠;1=展开根(露出一级子,默认);\n * 传很大的数或 Infinity ≈ 全展开(仅小树建议)。\n */\n defaultExpandDepth?: number;\n /** 虚拟列表可视高度(px);节点多时默认开启 */\n virtualHeight?: number | false;\n /** 受控选中(点选节点,如右侧岗位面板) */\n selectedKeys?: Key[];\n onSelect?: (node: { id: string; name: string; parentId: string | null } | null) => void;\n onAdd?: (parentId: string) => void;\n onEdit?: (node: { id: string; name: string; parentId: string | null }) => void;\n /** 确认删除后回调;由业务执行 API */\n onDelete?: (node: { id: string; name: string }) => void | Promise<void>;\n /** 删除确认文案 */\n deleteConfirmTitle?: string;\n /** 确认钮文案(软禁用场景可传「禁用」) */\n deleteOkText?: string;\n deleteOkType?: 'primary' | 'danger';\n};\n\n/** 收集需展开的 key:depth=1 只展开根,露出一级子节点 */\nfunction collectExpandedKeys(nodes: OrgTreeNode[], depth: number): string[] {\n if (depth <= 0 || !nodes.length) return [];\n const keys: string[] = [];\n for (const n of nodes) {\n if (n.children?.length) {\n keys.push(n.id);\n if (depth > 1) {\n keys.push(...collectExpandedKeys(n.children, depth - 1));\n }\n }\n }\n return keys;\n}\n\nfunction countNodes(nodes: OrgTreeNode[]): number {\n let n = 0;\n for (const node of nodes) {\n n += 1;\n if (node.children?.length) n += countNodes(node.children);\n }\n return n;\n}\n\nfunction findOrgNode(\n list: OrgTreeNode[],\n id: string,\n): { id: string; name: string; parentId: string | null } | null {\n for (const n of list) {\n if (n.id === id) {\n return { id: n.id, name: n.name, parentId: n.parentId ?? null };\n }\n if (n.children?.length) {\n const hit = findOrgNode(n.children, id);\n if (hit) return hit;\n }\n }\n return null;\n}\n\n/**\n * 组织树(对齐 Assets 组织架构行为):可配置展开深度、节点 hover 增删改。\n * 纯 UI,无业务 API。大树勿默认全展开(会卡死 DOM)。\n */\nconst OrgTree: React.FC<OrgTreeProps> = ({\n nodes,\n loading = false,\n editable = false,\n className,\n defaultExpandDepth = 1,\n virtualHeight,\n selectedKeys,\n onSelect,\n onAdd,\n onEdit,\n onDelete,\n deleteConfirmTitle = '确认删除该节点?',\n deleteOkText = '删除',\n deleteOkType = 'danger',\n}) => {\n const nodeCount = useMemo(() => countNodes(nodes), [nodes]);\n const initialExpanded = useMemo(\n () => collectExpandedKeys(nodes, defaultExpandDepth),\n [nodes, defaultExpandDepth],\n );\n const [expandedKeys, setExpandedKeys] = useState<Key[]>(initialExpanded);\n\n useEffect(() => {\n setExpandedKeys(initialExpanded);\n }, [initialExpanded]);\n\n const treeData = useMemo(() => {\n const buildTreeNodes = (list: OrgTreeNode[]): DataNode[] =>\n list.map((node) => ({\n key: node.id,\n title: (\n <div className={classNames('marsun-org-tree-row', styles['marsun-org-tree-row'])}>\n <Tooltip\n title={\n node.nameExtra ? (\n <>\n {node.name}\n {node.nameExtra}\n </>\n ) : (\n node.name\n )\n }\n >\n <span className={classNames('marsun-org-tree-name', styles['marsun-org-tree-name'])}>\n {node.name}\n {node.nameExtra ? (\n <span\n className={classNames('marsun-org-tree-extra', styles['marsun-org-tree-extra'])}\n >\n {node.nameExtra}\n </span>\n ) : null}\n </span>\n </Tooltip>\n {editable ? (\n <Space\n size={0}\n className={classNames('marsun-org-tree-actions', styles['marsun-org-tree-actions'])}\n >\n {onAdd ? (\n <Button\n type=\"text\"\n size=\"small\"\n aria-label=\"添加子节点\"\n icon={<Plus size={14} />}\n onClick={(e) => {\n e.stopPropagation();\n onAdd(node.id);\n }}\n />\n ) : null}\n {onEdit ? (\n <Button\n type=\"text\"\n size=\"small\"\n aria-label=\"编辑\"\n icon={<Pencil size={14} />}\n onClick={(e) => {\n e.stopPropagation();\n onEdit({\n id: node.id,\n name: node.name,\n parentId: node.parentId ?? null,\n });\n }}\n />\n ) : null}\n {onDelete ? (\n <Popconfirm\n title={deleteConfirmTitle}\n okText={deleteOkText}\n okType={deleteOkType}\n cancelText=\"取消\"\n onConfirm={(e) => {\n e?.stopPropagation();\n return onDelete({ id: node.id, name: node.name });\n }}\n onCancel={(e) => e?.stopPropagation()}\n >\n <Button\n type=\"text\"\n size=\"small\"\n danger\n aria-label={deleteOkText}\n icon={<Trash2 size={14} />}\n onClick={(e) => e.stopPropagation()}\n />\n </Popconfirm>\n ) : null}\n </Space>\n ) : null}\n </div>\n ),\n children: node.children?.length ? buildTreeNodes(node.children) : undefined,\n }));\n return buildTreeNodes(nodes);\n }, [nodes, editable, onAdd, onEdit, onDelete, deleteConfirmTitle, deleteOkText, deleteOkType]);\n\n const resolvedVirtualHeight =\n virtualHeight === false ? undefined : (virtualHeight ?? (nodeCount > 80 ? 520 : undefined));\n\n return (\n <Spin spinning={loading}>\n <Tree\n className={classNames('marsun-org-tree', styles['marsun-org-tree'], className)}\n treeData={treeData}\n expandedKeys={expandedKeys}\n onExpand={(keys) => setExpandedKeys(keys)}\n selectedKeys={selectedKeys}\n onSelect={(keys) => {\n if (!onSelect) return;\n const id = keys[0] != null ? String(keys[0]) : '';\n onSelect(id ? findOrgNode(nodes, id) : null);\n }}\n showLine\n blockNode\n {...(resolvedVirtualHeight ? { virtual: true, height: resolvedVirtualHeight } : {})}\n />\n </Spin>\n );\n};\n\nexport default OrgTree;\n"],"names":["collectExpandedKeys","nodes","depth","keys","n","_a","countNodes","node","findOrgNode","list","id","hit","OrgTree","loading","editable","className","defaultExpandDepth","virtualHeight","selectedKeys","onSelect","onAdd","onEdit","onDelete","deleteConfirmTitle","deleteOkText","deleteOkType","nodeCount","useMemo","initialExpanded","expandedKeys","setExpandedKeys","useState","useEffect","treeData","buildTreeNodes","classNames","styles","jsx","Tooltip","jsxs","Fragment","Space","Button","Plus","Pencil","Popconfirm","Trash2","resolvedVirtualHeight","Spin","Tree"],"mappings":";;;;;;;;AA4CA,SAASA,EAAoBC,GAAsBC,GAAyB;;AAC1E,MAAIA,KAAS,KAAK,CAACD,EAAM,eAAe,CAAA;AACxC,QA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