useMaxLevel.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. import { n as x, d as w, ac as M, aS as F, o as G, aT as $ } from "./index2.js";
  2. import { ref as z, shallowRef as B, watchEffect as R } from "vue";
  3. function ee(e, t) {
  4. if (!e) return [];
  5. const o = e.slice(), n = o.indexOf(t);
  6. return n >= 0 && o.splice(n, 1), o;
  7. }
  8. function te(e, t) {
  9. const o = (e || []).slice();
  10. return o.indexOf(t) === -1 && o.push(t), o;
  11. }
  12. function j(e) {
  13. return e.split("-");
  14. }
  15. function _(e, t) {
  16. return `${e}-${t}`;
  17. }
  18. function U(e) {
  19. return e && e.type && e.type.isTreeNode;
  20. }
  21. function ne(e, t) {
  22. const o = [], n = t[e];
  23. function r() {
  24. (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []).forEach((f) => {
  25. let {
  26. key: c,
  27. children: u
  28. } = f;
  29. o.push(c), r(u);
  30. });
  31. }
  32. return r(n.children), o;
  33. }
  34. function V(e) {
  35. if (e.parent) {
  36. const t = j(e.pos);
  37. return Number(t[t.length - 1]) === e.parent.children.length - 1;
  38. }
  39. return !1;
  40. }
  41. function W(e) {
  42. const t = j(e.pos);
  43. return Number(t[t.length - 1]) === 0;
  44. }
  45. function re(e, t, o, n, r, s, f, c, u, l) {
  46. var a;
  47. const {
  48. clientX: i,
  49. clientY: d
  50. } = e, {
  51. top: p,
  52. height: h
  53. } = e.target.getBoundingClientRect(), g = ((l === "rtl" ? -1 : 1) * (((r == null ? void 0 : r.x) || 0) - i) - 12) / n;
  54. let y = c[o.eventKey];
  55. if (d < p + h / 2) {
  56. const N = f.findIndex((D) => D.key === y.key), E = N <= 0 ? 0 : N - 1, L = f[E].key;
  57. y = c[L];
  58. }
  59. const k = y.key, b = y, m = y.key;
  60. let K = 0, C = 0;
  61. if (!u.has(k))
  62. for (let N = 0; N < g && V(y); N += 1)
  63. y = y.parent, C += 1;
  64. const S = t.eventData, O = y.node;
  65. let P = !0;
  66. return W(y) && y.level === 0 && d < p + h / 2 && s({
  67. dragNode: S,
  68. dropNode: O,
  69. dropPosition: -1
  70. }) && y.key === o.eventKey ? K = -1 : (b.children || []).length && u.has(m) ? s({
  71. dragNode: S,
  72. dropNode: O,
  73. dropPosition: 0
  74. }) ? K = 0 : P = !1 : C === 0 ? g > -1.5 ? s({
  75. dragNode: S,
  76. dropNode: O,
  77. dropPosition: 1
  78. }) ? K = 1 : P = !1 : s({
  79. dragNode: S,
  80. dropNode: O,
  81. dropPosition: 0
  82. }) ? K = 0 : s({
  83. dragNode: S,
  84. dropNode: O,
  85. dropPosition: 1
  86. }) ? K = 1 : P = !1 : s({
  87. dragNode: S,
  88. dropNode: O,
  89. dropPosition: 1
  90. }) ? K = 1 : P = !1, {
  91. dropPosition: K,
  92. dropLevelOffset: C,
  93. dropTargetKey: y.key,
  94. dropTargetPos: y.pos,
  95. dragOverNodeKey: m,
  96. dropContainerKey: K === 0 ? null : ((a = y.parent) === null || a === void 0 ? void 0 : a.key) || null,
  97. dropAllowed: P
  98. };
  99. }
  100. function oe(e, t) {
  101. if (!e) return;
  102. const {
  103. multiple: o
  104. } = t;
  105. return o ? e.slice() : e.length ? [e[0]] : e;
  106. }
  107. function se(e) {
  108. if (!e)
  109. return null;
  110. let t;
  111. if (Array.isArray(e))
  112. t = {
  113. checkedKeys: e,
  114. halfCheckedKeys: void 0
  115. };
  116. else if (typeof e == "object")
  117. t = {
  118. checkedKeys: e.checked || void 0,
  119. halfCheckedKeys: e.halfChecked || void 0
  120. };
  121. else
  122. return x(!1, "`checkedKeys` is not an array or an object"), null;
  123. return t;
  124. }
  125. function ie(e, t) {
  126. const o = /* @__PURE__ */ new Set();
  127. function n(r) {
  128. if (o.has(r)) return;
  129. const s = t[r];
  130. if (!s) return;
  131. o.add(r);
  132. const {
  133. parent: f,
  134. node: c
  135. } = s;
  136. c.disabled || f && n(f.key);
  137. }
  138. return (e || []).forEach((r) => {
  139. n(r);
  140. }), [...o];
  141. }
  142. var X = function(e, t) {
  143. var o = {};
  144. for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (o[n] = e[n]);
  145. if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var r = 0, n = Object.getOwnPropertySymbols(e); r < n.length; r++)
  146. t.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[r]) && (o[n[r]] = e[n[r]]);
  147. return o;
  148. };
  149. function T(e, t) {
  150. return e != null ? e : t;
  151. }
  152. function A(e) {
  153. const {
  154. title: t,
  155. _title: o,
  156. key: n,
  157. children: r
  158. } = e || {}, s = t || "title";
  159. return {
  160. title: s,
  161. _title: o || [s],
  162. key: n || "key",
  163. children: r || "children"
  164. };
  165. }
  166. function ae(e) {
  167. function t() {
  168. let o = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
  169. return M(o).map((r) => {
  170. var s, f, c, u;
  171. if (!U(r))
  172. return x(!r, "Tree/TreeNode can only accept TreeNode as children."), null;
  173. const l = r.children || {}, a = r.key, i = {};
  174. for (const [N, E] of Object.entries(r.props))
  175. i[F(N)] = E;
  176. const {
  177. isLeaf: d,
  178. checkable: p,
  179. selectable: h,
  180. disabled: v,
  181. disableCheckbox: g
  182. } = i, y = {
  183. isLeaf: d || d === "" || void 0,
  184. checkable: p || p === "" || void 0,
  185. selectable: h || h === "" || void 0,
  186. disabled: v || v === "" || void 0,
  187. disableCheckbox: g || g === "" || void 0
  188. }, k = w(w({}, i), y), {
  189. title: b = (s = l.title) === null || s === void 0 ? void 0 : s.call(l, k),
  190. icon: m = (f = l.icon) === null || f === void 0 ? void 0 : f.call(l, k),
  191. switcherIcon: K = (c = l.switcherIcon) === null || c === void 0 ? void 0 : c.call(l, k)
  192. } = i, C = X(i, ["title", "icon", "switcherIcon"]), S = (u = l.default) === null || u === void 0 ? void 0 : u.call(l), O = w(w(w({}, C), {
  193. title: b,
  194. icon: m,
  195. switcherIcon: K,
  196. key: a,
  197. isLeaf: d
  198. }), y), P = t(S);
  199. return P.length && (O.children = P), O;
  200. });
  201. }
  202. return t(e);
  203. }
  204. function le(e, t, o) {
  205. const {
  206. _title: n,
  207. key: r,
  208. children: s
  209. } = A(o), f = new Set(t === !0 ? [] : t), c = [];
  210. function u(l) {
  211. let a = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
  212. return l.map((i, d) => {
  213. const p = _(a ? a.pos : "0", d), h = T(i[r], p);
  214. let v;
  215. for (let y = 0; y < n.length; y += 1) {
  216. const k = n[y];
  217. if (i[k] !== void 0) {
  218. v = i[k];
  219. break;
  220. }
  221. }
  222. const g = w(w({}, G(i, [...n, r, s])), {
  223. title: v,
  224. key: h,
  225. parent: a,
  226. pos: p,
  227. children: null,
  228. data: i,
  229. isStart: [...a ? a.isStart : [], d === 0],
  230. isEnd: [...a ? a.isEnd : [], d === l.length - 1]
  231. });
  232. return c.push(g), t === !0 || f.has(h) ? g.children = u(i[s] || [], g) : g.children = [], g;
  233. });
  234. }
  235. return u(e), c;
  236. }
  237. function Y(e, t, o) {
  238. let n = {};
  239. typeof o == "object" ? n = o : n = {
  240. externalGetKey: o
  241. }, n = n || {};
  242. const {
  243. childrenPropName: r,
  244. externalGetKey: s,
  245. fieldNames: f
  246. } = n, {
  247. key: c,
  248. children: u
  249. } = A(f), l = r || u;
  250. let a;
  251. s ? typeof s == "string" ? a = (d) => d[s] : typeof s == "function" && (a = (d) => s(d)) : a = (d, p) => T(d[c], p);
  252. function i(d, p, h, v) {
  253. const g = d ? d[l] : e, y = d ? _(h.pos, p) : "0", k = d ? [...v, d] : [];
  254. if (d) {
  255. const b = a(d, y), m = {
  256. node: d,
  257. index: p,
  258. pos: y,
  259. key: b,
  260. parentPos: h.node ? h.pos : null,
  261. level: h.level + 1,
  262. nodes: k
  263. };
  264. t(m);
  265. }
  266. g && g.forEach((b, m) => {
  267. i(b, m, {
  268. node: d,
  269. pos: y,
  270. level: h ? h.level + 1 : -1
  271. }, k);
  272. });
  273. }
  274. i(null);
  275. }
  276. function ce(e) {
  277. let {
  278. initWrapper: t,
  279. processEntity: o,
  280. onProcessFinished: n,
  281. externalGetKey: r,
  282. childrenPropName: s,
  283. fieldNames: f
  284. } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, c = arguments.length > 2 ? arguments[2] : void 0;
  285. const u = r || c, l = {}, a = {};
  286. let i = {
  287. posEntities: l,
  288. keyEntities: a
  289. };
  290. return t && (i = t(i) || i), Y(e, (d) => {
  291. const {
  292. node: p,
  293. index: h,
  294. pos: v,
  295. key: g,
  296. parentPos: y,
  297. level: k,
  298. nodes: b
  299. } = d, m = {
  300. node: p,
  301. nodes: b,
  302. index: h,
  303. key: g,
  304. pos: v,
  305. level: k
  306. }, K = T(g, v);
  307. l[v] = m, a[K] = m, m.parent = l[y], m.parent && (m.parent.children = m.parent.children || [], m.parent.children.push(m)), o && o(m, i);
  308. }, {
  309. externalGetKey: u,
  310. childrenPropName: s,
  311. fieldNames: f
  312. }), n && n(i), i;
  313. }
  314. function de(e, t) {
  315. let {
  316. expandedKeysSet: o,
  317. selectedKeysSet: n,
  318. loadedKeysSet: r,
  319. loadingKeysSet: s,
  320. checkedKeysSet: f,
  321. halfCheckedKeysSet: c,
  322. dragOverNodeKey: u,
  323. dropPosition: l,
  324. keyEntities: a
  325. } = t;
  326. const i = a[e];
  327. return {
  328. eventKey: e,
  329. expanded: o.has(e),
  330. selected: n.has(e),
  331. loaded: r.has(e),
  332. loading: s.has(e),
  333. checked: f.has(e),
  334. halfChecked: c.has(e),
  335. pos: String(i ? i.pos : ""),
  336. parent: i.parent,
  337. // [Legacy] Drag props
  338. // Since the interaction of drag is changed, the semantic of the props are
  339. // not accuracy, I think it should be finally removed
  340. dragOver: u === e && l === 0,
  341. dragOverGapTop: u === e && l === -1,
  342. dragOverGapBottom: u === e && l === 1
  343. };
  344. }
  345. function fe(e) {
  346. const {
  347. data: t,
  348. expanded: o,
  349. selected: n,
  350. checked: r,
  351. loaded: s,
  352. loading: f,
  353. halfChecked: c,
  354. dragOver: u,
  355. dragOverGapTop: l,
  356. dragOverGapBottom: a,
  357. pos: i,
  358. active: d,
  359. eventKey: p
  360. } = e, h = w(w({
  361. dataRef: t
  362. }, t), {
  363. expanded: o,
  364. selected: n,
  365. checked: r,
  366. loaded: s,
  367. loading: f,
  368. halfChecked: c,
  369. dragOver: u,
  370. dragOverGapTop: l,
  371. dragOverGapBottom: a,
  372. pos: i,
  373. active: d,
  374. eventKey: p,
  375. key: p
  376. });
  377. return "props" in h || Object.defineProperty(h, "props", {
  378. get() {
  379. return x(!1, "Second param return from event is node data instead of TreeNode instance. Please read value directly instead of reading from `props`."), e;
  380. }
  381. }), h;
  382. }
  383. function I(e, t) {
  384. const o = /* @__PURE__ */ new Set();
  385. return e.forEach((n) => {
  386. t.has(n) || o.add(n);
  387. }), o;
  388. }
  389. function q(e) {
  390. const {
  391. disabled: t,
  392. disableCheckbox: o,
  393. checkable: n
  394. } = e || {};
  395. return !!(t || o) || n === !1;
  396. }
  397. function H(e, t, o, n) {
  398. const r = new Set(e), s = /* @__PURE__ */ new Set();
  399. for (let c = 0; c <= o; c += 1)
  400. (t.get(c) || /* @__PURE__ */ new Set()).forEach((l) => {
  401. const {
  402. key: a,
  403. node: i,
  404. children: d = []
  405. } = l;
  406. r.has(a) && !n(i) && d.filter((p) => !n(p.node)).forEach((p) => {
  407. r.add(p.key);
  408. });
  409. });
  410. const f = /* @__PURE__ */ new Set();
  411. for (let c = o; c >= 0; c -= 1)
  412. (t.get(c) || /* @__PURE__ */ new Set()).forEach((l) => {
  413. const {
  414. parent: a,
  415. node: i
  416. } = l;
  417. if (n(i) || !l.parent || f.has(l.parent.key))
  418. return;
  419. if (n(l.parent.node)) {
  420. f.add(a.key);
  421. return;
  422. }
  423. let d = !0, p = !1;
  424. (a.children || []).filter((h) => !n(h.node)).forEach((h) => {
  425. let {
  426. key: v
  427. } = h;
  428. const g = r.has(v);
  429. d && !g && (d = !1), !p && (g || s.has(v)) && (p = !0);
  430. }), d && r.add(a.key), p && s.add(a.key), f.add(a.key);
  431. });
  432. return {
  433. checkedKeys: Array.from(r),
  434. halfCheckedKeys: Array.from(I(s, r))
  435. };
  436. }
  437. function J(e, t, o, n, r) {
  438. const s = new Set(e);
  439. let f = new Set(t);
  440. for (let u = 0; u <= n; u += 1)
  441. (o.get(u) || /* @__PURE__ */ new Set()).forEach((a) => {
  442. const {
  443. key: i,
  444. node: d,
  445. children: p = []
  446. } = a;
  447. !s.has(i) && !f.has(i) && !r(d) && p.filter((h) => !r(h.node)).forEach((h) => {
  448. s.delete(h.key);
  449. });
  450. });
  451. f = /* @__PURE__ */ new Set();
  452. const c = /* @__PURE__ */ new Set();
  453. for (let u = n; u >= 0; u -= 1)
  454. (o.get(u) || /* @__PURE__ */ new Set()).forEach((a) => {
  455. const {
  456. parent: i,
  457. node: d
  458. } = a;
  459. if (r(d) || !a.parent || c.has(a.parent.key))
  460. return;
  461. if (r(a.parent.node)) {
  462. c.add(i.key);
  463. return;
  464. }
  465. let p = !0, h = !1;
  466. (i.children || []).filter((v) => !r(v.node)).forEach((v) => {
  467. let {
  468. key: g
  469. } = v;
  470. const y = s.has(g);
  471. p && !y && (p = !1), !h && (y || f.has(g)) && (h = !0);
  472. }), p || s.delete(i.key), h && f.add(i.key), c.add(i.key);
  473. });
  474. return {
  475. checkedKeys: Array.from(s),
  476. halfCheckedKeys: Array.from(I(f, s))
  477. };
  478. }
  479. function ue(e, t, o, n, r, s) {
  480. const f = [];
  481. let c;
  482. s ? c = s : c = q;
  483. const u = new Set(e.filter((a) => {
  484. const i = !!o[a];
  485. return i || f.push(a), i;
  486. }));
  487. $(!f.length, `Tree missing follow keys: ${f.slice(0, 100).map((a) => `'${a}'`).join(", ")}`);
  488. let l;
  489. return t === !0 ? l = H(u, r, n, c) : l = J(u, t.halfCheckedKeys, r, n, c), l;
  490. }
  491. function he(e) {
  492. const t = z(0), o = B();
  493. return R(() => {
  494. const n = /* @__PURE__ */ new Map();
  495. let r = 0;
  496. const s = e.value || {};
  497. for (const f in s)
  498. if (Object.prototype.hasOwnProperty.call(s, f)) {
  499. const c = s[f], {
  500. level: u
  501. } = c;
  502. let l = n.get(u);
  503. l || (l = /* @__PURE__ */ new Set(), n.set(u, l)), l.add(c), r = Math.max(r, u);
  504. }
  505. t.value = r, o.value = n;
  506. }), {
  507. maxLevel: t,
  508. levelEntities: o
  509. };
  510. }
  511. export {
  512. ue as a,
  513. ee as b,
  514. ce as c,
  515. te as d,
  516. ae as e,
  517. A as f,
  518. ie as g,
  519. de as h,
  520. fe as i,
  521. T as j,
  522. le as k,
  523. oe as l,
  524. ne as m,
  525. re as n,
  526. j as o,
  527. se as p,
  528. he as u
  529. };