@nivaro/react 0.3.9 → 0.3.11

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.
Files changed (80) hide show
  1. package/dist/components/fields/FileField.js +20 -19
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useNivaroForm.js +129 -126
  4. package/dist/hooks/useSessionRecorder.js +1 -1
  5. package/dist/index.d.ts +103 -4
  6. package/dist/index.js +512 -501
  7. package/dist/shared/components/CollectionBrowserView.js +1632 -1564
  8. package/dist/shared/components/ConformanceView.js +36 -35
  9. package/dist/shared/components/ForceReloadBanner.js +58 -34
  10. package/dist/shared/components/ItemEditForm.js +4386 -4142
  11. package/dist/shared/components/JsonMapEditor.js +18 -17
  12. package/dist/shared/components/MatrixEditor.js +8 -7
  13. package/dist/shared/components/MyWorkView.js +32 -31
  14. package/dist/shared/components/PageRenderer.js +527 -479
  15. package/dist/shared/components/QueryStatStrip.js +74 -70
  16. package/dist/shared/components/RecordGridEditor.js +76 -75
  17. package/dist/shared/components/ReportView.js +818 -827
  18. package/dist/shared/components/SheetHeaderBody.js +16 -14
  19. package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
  20. package/dist/shared/components/ai/AskPanel.js +55 -54
  21. package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
  22. package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
  23. package/dist/shared/components/chat/SlashCommands.js +30 -29
  24. package/dist/shared/components/chat/chat-outbox.js +76 -75
  25. package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
  26. package/dist/shared/components/integrations/console/SignalCard.js +124 -123
  27. package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
  28. package/dist/shared/components/item-edit/CatalogPickerField.js +1029 -933
  29. package/dist/shared/components/item-edit/CloneDialog.js +85 -78
  30. package/dist/shared/components/item-edit/FieldRenderer.js +161 -156
  31. package/dist/shared/components/item-edit/FieldRow.js +20 -19
  32. package/dist/shared/components/item-edit/FilePickerField.js +52 -40
  33. package/dist/shared/components/item-edit/GroupSection.js +221 -221
  34. package/dist/shared/components/item-edit/InlineGridField.js +41 -41
  35. package/dist/shared/components/item-edit/InlineTableField.js +2287 -2275
  36. package/dist/shared/components/item-edit/M2MCombobox.js +46 -44
  37. package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
  38. package/dist/shared/components/item-edit/NestedRelationEditor.js +11 -11
  39. package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
  40. package/dist/shared/components/item-edit/QuickPicker.js +263 -216
  41. package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
  42. package/dist/shared/components/item-edit/RelationCombobox.js +285 -245
  43. package/dist/shared/components/item-edit/RichTextEditorImpl.js +42 -32
  44. package/dist/shared/components/item-edit/RowHistorySheet.js +130 -134
  45. package/dist/shared/components/item-edit/SummaryPanel.js +305 -279
  46. package/dist/shared/components/item-edit/helpers.js +133 -134
  47. package/dist/shared/components/item-edit/line-qty.js +57 -0
  48. package/dist/shared/components/item-edit/option-disambiguate.js +53 -0
  49. package/dist/shared/components/item-edit/staged-links.js +86 -0
  50. package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
  51. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
  52. package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
  53. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
  54. package/dist/shared/components/panels/AddendumLinesDiff.js +87 -90
  55. package/dist/shared/components/panels/CommentPanel.js +350 -315
  56. package/dist/shared/components/panels/ItemLockBanner.js +297 -230
  57. package/dist/shared/components/panels/PipelinePanel.js +719 -701
  58. package/dist/shared/components/profile/AiMemoryCard.js +15 -14
  59. package/dist/shared/components/profile/PersonAdminTools.js +70 -67
  60. package/dist/shared/components/queue/QueueItemSheet.js +36 -35
  61. package/dist/shared/components/queue/QueueQuickFilters.js +43 -41
  62. package/dist/shared/components/queue/QueueWorklist.js +1026 -957
  63. package/dist/shared/components/widgets/ReviewListWidget.js +99 -93
  64. package/dist/shared/lib/client-version.js +63 -0
  65. package/dist/shared/lib/force-reload.js +36 -0
  66. package/dist/shared/lib/load-error.js +11 -10
  67. package/dist/shared/lib/obligation-banner.js +14 -13
  68. package/dist/shared/lib/obligation-reason-text.js +13 -0
  69. package/dist/shared/lib/presence-live.js +54 -35
  70. package/dist/shared/lib/query-filter-seed.js +34 -11
  71. package/dist/shared/lib/record-outbox.js +76 -75
  72. package/dist/shared/lib/safe-error.js +39 -0
  73. package/dist/shared/lib/sanitize-html.js +24 -15
  74. package/dist/shared/lib/server-clock.js +11 -7
  75. package/dist/shared/lib/sheet-def.js +38 -22
  76. package/dist/shared/lib/unique-options.js +10 -0
  77. package/dist/shared/lib/unsaved-work.js +62 -0
  78. package/dist/shared/lib/utils.js +57 -43
  79. package/dist/shared/lib/validation-rules.js +58 -34
  80. package/package.json +1 -1
