@himanshu-sorathiya/react-kit 1.0.32 → 1.0.33
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/dist/index.d.ts +557 -24
- package/dist/index.js +4 -4
- package/dist/state.d.ts +557 -24
- package/dist/state.js +2 -2
- package/dist/state2.js +509 -112
- package/package.json +1 -1
package/dist/state2.js
CHANGED
|
@@ -279,88 +279,131 @@ function l(r = {}) {
|
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
//#endregion
|
|
282
|
+
//#region src/shared/stateShared/utils.ts
|
|
283
|
+
function u(e, t, n) {
|
|
284
|
+
if (!((typeof e == "object" || typeof e == "function") && e !== null)) return e;
|
|
285
|
+
let r = typeof t == "string" ? t.split(".") : Array.isArray(t) ? t : [];
|
|
286
|
+
if (r.length === 0) return n ?? void 0;
|
|
287
|
+
let i = r.reduce((e, t) => {
|
|
288
|
+
if ((typeof e == "object" || typeof e == "function") && e !== null) return e[t];
|
|
289
|
+
}, e);
|
|
290
|
+
return i === void 0 ? n ?? void 0 : i;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/shared/selectionShared/utils.ts
|
|
294
|
+
var d = globalThis.process?.env?.NODE_ENV !== "production";
|
|
295
|
+
function f(e, t) {
|
|
296
|
+
let n = u(e, t);
|
|
297
|
+
if (d && n == null) throw console.warn("[resolveSelectionId] Resolved id is", n, "— this usually means `field` does not point to a valid property on the item, or the item's runtime shape doesn't match its declared type.", {
|
|
298
|
+
item: e,
|
|
299
|
+
field: t
|
|
300
|
+
}), Error(`[resolveSelectionId] Invalid id resolved: ${String(n)}`);
|
|
301
|
+
return n;
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
282
304
|
//#region src/state/useMultipleSelection/useMultipleSelection.ts
|
|
283
|
-
function
|
|
284
|
-
let
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
305
|
+
function p(e = {}) {
|
|
306
|
+
let { items: r, defaultSelectedIds: a, isDisabled: o, field: s } = e, c = n(() => Array.isArray(r) ? r : [], [r]), l = n(() => Array.isArray(a) ? a : [], [a]), [u, d] = i(() => new Set(l)), p = n(() => c.map((e) => ({
|
|
307
|
+
item: e,
|
|
308
|
+
id: f(e, s)
|
|
309
|
+
})), [c, s]), m = n(() => p.map((e) => e.id), [p]), h = n(() => m.filter((e) => !(o?.(e) ?? !1)), [m, o]), g = n(() => p.filter((e) => u.has(e.id)).map((e) => e.item), [p, u]), _ = n(() => {
|
|
310
|
+
let e = m.filter((e) => u.has(e));
|
|
311
|
+
if (e.length === u.size) return e;
|
|
312
|
+
let t = new Set(e), n = [];
|
|
313
|
+
return u.forEach((e) => {
|
|
314
|
+
t.has(e) || n.push(e);
|
|
315
|
+
}), [...e, ...n];
|
|
316
|
+
}, [m, u]), v = n(() => h.length > 0 && h.every((e) => u.has(e)), [h, u]), y = n(() => !v && h.some((e) => u.has(e)), [
|
|
317
|
+
v,
|
|
318
|
+
h,
|
|
319
|
+
u
|
|
320
|
+
]), b = t((e) => {
|
|
321
|
+
let t = f(e, s);
|
|
322
|
+
o?.(t) || d((e) => {
|
|
323
|
+
if (e.has(t)) return e;
|
|
324
|
+
let n = new Set(e);
|
|
325
|
+
return n.add(t), n;
|
|
288
326
|
});
|
|
289
|
-
}, [
|
|
290
|
-
f(
|
|
291
|
-
|
|
292
|
-
|
|
327
|
+
}, [s, o]), x = t((e) => {
|
|
328
|
+
let t = f(e, s);
|
|
329
|
+
d((e) => {
|
|
330
|
+
if (!e.has(t)) return e;
|
|
331
|
+
let n = new Set(e);
|
|
332
|
+
return n.delete(t), n;
|
|
293
333
|
});
|
|
294
|
-
}, [
|
|
295
|
-
f(
|
|
296
|
-
|
|
297
|
-
|
|
334
|
+
}, [s]), S = t((e) => {
|
|
335
|
+
let t = f(e, s);
|
|
336
|
+
d((e) => {
|
|
337
|
+
let n = e.has(t);
|
|
338
|
+
if (!n && o?.(t)) return e;
|
|
339
|
+
let r = new Set(e);
|
|
340
|
+
return n ? r.delete(t) : r.add(t), r;
|
|
298
341
|
});
|
|
299
|
-
}, [
|
|
300
|
-
let
|
|
301
|
-
|
|
302
|
-
}, [
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}, [
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
let n = s.map((t) => e(t, l));
|
|
313
|
-
return new Set(n);
|
|
314
|
-
}), [s, l]), S = t(() => f((t) => {
|
|
315
|
-
if (t.size === s.length) return /* @__PURE__ */ new Set();
|
|
316
|
-
let n = s.filter((n) => !t.has(e(n, l))).map((t) => e(t, l));
|
|
317
|
-
return new Set(n);
|
|
318
|
-
}), [s, l]), C = t((t) => {
|
|
319
|
-
f((n) => {
|
|
320
|
-
let r = new Set(n);
|
|
321
|
-
return (Array.isArray(t) ? t : []).map((t) => e(t, l)).forEach((e) => r.add(e)), r;
|
|
342
|
+
}, [s, o]), C = t((e) => u.has(f(e, s)), [u, s]), w = t(() => d(new Set(l)), [l]), T = t((e) => {
|
|
343
|
+
let t = (Array.isArray(e) ? e : []).map((e) => f(e, s)).filter((e) => !(o?.(e) ?? !1));
|
|
344
|
+
d(new Set(t));
|
|
345
|
+
}, [s, o]), E = t(() => {
|
|
346
|
+
d(new Set(h));
|
|
347
|
+
}, [h]), D = t(() => {
|
|
348
|
+
d((e) => e.size === 0 ? e : /* @__PURE__ */ new Set());
|
|
349
|
+
}, []), O = t(() => {
|
|
350
|
+
d((e) => h.length > 0 && h.every((t) => e.has(t)) ? /* @__PURE__ */ new Set() : new Set(h));
|
|
351
|
+
}, [h]), k = t(() => {
|
|
352
|
+
d((e) => {
|
|
353
|
+
let t = h.filter((t) => !e.has(t));
|
|
354
|
+
return new Set(t);
|
|
322
355
|
});
|
|
323
|
-
}, [
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
356
|
+
}, [h]), A = t((e) => {
|
|
357
|
+
let t = Array.isArray(e) ? e : [];
|
|
358
|
+
d((e) => {
|
|
359
|
+
let n = new Set(e);
|
|
360
|
+
for (let e of t) {
|
|
361
|
+
let t = f(e, s);
|
|
362
|
+
(o?.(t) ?? !1) || n.add(t);
|
|
363
|
+
}
|
|
364
|
+
return n;
|
|
327
365
|
});
|
|
328
|
-
}, [
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
366
|
+
}, [s, o]), j = t((e) => {
|
|
367
|
+
let t = Array.isArray(e) ? e : [];
|
|
368
|
+
d((e) => {
|
|
369
|
+
let n = new Set(e);
|
|
370
|
+
for (let e of t) n.delete(f(e, s));
|
|
371
|
+
return n;
|
|
332
372
|
});
|
|
333
|
-
}, [
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
373
|
+
}, [s]), M = t((e) => {
|
|
374
|
+
let t = new Set((Array.isArray(e) ? e : []).map((e) => f(e, s)));
|
|
375
|
+
d((e) => {
|
|
376
|
+
let n = /* @__PURE__ */ new Set();
|
|
377
|
+
return e.forEach((e) => {
|
|
378
|
+
t.has(e) && n.add(e);
|
|
379
|
+
}), n;
|
|
380
|
+
});
|
|
381
|
+
}, [s]);
|
|
341
382
|
return {
|
|
342
|
-
selectedIds:
|
|
343
|
-
selectedCount:
|
|
344
|
-
selectedItems:
|
|
345
|
-
isEmpty:
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
383
|
+
selectedIds: _,
|
|
384
|
+
selectedCount: u.size,
|
|
385
|
+
selectedItems: g,
|
|
386
|
+
isEmpty: u.size === 0,
|
|
387
|
+
isAllSelected: v,
|
|
388
|
+
isPartiallySelected: y,
|
|
389
|
+
select: b,
|
|
390
|
+
deselect: x,
|
|
391
|
+
toggle: S,
|
|
392
|
+
isSelected: C,
|
|
393
|
+
reset: w,
|
|
394
|
+
replaceSelection: T,
|
|
395
|
+
selectAll: E,
|
|
396
|
+
deselectAll: D,
|
|
397
|
+
toggleAll: O,
|
|
398
|
+
invertSelection: k,
|
|
399
|
+
selectMultiple: A,
|
|
400
|
+
deselectMultiple: j,
|
|
401
|
+
retainOnly: M
|
|
359
402
|
};
|
|
360
403
|
}
|
|
361
404
|
//#endregion
|
|
362
405
|
//#region src/state/useOrder/useOrder.ts
|
|
363
|
-
function
|
|
406
|
+
function m(e = []) {
|
|
364
407
|
let a = n(() => Array.isArray(e) ? e : [], [e]), o = r(a), [s, c] = i(() => a), l = t((e) => {
|
|
365
408
|
typeof e == "number" && c((t) => {
|
|
366
409
|
if (e <= 0 || e >= t.length) return t;
|
|
@@ -418,7 +461,7 @@ function d(e = []) {
|
|
|
418
461
|
}
|
|
419
462
|
//#endregion
|
|
420
463
|
//#region src/state/usePagination/usePagination.ts
|
|
421
|
-
function
|
|
464
|
+
function h(e = [], r, a = 0) {
|
|
422
465
|
let o = n(() => Array.isArray(e) ? e : [], [e]), [s, c] = i(r), [l, u] = i(a), d = Math.max(1, Math.ceil(o.length / Math.max(1, s))), f = Math.min(Math.max(0, l), d - 1);
|
|
423
466
|
return l !== f && u(f), {
|
|
424
467
|
pageItems: n(() => typeof s != "number" || s < 1 ? [] : o.slice(l * s, (l + 1) * s), [
|
|
@@ -474,40 +517,44 @@ function f(e = [], r, a = 0) {
|
|
|
474
517
|
}
|
|
475
518
|
//#endregion
|
|
476
519
|
//#region src/state/useSingleSelection/useSingleSelection.ts
|
|
477
|
-
function
|
|
478
|
-
let
|
|
520
|
+
function g(e = {}) {
|
|
521
|
+
let { defaultSelectedId: n, isDisabled: r } = e, [a, o] = i(n), s = t((e) => {
|
|
522
|
+
r?.(e) || o(e);
|
|
523
|
+
}, [r]), c = t(() => o(void 0), []), l = t((e) => {
|
|
524
|
+
r?.(e) || o((t) => t === e ? void 0 : e);
|
|
525
|
+
}, [r]), u = t((e) => a === e, [a]), d = t(() => o(n), [n]);
|
|
479
526
|
return {
|
|
480
|
-
selectedId:
|
|
481
|
-
hasSelection:
|
|
482
|
-
select:
|
|
483
|
-
deselect:
|
|
484
|
-
toggle:
|
|
485
|
-
isSelected:
|
|
486
|
-
|
|
527
|
+
selectedId: a,
|
|
528
|
+
hasSelection: a !== void 0,
|
|
529
|
+
select: s,
|
|
530
|
+
deselect: c,
|
|
531
|
+
toggle: l,
|
|
532
|
+
isSelected: u,
|
|
533
|
+
reset: d
|
|
487
534
|
};
|
|
488
535
|
}
|
|
489
536
|
//#endregion
|
|
490
537
|
//#region src/state/useSort/utils.ts
|
|
491
|
-
function
|
|
492
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
538
|
+
function _(e, t, n = {}) {
|
|
539
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = w(e, t, r, i);
|
|
493
540
|
if (a !== null) return a;
|
|
494
541
|
let o = !!e;
|
|
495
542
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
496
543
|
}
|
|
497
|
-
function
|
|
498
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
544
|
+
function v(e, t, n = {}) {
|
|
545
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = w(e, t, r, i);
|
|
499
546
|
if (a !== null) return a;
|
|
500
547
|
let o = Number(e), s = Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
501
|
-
return c || l ?
|
|
548
|
+
return c || l ? w(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
502
549
|
}
|
|
503
|
-
function
|
|
504
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
550
|
+
function y(e, t, n = {}) {
|
|
551
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = w(e, t, i, r);
|
|
505
552
|
if (o !== null) return o;
|
|
506
553
|
let s = String(e), c = String(t);
|
|
507
554
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
508
555
|
}
|
|
509
|
-
function
|
|
510
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
556
|
+
function b(e, t, n = {}) {
|
|
557
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = w(e, t, i, r);
|
|
511
558
|
if (o !== null) return o;
|
|
512
559
|
let s = String(e), c = String(t);
|
|
513
560
|
return s.localeCompare(c, void 0, {
|
|
@@ -515,21 +562,21 @@ function _(e, t, n = {}) {
|
|
|
515
562
|
sensitivity: a ? "variant" : "base"
|
|
516
563
|
});
|
|
517
564
|
}
|
|
518
|
-
function
|
|
519
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
565
|
+
function x(e, t, n = {}) {
|
|
566
|
+
let { desc: r = !1, sortUndefined: i } = n, a = w(e, t, i, r);
|
|
520
567
|
if (a !== null) return a;
|
|
521
568
|
let o = new Date(e).getTime(), s = new Date(t).getTime(), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
522
|
-
return (c || l) && (a =
|
|
569
|
+
return (c || l) && (a = w(c ? void 0 : o, l ? void 0 : s, i, r), a !== null) ? a : o - s;
|
|
523
570
|
}
|
|
524
|
-
function
|
|
525
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
571
|
+
function S(e, t, n = {}) {
|
|
572
|
+
let { desc: r = !1, sortUndefined: i } = n, a = w(e, t, i, r);
|
|
526
573
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
527
574
|
}
|
|
528
|
-
function
|
|
529
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
575
|
+
function C(e, t, n = {}) {
|
|
576
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = w(e, t, i, r);
|
|
530
577
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
531
578
|
}
|
|
532
|
-
function
|
|
579
|
+
function w(e, t, n = "last", r) {
|
|
533
580
|
let i = e == null || e === "", a = t == null || t === "";
|
|
534
581
|
if (i && a) return 0;
|
|
535
582
|
if (!i && !a) return null;
|
|
@@ -547,7 +594,7 @@ function x(e, t, n = "last", r) {
|
|
|
547
594
|
}
|
|
548
595
|
//#endregion
|
|
549
596
|
//#region src/state/useSort/useSort.ts
|
|
550
|
-
function
|
|
597
|
+
function T(a = [], o = []) {
|
|
551
598
|
let s = n(() => Array.isArray(a) ? a : [], [a]), c = n(() => Array.isArray(o) ? o : [], [o]), l = r(c), [u, d] = i(() => c), f = n(() => {
|
|
552
599
|
let t = u.map((e) => ({
|
|
553
600
|
...e,
|
|
@@ -558,35 +605,35 @@ function S(a = [], o = []) {
|
|
|
558
605
|
let { type: t, id: a, desc: o = !1, invertSorting: s = !1, pathArray: c } = i, l = e(n, c, a), u = e(r, c, a), d;
|
|
559
606
|
switch (t) {
|
|
560
607
|
case "numeric":
|
|
561
|
-
d =
|
|
608
|
+
d = v(l, u, i);
|
|
562
609
|
break;
|
|
563
610
|
case "alphabetical":
|
|
564
|
-
d =
|
|
611
|
+
d = y(l, u, i);
|
|
565
612
|
break;
|
|
566
613
|
case "alphanumeric":
|
|
567
|
-
d =
|
|
614
|
+
d = b(l, u, i);
|
|
568
615
|
break;
|
|
569
616
|
case "boolean":
|
|
570
|
-
d =
|
|
617
|
+
d = _(l, u, i);
|
|
571
618
|
break;
|
|
572
619
|
case "date":
|
|
573
|
-
d =
|
|
620
|
+
d = x(l, u, i);
|
|
574
621
|
break;
|
|
575
622
|
case "basic":
|
|
576
|
-
d =
|
|
623
|
+
d = S(l, u, i);
|
|
577
624
|
break;
|
|
578
625
|
case "custom":
|
|
579
|
-
d =
|
|
626
|
+
d = C(l, u, i);
|
|
580
627
|
break;
|
|
581
|
-
default: d =
|
|
628
|
+
default: d = S(l, u, i);
|
|
582
629
|
}
|
|
583
630
|
if (d !== 0) return d * (o === s ? 1 : -1);
|
|
584
631
|
}
|
|
585
632
|
return 0;
|
|
586
633
|
});
|
|
587
|
-
}, [u, s]), p = t((e) => d((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]), []),
|
|
634
|
+
}, [u, s]), p = t((e) => d((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]), []), m = t((e) => {
|
|
588
635
|
d((t) => Array.isArray(e) ? t.filter((t) => !e.includes(t.id)) : t.filter((t) => t.id !== e));
|
|
589
|
-
}, []),
|
|
636
|
+
}, []), h = t(() => d([]), []), g = t(() => d(l.current), []), w = t((e) => {
|
|
590
637
|
d(Array.isArray(e) ? e : []);
|
|
591
638
|
}, []), T = t((e, t, n) => {
|
|
592
639
|
let { multi: r = !1, ...i } = n || {};
|
|
@@ -624,9 +671,9 @@ function S(a = [], o = []) {
|
|
|
624
671
|
sortedItems: f,
|
|
625
672
|
sorts: u,
|
|
626
673
|
upsertSorts: p,
|
|
627
|
-
removeSort:
|
|
628
|
-
clearSorts:
|
|
629
|
-
resetSorts:
|
|
674
|
+
removeSort: m,
|
|
675
|
+
clearSorts: h,
|
|
676
|
+
resetSorts: g,
|
|
630
677
|
replaceSorts: w,
|
|
631
678
|
getSortDirection: t((e) => {
|
|
632
679
|
let t = u.find((t) => t.id === e);
|
|
@@ -644,4 +691,354 @@ function S(a = [], o = []) {
|
|
|
644
691
|
};
|
|
645
692
|
}
|
|
646
693
|
//#endregion
|
|
647
|
-
|
|
694
|
+
//#region src/state/useTreeSelection/core.ts
|
|
695
|
+
function E(e, t) {
|
|
696
|
+
let n;
|
|
697
|
+
if (n = typeof t == "function" ? t(e) : e[t], typeof process < "u" && process.env.NODE_ENV !== "production" && n == null) throw console.warn("[resolveTreeItemId] Resolved id is", n, "— this usually means `field` does not point to a valid property on the item."), Error(`[resolveTreeItemId] Invalid id resolved: ${String(n)}`);
|
|
698
|
+
return n;
|
|
699
|
+
}
|
|
700
|
+
function D(e, t) {
|
|
701
|
+
return typeof t == "function" ? t(e) : e[t];
|
|
702
|
+
}
|
|
703
|
+
function O(e, t, n) {
|
|
704
|
+
let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
705
|
+
function o(e, s, c, l) {
|
|
706
|
+
let u = E(e, t);
|
|
707
|
+
if (l.has(u)) {
|
|
708
|
+
if (typeof process < "u" && process.env.NODE_ENV !== "production") throw console.warn("[useTreeSelection] Cycle detected: node", u, "is its own ancestor. This subtree is being skipped rather than recursed forever."), Error(`[useTreeSelection] Cycle detected: node ${u} is its own ancestor.`);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
let d = {
|
|
712
|
+
item: e,
|
|
713
|
+
id: u,
|
|
714
|
+
parentId: s,
|
|
715
|
+
depth: c
|
|
716
|
+
};
|
|
717
|
+
r.push(d), i.set(u, d);
|
|
718
|
+
let f = a.get(s);
|
|
719
|
+
f ? f.push(u) : a.set(s, [u]);
|
|
720
|
+
let p = D(e, n);
|
|
721
|
+
if (!p || p.length === 0) return;
|
|
722
|
+
let m = new Set(l);
|
|
723
|
+
m.add(u);
|
|
724
|
+
for (let e of p) o(e, u, c + 1, m);
|
|
725
|
+
}
|
|
726
|
+
for (let t of e) o(t, void 0, 0, /* @__PURE__ */ new Set());
|
|
727
|
+
return {
|
|
728
|
+
entries: r,
|
|
729
|
+
entryById: i,
|
|
730
|
+
childIdsByParentId: a
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function k(e, t) {
|
|
734
|
+
return !(t?.(e) ?? !1);
|
|
735
|
+
}
|
|
736
|
+
function A(e, t) {
|
|
737
|
+
return typeof e == "string" || typeof e == "number" ? e : E(e, t);
|
|
738
|
+
}
|
|
739
|
+
function j(e, t, n, r) {
|
|
740
|
+
let i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
741
|
+
function o(s) {
|
|
742
|
+
let c = e.childIdsByParentId.get(s);
|
|
743
|
+
if (!c || c.length === 0 || !r) {
|
|
744
|
+
let e = t.has(s) ? "selected" : "unselected";
|
|
745
|
+
return e === "selected" && i.add(s), e;
|
|
746
|
+
}
|
|
747
|
+
let l = c.filter((e) => k(e, n));
|
|
748
|
+
if (l.length === 0) {
|
|
749
|
+
let e = t.has(s) ? "selected" : "unselected";
|
|
750
|
+
return e === "selected" && i.add(s), e;
|
|
751
|
+
}
|
|
752
|
+
let u = !0, d = !1;
|
|
753
|
+
for (let e of l) {
|
|
754
|
+
let t = o(e);
|
|
755
|
+
t !== "selected" && (u = !1), t !== "unselected" && (d = !0);
|
|
756
|
+
}
|
|
757
|
+
return u ? (i.add(s), "selected") : d ? (a.add(s), "indeterminate") : "unselected";
|
|
758
|
+
}
|
|
759
|
+
let s = e.childIdsByParentId.get(void 0) ?? [];
|
|
760
|
+
for (let e of s) o(e);
|
|
761
|
+
return {
|
|
762
|
+
selectedIds: i,
|
|
763
|
+
indeterminateIds: a
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function M(e, t, n, r, i, a, o, s) {
|
|
767
|
+
let c = new Set(t), l = new Set(n), u = [r];
|
|
768
|
+
if (o) {
|
|
769
|
+
let t = [r];
|
|
770
|
+
for (; t.length > 0;) {
|
|
771
|
+
let n = t.pop(), r = e.childIdsByParentId.get(n);
|
|
772
|
+
if (r) for (let e of r) u.push(e), t.push(e);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
for (let e of u) l.delete(e), !(i && !k(e, a)) && (i ? c.add(e) : c.delete(e));
|
|
776
|
+
if (s) {
|
|
777
|
+
let t = e.entryById.get(r)?.parentId;
|
|
778
|
+
for (; t !== void 0;) {
|
|
779
|
+
let n = (e.childIdsByParentId.get(t) ?? []).filter((e) => k(e, a));
|
|
780
|
+
if (n.length === 0) {
|
|
781
|
+
t = e.entryById.get(t)?.parentId;
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
let r = !0, i = !1;
|
|
785
|
+
for (let e of n) {
|
|
786
|
+
let t = c.has(e), n = l.has(e);
|
|
787
|
+
t || (r = !1), (t || n) && (i = !0);
|
|
788
|
+
}
|
|
789
|
+
r ? (c.add(t), l.delete(t)) : i ? (l.add(t), c.delete(t)) : (c.delete(t), l.delete(t)), t = e.entryById.get(t)?.parentId;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return {
|
|
793
|
+
selectedIds: c,
|
|
794
|
+
indeterminateIds: l
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
function N(e, t, n, r, i, a, o, s) {
|
|
798
|
+
let c = new Set(t), l = new Set(n), u = /* @__PURE__ */ new Set();
|
|
799
|
+
for (let t of r) {
|
|
800
|
+
let n = [t];
|
|
801
|
+
if (o) {
|
|
802
|
+
let r = [t];
|
|
803
|
+
for (; r.length > 0;) {
|
|
804
|
+
let t = r.pop(), i = e.childIdsByParentId.get(t);
|
|
805
|
+
if (i) for (let e of i) n.push(e), r.push(e);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
for (let e of n) l.delete(e), !(i && !k(e, a)) && (i ? c.add(e) : c.delete(e));
|
|
809
|
+
if (s) {
|
|
810
|
+
let n = e.entryById.get(t)?.parentId;
|
|
811
|
+
for (; n !== void 0;) u.add(n), n = e.entryById.get(n)?.parentId;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (u.size > 0) {
|
|
815
|
+
let t = [...u].sort((t, n) => (e.entryById.get(n)?.depth ?? 0) - (e.entryById.get(t)?.depth ?? 0));
|
|
816
|
+
for (let n of t) {
|
|
817
|
+
let t = (e.childIdsByParentId.get(n) ?? []).filter((e) => k(e, a));
|
|
818
|
+
if (t.length === 0) continue;
|
|
819
|
+
let r = !0, i = !1;
|
|
820
|
+
for (let e of t) {
|
|
821
|
+
let t = c.has(e), n = l.has(e);
|
|
822
|
+
t || (r = !1), (t || n) && (i = !0);
|
|
823
|
+
}
|
|
824
|
+
r ? (c.add(n), l.delete(n)) : i ? (l.add(n), c.delete(n)) : (c.delete(n), l.delete(n));
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
selectedIds: c,
|
|
829
|
+
indeterminateIds: l
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region src/state/useTreeSelection/useTreeSelection.ts
|
|
834
|
+
function P(e) {
|
|
835
|
+
let { items: r, field: a, childrenField: o, isDisabled: s, leafOnly: c = !1 } = e, l = n(() => Array.isArray(r) ? r : [], [r]), u = n(() => Array.isArray(e.defaultSelectedIds) ? e.defaultSelectedIds : [], [e.defaultSelectedIds]), d = e.cascade?.down ?? !0, f = e.cascade?.up ?? !0, p = n(() => O(l, a, o), [
|
|
836
|
+
l,
|
|
837
|
+
a,
|
|
838
|
+
o
|
|
839
|
+
]), [m, h] = i(() => j(p, new Set(u), s, f)), g = t((e) => {
|
|
840
|
+
let t = p.childIdsByParentId.get(e);
|
|
841
|
+
return !t || t.length === 0;
|
|
842
|
+
}, [p]), _ = n(() => {
|
|
843
|
+
let e = [];
|
|
844
|
+
for (let t of p.entries) m.selectedIds.has(t.id) && (c && !g(t.id) || e.push(t.id));
|
|
845
|
+
return e;
|
|
846
|
+
}, [
|
|
847
|
+
p,
|
|
848
|
+
m.selectedIds,
|
|
849
|
+
c,
|
|
850
|
+
g
|
|
851
|
+
]), v = n(() => {
|
|
852
|
+
let e = [];
|
|
853
|
+
for (let t of p.entries) m.selectedIds.has(t.id) && g(t.id) && e.push(t.id);
|
|
854
|
+
return e;
|
|
855
|
+
}, [
|
|
856
|
+
p,
|
|
857
|
+
m.selectedIds,
|
|
858
|
+
g
|
|
859
|
+
]), y = n(() => {
|
|
860
|
+
let e = [];
|
|
861
|
+
for (let t of p.entries) m.indeterminateIds.has(t.id) && e.push(t.id);
|
|
862
|
+
return e;
|
|
863
|
+
}, [p, m.indeterminateIds]), b = n(() => {
|
|
864
|
+
let e = new Set(_);
|
|
865
|
+
return p.entries.filter((t) => e.has(t.id)).map((e) => e.item);
|
|
866
|
+
}, [p, _]), x = n(() => p.childIdsByParentId.get(void 0) ?? [], [p]), S = n(() => {
|
|
867
|
+
let e = x.filter((e) => k(e, s));
|
|
868
|
+
return e.length > 0 && e.every((e) => m.selectedIds.has(e));
|
|
869
|
+
}, [
|
|
870
|
+
x,
|
|
871
|
+
s,
|
|
872
|
+
m.selectedIds
|
|
873
|
+
]), C = n(() => !S && x.some((e) => m.selectedIds.has(e) || m.indeterminateIds.has(e)), [
|
|
874
|
+
S,
|
|
875
|
+
x,
|
|
876
|
+
m.selectedIds,
|
|
877
|
+
m.indeterminateIds
|
|
878
|
+
]), w = t((e) => {
|
|
879
|
+
let t = A(e, a);
|
|
880
|
+
return m.selectedIds.has(t) ? "selected" : m.indeterminateIds.has(t) ? "indeterminate" : "unselected";
|
|
881
|
+
}, [m, a]), T = t((e) => w(e) === "selected", [w]), E = t((e) => w(e) === "indeterminate", [w]), D = t((e) => {
|
|
882
|
+
let t = A(e, a);
|
|
883
|
+
s?.(t) || h((e) => M(p, e.selectedIds, e.indeterminateIds, t, !0, s, d, f));
|
|
884
|
+
}, [
|
|
885
|
+
a,
|
|
886
|
+
p,
|
|
887
|
+
s,
|
|
888
|
+
d,
|
|
889
|
+
f
|
|
890
|
+
]), P = t((e) => {
|
|
891
|
+
let t = A(e, a);
|
|
892
|
+
h((e) => M(p, e.selectedIds, e.indeterminateIds, t, !1, s, d, f));
|
|
893
|
+
}, [
|
|
894
|
+
a,
|
|
895
|
+
p,
|
|
896
|
+
s,
|
|
897
|
+
d,
|
|
898
|
+
f
|
|
899
|
+
]), F = t((e) => {
|
|
900
|
+
let t = A(e, a);
|
|
901
|
+
h((e) => {
|
|
902
|
+
let n = e.selectedIds.has(t);
|
|
903
|
+
return !n && s?.(t) ? e : M(p, e.selectedIds, e.indeterminateIds, t, !n, s, d, f);
|
|
904
|
+
});
|
|
905
|
+
}, [
|
|
906
|
+
a,
|
|
907
|
+
p,
|
|
908
|
+
s,
|
|
909
|
+
d,
|
|
910
|
+
f
|
|
911
|
+
]), I = t(() => {
|
|
912
|
+
h(j(p, new Set(u), s, f));
|
|
913
|
+
}, [
|
|
914
|
+
p,
|
|
915
|
+
u,
|
|
916
|
+
s,
|
|
917
|
+
f
|
|
918
|
+
]), L = t((e) => {
|
|
919
|
+
let t = (Array.isArray(e) ? e : []).map((e) => A(e, a));
|
|
920
|
+
h(j(p, new Set(t), s, f));
|
|
921
|
+
}, [
|
|
922
|
+
a,
|
|
923
|
+
p,
|
|
924
|
+
s,
|
|
925
|
+
f
|
|
926
|
+
]), R = t(() => {
|
|
927
|
+
let e = p.entries.map((e) => e.id);
|
|
928
|
+
h(j(p, new Set(e), s, f));
|
|
929
|
+
}, [
|
|
930
|
+
p,
|
|
931
|
+
s,
|
|
932
|
+
f
|
|
933
|
+
]), z = t(() => {
|
|
934
|
+
h((e) => e.selectedIds.size === 0 && e.indeterminateIds.size === 0 ? e : {
|
|
935
|
+
selectedIds: /* @__PURE__ */ new Set(),
|
|
936
|
+
indeterminateIds: /* @__PURE__ */ new Set()
|
|
937
|
+
});
|
|
938
|
+
}, []), B = t(() => {
|
|
939
|
+
h((e) => {
|
|
940
|
+
let t = x.filter((e) => k(e, s));
|
|
941
|
+
if (t.length > 0 && t.every((t) => e.selectedIds.has(t))) return {
|
|
942
|
+
selectedIds: /* @__PURE__ */ new Set(),
|
|
943
|
+
indeterminateIds: /* @__PURE__ */ new Set()
|
|
944
|
+
};
|
|
945
|
+
let n = p.entries.map((e) => e.id);
|
|
946
|
+
return j(p, new Set(n), s, f);
|
|
947
|
+
});
|
|
948
|
+
}, [
|
|
949
|
+
x,
|
|
950
|
+
p,
|
|
951
|
+
s,
|
|
952
|
+
f
|
|
953
|
+
]), V = t((e) => {
|
|
954
|
+
let t = (Array.isArray(e) ? e : []).map((e) => A(e, a));
|
|
955
|
+
h((e) => N(p, e.selectedIds, e.indeterminateIds, t, !0, s, d, f));
|
|
956
|
+
}, [
|
|
957
|
+
a,
|
|
958
|
+
p,
|
|
959
|
+
s,
|
|
960
|
+
d,
|
|
961
|
+
f
|
|
962
|
+
]), H = t((e) => {
|
|
963
|
+
let t = (Array.isArray(e) ? e : []).map((e) => A(e, a));
|
|
964
|
+
h((e) => N(p, e.selectedIds, e.indeterminateIds, t, !1, s, d, f));
|
|
965
|
+
}, [
|
|
966
|
+
a,
|
|
967
|
+
p,
|
|
968
|
+
s,
|
|
969
|
+
d,
|
|
970
|
+
f
|
|
971
|
+
]), U = t((e) => {
|
|
972
|
+
let t = new Set((Array.isArray(e) ? e : []).map((e) => A(e, a)));
|
|
973
|
+
h((e) => {
|
|
974
|
+
let n = /* @__PURE__ */ new Set();
|
|
975
|
+
return e.selectedIds.forEach((e) => {
|
|
976
|
+
t.has(e) && n.add(e);
|
|
977
|
+
}), j(p, n, s, f);
|
|
978
|
+
});
|
|
979
|
+
}, [
|
|
980
|
+
a,
|
|
981
|
+
p,
|
|
982
|
+
s,
|
|
983
|
+
f
|
|
984
|
+
]), W = t(() => {
|
|
985
|
+
h((e) => {
|
|
986
|
+
let t = /* @__PURE__ */ new Set();
|
|
987
|
+
for (let n of p.entries) {
|
|
988
|
+
let r = p.childIdsByParentId.get(n.id);
|
|
989
|
+
(!r || r.length === 0) && k(n.id, s) && (e.selectedIds.has(n.id) || t.add(n.id));
|
|
990
|
+
}
|
|
991
|
+
return j(p, t, s, f);
|
|
992
|
+
});
|
|
993
|
+
}, [
|
|
994
|
+
p,
|
|
995
|
+
s,
|
|
996
|
+
f
|
|
997
|
+
]), G = t((e) => {
|
|
998
|
+
let t = A(e, a);
|
|
999
|
+
return p.entryById.get(t)?.parentId;
|
|
1000
|
+
}, [p, a]), K = t((e) => {
|
|
1001
|
+
let t = A(e, a), n = [], r = p.entryById.get(t)?.parentId;
|
|
1002
|
+
for (; r !== void 0;) n.push(r), r = p.entryById.get(r)?.parentId;
|
|
1003
|
+
return n;
|
|
1004
|
+
}, [p, a]), q = t((e) => {
|
|
1005
|
+
let t = A(e, a), n = [], r = [...p.childIdsByParentId.get(t) ?? []];
|
|
1006
|
+
for (; r.length > 0;) {
|
|
1007
|
+
let e = r.pop();
|
|
1008
|
+
n.push(e);
|
|
1009
|
+
let t = p.childIdsByParentId.get(e);
|
|
1010
|
+
t && r.push(...t);
|
|
1011
|
+
}
|
|
1012
|
+
return n;
|
|
1013
|
+
}, [p, a]);
|
|
1014
|
+
return {
|
|
1015
|
+
selectedIds: _,
|
|
1016
|
+
selectedLeafIds: v,
|
|
1017
|
+
indeterminateIds: y,
|
|
1018
|
+
selectedItems: b,
|
|
1019
|
+
selectedCount: _.length,
|
|
1020
|
+
isEmpty: m.selectedIds.size === 0 && m.indeterminateIds.size === 0,
|
|
1021
|
+
isAllSelected: S,
|
|
1022
|
+
isPartiallySelected: C,
|
|
1023
|
+
getNodeState: w,
|
|
1024
|
+
isSelected: T,
|
|
1025
|
+
isIndeterminate: E,
|
|
1026
|
+
select: D,
|
|
1027
|
+
deselect: P,
|
|
1028
|
+
toggle: F,
|
|
1029
|
+
reset: I,
|
|
1030
|
+
replaceSelection: L,
|
|
1031
|
+
selectAll: R,
|
|
1032
|
+
deselectAll: z,
|
|
1033
|
+
toggleAll: B,
|
|
1034
|
+
selectMultiple: V,
|
|
1035
|
+
deselectMultiple: H,
|
|
1036
|
+
retainOnly: U,
|
|
1037
|
+
invertSelection: W,
|
|
1038
|
+
getParentId: G,
|
|
1039
|
+
getAncestorIds: K,
|
|
1040
|
+
getDescendantIds: q
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
//#endregion
|
|
1044
|
+
export { m as a, c, h as i, o as l, T as n, p as o, g as r, l as s, P as t };
|