@nice2dev/ui 1.4.12 → 1.4.14
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/CHANGELOG.md +42 -0
- package/dist/NiceSavedQueryPanel-C1nxEmMu.cjs +587 -0
- package/dist/data/NiceTreeGrid.mjs +619 -545
- package/dist/data/NiceTreeView.mjs +222 -180
- package/dist/data/treeRowDrop.mjs +130 -0
- package/dist/data.cjs +1 -1
- package/dist/data.d.ts +26 -4
- package/dist/index.cjs +21 -21
- package/dist/index.d.ts +96 -4
- package/dist/index.mjs +935 -929
- package/dist/style.css +1 -1
- package/package.json +4 -4
- package/dist/NiceSavedQueryPanel-BSZhE-_l.cjs +0 -587
|
@@ -1,274 +1,316 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useNiceAccessMode as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { buildTreeCheckIndex as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsxs as T, jsx as a, Fragment as Oe } from "react/jsx-runtime";
|
|
2
|
+
import { useNiceAccessMode as Pe, useNiceTranslation as Ye, useTreeFocus as je, useRovingFocus as qe, useOverlayFocus as Be, NiceIcon as fe } from "@nice2dev/ui-core";
|
|
3
|
+
import { useState as m, useRef as E, useMemo as $, useCallback as M, useEffect as He } from "react";
|
|
4
|
+
import { buildTreeCheckIndex as Ve, normalizeCheckedKeys as We, computeTreeCheck as Xe, toggleTreeCheck as Ge, emitCheckedKeys as Je } from "./treeCheck.mjs";
|
|
5
|
+
import { useTreeRowDrop as Qe, treeKeyboardMove as Ue, treeKeyboardTarget as Ze } from "./treeRowDrop.mjs";
|
|
6
|
+
function he(p, k = []) {
|
|
7
|
+
for (const l of p)
|
|
8
|
+
l.expanded && k.push(l.key), l.children && he(l.children, k);
|
|
9
|
+
return k;
|
|
9
10
|
}
|
|
10
|
-
const
|
|
11
|
-
nodes:
|
|
12
|
-
header:
|
|
13
|
-
selectedKeys:
|
|
14
|
-
expandedKeys:
|
|
15
|
-
onSelectionChange:
|
|
16
|
-
onExpandedChange:
|
|
17
|
-
selectionMode:
|
|
18
|
-
showCheckboxes:
|
|
19
|
-
searchable:
|
|
20
|
-
searchPlaceholder:
|
|
21
|
-
onNodeClick:
|
|
22
|
-
renderNode:
|
|
23
|
-
showLines:
|
|
24
|
-
loading:
|
|
25
|
-
className:
|
|
26
|
-
style:
|
|
27
|
-
accessMode:
|
|
28
|
-
id:
|
|
29
|
-
draggable:
|
|
30
|
-
onNodeDrop:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
const G = [], et = [], lt = ({
|
|
12
|
+
nodes: p = G,
|
|
13
|
+
header: k,
|
|
14
|
+
selectedKeys: l = et,
|
|
15
|
+
expandedKeys: ge,
|
|
16
|
+
onSelectionChange: D,
|
|
17
|
+
onExpandedChange: I,
|
|
18
|
+
selectionMode: y = "none",
|
|
19
|
+
showCheckboxes: J,
|
|
20
|
+
searchable: ve,
|
|
21
|
+
searchPlaceholder: Q,
|
|
22
|
+
onNodeClick: me,
|
|
23
|
+
renderNode: U,
|
|
24
|
+
showLines: ke,
|
|
25
|
+
loading: ye,
|
|
26
|
+
className: be,
|
|
27
|
+
style: _e,
|
|
28
|
+
accessMode: xe,
|
|
29
|
+
id: we,
|
|
30
|
+
draggable: Ne,
|
|
31
|
+
onNodeDrop: O,
|
|
32
|
+
canDrop: Z,
|
|
33
|
+
onLoadChildren: K,
|
|
34
|
+
contextMenuItems: R,
|
|
35
|
+
onContextMenuAction: Ce,
|
|
36
|
+
editable: ee,
|
|
37
|
+
onNodeEdit: P,
|
|
38
|
+
maxDepth: te,
|
|
39
|
+
"data-testid": De
|
|
38
40
|
}) => {
|
|
39
|
-
const
|
|
40
|
-
() =>
|
|
41
|
-
), [
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
() =>
|
|
45
|
-
|
|
41
|
+
const Se = Pe(xe, we) === "hidden", { t: _ } = Ye(), [Te, Ee] = m(
|
|
42
|
+
() => he(p)
|
|
43
|
+
), [S, $e] = m(""), [Me, ne] = m(/* @__PURE__ */ new Set()), [u, Ke] = m(/* @__PURE__ */ new Map()), [x, z] = m(null), [b, F] = m(null), [Y, j] = m(""), Re = E(null), q = ge ?? Te, w = E(q);
|
|
44
|
+
w.current = q;
|
|
45
|
+
const re = $(() => new Set(l), [l]), B = typeof te == "number" ? Math.min(10, Math.max(1, te)) : 1 / 0, ie = !!J && y === "multiple", d = $(
|
|
46
|
+
() => ie ? Ve(
|
|
47
|
+
p,
|
|
46
48
|
{
|
|
47
49
|
getKey: (e) => e.key,
|
|
48
|
-
getChildren: (e,
|
|
50
|
+
getChildren: (e, t) => t + 1 >= B ? null : u.get(e.key) ?? e.children,
|
|
49
51
|
isDisabled: (e) => !!e.disabled
|
|
50
52
|
},
|
|
51
53
|
{ inheritDisabled: !1 }
|
|
52
54
|
) : null,
|
|
53
|
-
[
|
|
54
|
-
),
|
|
55
|
-
() =>
|
|
56
|
-
[
|
|
57
|
-
),
|
|
58
|
-
() =>
|
|
59
|
-
[
|
|
60
|
-
),
|
|
61
|
-
async (e,
|
|
62
|
-
const r =
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return
|
|
55
|
+
[ie, p, u, B]
|
|
56
|
+
), h = $(
|
|
57
|
+
() => d ? We(d, l) : null,
|
|
58
|
+
[d, l]
|
|
59
|
+
), H = $(
|
|
60
|
+
() => d && h ? Xe(d, h.leaves) : null,
|
|
61
|
+
[d, h]
|
|
62
|
+
), L = M(
|
|
63
|
+
async (e, t) => {
|
|
64
|
+
const r = w.current, n = !r.includes(e), s = n ? [...r, e] : r.filter((i) => i !== e);
|
|
65
|
+
if (w.current = s, I ? I(s) : Ee(s), n && K && !t.children?.length && t.leaf !== !0 && !u.has(e)) {
|
|
66
|
+
ne((o) => new Set(o).add(e));
|
|
67
|
+
const i = await K(t);
|
|
68
|
+
Ke((o) => new Map(o).set(e, i)), ne((o) => {
|
|
69
|
+
const f = new Set(o);
|
|
70
|
+
return f.delete(e), f;
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
|
-
[
|
|
73
|
-
),
|
|
74
|
+
[I, K, u]
|
|
75
|
+
), ce = M(
|
|
74
76
|
(e) => {
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
else if (
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
|
|
77
|
+
if (D) {
|
|
78
|
+
if (y === "single")
|
|
79
|
+
D(l.includes(e) ? [] : [e]);
|
|
80
|
+
else if (y === "multiple")
|
|
81
|
+
if (d && h) {
|
|
82
|
+
const t = Ge(d, h.leaves, e);
|
|
83
|
+
t !== h.leaves && D(Je(d, t, "all", h.unknown));
|
|
82
84
|
} else
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
D(
|
|
86
|
+
l.includes(e) ? l.filter((t) => t !== e) : [...l, e]
|
|
85
87
|
);
|
|
86
88
|
}
|
|
87
89
|
},
|
|
88
|
-
[
|
|
89
|
-
),
|
|
90
|
+
[l, y, D, d, h]
|
|
91
|
+
), ae = M(
|
|
90
92
|
(e) => {
|
|
91
|
-
if (!
|
|
93
|
+
if (!S)
|
|
92
94
|
return !0;
|
|
93
|
-
const
|
|
94
|
-
return e.text.toLowerCase().includes(
|
|
95
|
+
const t = S.toLowerCase();
|
|
96
|
+
return e.text.toLowerCase().includes(t) ? !0 : (u.get(e.key) ?? e.children)?.some((n) => ae(n)) ?? !1;
|
|
95
97
|
},
|
|
96
|
-
[
|
|
97
|
-
),
|
|
98
|
-
(e,
|
|
99
|
-
|
|
98
|
+
[S, u]
|
|
99
|
+
), ze = M(
|
|
100
|
+
(e, t) => {
|
|
101
|
+
R?.length && (e.preventDefault(), z({ x: e.clientX, y: e.clientY, node: t }));
|
|
100
102
|
},
|
|
101
|
-
[
|
|
102
|
-
),
|
|
103
|
-
|
|
104
|
-
}, [
|
|
105
|
-
for (const r of
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
103
|
+
[R]
|
|
104
|
+
), le = M(() => {
|
|
105
|
+
b && P && P(b, Y), F(null);
|
|
106
|
+
}, [b, Y, P]), V = E(null), g = (e, t = p) => {
|
|
107
|
+
for (const r of t) {
|
|
108
|
+
const n = r.key === e ? r : g(e, u.get(r.key) ?? r.children ?? G);
|
|
109
|
+
if (n)
|
|
110
|
+
return n;
|
|
109
111
|
}
|
|
112
|
+
}, v = !!Ne && !!O, se = $(() => {
|
|
113
|
+
const e = /* @__PURE__ */ new Map();
|
|
114
|
+
if (!v)
|
|
115
|
+
return e;
|
|
116
|
+
const t = (r, n) => {
|
|
117
|
+
const s = r.map((i) => i.key);
|
|
118
|
+
r.forEach((i) => {
|
|
119
|
+
e.set(i.key, { parent: n, siblings: s }), t(u.get(i.key) ?? i.children ?? G, i.key);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
return t(p, null), e;
|
|
123
|
+
}, [v, p, u]), oe = (e, t) => {
|
|
124
|
+
const r = /* @__PURE__ */ new Set();
|
|
125
|
+
for (let n = e; n != null && !r.has(n); n = se.get(n)?.parent) {
|
|
126
|
+
if (n === t)
|
|
127
|
+
return !0;
|
|
128
|
+
r.add(n);
|
|
129
|
+
}
|
|
130
|
+
return !1;
|
|
131
|
+
}, de = (e, t, r) => !oe(t, e) && (r !== "inside" || g(t)?.leaf !== !0) && (Z ? Z(e, t, r) : !0), A = Qe({
|
|
132
|
+
enabled: v,
|
|
133
|
+
rowSelector: '[role="treeitem"]',
|
|
134
|
+
rectOf: (e) => [...e.children].find((t) => t.classList.contains("nice-tree__row")) ?? e,
|
|
135
|
+
canDrag: (e) => !g(e)?.disabled,
|
|
136
|
+
canNest: (e) => g(e)?.leaf !== !0,
|
|
137
|
+
isWithin: oe,
|
|
138
|
+
canDrop: de,
|
|
139
|
+
onDrop: (e, t, r) => O?.(e, t, r),
|
|
140
|
+
onHoverOpen: (e) => {
|
|
141
|
+
const t = g(e);
|
|
142
|
+
t && !w.current.includes(e) && L(e, t);
|
|
143
|
+
}
|
|
144
|
+
}), [Fe, ue] = m(""), Le = (e) => {
|
|
145
|
+
const t = e.target.closest?.('[role="treeitem"]'), r = v && t && b === null ? Ue(e, getComputedStyle(t).direction === "rtl") : null;
|
|
146
|
+
if (!t || !r)
|
|
147
|
+
return;
|
|
148
|
+
e.preventDefault(), e.stopPropagation();
|
|
149
|
+
const n = t.dataset.key ?? "", s = se.get(n), i = s ? Ze(r, n, s.parent, s.siblings) : null, o = g(n), f = i ? g(i.key) : void 0;
|
|
150
|
+
if (!i || !o || !f || o.disabled || !de(n, i.key, i.position)) {
|
|
151
|
+
ue(
|
|
152
|
+
_("treeDrop.cannotMove", "Cannot move {label} there").replace("{label}", o?.text ?? n)
|
|
153
|
+
);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
i.position === "inside" && !w.current.includes(i.key) && L(i.key, f), O?.(n, i.key, i.position), N.current = n;
|
|
157
|
+
const X = i.position === "before" ? _("treeDrop.movedBefore", "{label} moved before {target}") : i.position === "after" ? _("treeDrop.movedAfter", "{label} moved after {target}") : _("treeDrop.movedInside", "{label} moved into {target}");
|
|
158
|
+
ue(X.replace("{label}", o.text).replace("{target}", f.text));
|
|
110
159
|
};
|
|
111
|
-
|
|
160
|
+
je(V, {
|
|
112
161
|
rowSelector: ".nice-tree__row",
|
|
113
|
-
onToggle: (e,
|
|
114
|
-
const r = e.dataset.key === void 0 ? void 0 :
|
|
115
|
-
r &&
|
|
162
|
+
onToggle: (e, t) => {
|
|
163
|
+
const r = e.dataset.key === void 0 ? void 0 : g(e.dataset.key);
|
|
164
|
+
r && w.current.includes(r.key) !== t && L(r.key, r);
|
|
116
165
|
}
|
|
117
166
|
});
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
if (
|
|
167
|
+
const N = E(null);
|
|
168
|
+
He(() => {
|
|
169
|
+
if (b !== null || N.current === null)
|
|
121
170
|
return;
|
|
122
|
-
const e =
|
|
123
|
-
|
|
124
|
-
}, [
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
171
|
+
const e = N.current;
|
|
172
|
+
N.current = null, [...V.current?.querySelectorAll('[role="treeitem"]') ?? []].find((t) => t.dataset.key === e)?.focus();
|
|
173
|
+
}, [b]);
|
|
174
|
+
const W = E(null);
|
|
175
|
+
qe(W, { orientation: "vertical", wrap: !0, typeahead: !0 }), Be(W, { open: !!x, modal: !1, onClose: () => z(null) });
|
|
176
|
+
const pe = (e, t) => {
|
|
177
|
+
if (S && !ae(e))
|
|
129
178
|
return null;
|
|
130
|
-
const r =
|
|
131
|
-
paddingLeft:
|
|
132
|
-
"--nice-row-bg": `var(--nice-tree-level-${
|
|
133
|
-
"--nice-row-text": `var(--nice-tree-level-${
|
|
134
|
-
"--nice-row-border": `var(--nice-tree-level-${
|
|
135
|
-
"--nice-row-hover-bg": `var(--nice-tree-level-${
|
|
136
|
-
"--nice-row-active-bg": `var(--nice-tree-level-${
|
|
179
|
+
const r = t + 1 >= B, n = r ? void 0 : u.get(e.key) ?? e.children, s = !r && (n && n.length > 0 || e.leaf !== !0 && K && !n?.length), i = q.includes(e.key), o = H ? H.state(e.key) : re.has(e.key) ? "checked" : "unchecked", f = H ? o === "checked" : re.has(e.key), X = !!e.disabled || !!d?.isLocked(e.key), Ae = Me.has(e.key), C = Math.min(t + 1, 10), Ie = {
|
|
180
|
+
paddingLeft: t * 20 + 4,
|
|
181
|
+
"--nice-row-bg": `var(--nice-tree-level-${C}-bg, transparent)`,
|
|
182
|
+
"--nice-row-text": `var(--nice-tree-level-${C}-text, inherit)`,
|
|
183
|
+
"--nice-row-border": `var(--nice-tree-level-${C}-border, transparent)`,
|
|
184
|
+
"--nice-row-hover-bg": `var(--nice-tree-level-${C}-hover-bg, var(--nice-hover-bg, color-mix(in srgb, var(--nice-text-primary) 6%, transparent)))`,
|
|
185
|
+
"--nice-row-active-bg": `var(--nice-tree-level-${C}-active-bg, color-mix(in srgb, var(--nice-color-primary) 14%, transparent))`
|
|
137
186
|
};
|
|
138
|
-
return /* @__PURE__ */
|
|
187
|
+
return /* @__PURE__ */ T(
|
|
139
188
|
"li",
|
|
140
189
|
{
|
|
141
190
|
className: "nice-tree__node",
|
|
142
191
|
role: "treeitem",
|
|
143
192
|
"aria-label": e.text,
|
|
144
|
-
"aria-expanded":
|
|
145
|
-
"aria-selected":
|
|
193
|
+
"aria-expanded": s ? i : void 0,
|
|
194
|
+
"aria-selected": y !== "none" ? f : void 0,
|
|
146
195
|
"aria-disabled": e.disabled || void 0,
|
|
147
196
|
"data-key": e.key,
|
|
148
|
-
"data-nice-depth":
|
|
149
|
-
onKeyDown:
|
|
150
|
-
|
|
151
|
-
} : void 0,
|
|
152
|
-
draggable: x && !e.disabled,
|
|
153
|
-
onDragStart: x ? (t) => {
|
|
154
|
-
t.stopPropagation(), M(e.key);
|
|
155
|
-
} : void 0,
|
|
156
|
-
onDragOver: x ? (t) => {
|
|
157
|
-
t.preventDefault(), t.stopPropagation();
|
|
197
|
+
"data-nice-depth": C,
|
|
198
|
+
onKeyDown: ee && !e.disabled ? (c) => {
|
|
199
|
+
c.key === "F2" && c.target === c.currentTarget && (c.preventDefault(), F(e.key), j(e.text));
|
|
158
200
|
} : void 0,
|
|
159
|
-
|
|
160
|
-
t.stopPropagation(), me?.(L, e.key, "inside"), M(null);
|
|
161
|
-
} : void 0,
|
|
162
|
-
onDragEnd: x ? () => M(null) : void 0,
|
|
201
|
+
draggable: v && !e.disabled || void 0,
|
|
163
202
|
children: [
|
|
164
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ T(
|
|
165
204
|
"div",
|
|
166
205
|
{
|
|
167
206
|
role: "presentation",
|
|
168
|
-
className: `nice-tree__row ${
|
|
169
|
-
style:
|
|
207
|
+
className: `nice-tree__row ${f ? "nice-tree__row--selected" : ""} ${e.disabled ? "nice-tree__row--disabled" : ""} ${A.dragKey === e.key ? "nice-tree__row--dragging" : ""} ${A.target?.key === e.key ? `nice-tree__row--drop-${A.target.position}` : ""}`,
|
|
208
|
+
style: Ie,
|
|
170
209
|
onClick: () => {
|
|
171
|
-
e.disabled || (
|
|
210
|
+
e.disabled || (ce(e.key), me?.(e));
|
|
172
211
|
},
|
|
173
|
-
onContextMenu: (
|
|
174
|
-
onDoubleClick:
|
|
175
|
-
|
|
212
|
+
onContextMenu: (c) => ze(c, e),
|
|
213
|
+
onDoubleClick: ee && !e.disabled ? () => {
|
|
214
|
+
F(e.key), j(e.text);
|
|
176
215
|
} : void 0,
|
|
177
216
|
children: [
|
|
178
|
-
/* @__PURE__ */
|
|
217
|
+
/* @__PURE__ */ a(
|
|
179
218
|
"span",
|
|
180
219
|
{
|
|
181
220
|
role: "presentation",
|
|
182
|
-
className: `nice-tree__toggle ${
|
|
183
|
-
onClick: (
|
|
184
|
-
|
|
221
|
+
className: `nice-tree__toggle ${s ? i ? "nice-tree__toggle--expanded" : "" : "nice-tree__toggle--leaf"}`,
|
|
222
|
+
onClick: (c) => {
|
|
223
|
+
c.stopPropagation(), s && L(e.key, e);
|
|
185
224
|
},
|
|
186
|
-
children:
|
|
225
|
+
children: Ae ? /* @__PURE__ */ a("span", { className: "nice-spinner nice-spinner--xs" }) : s ? i ? /* @__PURE__ */ a(fe, { name: "chevron-down", size: 12 }) : /* @__PURE__ */ a(fe, { name: "chevron-right", size: 12 }) : ""
|
|
187
226
|
}
|
|
188
227
|
),
|
|
189
|
-
|
|
228
|
+
J && y !== "none" && /* @__PURE__ */ a(
|
|
190
229
|
"input",
|
|
191
230
|
{
|
|
192
231
|
type: "checkbox",
|
|
193
|
-
checked:
|
|
194
|
-
ref: (
|
|
195
|
-
|
|
232
|
+
checked: o === "checked",
|
|
233
|
+
ref: (c) => {
|
|
234
|
+
c && (c.indeterminate = o === "indeterminate");
|
|
196
235
|
},
|
|
197
|
-
onChange: () =>
|
|
198
|
-
onClick: (
|
|
199
|
-
disabled:
|
|
236
|
+
onChange: () => ce(e.key),
|
|
237
|
+
onClick: (c) => c.stopPropagation(),
|
|
238
|
+
disabled: X,
|
|
200
239
|
tabIndex: -1,
|
|
201
240
|
"aria-label": e.text,
|
|
202
241
|
className: "nice-tree__checkbox"
|
|
203
242
|
}
|
|
204
243
|
),
|
|
205
|
-
|
|
244
|
+
b === e.key ? /* @__PURE__ */ a(
|
|
206
245
|
"input",
|
|
207
246
|
{
|
|
208
247
|
type: "text",
|
|
209
248
|
className: "nice-tree__edit-input",
|
|
210
|
-
value:
|
|
211
|
-
onChange: (
|
|
212
|
-
onBlur:
|
|
213
|
-
onKeyDown: (
|
|
214
|
-
|
|
249
|
+
value: Y,
|
|
250
|
+
onChange: (c) => j(c.target.value),
|
|
251
|
+
onBlur: le,
|
|
252
|
+
onKeyDown: (c) => {
|
|
253
|
+
c.key === "Enter" && (N.current = e.key, le()), c.key === "Escape" && (c.preventDefault(), N.current = e.key, F(null));
|
|
215
254
|
},
|
|
216
255
|
autoFocus: !0,
|
|
217
|
-
onClick: (
|
|
256
|
+
onClick: (c) => c.stopPropagation()
|
|
218
257
|
}
|
|
219
|
-
) :
|
|
220
|
-
e.icon && /* @__PURE__ */
|
|
221
|
-
/* @__PURE__ */
|
|
258
|
+
) : U ? U(e) : /* @__PURE__ */ T(Oe, { children: [
|
|
259
|
+
e.icon && /* @__PURE__ */ a("span", { className: "nice-tree__icon", children: e.icon }),
|
|
260
|
+
/* @__PURE__ */ a("span", { className: "nice-tree__text", children: e.text })
|
|
222
261
|
] })
|
|
223
262
|
]
|
|
224
263
|
}
|
|
225
264
|
),
|
|
226
|
-
|
|
265
|
+
n && n.length > 0 && i && /* @__PURE__ */ a("ul", { className: "nice-tree__children", role: "group", children: n.map((c) => pe(c, t + 1)) })
|
|
227
266
|
]
|
|
228
267
|
},
|
|
229
268
|
e.key
|
|
230
269
|
);
|
|
231
270
|
};
|
|
232
|
-
return
|
|
271
|
+
return Se ? null : /* @__PURE__ */ T(
|
|
233
272
|
"div",
|
|
234
273
|
{
|
|
235
274
|
role: "presentation",
|
|
236
|
-
className: `nice-tree ${
|
|
237
|
-
style:
|
|
238
|
-
ref:
|
|
239
|
-
"data-testid":
|
|
240
|
-
onClick: () =>
|
|
275
|
+
className: `nice-tree ${ke ? "nice-tree--lines" : ""} ${be || ""}`,
|
|
276
|
+
style: _e,
|
|
277
|
+
ref: Re,
|
|
278
|
+
"data-testid": De,
|
|
279
|
+
onClick: () => z(null),
|
|
241
280
|
children: [
|
|
242
|
-
|
|
243
|
-
|
|
281
|
+
k != null && k !== !1 && /* @__PURE__ */ a("div", { className: "nice-tree__header", children: k }),
|
|
282
|
+
ve && /* @__PURE__ */ a("div", { className: "nice-tree__search", children: /* @__PURE__ */ a(
|
|
244
283
|
"input",
|
|
245
284
|
{
|
|
246
285
|
type: "text",
|
|
247
|
-
value:
|
|
248
|
-
onChange: (e) =>
|
|
249
|
-
placeholder:
|
|
250
|
-
"aria-label":
|
|
286
|
+
value: S,
|
|
287
|
+
onChange: (e) => $e(e.target.value),
|
|
288
|
+
placeholder: Q || _("controls.search", "Search..."),
|
|
289
|
+
"aria-label": Q || _("controls.search", "Search tree")
|
|
251
290
|
}
|
|
252
291
|
) }),
|
|
253
|
-
|
|
292
|
+
ye ? /* @__PURE__ */ a("div", { className: "nice-tree__loading", children: /* @__PURE__ */ a("div", { className: "nice-spinner nice-spinner--sm" }) }) : /* @__PURE__ */ a(
|
|
254
293
|
"ul",
|
|
255
294
|
{
|
|
256
|
-
ref:
|
|
295
|
+
ref: V,
|
|
257
296
|
className: "nice-tree__root",
|
|
258
297
|
role: "tree",
|
|
259
|
-
"aria-multiselectable":
|
|
260
|
-
|
|
298
|
+
"aria-multiselectable": y === "multiple" || void 0,
|
|
299
|
+
onKeyDownCapture: v ? Le : void 0,
|
|
300
|
+
...v ? A.handlers : void 0,
|
|
301
|
+
children: p.map((e) => pe(e, 0))
|
|
261
302
|
}
|
|
262
303
|
),
|
|
263
|
-
|
|
304
|
+
v && /* @__PURE__ */ a("span", { className: "nice-sr-only", role: "status", "aria-live": "polite", children: Fe }),
|
|
305
|
+
x && R && /* @__PURE__ */ a(
|
|
264
306
|
"div",
|
|
265
307
|
{
|
|
266
|
-
ref:
|
|
308
|
+
ref: W,
|
|
267
309
|
className: "nice-tree__context-menu",
|
|
268
310
|
role: "menu",
|
|
269
|
-
"aria-label":
|
|
270
|
-
style: { position: "fixed", top:
|
|
271
|
-
children:
|
|
311
|
+
"aria-label": x.node.text,
|
|
312
|
+
style: { position: "fixed", top: x.y, left: x.x, zIndex: 9999 },
|
|
313
|
+
children: R.map((e) => /* @__PURE__ */ T(
|
|
272
314
|
"button",
|
|
273
315
|
{
|
|
274
316
|
type: "button",
|
|
@@ -276,10 +318,10 @@ const le = [], Ve = [], Qe = ({
|
|
|
276
318
|
disabled: e.disabled,
|
|
277
319
|
className: `nice-tree__context-item ${e.disabled ? "nice-tree__context-item--disabled" : ""}`,
|
|
278
320
|
onClick: () => {
|
|
279
|
-
e.disabled || (
|
|
321
|
+
e.disabled || (Ce?.(e.key, x.node), z(null));
|
|
280
322
|
},
|
|
281
323
|
children: [
|
|
282
|
-
e.icon && /* @__PURE__ */
|
|
324
|
+
e.icon && /* @__PURE__ */ a("span", { children: e.icon }),
|
|
283
325
|
e.label
|
|
284
326
|
]
|
|
285
327
|
},
|
|
@@ -292,5 +334,5 @@ const le = [], Ve = [], Qe = ({
|
|
|
292
334
|
);
|
|
293
335
|
};
|
|
294
336
|
export {
|
|
295
|
-
|
|
337
|
+
lt as NiceTreeView
|
|
296
338
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useRef as y, useState as O, useCallback as v, useEffect as A } from "react";
|
|
2
|
+
const M = 600, _ = "application/x-nice-tree-row";
|
|
3
|
+
function K(o, n, s = !0) {
|
|
4
|
+
const a = (o - n.top) / Math.max(1, n.height);
|
|
5
|
+
return s ? a < 0.25 ? "before" : a > 0.75 ? "after" : "inside" : a < 0.5 ? "before" : "after";
|
|
6
|
+
}
|
|
7
|
+
function P(o, n = !1) {
|
|
8
|
+
if (!(o.ctrlKey || o.metaKey) || !o.shiftKey || o.altKey)
|
|
9
|
+
return null;
|
|
10
|
+
switch (o.key) {
|
|
11
|
+
case "ArrowUp":
|
|
12
|
+
return "up";
|
|
13
|
+
case "ArrowDown":
|
|
14
|
+
return "down";
|
|
15
|
+
case "ArrowRight":
|
|
16
|
+
return n ? "out" : "in";
|
|
17
|
+
case "ArrowLeft":
|
|
18
|
+
return n ? "in" : "out";
|
|
19
|
+
default:
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function S(o, n, s, a) {
|
|
24
|
+
const u = a.indexOf(n);
|
|
25
|
+
if (u < 0)
|
|
26
|
+
return null;
|
|
27
|
+
switch (o) {
|
|
28
|
+
case "up":
|
|
29
|
+
return u > 0 ? { key: a[u - 1], position: "before" } : null;
|
|
30
|
+
case "down":
|
|
31
|
+
return u < a.length - 1 ? { key: a[u + 1], position: "after" } : null;
|
|
32
|
+
case "in":
|
|
33
|
+
return u > 0 ? { key: a[u - 1], position: "inside" } : null;
|
|
34
|
+
case "out":
|
|
35
|
+
return s !== null ? { key: s, position: "after" } : null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function b(o) {
|
|
39
|
+
const n = y(o);
|
|
40
|
+
n.current = o;
|
|
41
|
+
const [s, a] = O(null), [u, D] = O(null), c = y({
|
|
42
|
+
drag: null,
|
|
43
|
+
target: null
|
|
44
|
+
}), f = y({
|
|
45
|
+
key: null,
|
|
46
|
+
timer: void 0
|
|
47
|
+
}), l = v(() => {
|
|
48
|
+
clearTimeout(f.current.timer), f.current = { key: null, timer: void 0 };
|
|
49
|
+
}, []), k = v(
|
|
50
|
+
(t) => {
|
|
51
|
+
const r = c.current.target;
|
|
52
|
+
if (r?.key === t?.key && r?.position === t?.position)
|
|
53
|
+
return;
|
|
54
|
+
c.current.target = t, D(t);
|
|
55
|
+
const e = t?.position === "inside" ? t.key : null;
|
|
56
|
+
e !== f.current.key && (l(), e !== null && n.current.onHoverOpen && (f.current = {
|
|
57
|
+
key: e,
|
|
58
|
+
timer: setTimeout(() => n.current.onHoverOpen?.(e), M)
|
|
59
|
+
}));
|
|
60
|
+
},
|
|
61
|
+
[l]
|
|
62
|
+
), w = v(() => {
|
|
63
|
+
l(), c.current = { drag: null, target: null }, a(null), D(null);
|
|
64
|
+
}, [l]);
|
|
65
|
+
A(() => l, [l]);
|
|
66
|
+
const h = (t) => {
|
|
67
|
+
const r = t.target?.closest?.(n.current.rowSelector);
|
|
68
|
+
return r && t.currentTarget.contains(r) ? r : null;
|
|
69
|
+
}, T = (t) => {
|
|
70
|
+
const r = n.current, e = c.current.drag, d = h(t), i = d?.dataset.key;
|
|
71
|
+
if (!d || i === void 0 || e === null || r.isWithin(i, e))
|
|
72
|
+
return null;
|
|
73
|
+
const m = (r.rectOf?.(d) ?? d).getBoundingClientRect(), R = r.canNest ? r.canNest(i) : !0, E = (p) => r.canDrop ? r.canDrop(e, i, p) : !0, g = K(t.clientY, m, R);
|
|
74
|
+
if (E(g))
|
|
75
|
+
return { key: i, position: g };
|
|
76
|
+
if (g === "inside") {
|
|
77
|
+
const p = K(t.clientY, m, !1);
|
|
78
|
+
return E(p) ? { key: i, position: p } : null;
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
return { dragKey: s, target: u, handlers: {
|
|
83
|
+
onDragStart: (t) => {
|
|
84
|
+
const r = n.current, e = h(t)?.dataset.key;
|
|
85
|
+
if (!(!r.enabled || e === void 0)) {
|
|
86
|
+
if (r.canDrag && !r.canDrag(e)) {
|
|
87
|
+
t.preventDefault();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
t.stopPropagation();
|
|
91
|
+
try {
|
|
92
|
+
t.dataTransfer.setData(_, e), t.dataTransfer.setData("text/plain", e), t.dataTransfer.effectAllowed = "move";
|
|
93
|
+
} catch {
|
|
94
|
+
}
|
|
95
|
+
c.current = { drag: e, target: null }, a(e);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
onDragOver: (t) => {
|
|
99
|
+
if (c.current.drag === null)
|
|
100
|
+
return;
|
|
101
|
+
const r = T(t);
|
|
102
|
+
if (k(r), r) {
|
|
103
|
+
t.preventDefault();
|
|
104
|
+
try {
|
|
105
|
+
t.dataTransfer.dropEffect = "move";
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onDragLeave: (t) => {
|
|
111
|
+
const r = t.relatedTarget;
|
|
112
|
+
(!r || !t.currentTarget.contains(r)) && k(null);
|
|
113
|
+
},
|
|
114
|
+
onDrop: (t) => {
|
|
115
|
+
const r = c.current.drag;
|
|
116
|
+
if (r === null)
|
|
117
|
+
return;
|
|
118
|
+
const e = T(t) ?? c.current.target;
|
|
119
|
+
t.preventDefault(), t.stopPropagation(), w(), e && n.current.onDrop?.(r, e.key, e.position);
|
|
120
|
+
},
|
|
121
|
+
onDragEnd: w
|
|
122
|
+
} };
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
_ as NICE_TREE_ROW_MIME,
|
|
126
|
+
K as treeDropPosition,
|
|
127
|
+
P as treeKeyboardMove,
|
|
128
|
+
S as treeKeyboardTarget,
|
|
129
|
+
b as useTreeRowDrop
|
|
130
|
+
};
|