@@ -3,19 +3,23 @@ const i = 1e3;
3
3
  function o() {
4
4
  return Date.now() + s;
5
5
  }
6
- function f(t) {
7
- s = Number.isFinite(t) && Math.abs(t) >= i ? Math.round(t) : 0;
6
+ function f() {
7
+ return s;
8
8
  }
9
9
  function u(t) {
10
+ s = Number.isFinite(t) && Math.abs(t) >= i ? Math.round(t) : 0;
11
+ }
12
+ function c(t) {
10
13
  let e = null;
11
- for (const n of t) {
12
- const r = n.received - n.sent;
13
- !Number.isFinite(r) || r < 0 || !Number.isFinite(n.server) || (!e || r < e.received - e.sent) && (e = n);
14
+ for (const r of t) {
15
+ const n = r.received - r.sent;
16
+ !Number.isFinite(n) || n < 0 || !Number.isFinite(r.server) || (!e || n < e.received - e.sent) && (e = r);
14
17
  }
15
18
  return e ? e.server - (e.sent + (e.received - e.sent) / 2) : null;
16
19
  }
17
20
  export {
18
- u as measureClockOffset,
21
+ c as measureClockOffset,
22
+ f as serverClockOffset,
19
23
  o as serverNow,
20
- f as setServerClockOffset
24
+ u as setServerClockOffset
21
25
  };
@@ -1,27 +1,43 @@
1
- function o(a, s) {
2
- const l = (a.tabs ?? (a.config ? [{ label: "View", config: a.config }] : [])).map(
3
- (r) => r.matrix ? { label: r.label, matrix: r.matrix } : { label: r.label, config: s(r.config ?? {}) }
4
- ), t = a.header ? {
5
- config: s({
6
- query_slug: a.header.query_slug,
7
- params: a.header.params ?? {}
8
- }),
9
- stats: a.header.stats,
10
- ...a.header.as_of ? { asOf: a.header.as_of } : {}
11
- } : null, e = Number.isInteger(a.initial_tab) ? a.initial_tab : 0, i = e >= 0 && e < l.length ? e : 0;
12
- return { resolvedTabs: l, header: t, initialTab: i };
1
+ function c(n, o, r = "all") {
2
+ return n.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (i, e) => {
3
+ const t = o == null ? void 0 : o[e];
4
+ return t == null || t === "" ? r : String(t).split(",").filter(Boolean).join(", ");
5
+ });
13
6
  }
14
- function c(a, s) {
15
- let n = null;
16
- for (const l of a) {
17
- const t = l[s];
18
- if (t == null || t === "") continue;
19
- const e = t instanceof Date ? t : String(t), i = new Date(e).getTime();
20
- Number.isNaN(i) || (!n || i > n.at) && (n = { at: i, raw: e });
7
+ function b(n, o) {
8
+ const i = (n.tabs ?? (n.config ? [{ label: "View", config: n.config }] : [])).map((a) => {
9
+ if (a.matrix) return { label: a.label, matrix: a.matrix };
10
+ const s = o(a.config ?? {}), u = s.params;
11
+ return { label: a.label, config: s, ...a.note ? { note: c(a.note, u) } : {} };
12
+ });
13
+ let e = null;
14
+ if (n.header) {
15
+ const a = o({
16
+ query_slug: n.header.query_slug,
17
+ params: n.header.params ?? {}
18
+ }), s = a.params;
19
+ e = {
20
+ config: a,
21
+ stats: n.header.stats,
22
+ ...n.header.as_of ? { asOf: n.header.as_of } : {},
23
+ ...n.header.note ? { note: c(n.header.note, s) } : {}
24
+ };
21
25
  }
22
- return (n == null ? void 0 : n.raw) ?? null;
26
+ const t = Number.isInteger(n.initial_tab) ? n.initial_tab : 0, l = t >= 0 && t < i.length ? t : 0;
27
+ return { resolvedTabs: i, header: e, initialTab: l };
28
+ }
29
+ function g(n, o) {
30
+ let r = null;
31
+ for (const i of n) {
32
+ const e = i[o];
33
+ if (e == null || e === "") continue;
34
+ const t = e instanceof Date ? e : String(e), l = new Date(t).getTime();
35
+ Number.isNaN(l) || (!r || l > r.at) && (r = { at: l, raw: t });
36
+ }
37
+ return (r == null ? void 0 : r.raw) ?? null;
23
38
  }
24
39
  export {
25
- c as latestAsOf,
26
- o as resolveSheetDef
40
+ c as fillSheetNote,
41
+ g as latestAsOf,
42
+ b as resolveSheetDef
27
43
  };
@@ -0,0 +1,10 @@
1
+ function s(t, r) {
2
+ const e = /* @__PURE__ */ new Set();
3
+ return t.filter((u) => {
4
+ const n = r(u);
5
+ return e.has(n) ? !1 : (e.add(n), !0);
6
+ });
7
+ }
8
+ export {
9
+ s as uniqueByValue
10
+ };
@@ -0,0 +1,62 @@
1
+ import { useEffect as c } from "react";
2
+ import { subscribeRecordOutbox as f, getRecordOutbox as i } from "./record-outbox.js";
3
+ const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
4
+ let a = 0;
5
+ function u() {
6
+ for (const e of [...s])
7
+ try {
8
+ e();
9
+ } catch {
10
+ }
11
+ }
12
+ function d(e, t) {
13
+ const n = ++a;
14
+ return r.set(n, { label: e, dirty: t }), u(), () => {
15
+ r.delete(n) && u();
16
+ };
17
+ }
18
+ function l() {
19
+ try {
20
+ return i().length;
21
+ } catch {
22
+ return 0;
23
+ }
24
+ }
25
+ function b() {
26
+ const e = [];
27
+ for (const n of r.values()) {
28
+ let o = !1;
29
+ try {
30
+ o = n.dirty();
31
+ } catch {
32
+ o = !1;
33
+ }
34
+ o && !e.includes(n.label) && e.push(n.label);
35
+ }
36
+ const t = l();
37
+ return t && e.push(`${t} save${t === 1 ? "" : "s"} waiting to be sent`), e;
38
+ }
39
+ function g() {
40
+ return b().length > 0;
41
+ }
42
+ function k(e) {
43
+ s.add(e);
44
+ const t = f(e);
45
+ return () => {
46
+ s.delete(e), t();
47
+ };
48
+ }
49
+ function p(e, t = "Unsaved changes") {
50
+ c(() => {
51
+ if (e)
52
+ return d(t, () => !0);
53
+ }, [e, t]);
54
+ }
55
+ export {
56
+ g as hasUnsavedWork,
57
+ u as notifyUnsavedWorkChanged,
58
+ d as registerUnsavedWork,
59
+ k as subscribeUnsavedWork,
60
+ b as unsavedWorkLabels,
61
+ p as useUnsavedWork
62
+ };
@@ -1,12 +1,12 @@
1
- import { clsx as s } from "clsx";
2
- import * as d from "lucide-react";
3
- import { twMerge as h } from "tailwind-merge";
4
- import { serverNow as _ } from "./server-clock.js";
5
- function F(...t) {
6
- return h(s(t));
1
+ import { clsx as d } from "clsx";
2
+ import * as h from "lucide-react";
3
+ import { twMerge as D } from "tailwind-merge";
4
+ import { serverNow as N } from "./server-clock.js";
5
+ function M(...t) {
6
+ return D(d(t));
7
7
  }
8
8
  let a = null;
9
- function N(t) {
9
+ function I(t) {
10
10
  if (t)
11
11
  try {
12
12
  new Intl.DateTimeFormat("en-US", { timeZone: t });
@@ -15,10 +15,17 @@ function N(t) {
15
15
  }
16
16
  a = t;
17
17
  }
18
- function I() {
18
+ function L() {
19
19
  return a;
20
20
  }
21
- function $(t, e) {
21
+ const g = /* @__PURE__ */ new Set(["1899-12-30", "1900-01-01"]);
22
+ function m(t) {
23
+ if (t == null || t === "") return !1;
24
+ const e = t instanceof Date ? Number.isNaN(t.getTime()) ? "" : t.toISOString() : String(t);
25
+ return g.has(e.slice(0, 10));
26
+ }
27
+ function _(t, e) {
28
+ if (m(t)) return "";
22
29
  const n = typeof t == "string" ? t.match(/^(\d{4})-(\d{2})-(\d{2})(?:T00:00:00(?:\.000)?Z)?$/) : null, r = n ? new Date(Number(n[1]), Number(n[2]) - 1, Number(n[3])) : new Date(t);
23
30
  return new Intl.DateTimeFormat("en-US", {
24
31
  month: "short",
@@ -30,7 +37,12 @@ function $(t, e) {
30
37
  ...e
31
38
  }).format(r);
32
39
  }
33
- function p(t) {
40
+ function b(t) {
41
+ if (m(t)) return "";
42
+ const e = t instanceof Date ? null : String(t), n = e == null ? void 0 : e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ]00:00:00(?:\.0+)?(?:Z|[+-]00:?00)?)?$/), r = n ? new Date(Number(n[1]), Number(n[2]) - 1, Number(n[3])) : t instanceof Date ? t : new Date(String(t));
43
+ return Number.isNaN(r.getTime()) ? String(t) : (n && r.setFullYear(Number(n[1])), r.toLocaleDateString());
44
+ }
45
+ function S(t) {
34
46
  return new Intl.DateTimeFormat("en-US", {
35
47
  ...a ? { timeZone: a } : {},
36
48
  month: "short",
@@ -40,11 +52,11 @@ function p(t) {
40
52
  minute: "2-digit"
41
53
  }).format(new Date(t));
42
54
  }
43
- let m = "relative", u = "en-US", l = !1;
55
+ let f = "relative", u = "en-US", l = !1;
44
56
  function x(t) {
45
- m = t === "exact" ? "exact" : "relative";
57
+ f = t === "exact" ? "exact" : "relative";
46
58
  }
47
- function S(t) {
59
+ function U(t) {
48
60
  if (t != null && t.locale)
49
61
  try {
50
62
  new Intl.NumberFormat(t.locale), u = t.locale;
@@ -60,7 +72,7 @@ function y(t, e) {
60
72
  const r = t.toLowerCase();
61
73
  return n.split(/\s+/).every((o) => r.includes(o));
62
74
  }
63
- function L(t) {
75
+ function E(t) {
64
76
  if (t == null || Number.isNaN(t)) return "—";
65
77
  const e = Math.max(0, t);
66
78
  if (e < 1) return `${Math.max(1, Math.round(e * 60))}m`;
@@ -74,65 +86,67 @@ function L(t) {
74
86
  const r = Math.floor(n / 30), o = Math.round(n - r * 30);
75
87
  return o > 0 ? `${r}mo ${o}d` : `${r}mo`;
76
88
  }
77
- function U(t) {
78
- if (m === "exact") return p(t);
79
- const e = new Date(t), n = _() - e.getTime(), r = Math.floor(n / 6e4);
89
+ function C(t) {
90
+ if (f === "exact") return S(t);
91
+ const e = new Date(t), n = N() - e.getTime(), r = Math.floor(n / 6e4);
80
92
  if (r < 1) return "just now";
81
93
  if (r < 60) return `${r}m ago`;
82
94
  const o = Math.floor(r / 60);
83
95
  if (o < 24) return `${o}h ago`;
84
96
  const i = Math.floor(o / 24);
85
- return i < 7 ? `${i}d ago` : $(e);
97
+ return i < 7 ? `${i}d ago` : _(e);
86
98
  }
87
99
  function T(t) {
88
100
  return t.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
89
101
  }
90
- const f = {
102
+ const s = {
91
103
  _and: [
92
104
  { is_redacted: { _eq: !1 } },
93
105
  { _or: [{ status: { _neq: "suspended" } }, { status: { _null: !0 } }] }
94
106
  ]
95
- }, w = {
96
- _and: [...f._and, { account_kind: { _null: !0 } }]
107
+ }, $ = {
108
+ _and: [...s._and, { account_kind: { _null: !0 } }]
97
109
  };
98
- function C(t) {
99
- return t ? f : w;
110
+ function O(t) {
111
+ return t ? s : $;
100
112
  }
101
- function E(t) {
113
+ function A(t) {
102
114
  const e = String(t ?? "");
103
115
  return e.startsWith("$t:") ? T(e.slice(3).replace(/-/g, "_")) : e;
104
116
  }
105
- function b(t) {
117
+ function R(t) {
106
118
  return t == null ? "—" : l && Math.abs(t) >= 1e4 ? new Intl.NumberFormat(u, {
107
119
  notation: "compact",
108
120
  maximumFractionDigits: 1
109
121
  }).format(t) : t.toLocaleString(u);
110
122
  }
111
- function v(t) {
123
+ function Z(t) {
112
124
  return t == null ? "—" : t < 1024 ? `${t} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(1)} KB` : t < 1024 * 1024 * 1024 ? `${(t / (1024 * 1024)).toFixed(1)} MB` : `${(t / (1024 * 1024 * 1024)).toFixed(2)} GB`;
113
125
  }
114
- function O(t) {
126
+ function B(t) {
115
127
  if (!t) return null;
116
128
  const e = t.split("-").map((n) => n.charAt(0).toUpperCase() + n.slice(1)).join("");
117
- return d[e];
129
+ return h[e];
118
130
  }
119
131
  export {
120
- f as ACTIVE_USER_OPTION_FILTER,
121
- w as PEOPLE_USER_OPTION_FILTER,
122
- E as choiceLabel,
123
- F as cn,
124
- $ as formatDate,
125
- p as formatDateTime,
126
- v as formatFileSize,
127
- b as formatNumber,
128
- U as formatRelative,
129
- I as getDisplayTimezone,
130
- L as humanHours,
132
+ s as ACTIVE_USER_OPTION_FILTER,
133
+ $ as PEOPLE_USER_OPTION_FILTER,
134
+ A as choiceLabel,
135
+ M as cn,
136
+ _ as formatDate,
137
+ S as formatDateTime,
138
+ Z as formatFileSize,
139
+ R as formatNumber,
140
+ C as formatRelative,
141
+ L as getDisplayTimezone,
142
+ E as humanHours,
143
+ m as isNullDate,
131
144
  y as matchesAllTokens,
132
- O as resolveCollectionIcon,
133
- N as setDisplayTimezone,
134
- S as setNumberFormat,
145
+ B as resolveCollectionIcon,
146
+ I as setDisplayTimezone,
147
+ U as setNumberFormat,
135
148
  x as setTimeDisplay,
136
149
  T as titleCase,
137
- C as userOptionFilter
150
+ b as toLocalDateString,
151
+ O as userOptionFilter
138
152
  };
@@ -1,92 +1,116 @@
1
- function a(t) {
1
+ function l(t) {
2
2
  return t == null || t === "" || Array.isArray(t) && t.length === 0;
3
3
  }
4
- function u(t) {
4
+ function c(t) {
5
5
  if (t == null || t === "") return null;
6
6
  const n = new Date(String(t));
7
7
  if (Number.isNaN(n.getTime())) return null;
8
- const s = /* @__PURE__ */ new Date(), r = Date.UTC(n.getFullYear(), n.getMonth(), n.getDate()), e = Date.UTC(s.getFullYear(), s.getMonth(), s.getDate());
9
- return Math.round((r - e) / 864e5);
8
+ const r = /* @__PURE__ */ new Date(), s = Date.UTC(n.getFullYear(), n.getMonth(), n.getDate()), e = Date.UTC(r.getFullYear(), r.getMonth(), r.getDate());
9
+ return Math.round((s - e) / 864e5);
10
10
  }
11
- function o(t) {
11
+ function d(t) {
12
12
  const n = String(t ?? "").trim();
13
13
  if (!n) return { stored: null, display: "", valid: !0 };
14
- const s = n.startsWith("+"), r = n.replace(/\D/g, "");
15
- if (r.length === 0) return { stored: null, display: n, valid: !1 };
16
- const e = r.length === 10 && !s ? r : r.length === 11 && r.startsWith("1") ? r.slice(1) : null;
14
+ const r = n.startsWith("+"), s = n.replace(/\D/g, "");
15
+ if (s.length === 0) return { stored: null, display: n, valid: !1 };
16
+ const e = s.length === 10 && !r ? s : s.length === 11 && s.startsWith("1") ? s.slice(1) : null;
17
17
  return e ? {
18
18
  stored: `+1${e}`,
19
19
  display: `+1 (${e.slice(0, 3)}) ${e.slice(3, 6)}-${e.slice(6)}`,
20
20
  valid: !0
21
- } : s && r.length >= 8 && r.length <= 15 ? { stored: `+${r}`, display: `+${r}`, valid: !0 } : { stored: s ? `+${r}` : r, display: n, valid: !1 };
21
+ } : r && s.length >= 8 && s.length <= 15 ? { stored: `+${s}`, display: `+${s}`, valid: !0 } : { stored: r ? `+${s}` : s, display: n, valid: !1 };
22
22
  }
23
- function c(t) {
24
- const n = o(t);
23
+ function y(t) {
24
+ const n = d(t);
25
25
  return n.valid && n.stored ? n.display : String(t ?? "");
26
26
  }
27
- function l(t, n, s) {
27
+ function f(t, n, r) {
28
28
  switch (n) {
29
29
  case "null":
30
- return a(t);
30
+ return l(t);
31
31
  case "nnull":
32
- return !a(t);
32
+ return !l(t);
33
33
  case "neq":
34
- return String(t ?? "") !== String(s ?? "");
34
+ return String(t ?? "") !== String(r ?? "");
35
35
  case "in":
36
- return (Array.isArray(s) ? s : String(s ?? "").split(",")).some((e) => String(e).trim() === String(t ?? ""));
36
+ return (Array.isArray(r) ? r : String(r ?? "").split(",")).some((e) => String(e).trim() === String(t ?? ""));
37
37
  default:
38
- return String(t ?? "") === String(s ?? "");
38
+ return String(t ?? "") === String(r ?? "");
39
39
  }
40
40
  }
41
- function d(t, n, s, r) {
41
+ function m(t, n) {
42
+ const r = (i) => typeof i == "number" ? i : typeof i == "string" && /^\s*-?(\d+\.?\d*|\.\d+)\s*$/.test(i) ? Number(i) : null, s = r(t), e = r(n);
43
+ if (s !== null && e !== null && Number.isFinite(s) && Number.isFinite(e)) return s - e;
44
+ const u = (i) => i instanceof Date ? Number.isNaN(i.getTime()) ? null : i.toISOString().slice(0, 10) : typeof i == "string" && /^\d{4}-\d{2}-\d{2}/.test(i) ? i.slice(0, 10) : null, o = u(t), a = u(n);
45
+ return o === null || a === null ? null : o < a ? -1 : o > a ? 1 : 0;
46
+ }
47
+ function g(t, n, r, s, e, u) {
48
+ if (!r || !s) return null;
49
+ const o = s[r];
50
+ if (l(n) || l(o)) return null;
51
+ const a = m(n, o);
52
+ if (a === null) return null;
53
+ const i = r.replace(/_/g, " ");
54
+ return t === "gte_field" && a < 0 ? u ?? `${e} must be on or after ${i}` : t === "lte_field" && a > 0 ? u ?? `${e} must be on or before ${i}` : null;
55
+ }
56
+ function $(t, n, r, s) {
42
57
  if (t.type === "required_if") {
43
58
  const e = t.field;
44
- return !e || !r || !l(r[e], String(t.op ?? "eq"), t.value) ? null : a(n) ? t.message ?? `${s} is required when ${e} matches this condition` : null;
59
+ return !e || !s || !f(s[e], String(t.op ?? "eq"), t.value) ? null : l(n) ? t.message ?? `${r} is required when ${e} matches this condition` : null;
45
60
  }
46
- if (a(n) && t.type !== "required") return null;
61
+ if (t.type === "gte_field" || t.type === "lte_field")
62
+ return g(
63
+ t.type,
64
+ n,
65
+ t.field,
66
+ s,
67
+ r,
68
+ t.message
69
+ );
70
+ if (l(n) && t.type !== "required") return null;
47
71
  switch (t.type) {
48
72
  case "required":
49
- return a(n) ? t.message ?? `${s} is required` : null;
73
+ return l(n) ? t.message ?? `${r} is required` : null;
50
74
  case "min": {
51
75
  const e = Number(t.value);
52
- return typeof n == "number" && n < e ? t.message ?? `${s} must be at least ${e}` : typeof n == "string" && n.length < e ? t.message ?? `${s} must be at least ${e} characters` : null;
76
+ return typeof n == "number" && n < e ? t.message ?? `${r} must be at least ${e}` : typeof n == "string" && n.length < e ? t.message ?? `${r} must be at least ${e} characters` : null;
53
77
  }
54
78
  case "max": {
55
79
  const e = Number(t.value);
56
- return typeof n == "number" && n > e ? t.message ?? `${s} must be at most ${e}` : typeof n == "string" && n.length > e ? t.message ?? `${s} must be at most ${e} characters` : null;
80
+ return typeof n == "number" && n > e ? t.message ?? `${r} must be at most ${e}` : typeof n == "string" && n.length > e ? t.message ?? `${r} must be at most ${e} characters` : null;
57
81
  }
58
82
  case "regex":
59
83
  try {
60
- return new RegExp(String(t.value)).test(String(n)) ? null : t.message ?? `${s} is invalid`;
84
+ return new RegExp(String(t.value)).test(String(n)) ? null : t.message ?? `${r} is invalid`;
61
85
  } catch {
62
86
  return null;
63
87
  }
64
88
  case "email":
65
- return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(n)) ? null : t.message ?? `${s} must be a valid email`;
89
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(n)) ? null : t.message ?? `${r} must be a valid email`;
66
90
  case "phone":
67
- return o(n).valid ? null : t.message ?? `${s} must be a valid phone number`;
91
+ return d(n).valid ? null : t.message ?? `${r} must be a valid phone number`;
68
92
  case "url":
69
93
  try {
70
94
  return new URL(String(n)), null;
71
95
  } catch {
72
- return t.message ?? `${s} must be a valid URL`;
96
+ return t.message ?? `${r} must be a valid URL`;
73
97
  }
74
98
  // Date must be at least N calendar days from today (e.g. delivery-date
75
99
  // minimums). max_days_from_today caps how far out a date may be.
76
100
  case "min_days_from_today": {
77
- const e = u(n), i = Number(t.value);
78
- return e === null || Number.isNaN(i) || e >= i ? null : t.message ?? `${s} must be at least ${i} days from today`;
101
+ const e = c(n), u = Number(t.value);
102
+ return e === null || Number.isNaN(u) || e >= u ? null : t.message ?? `${r} must be at least ${u} days from today`;
79
103
  }
80
104
  case "max_days_from_today": {
81
- const e = u(n), i = Number(t.value);
82
- return e === null || Number.isNaN(i) || e <= i ? null : t.message ?? `${s} must be within ${i} days of today`;
105
+ const e = c(n), u = Number(t.value);
106
+ return e === null || Number.isNaN(u) || e <= u ? null : t.message ?? `${r} must be within ${u} days of today`;
83
107
  }
84
108
  default:
85
109
  return null;
86
110
  }
87
111
  }
88
112
  export {
89
- d as applyValidationRule,
90
- c as formatPhone,
91
- o as normalizePhone
113
+ $ as applyValidationRule,
114
+ y as formatPhone,
115
+ d as normalizePhone
92
116
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",