@unicom-cloud/ui 0.8.92 → 0.8.93
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/package.json +1 -1
- package/tree/Node.js +71 -71
- package/tree/Tree.js +162 -166
- package/types/pc/tree/Context.d.ts +0 -1
- package/version/index.js +1 -1
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/ui","version":"0.8.
|
|
1
|
+
{"name":"@unicom-cloud/ui","version":"0.8.93","dependencies":{"@unicom-cloud/icons":"latest"},"peerDependencies":{"dayjs":"^1.11.10","lodash":"^4.17.21","react":"^18.3.1","react-dom":"^18.3.1"},"peerDependenciesMeta":{},"type":"module","types":"types/pc/index.d.ts","main":"./index.js","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
|
package/tree/Node.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { jsxs as w, Fragment as q, jsx as
|
|
1
|
+
import { jsxs as w, Fragment as q, jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import z from "@unicom-cloud/icons/IconUiCaretDown";
|
|
3
3
|
import G from "@unicom-cloud/icons/IconUiDragDotVertical";
|
|
4
4
|
import J from "@unicom-cloud/icons/IconUiFile";
|
|
5
5
|
import K from "@unicom-cloud/icons/IconUiLoading";
|
|
6
|
-
import
|
|
6
|
+
import m from "lodash/isFunction";
|
|
7
7
|
import Q, { forwardRef as W, useContext as _, useRef as X, useState as Z, useCallback as I } from "react";
|
|
8
8
|
import ee from "../checkbox/Checkbox.js";
|
|
9
9
|
import "../config-provider/ConfigProvider.js";
|
|
10
|
-
import
|
|
10
|
+
import ne from "../icon-hover/index.js";
|
|
11
11
|
import b from "@unicom-cloud/utils/class-name";
|
|
12
|
-
import { throttleByRaf as
|
|
12
|
+
import { throttleByRaf as ae } from "../components/common/utils/throttleByRaf.js";
|
|
13
13
|
import ie from "./Animation.js";
|
|
14
14
|
import { TreeContext as oe } from "./Context.js";
|
|
15
15
|
import te from "../config-provider/context.js";
|
|
16
16
|
function re(i, U) {
|
|
17
|
-
const
|
|
17
|
+
const n = _(oe), { getPrefixCls: $ } = _(te), x = X(), [t, f] = Z({
|
|
18
18
|
isAllowDrop: !0,
|
|
19
19
|
isDragOver: !1,
|
|
20
20
|
dragPosition: 0,
|
|
21
21
|
isDragging: !1
|
|
22
22
|
}), {
|
|
23
|
-
_key:
|
|
23
|
+
_key: h = "",
|
|
24
24
|
title: Y,
|
|
25
|
-
icon:
|
|
26
|
-
checkable:
|
|
25
|
+
icon: p,
|
|
26
|
+
checkable: O,
|
|
27
27
|
selected: F,
|
|
28
28
|
disabled: N,
|
|
29
29
|
disableCheckbox: H,
|
|
30
30
|
isLeaf: P,
|
|
31
|
-
draggable:
|
|
32
|
-
expanded:
|
|
31
|
+
draggable: l,
|
|
32
|
+
expanded: d,
|
|
33
33
|
showLine: v,
|
|
34
34
|
loading: M,
|
|
35
35
|
selectable: T = !0
|
|
@@ -38,67 +38,67 @@ function re(i, U) {
|
|
|
38
38
|
{
|
|
39
39
|
[`${o}-selected`]: F,
|
|
40
40
|
[`${o}-is-leaf`]: P,
|
|
41
|
-
[`${o}-expanded`]:
|
|
41
|
+
[`${o}-expanded`]: d,
|
|
42
42
|
[`${o}-disabled-selectable`]: !T,
|
|
43
43
|
[`${o}-disabled`]: N,
|
|
44
|
-
[`${o}-draggable`]:
|
|
44
|
+
[`${o}-draggable`]: l
|
|
45
45
|
},
|
|
46
46
|
i.className
|
|
47
47
|
), c = (() => {
|
|
48
|
-
const e =
|
|
49
|
-
return { ...e, ...
|
|
48
|
+
const e = m(n.icons) ? n.icons(i) : n.icons, a = m(i.icons) ? i.icons(i) : i.icons;
|
|
49
|
+
return { ...e, ...a };
|
|
50
50
|
})(), y = I(
|
|
51
51
|
(e) => {
|
|
52
|
-
var
|
|
53
|
-
e !==
|
|
52
|
+
var a;
|
|
53
|
+
e !== d && ((a = n.onExpand) == null || a.call(n, e, h));
|
|
54
54
|
},
|
|
55
|
-
[
|
|
55
|
+
[d, n.onExpand]
|
|
56
56
|
), A = I(async () => {
|
|
57
|
-
var
|
|
58
|
-
const { isLeaf: e, expanded:
|
|
59
|
-
e || (!((
|
|
60
|
-
}, [i, y,
|
|
57
|
+
var s;
|
|
58
|
+
const { isLeaf: e, expanded: a } = i;
|
|
59
|
+
e || (!((s = i.childrenData) != null && s.length) && m(n.loadMore) && !a ? await n.loadMore(i) : y(!a));
|
|
60
|
+
}, [i, y, n.loadMore]), B = () => {
|
|
61
61
|
if (M)
|
|
62
|
-
return "loadingIcon" in c ? c.loadingIcon : /* @__PURE__ */
|
|
63
|
-
let e = null,
|
|
62
|
+
return "loadingIcon" in c ? c.loadingIcon : /* @__PURE__ */ r(K, {});
|
|
63
|
+
let e = null, a = !1;
|
|
64
64
|
if (P)
|
|
65
|
-
v && (e = "switcherIcon" in c ? c.switcherIcon : /* @__PURE__ */
|
|
65
|
+
v && (e = "switcherIcon" in c ? c.switcherIcon : /* @__PURE__ */ r(J, {}), a = !0);
|
|
66
66
|
else {
|
|
67
|
-
const
|
|
68
|
-
e = "switcherIcon" in c ? c.switcherIcon :
|
|
67
|
+
const s = v ? /* @__PURE__ */ r("span", { className: `${o}-${d ? "minus" : "plus"}-icon` }) : /* @__PURE__ */ r(z, {});
|
|
68
|
+
e = "switcherIcon" in c ? c.switcherIcon : s, a = !v;
|
|
69
69
|
}
|
|
70
70
|
if (e)
|
|
71
|
-
return e = /* @__PURE__ */
|
|
71
|
+
return e = /* @__PURE__ */ r(
|
|
72
72
|
"span",
|
|
73
73
|
{
|
|
74
74
|
className: `${o}-switcher-icon`,
|
|
75
|
-
"aria-label":
|
|
75
|
+
"aria-label": d ? "fold button" : "expand button",
|
|
76
76
|
role: "button",
|
|
77
77
|
tabIndex: 0,
|
|
78
78
|
onClick: A,
|
|
79
79
|
children: e
|
|
80
80
|
}
|
|
81
|
-
),
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
81
|
+
), a ? /* @__PURE__ */ r(ne, { prefix: o, children: e }) : e;
|
|
82
|
+
}, u = I(
|
|
83
|
+
ae((e) => {
|
|
84
|
+
var R;
|
|
85
|
+
const a = x.current;
|
|
86
|
+
if (!a)
|
|
87
87
|
return;
|
|
88
|
-
const
|
|
88
|
+
const s = a.getBoundingClientRect(), g = window.pageYOffset + s.top, D = e.pageY, L = s.height / 4, C = D - g, k = C < L ? -1 : C < s.height - L ? 0 : 1, V = n.allowDrop(i, k);
|
|
89
89
|
f({
|
|
90
90
|
...t,
|
|
91
91
|
isAllowDrop: V,
|
|
92
92
|
isDragOver: !0,
|
|
93
93
|
dragPosition: k
|
|
94
|
-
}), (
|
|
94
|
+
}), (R = n.onNodeDragOver) == null || R.call(n, e, i, k);
|
|
95
95
|
}),
|
|
96
|
-
[
|
|
96
|
+
[n.onNodeDragOver]
|
|
97
97
|
);
|
|
98
|
-
function E(e,
|
|
99
|
-
var
|
|
100
|
-
const { disableCheckbox:
|
|
101
|
-
|
|
98
|
+
function E(e, a) {
|
|
99
|
+
var D;
|
|
100
|
+
const { disableCheckbox: s, disabled: g } = i;
|
|
101
|
+
s || g || (D = n.onCheck) == null || D.call(n, e, h, a);
|
|
102
102
|
}
|
|
103
103
|
return /* @__PURE__ */ w(q, { children: [
|
|
104
104
|
/* @__PURE__ */ w(
|
|
@@ -109,32 +109,32 @@ function re(i, U) {
|
|
|
109
109
|
ref: U,
|
|
110
110
|
role: "treeitem",
|
|
111
111
|
"aria-disabled": N,
|
|
112
|
-
"aria-expanded":
|
|
112
|
+
"aria-expanded": d,
|
|
113
113
|
"aria-level": i._level,
|
|
114
114
|
children: [
|
|
115
|
-
/* @__PURE__ */
|
|
115
|
+
/* @__PURE__ */ r("span", { className: `${o}-indent`, "aria-hidden": !0, children: [...Array(i._level)].map((e, a) => /* @__PURE__ */ r(
|
|
116
116
|
"span",
|
|
117
117
|
{
|
|
118
118
|
className: b(`${o}-indent-block`, {
|
|
119
|
-
[`${o}-indent-block-lineless`]: i._lineless && i._lineless[
|
|
119
|
+
[`${o}-indent-block-lineless`]: i._lineless && i._lineless[a]
|
|
120
120
|
})
|
|
121
121
|
},
|
|
122
|
-
|
|
122
|
+
a
|
|
123
123
|
)) }),
|
|
124
|
-
/* @__PURE__ */
|
|
124
|
+
/* @__PURE__ */ r(
|
|
125
125
|
"span",
|
|
126
126
|
{
|
|
127
127
|
className: b(`${o}-switcher`, {
|
|
128
|
-
[`${o}-switcher-expanded`]:
|
|
128
|
+
[`${o}-switcher-expanded`]: d
|
|
129
129
|
}),
|
|
130
130
|
children: B()
|
|
131
131
|
}
|
|
132
132
|
),
|
|
133
|
-
|
|
133
|
+
O ? /* @__PURE__ */ r(
|
|
134
134
|
ee,
|
|
135
135
|
{
|
|
136
136
|
disabled: H || N,
|
|
137
|
-
value:
|
|
137
|
+
value: h,
|
|
138
138
|
indeterminate: i.indeterminated,
|
|
139
139
|
checked: i.checked,
|
|
140
140
|
onChange: E
|
|
@@ -146,7 +146,7 @@ function re(i, U) {
|
|
|
146
146
|
"aria-grabbed": t.isDragging,
|
|
147
147
|
ref: x,
|
|
148
148
|
className: b(`${o}-title`, {
|
|
149
|
-
[`${o}-title-draggable`]:
|
|
149
|
+
[`${o}-title-draggable`]: l,
|
|
150
150
|
[`${o}-title-gap-top`]: t.isDragOver && t.isAllowDrop && t.dragPosition < 0,
|
|
151
151
|
[`${o}-title-gap-bottom`]: t.isDragOver && t.isAllowDrop && t.dragPosition > 0,
|
|
152
152
|
[`${o}-title-highlight`]: !t.isDragging && t.isDragOver && t.isAllowDrop && t.dragPosition === 0,
|
|
@@ -154,56 +154,56 @@ function re(i, U) {
|
|
|
154
154
|
[`${o}-title-block`]: i.blockNode
|
|
155
155
|
}),
|
|
156
156
|
onClick: (e) => {
|
|
157
|
-
const { onSelect:
|
|
157
|
+
const { onSelect: a, actionOnClick: s } = n;
|
|
158
158
|
if (!i.disabled) {
|
|
159
|
-
const
|
|
160
|
-
T &&
|
|
159
|
+
const g = [].concat(s);
|
|
160
|
+
T && g.indexOf("select") > -1 && (a == null || a(h, e)), g.indexOf("expand") > -1 && A(), O && g.indexOf("check") > -1 && E(!i.checked, e);
|
|
161
161
|
}
|
|
162
162
|
},
|
|
163
|
-
draggable:
|
|
163
|
+
draggable: l,
|
|
164
164
|
onDrop: (e) => {
|
|
165
|
-
var
|
|
166
|
-
e.stopPropagation(), e.preventDefault(), (
|
|
165
|
+
var a;
|
|
166
|
+
e.stopPropagation(), e.preventDefault(), (a = n.onNodeDrop) == null || a.call(n, e, i, t.dragPosition), u.cancel(), f({
|
|
167
167
|
...t,
|
|
168
168
|
isDragOver: !1,
|
|
169
169
|
dragPosition: 0
|
|
170
170
|
});
|
|
171
171
|
},
|
|
172
172
|
onDragStart: (e) => {
|
|
173
|
-
var
|
|
174
|
-
if (
|
|
173
|
+
var a;
|
|
174
|
+
if (l) {
|
|
175
175
|
e.stopPropagation(), f({ ...t, isDragging: !0 });
|
|
176
176
|
try {
|
|
177
177
|
e.dataTransfer.setData("text/plain", "");
|
|
178
|
-
} catch (
|
|
179
|
-
console.error(
|
|
178
|
+
} catch (s) {
|
|
179
|
+
console.error(s);
|
|
180
180
|
}
|
|
181
|
-
(
|
|
181
|
+
(a = n.onNodeDragStart) == null || a.call(n, e, i);
|
|
182
182
|
}
|
|
183
183
|
},
|
|
184
184
|
onDragEnd: (e) => {
|
|
185
|
-
var
|
|
186
|
-
|
|
185
|
+
var a;
|
|
186
|
+
l && (e.stopPropagation(), u.cancel(), f({ ...t, isDragOver: !1, isDragging: !1 }), (a = n.onNodeDragEnd) == null || a.call(n, e, i));
|
|
187
187
|
},
|
|
188
188
|
onDragOver: (e) => {
|
|
189
|
-
e.preventDefault(), e.stopPropagation(), e.persist(),
|
|
189
|
+
e.preventDefault(), e.stopPropagation(), e.persist(), u(e);
|
|
190
190
|
},
|
|
191
191
|
onDragLeave: (e) => {
|
|
192
|
-
var
|
|
193
|
-
|
|
192
|
+
var a;
|
|
193
|
+
l && (e.stopPropagation(), u.cancel(), f({ ...t, isDragOver: !1 }), (a = n.onNodeDragLeave) == null || a.call(n, e, i));
|
|
194
194
|
},
|
|
195
195
|
children: [
|
|
196
|
-
|
|
197
|
-
/* @__PURE__ */
|
|
198
|
-
|
|
196
|
+
p && /* @__PURE__ */ r("span", { className: `${o}-icon ${o}-custom-icon`, children: p }),
|
|
197
|
+
/* @__PURE__ */ r("span", { className: `${o}-title-text`, children: m(n.renderTitle) ? n.renderTitle(i) : Y }),
|
|
198
|
+
l && /* @__PURE__ */ r("span", { className: `${o}-icon ${o}-drag-icon`, children: "dragIcon" in c ? c.dragIcon : /* @__PURE__ */ r(G, {}) })
|
|
199
199
|
]
|
|
200
200
|
}
|
|
201
201
|
),
|
|
202
|
-
|
|
202
|
+
m(n.renderExtra) && n.renderExtra(i)
|
|
203
203
|
]
|
|
204
204
|
}
|
|
205
205
|
),
|
|
206
|
-
|
|
206
|
+
n.animation && /* @__PURE__ */ r(ie, { ...i })
|
|
207
207
|
] });
|
|
208
208
|
}
|
|
209
209
|
const S = W(re);
|
package/tree/Tree.js
CHANGED
|
@@ -50,9 +50,9 @@ const ae = {
|
|
|
50
50
|
"animation"
|
|
51
51
|
];
|
|
52
52
|
function Ge(r, fe) {
|
|
53
|
-
const
|
|
54
|
-
var
|
|
55
|
-
const e = H(), n = $(e, (
|
|
53
|
+
const C = ve(qe), U = S(null), f = S({}), b = S(), T = S(), M = S(), [o, m] = Te(() => {
|
|
54
|
+
var s;
|
|
55
|
+
const e = H(), n = $(e, (s = C.getPrefixCls) == null ? void 0 : s.call(C, "tree")), { checkedKeys: c, halfCheckedKeys: t } = R(
|
|
56
56
|
r.checkedKeys || r.defaultCheckedKeys || []
|
|
57
57
|
);
|
|
58
58
|
return {
|
|
@@ -68,11 +68,11 @@ function Ge(r, fe) {
|
|
|
68
68
|
nodeList: n
|
|
69
69
|
};
|
|
70
70
|
});
|
|
71
|
-
function
|
|
72
|
-
const { componentConfig: n } =
|
|
73
|
-
return Ve.forEach((
|
|
74
|
-
le(c[
|
|
75
|
-
}),
|
|
71
|
+
function N(e) {
|
|
72
|
+
const { componentConfig: n } = C ?? {}, c = e || r, t = (n == null ? void 0 : n.Tree) || {}, s = {};
|
|
73
|
+
return Ve.forEach((l) => {
|
|
74
|
+
le(c[l]) ? le(t[l]) ? s[l] = Ue[l] : s[l] = t[l] : s[l] = c[l];
|
|
75
|
+
}), s;
|
|
76
76
|
}
|
|
77
77
|
function he(e, n) {
|
|
78
78
|
let c = e;
|
|
@@ -99,10 +99,10 @@ function Ge(r, fe) {
|
|
|
99
99
|
return e.treeData !== n.treeData || e.children !== n.children || c.some((t) => L(e[t], n[t]));
|
|
100
100
|
}
|
|
101
101
|
function V(e) {
|
|
102
|
-
const n =
|
|
102
|
+
const n = N(), { selectable: c } = n, t = {
|
|
103
103
|
...ae,
|
|
104
104
|
..."treeData" in r ? n.fieldNames : {}
|
|
105
|
-
},
|
|
105
|
+
}, s = {
|
|
106
106
|
children: E(e, t.children),
|
|
107
107
|
selectable: q(e, t.selectable) ? E(e, t.selectable) : c,
|
|
108
108
|
checkable: q(e, t.checkable) ? E(e, t.checkable) : r.checkable,
|
|
@@ -112,58 +112,58 @@ function Ge(r, fe) {
|
|
|
112
112
|
isLeaf: E(e, t.isLeaf),
|
|
113
113
|
key: E(e, t.key)
|
|
114
114
|
};
|
|
115
|
-
return q(e, t.key) || delete
|
|
115
|
+
return q(e, t.key) || delete s.key, s;
|
|
116
116
|
}
|
|
117
117
|
function $(e, n) {
|
|
118
|
-
var
|
|
118
|
+
var i;
|
|
119
119
|
f.current = {};
|
|
120
|
-
const c = n || ((
|
|
121
|
-
let
|
|
122
|
-
const { showLine:
|
|
123
|
-
const w =
|
|
124
|
-
return
|
|
120
|
+
const c = n || ((i = C.getPrefixCls) == null ? void 0 : i.call(C, "tree")), t = [];
|
|
121
|
+
let s = 0;
|
|
122
|
+
const { showLine: l, blockNode: d } = N(), a = (k, u) => {
|
|
123
|
+
const w = k.length;
|
|
124
|
+
return k.map((x, g) => {
|
|
125
125
|
const {
|
|
126
|
-
children:
|
|
126
|
+
children: y,
|
|
127
127
|
selectable: h,
|
|
128
128
|
checkable: D,
|
|
129
|
-
key:
|
|
129
|
+
key: _ = `${(u == null ? void 0 : u._key) || ""}-${g}`,
|
|
130
130
|
...z
|
|
131
|
-
} = V(
|
|
131
|
+
} = V(x), O = {
|
|
132
132
|
// data 中含有 dataRef 时,优先级较高
|
|
133
|
-
dataRef:
|
|
133
|
+
dataRef: x,
|
|
134
134
|
draggable: r.draggable,
|
|
135
135
|
selectable: h,
|
|
136
136
|
checkable: D,
|
|
137
|
-
showLine:
|
|
137
|
+
showLine: l,
|
|
138
138
|
blockNode: d,
|
|
139
|
-
...
|
|
139
|
+
...x,
|
|
140
140
|
...z,
|
|
141
|
-
key:
|
|
142
|
-
children:
|
|
143
|
-
_key:
|
|
144
|
-
_index:
|
|
141
|
+
key: _,
|
|
142
|
+
children: y,
|
|
143
|
+
_key: _,
|
|
144
|
+
_index: s++,
|
|
145
145
|
parentKey: u ? u._key : void 0,
|
|
146
146
|
pathParentKeys: u && u.pathParentKeys || [],
|
|
147
147
|
_level: u._level || 0,
|
|
148
148
|
// 保存node在sowLine模式下是否显示缩进线。如果父节点是其所在层级的最后一个节点,那么所有的子节点(包括孙子节点等)在父节点所在层级的缩进格都不显示缩进线。
|
|
149
149
|
_lineless: u && u._lineless ? [...u._lineless || [], u._isTail] : []
|
|
150
150
|
};
|
|
151
|
-
return w ===
|
|
151
|
+
return w === g + 1 && (O.className = de(
|
|
152
152
|
`${c}-node-is-tail`,
|
|
153
153
|
O.className
|
|
154
|
-
)), t.push(O), f.current[
|
|
155
|
-
_key:
|
|
154
|
+
)), t.push(O), f.current[_] = O, y && y.length && (f.current[_].children = a(y, {
|
|
155
|
+
_key: _,
|
|
156
156
|
_level: O._level + 1,
|
|
157
157
|
_lineless: O._lineless,
|
|
158
|
-
_isTail: w ===
|
|
159
|
-
pathParentKeys: [...(u == null ? void 0 : u.pathParentKeys) || [],
|
|
158
|
+
_isTail: w === g + 1,
|
|
159
|
+
pathParentKeys: [...(u == null ? void 0 : u.pathParentKeys) || [], _]
|
|
160
160
|
})), O;
|
|
161
161
|
});
|
|
162
162
|
};
|
|
163
|
-
return
|
|
163
|
+
return a(e || [], {}), t;
|
|
164
164
|
}
|
|
165
165
|
function G(e) {
|
|
166
|
-
if (!
|
|
166
|
+
if (!N().autoExpandParent)
|
|
167
167
|
return e || [];
|
|
168
168
|
if (!e)
|
|
169
169
|
return Object.keys(f.current).filter((c) => {
|
|
@@ -173,8 +173,8 @@ function Ge(r, fe) {
|
|
|
173
173
|
const n = {};
|
|
174
174
|
return e.forEach((c) => {
|
|
175
175
|
const t = f.current[c];
|
|
176
|
-
t && (n[c] = 1, t.pathParentKeys && t.pathParentKeys.forEach((
|
|
177
|
-
n[
|
|
176
|
+
t && (n[c] = 1, t.pathParentKeys && t.pathParentKeys.forEach((s) => {
|
|
177
|
+
n[s] = 1;
|
|
178
178
|
}));
|
|
179
179
|
}), Object.keys(n);
|
|
180
180
|
}
|
|
@@ -195,84 +195,84 @@ function Ge(r, fe) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
function ke(e, n) {
|
|
198
|
-
var l;
|
|
199
|
-
const { onSelect: c } = r, t = {
|
|
198
|
+
var l, d;
|
|
199
|
+
const { onSelect: c } = r, t = (l = f.current[e]) == null ? void 0 : l.dataRef, s = {
|
|
200
200
|
e: n,
|
|
201
|
-
data:
|
|
201
|
+
data: t,
|
|
202
202
|
// 潘启宝添加
|
|
203
203
|
node: K([e])[0]
|
|
204
204
|
};
|
|
205
205
|
if (r.multiple) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
return
|
|
210
|
-
}), c == null || c(
|
|
206
|
+
const a = [...o.selectedKeys], i = a.indexOf(e);
|
|
207
|
+
i > -1 ? (a.splice(i, 1), s.selected = !1) : (s.selected = !0, a.push(e)), s.selectedNodes = K(a), "selectedKeys" in r || m((k) => {
|
|
208
|
+
const u = { ...k };
|
|
209
|
+
return u.selectedKeys = a, u;
|
|
210
|
+
}), c == null || c(a, s);
|
|
211
211
|
} else
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
return
|
|
215
|
-
}), c == null || c([e],
|
|
212
|
+
s.selected = !0, s.selectedNodes = K([e]), "selectedKeys" in r || m((a) => {
|
|
213
|
+
const i = { ...a };
|
|
214
|
+
return i.selectedKeys = [e], i;
|
|
215
|
+
}), c == null || c([e], s);
|
|
216
|
+
(d = r.onNodeSelect) == null || d.call(r, e, t, s);
|
|
216
217
|
}
|
|
217
218
|
function J(e, n, c) {
|
|
218
219
|
var u, w;
|
|
219
|
-
const { checkedStrategy: t } =
|
|
220
|
-
let i = [...
|
|
221
|
-
if (
|
|
222
|
-
e ? i = i.concat(n) : i = i.filter((
|
|
223
|
-
const
|
|
224
|
-
"checkedKeys" in r || (
|
|
220
|
+
const { checkedStrategy: t } = N(), { onCheck: s, checkStrictly: l } = r, d = (u = f.current[n]) == null ? void 0 : u.dataRef, a = { e: c, node: K([n])[0] };
|
|
221
|
+
let i = [...o.checkedKeys || []], k = o.halfCheckedKeys;
|
|
222
|
+
if (l) {
|
|
223
|
+
e ? i = i.concat(n) : i = i.filter((g) => g !== n);
|
|
224
|
+
const x = {};
|
|
225
|
+
"checkedKeys" in r || (x.checkedKeys = i), "halfCheckedKeys" in r || (x.halfCheckedKeys = k), Me(x) || m((g) => ({ ...g, ...x }));
|
|
225
226
|
} else {
|
|
226
|
-
const { checkedKeys:
|
|
227
|
+
const { checkedKeys: x, indeterminateKeys: g } = Be(
|
|
227
228
|
n,
|
|
228
229
|
e,
|
|
229
230
|
i,
|
|
230
231
|
f.current,
|
|
231
|
-
|
|
232
|
+
k
|
|
232
233
|
);
|
|
233
|
-
i =
|
|
234
|
-
const h = { ...
|
|
235
|
-
return h.halfCheckedKeys =
|
|
236
|
-
}) :
|
|
237
|
-
const h = { ...
|
|
238
|
-
return h.checkedKeys = i, h.halfCheckedKeys =
|
|
239
|
-
}), t === oe ? i = i.filter((
|
|
240
|
-
const h = f.current[
|
|
234
|
+
i = x, k = g, "checkedKeys" in r ? m((y) => {
|
|
235
|
+
const h = { ...y };
|
|
236
|
+
return h.halfCheckedKeys = k, h;
|
|
237
|
+
}) : m((y) => {
|
|
238
|
+
const h = { ...y };
|
|
239
|
+
return h.checkedKeys = i, h.halfCheckedKeys = k, h;
|
|
240
|
+
}), t === oe ? i = i.filter((y) => {
|
|
241
|
+
const h = f.current[y];
|
|
241
242
|
if (!h || i.indexOf(h.parentKey) === -1)
|
|
242
243
|
return !0;
|
|
243
|
-
}) : t === ue && (i = i.filter((
|
|
244
|
-
var D,
|
|
245
|
-
const h = f.current[
|
|
246
|
-
if (!h || !((D = h.children) != null && D.length) || (
|
|
244
|
+
}) : t === ue && (i = i.filter((y) => {
|
|
245
|
+
var D, _;
|
|
246
|
+
const h = f.current[y];
|
|
247
|
+
if (!h || !((D = h.children) != null && D.length) || (_ = h.children) != null && _.every((z) => i.indexOf(z._key) === -1))
|
|
247
248
|
return !0;
|
|
248
249
|
}));
|
|
249
250
|
}
|
|
250
|
-
|
|
251
|
-
l == null || l(i, {
|
|
252
|
-
data: _,
|
|
253
|
-
// 潘启宝添加
|
|
251
|
+
s == null || s(i, {
|
|
254
252
|
checkedNodes: K(i),
|
|
255
253
|
checked: e,
|
|
256
|
-
halfCheckedKeys:
|
|
257
|
-
halfCheckedNodes: K(
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
halfCheckedKeys: k,
|
|
255
|
+
halfCheckedNodes: K(k),
|
|
256
|
+
data: d,
|
|
257
|
+
// 潘启宝添加
|
|
258
|
+
...a
|
|
259
|
+
}), (w = r.onNodeCheck) == null || w.call(r, n, d, a);
|
|
260
260
|
}
|
|
261
261
|
function me(e) {
|
|
262
262
|
if ($e(r.loadMore)) {
|
|
263
|
-
const { loadingKeys: n = [], loadedKeys: c } =
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
return
|
|
263
|
+
const { loadingKeys: n = [], loadedKeys: c } = o;
|
|
264
|
+
m((t) => {
|
|
265
|
+
const s = { ...t };
|
|
266
|
+
return s.loadingKeys = Array.from(/* @__PURE__ */ new Set([...n, e._key])), s.loadedKeys = c.filter((l) => l !== e._key), s;
|
|
267
267
|
}), I == null || I(K([e._key])[0]).then((t) => {
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
return
|
|
268
|
+
m((s) => {
|
|
269
|
+
const l = { ...s };
|
|
270
|
+
return l.loadingKeys = s.loadingKeys.filter((d) => d !== e._key), l.loadedKeys = Array.from(/* @__PURE__ */ new Set([...s.loadedKeys, e._key])), l;
|
|
271
271
|
}), W(!e.expanded, e._key);
|
|
272
272
|
}).catch((t) => {
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
return
|
|
273
|
+
m((s) => {
|
|
274
|
+
const l = { ...s };
|
|
275
|
+
return l.loadingKeys = s.loadingKeys.filter((d) => d !== e._key), l;
|
|
276
276
|
}), console.error("[tree]load data error: ", t);
|
|
277
277
|
}).finally(() => {
|
|
278
278
|
});
|
|
@@ -301,12 +301,12 @@ function Ge(r, fe) {
|
|
|
301
301
|
function _e(e, n) {
|
|
302
302
|
let c = f.current[e.parentKey];
|
|
303
303
|
for (; c; ) {
|
|
304
|
-
const { _key: t, parentKey:
|
|
304
|
+
const { _key: t, parentKey: s } = c;
|
|
305
305
|
if (t === n.props._key)
|
|
306
306
|
return !0;
|
|
307
|
-
if (
|
|
307
|
+
if (s === t)
|
|
308
308
|
return;
|
|
309
|
-
c = f.current[
|
|
309
|
+
c = f.current[s];
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
function Q(e, n) {
|
|
@@ -317,22 +317,22 @@ function Ge(r, fe) {
|
|
|
317
317
|
const c = e.key, t = n.key;
|
|
318
318
|
if (c !== void 0 || t !== void 0)
|
|
319
319
|
return c === t;
|
|
320
|
-
const
|
|
321
|
-
return
|
|
320
|
+
const s = e.props._key, l = n.props._key;
|
|
321
|
+
return s === void 0 && l === void 0 ? !1 : s === l;
|
|
322
322
|
}
|
|
323
323
|
function X(e, n, c) {
|
|
324
324
|
if (b.current) {
|
|
325
|
-
const { allowDrop: t } =
|
|
326
|
-
if (
|
|
325
|
+
const { allowDrop: t } = N(), { onDrop: s } = r, l = K([n._key])[0];
|
|
326
|
+
if (s && !_e(n, b.current) && !Q(b.current, l)) {
|
|
327
327
|
if (t && !t({
|
|
328
|
-
dropNode:
|
|
328
|
+
dropNode: l,
|
|
329
329
|
dragNode: b.current,
|
|
330
330
|
dropPosition: c
|
|
331
331
|
}))
|
|
332
332
|
return;
|
|
333
|
-
|
|
333
|
+
s({
|
|
334
334
|
dragNode: b.current,
|
|
335
|
-
dropNode:
|
|
335
|
+
dropNode: l,
|
|
336
336
|
dropPosition: c,
|
|
337
337
|
e
|
|
338
338
|
});
|
|
@@ -340,7 +340,7 @@ function Ge(r, fe) {
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
function Y(e, n) {
|
|
343
|
-
const { allowDrop: c } =
|
|
343
|
+
const { allowDrop: c } = N();
|
|
344
344
|
let t = !0;
|
|
345
345
|
return typeof c == "function" && (t = c({
|
|
346
346
|
dropNode: K([e._key])[0],
|
|
@@ -349,14 +349,14 @@ function Ge(r, fe) {
|
|
|
349
349
|
})), t;
|
|
350
350
|
}
|
|
351
351
|
function W(e, n) {
|
|
352
|
-
const { currentExpandKeys: c, expandedKeys: t = [] } =
|
|
352
|
+
const { currentExpandKeys: c, expandedKeys: t = [] } = o, { animation: s } = N(), { onExpand: l } = r;
|
|
353
353
|
if (c.indexOf(n) > -1)
|
|
354
354
|
return;
|
|
355
355
|
let d = [];
|
|
356
|
-
e ? d = Array.from(/* @__PURE__ */ new Set([...t, n])) : d = t.filter((
|
|
357
|
-
const
|
|
358
|
-
return
|
|
359
|
-
}),
|
|
356
|
+
e ? d = Array.from(/* @__PURE__ */ new Set([...t, n])) : d = t.filter((a) => a !== n), "expandedKeys" in r || m((a) => {
|
|
357
|
+
const i = { ...a };
|
|
358
|
+
return i.expandedKeys = d, i.currentExpandKeys = s ? [...c, n] : [], i;
|
|
359
|
+
}), l == null || l(d, {
|
|
360
360
|
expanded: e,
|
|
361
361
|
node: K([n])[0],
|
|
362
362
|
expandedNodes: K(d)
|
|
@@ -373,60 +373,60 @@ function Ge(r, fe) {
|
|
|
373
373
|
}
|
|
374
374
|
function j(e) {
|
|
375
375
|
return {
|
|
376
|
-
expandedKeysSet: (e == null ? void 0 : e.expandedKeysSet) || new Set((
|
|
377
|
-
checkedKeysSet: (e == null ? void 0 : e.checkedKeysSet) || new Set((
|
|
378
|
-
selectedKeysSet: (e == null ? void 0 : e.selectedKeysSet) || new Set((
|
|
379
|
-
halfCheckedKeysSet: (e == null ? void 0 : e.halfCheckedKeysSet) || new Set((
|
|
376
|
+
expandedKeysSet: (e == null ? void 0 : e.expandedKeysSet) || new Set((o == null ? void 0 : o.expandedKeys) || []),
|
|
377
|
+
checkedKeysSet: (e == null ? void 0 : e.checkedKeysSet) || new Set((o == null ? void 0 : o.checkedKeys) || []),
|
|
378
|
+
selectedKeysSet: (e == null ? void 0 : e.selectedKeysSet) || new Set((o == null ? void 0 : o.selectedKeys) || []),
|
|
379
|
+
halfCheckedKeysSet: (e == null ? void 0 : e.halfCheckedKeysSet) || new Set((o == null ? void 0 : o.halfCheckedKeys) || [])
|
|
380
380
|
};
|
|
381
381
|
}
|
|
382
382
|
function A(e, n) {
|
|
383
|
-
const { autoExpandParent: c } =
|
|
384
|
-
selectedKeys:
|
|
385
|
-
expandedKeys:
|
|
383
|
+
const { autoExpandParent: c } = N(), { loadMore: t } = r, {
|
|
384
|
+
selectedKeys: s,
|
|
385
|
+
expandedKeys: l,
|
|
386
386
|
checkedKeys: d,
|
|
387
|
-
loadingKeys:
|
|
388
|
-
loadedKeys:
|
|
389
|
-
} =
|
|
390
|
-
expandedKeysSet:
|
|
387
|
+
loadingKeys: a = [],
|
|
388
|
+
loadedKeys: i = []
|
|
389
|
+
} = o, {
|
|
390
|
+
expandedKeysSet: k,
|
|
391
391
|
checkedKeysSet: u,
|
|
392
392
|
selectedKeysSet: w,
|
|
393
|
-
halfCheckedKeysSet:
|
|
394
|
-
} = j(n),
|
|
395
|
-
const h =
|
|
393
|
+
halfCheckedKeysSet: x
|
|
394
|
+
} = j(n), g = (y) => {
|
|
395
|
+
const h = y.children && y.children.length, D = {
|
|
396
396
|
isLeaf: !h,
|
|
397
397
|
autoExpandParent: h ? c : !1,
|
|
398
|
-
expanded:
|
|
398
|
+
expanded: k ? k.has(y._key) : l.indexOf(y._key) > -1
|
|
399
399
|
};
|
|
400
400
|
if (t) {
|
|
401
|
-
const
|
|
402
|
-
D.loaded =
|
|
401
|
+
const _ = i.indexOf(y._key) > -1;
|
|
402
|
+
D.loaded = _, D.isLeaf = h ? !1 : y.isLeaf;
|
|
403
403
|
}
|
|
404
404
|
return {
|
|
405
|
-
...
|
|
405
|
+
...y,
|
|
406
406
|
...D,
|
|
407
|
-
selected: w.has(
|
|
408
|
-
indeterminated:
|
|
409
|
-
loading:
|
|
410
|
-
checked: u.has(
|
|
411
|
-
selectedKeys:
|
|
407
|
+
selected: w.has(y._key),
|
|
408
|
+
indeterminated: x.has(y._key),
|
|
409
|
+
loading: a.indexOf(y._key) > -1,
|
|
410
|
+
checked: u.has(y._key),
|
|
411
|
+
selectedKeys: s,
|
|
412
412
|
checkedKeys: d,
|
|
413
|
-
loadingKeys:
|
|
414
|
-
loadedKeys:
|
|
415
|
-
expandedKeys:
|
|
416
|
-
childrenData:
|
|
413
|
+
loadingKeys: a,
|
|
414
|
+
loadedKeys: i,
|
|
415
|
+
expandedKeys: l,
|
|
416
|
+
childrenData: y.children || [],
|
|
417
417
|
children: null
|
|
418
418
|
};
|
|
419
419
|
};
|
|
420
|
-
return He(e) ? e.map((
|
|
420
|
+
return He(e) ? e.map((y) => g(y)) : g(e);
|
|
421
421
|
}
|
|
422
422
|
function Z(e) {
|
|
423
|
-
|
|
423
|
+
m((n) => {
|
|
424
424
|
const c = { ...n }, { currentExpandKeys: t } = n;
|
|
425
|
-
return t.indexOf(e) > -1 && (c.currentExpandKeys = t.filter((
|
|
425
|
+
return t.indexOf(e) > -1 && (c.currentExpandKeys = t.filter((s, l, d) => s !== e)), c;
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
428
|
function p() {
|
|
429
|
-
return
|
|
429
|
+
return o;
|
|
430
430
|
}
|
|
431
431
|
Ae(fe, () => ({
|
|
432
432
|
scrollIntoView: he,
|
|
@@ -441,49 +441,49 @@ function Ge(r, fe) {
|
|
|
441
441
|
handleNodeDrop: X,
|
|
442
442
|
isSameNode: Q
|
|
443
443
|
})), B(() => {
|
|
444
|
-
const e = U.current, n =
|
|
444
|
+
const e = U.current, n = N(e), c = N();
|
|
445
445
|
if (e !== r || !L(n, c)) {
|
|
446
446
|
const t = {};
|
|
447
447
|
if (Ke(
|
|
448
448
|
{ prevMergedProps: n, ...e },
|
|
449
449
|
{ ...c, ...r }
|
|
450
450
|
)) {
|
|
451
|
-
const
|
|
452
|
-
t.treeData =
|
|
451
|
+
const l = H(), d = $(l);
|
|
452
|
+
t.treeData = l, t.nodeList = d;
|
|
453
453
|
}
|
|
454
454
|
if (t.treeData || "checkedKeys" in r && !L(e == null ? void 0 : e.checkedKeys, r.checkedKeys)) {
|
|
455
|
-
const
|
|
456
|
-
|
|
455
|
+
const l = "checkedKeys" in r ? r.checkedKeys : o.checkedKeys, { halfCheckedKeys: d, checkedKeys: a } = R(
|
|
456
|
+
l || []
|
|
457
457
|
);
|
|
458
|
-
L(
|
|
458
|
+
L(a, o.checkedKeys) || (t.checkedKeys = a), L(d, o.halfCheckedKeys) || (t.halfCheckedKeys = d);
|
|
459
459
|
}
|
|
460
|
-
r.checkStrictly && "halfCheckedKeys" in r && !L(e == null ? void 0 : e.halfCheckedKeys, r.halfCheckedKeys) && (t.halfCheckedKeys = r.halfCheckedKeys), "expandedKeys" in r && !L(r.expandedKeys, e == null ? void 0 : e.expandedKeys) && (t.expandedKeys = r.expandedKeys, t.currentExpandKeys = c.animation ? [...t.expandedKeys ?? [], ...
|
|
461
|
-
const
|
|
462
|
-
return
|
|
463
|
-
}, []).filter((
|
|
464
|
-
var
|
|
465
|
-
if (f.current[
|
|
466
|
-
return f.current[
|
|
460
|
+
r.checkStrictly && "halfCheckedKeys" in r && !L(e == null ? void 0 : e.halfCheckedKeys, r.halfCheckedKeys) && (t.halfCheckedKeys = r.halfCheckedKeys), "expandedKeys" in r && !L(r.expandedKeys, e == null ? void 0 : e.expandedKeys) && (t.expandedKeys = r.expandedKeys, t.currentExpandKeys = c.animation ? [...t.expandedKeys ?? [], ...o.expandedKeys ?? []].reduce((l, d) => {
|
|
461
|
+
const a = l.indexOf(d);
|
|
462
|
+
return a === -1 ? l.push(d) : l.splice(a, 1), l;
|
|
463
|
+
}, []).filter((l, d, a) => {
|
|
464
|
+
var i;
|
|
465
|
+
if (f.current[l])
|
|
466
|
+
return f.current[l].pathParentKeys.some((u) => a.indexOf(u) > -1) ? !1 : (i = f.current[l].children) == null ? void 0 : i.length;
|
|
467
467
|
}) : []);
|
|
468
|
-
const
|
|
469
|
-
t.treeData &&
|
|
470
|
-
const d = t.treeData.find((
|
|
468
|
+
const s = t.currentExpandKeys || o.currentExpandKeys;
|
|
469
|
+
t.treeData && s && (t.currentExpandKeys = s.filter((l) => {
|
|
470
|
+
const d = t.treeData.find((a) => a.key === l);
|
|
471
471
|
return d && d.children && d.children.length;
|
|
472
|
-
})), Object.keys(t).length &&
|
|
472
|
+
})), Object.keys(t).length && m((l) => ({ ...l, ...t }));
|
|
473
473
|
}
|
|
474
474
|
return U.current = r, () => {
|
|
475
475
|
};
|
|
476
|
-
}), B(() => ("selectedKeys" in r && !L(r.selectedKeys,
|
|
476
|
+
}), B(() => ("selectedKeys" in r && !L(r.selectedKeys, o.selectedKeys) && m((e) => {
|
|
477
477
|
const n = { ...e };
|
|
478
478
|
return n.selectedKeys = r.selectedKeys || [], n;
|
|
479
479
|
}), () => {
|
|
480
|
-
}), [r.selectedKeys,
|
|
481
|
-
var
|
|
482
|
-
const e = H(), n = $(e, (
|
|
480
|
+
}), [r.selectedKeys, o.selectedKeys]), B(() => {
|
|
481
|
+
var s;
|
|
482
|
+
const e = H(), n = $(e, (s = C.getPrefixCls) == null ? void 0 : s.call(C, "tree")), { checkedKeys: c, halfCheckedKeys: t } = R(
|
|
483
483
|
r.checkedKeys || r.defaultCheckedKeys || []
|
|
484
484
|
);
|
|
485
|
-
return
|
|
486
|
-
let d = { ...
|
|
485
|
+
return m((l) => {
|
|
486
|
+
let d = { ...l };
|
|
487
487
|
return d = {
|
|
488
488
|
...d,
|
|
489
489
|
selectedKeys: r.selectedKeys || r.defaultSelectedKeys || [],
|
|
@@ -510,12 +510,12 @@ function Ge(r, fe) {
|
|
|
510
510
|
icons: Le,
|
|
511
511
|
actionOnClick: we,
|
|
512
512
|
animation: ce
|
|
513
|
-
} =
|
|
513
|
+
} = N(), { loadMore: I, checkable: Oe } = r, re = te ? {
|
|
514
514
|
threshold: 100,
|
|
515
515
|
...te
|
|
516
516
|
} : ne ? { height: ne, threshold: 100 } : {
|
|
517
517
|
threshold: null
|
|
518
|
-
}, { getPrefixCls: F, rtl: Pe } =
|
|
518
|
+
}, { getPrefixCls: F, rtl: Pe } = C, P = F == null ? void 0 : F("tree");
|
|
519
519
|
return /* @__PURE__ */ se(
|
|
520
520
|
We.Provider,
|
|
521
521
|
{
|
|
@@ -541,11 +541,7 @@ function Ge(r, fe) {
|
|
|
541
541
|
loadMore: I && me,
|
|
542
542
|
allowDrop: Y,
|
|
543
543
|
actionOnClick: we,
|
|
544
|
-
virtualListProps: re
|
|
545
|
-
onNodeSelect(e, n, c) {
|
|
546
|
-
var t;
|
|
547
|
-
(t = r.onNodeSelect) == null || t.call(r, e, n, c);
|
|
548
|
-
}
|
|
544
|
+
virtualListProps: re
|
|
549
545
|
},
|
|
550
546
|
children: /* @__PURE__ */ se(
|
|
551
547
|
je,
|
|
@@ -566,11 +562,11 @@ function Ge(r, fe) {
|
|
|
566
562
|
style: Ee,
|
|
567
563
|
filterNode: r.filterNode,
|
|
568
564
|
virtualListProps: re,
|
|
569
|
-
expandedKeys:
|
|
570
|
-
currentExpandKeys:
|
|
565
|
+
expandedKeys: o.expandedKeys,
|
|
566
|
+
currentExpandKeys: o.currentExpandKeys,
|
|
571
567
|
getNodeProps: A,
|
|
572
568
|
getDataSet: j,
|
|
573
|
-
nodeList:
|
|
569
|
+
nodeList: o.nodeList,
|
|
574
570
|
onMouseDown: r.onMouseDown,
|
|
575
571
|
ariaProps: {
|
|
576
572
|
role: "tree",
|
|
@@ -25,5 +25,4 @@ export declare const TreeContext: import("react").Context<{
|
|
|
25
25
|
onNodeDragLeave?: (e: DragEvent<HTMLSpanElement>, nodeProps: NodeProps) => void;
|
|
26
26
|
allowDrop?: (nodeProps: NodeProps, dragPosition: 0 | 1 | -1) => boolean;
|
|
27
27
|
getFieldInfo?: (nodeProps: NodeProps) => TreeDataType;
|
|
28
|
-
onNodeSelect?: (key: string, data: unknown, extra: unknown) => void;
|
|
29
28
|
}>;
|
package/version/index.js
CHANGED