@nivaro/react 0.3.81 → 0.3.83

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.
@@ -1,56 +1,60 @@
1
- import { useRef as s, useEffect as f, useCallback as d, createContext as m, useContext as h } from "react";
1
+ import { useRef as l, useEffect as f, useCallback as d, createContext as h, useContext as m } from "react";
2
2
  import { toast as C } from "sonner";
3
- const p = m(null), E = () => h(p);
4
- function w(n) {
5
- const e = [...new Set(n.filter(Boolean))];
3
+ const p = h(null), v = () => m(p);
4
+ function S(t) {
5
+ const e = [...new Set(t.filter(Boolean))];
6
6
  return e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
7
7
  }
8
- function T(n, e) {
9
- const r = w(n);
8
+ function T(t, e) {
9
+ const r = S(t);
10
10
  return e ? `${r} cleared — not available for the ${e} you picked` : `${r} cleared — no longer available for what you picked`;
11
11
  }
12
- function x(n, e) {
13
- const r = new Set(n.map((t) => t.field)), o = [...new Set(n.flatMap((t) => t.parents))].filter((t) => !r.has(t));
14
- return o.length === 0 ? null : o.reduce((t, c) => e(c) > e(t) ? c : t, o[0]);
12
+ function w(t, e) {
13
+ const r = new Set(t.map((n) => n.field)), o = [...new Set(t.flatMap((n) => n.parents))].filter((n) => !r.has(n));
14
+ return o.length === 0 ? null : o.reduce((n, c) => e(c) > e(n) ? c : n, o[0]);
15
15
  }
16
- const S = 4e3, g = 500, R = "nvr-cascade-clear";
17
- function N(n) {
18
- const e = s(n);
19
- e.current = n;
20
- const r = s([]), o = s(0), t = s(null);
16
+ const g = 4e3, x = 500, k = "nvr-cascade-clear";
17
+ function A(t) {
18
+ const e = l(t);
19
+ e.current = t;
20
+ const r = l([]), o = l(0), n = l(null);
21
21
  return f(
22
22
  () => () => {
23
- t.current && clearTimeout(t.current);
23
+ n.current && clearTimeout(n.current);
24
24
  },
25
25
  []
26
26
  ), d((c) => {
27
- const l = Date.now();
28
- l - o.current > S && (r.current = []), o.current = l, r.current.some((a) => a.field === c.field) || r.current.push(c), t.current && clearTimeout(t.current), t.current = setTimeout(() => {
27
+ const u = Date.now();
28
+ u - o.current > g && (r.current = []), o.current = u, r.current.some((a) => a.field === c.field) || r.current.push(c), n.current && clearTimeout(n.current), n.current = setTimeout(() => {
29
29
  const a = r.current;
30
30
  if (a.length === 0) return;
31
- const u = x(a, e.current.editSeq);
31
+ const s = w(a, e.current.editSeq);
32
32
  C.info(
33
33
  T(
34
34
  a.map((i) => i.label),
35
- u ? e.current.labelOf(u) : null
35
+ s ? e.current.labelOf(s) : null
36
36
  ),
37
37
  {
38
- id: R,
38
+ id: k,
39
39
  description: "Pick them again from the narrowed lists."
40
40
  }
41
41
  );
42
- }, g);
42
+ }, x);
43
43
  }, []);
44
44
  }
45
- function P(n, e, r) {
46
- return r.crossFill > 0 || r.notPerson > 0 ? !1 : (n.touched.add(e), n.seq.set(e, n.next()), !0);
45
+ function E(t, e, r) {
46
+ return r.crossFill > 0 || r.notPerson > 0 ? !1 : (t.touched.add(e), t.seq.set(e, t.next()), !0);
47
+ }
48
+ function N(t, e) {
49
+ e.leftWorkStaged || t.clear();
47
50
  }
48
51
  export {
49
52
  p as CascadeClearNoticeContext,
50
53
  T as cascadeClearText,
51
- x as cascadeRootParent,
52
- w as joinLabels,
53
- P as notePersonLinkEdit,
54
- N as useCascadeClearNotices,
55
- E as useCascadeClearNotifier
54
+ w as cascadeRootParent,
55
+ S as joinLabels,
56
+ E as notePersonLinkEdit,
57
+ N as settleTouchedAfterSave,
58
+ A as useCascadeClearNotices,
59
+ v as useCascadeClearNotifier
56
60
  };
@@ -0,0 +1,84 @@
1
+ const l = (r) => r == null ? "" : String(r);
2
+ function v(r, o) {
3
+ if (!o || o.length !== 2) return null;
4
+ const [i, t] = o;
5
+ return i === t || !r.some((u) => u.key === i) || !r.some((u) => u.key === t) ? null : [i, t];
6
+ }
7
+ function b(r, o, i, t, u) {
8
+ const e = v(i, t);
9
+ for (const n of i) {
10
+ if (n.key === u || e && (n.key === e[0] || n.key === e[1])) continue;
11
+ const f = o[n.key];
12
+ if (f && l(r[n.key]) !== f) return !1;
13
+ }
14
+ if (e) {
15
+ const [n, f] = e, c = u === n ? void 0 : o[n], s = u === f ? void 0 : o[f], a = l(r[n]), d = l(r[f]);
16
+ if (c && s) {
17
+ if (!(a === c && d === s || a === s && d === c)) return !1;
18
+ } else if (c || s) {
19
+ const y = c ?? s;
20
+ if (a !== y && d !== y) return !1;
21
+ }
22
+ }
23
+ return !0;
24
+ }
25
+ const m = (r) => [...r].sort((o, i) => o.localeCompare(i, void 0, { numeric: !0, sensitivity: "base" }));
26
+ function K(r, o, i, t, u) {
27
+ const e = v(i, u), n = /* @__PURE__ */ new Set();
28
+ if (e && (t === e[0] || t === e[1])) {
29
+ const f = t === e[0] ? e[1] : e[0], c = o[f];
30
+ for (const s of r) {
31
+ if (!b(
32
+ s,
33
+ { ...o, [t]: void 0, [f]: void 0 },
34
+ i,
35
+ u
36
+ ))
37
+ continue;
38
+ const a = l(s[e[0]]), d = l(s[e[1]]);
39
+ c ? (a === c && d && n.add(d), d === c && a && n.add(a)) : (a && n.add(a), d && n.add(d));
40
+ }
41
+ return m(n);
42
+ }
43
+ for (const f of r) {
44
+ if (!b(f, o, i, u, t)) continue;
45
+ const c = l(f[t]);
46
+ c && n.add(c);
47
+ }
48
+ return m(n);
49
+ }
50
+ function N(r, o) {
51
+ return o.length > 0 && o.every((i) => !!r[i.key]);
52
+ }
53
+ function g(r, o, i, t) {
54
+ const u = (e) => {
55
+ const n = typeof e == "number" ? e : Number.parseFloat(l(e));
56
+ return Number.isFinite(n) ? n : Number.POSITIVE_INFINITY;
57
+ };
58
+ return r.filter((e) => l(e[t.itemKey]) !== "" && b(e, o, i, t.symmetric)).sort((e, n) => {
59
+ if (t.sortKey) {
60
+ const f = u(e[t.sortKey]) - u(n[t.sortKey]);
61
+ if (f !== 0 && Number.isFinite(f)) return f;
62
+ }
63
+ return l(e[t.labelKey]).localeCompare(l(n[t.labelKey]), void 0, {
64
+ numeric: !0
65
+ });
66
+ });
67
+ }
68
+ function h(r, o, i, t, u, e) {
69
+ const n = { ...o, [t]: u ?? void 0 };
70
+ for (let f = 0; f < i.length; f++) {
71
+ let c = !1;
72
+ for (const s of i)
73
+ s.key === t || !n[s.key] || K(r, n, i, s.key, e).includes(n[s.key]) || (n[s.key] = void 0, c = !0);
74
+ if (!c) break;
75
+ }
76
+ return n;
77
+ }
78
+ export {
79
+ K as facetOptions,
80
+ g as facetResults,
81
+ b as facetRowMatches,
82
+ N as facetsComplete,
83
+ h as setFacetPick
84
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.81",
3
+ "version": "0.3.83",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",