@nivaro/react 0.3.10 → 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 (43) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useNivaroForm.js +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +34 -3
  5. package/dist/shared/components/CollectionBrowserView.js +1546 -1477
  6. package/dist/shared/components/ItemEditForm.js +4332 -4195
  7. package/dist/shared/components/PageRenderer.js +512 -465
  8. package/dist/shared/components/QueryStatStrip.js +74 -70
  9. package/dist/shared/components/ReportView.js +818 -827
  10. package/dist/shared/components/SheetHeaderBody.js +16 -14
  11. package/dist/shared/components/item-edit/CatalogPickerField.js +1029 -933
  12. package/dist/shared/components/item-edit/FieldRenderer.js +161 -156
  13. package/dist/shared/components/item-edit/FieldRow.js +20 -19
  14. package/dist/shared/components/item-edit/FilePickerField.js +52 -40
  15. package/dist/shared/components/item-edit/GroupSection.js +221 -221
  16. package/dist/shared/components/item-edit/InlineGridField.js +41 -41
  17. package/dist/shared/components/item-edit/InlineTableField.js +2249 -2238
  18. package/dist/shared/components/item-edit/M2MCombobox.js +46 -44
  19. package/dist/shared/components/item-edit/NestedRelationEditor.js +11 -11
  20. package/dist/shared/components/item-edit/QuickPicker.js +263 -216
  21. package/dist/shared/components/item-edit/RelationCombobox.js +285 -245
  22. package/dist/shared/components/item-edit/RichTextEditorImpl.js +42 -32
  23. package/dist/shared/components/item-edit/RowHistorySheet.js +130 -134
  24. package/dist/shared/components/item-edit/SummaryPanel.js +305 -279
  25. package/dist/shared/components/item-edit/helpers.js +133 -134
  26. package/dist/shared/components/item-edit/line-qty.js +57 -0
  27. package/dist/shared/components/item-edit/option-disambiguate.js +53 -0
  28. package/dist/shared/components/panels/AddendumLinesDiff.js +87 -90
  29. package/dist/shared/components/panels/CommentPanel.js +350 -315
  30. package/dist/shared/components/panels/ItemLockBanner.js +297 -230
  31. package/dist/shared/components/panels/PipelinePanel.js +719 -701
  32. package/dist/shared/components/queue/QueueQuickFilters.js +43 -41
  33. package/dist/shared/components/queue/QueueWorklist.js +1005 -935
  34. package/dist/shared/components/widgets/ReviewListWidget.js +99 -93
  35. package/dist/shared/lib/obligation-banner.js +14 -13
  36. package/dist/shared/lib/obligation-reason-text.js +13 -0
  37. package/dist/shared/lib/query-filter-seed.js +34 -11
  38. package/dist/shared/lib/sanitize-html.js +24 -15
  39. package/dist/shared/lib/sheet-def.js +38 -22
  40. package/dist/shared/lib/unique-options.js +10 -0
  41. package/dist/shared/lib/utils.js +57 -43
  42. package/dist/shared/lib/validation-rules.js +58 -34
  43. package/package.json +1 -1
@@ -1,21 +1,26 @@
1
1
  import { useRef as b, useEffect as w, useState as E } from "react";
2
2
  import { useNivaroClient as N, useParentDraft as P } from "../../context.js";
3
3
  import { get as j } from "../../lib/commands.js";
4
- function M(t, n) {
5
- return t ? t.replace(/\{\{([^}]+)\}\}/g, (o, c) => {
6
- const l = c.trim().split(".");
7
- let i = n;
8
- for (const d of l) {
9
- if (i == null || typeof i != "object") {
10
- i = null;
4
+ import { htmlToText as I } from "../../lib/sanitize-html.js";
5
+ function L(t, n) {
6
+ if (!t) {
7
+ const i = [n.first_name, n.last_name].filter((l) => l != null && String(l).trim() !== "").join(" ");
8
+ return String(
9
+ n.name ?? n.title ?? n.label ?? n.type ?? n.description ?? (i || null) ?? n.email ?? n.id ?? ""
10
+ );
11
+ }
12
+ return t.replace(/\{\{([^}]+)\}\}/g, (i, l) => {
13
+ const f = l.trim().split(".");
14
+ let s = n;
15
+ for (const d of f) {
16
+ if (s == null || typeof s != "object") {
17
+ s = null;
11
18
  break;
12
19
  }
13
- i = i[d];
20
+ s = s[d];
14
21
  }
15
- return String(i ?? "");
16
- }) : String(
17
- n.name ?? n.title ?? n.label ?? n.type ?? n.description ?? n.id ?? ""
18
- );
22
+ return String(s ?? "");
23
+ });
19
24
  }
20
25
  function T(t) {
21
26
  if (t == null) return null;
@@ -27,162 +32,162 @@ function T(t) {
27
32
  return null;
28
33
  }
29
34
  }
30
- function I(t) {
35
+ function q(t) {
31
36
  const n = T(t);
32
37
  return Array.isArray(n == null ? void 0 : n.cascade_filters) ? n.cascade_filters : [];
33
38
  }
34
- function $(t) {
35
- var d, g;
39
+ function M(t) {
40
+ var d, h;
36
41
  let n;
37
- const o = [], c = [], l = [], i = (s, a) => {
38
- if (n || (n = {}), s.filter_is_m2m)
39
- n[s.filter_column] = { _some: a };
40
- else if (s.filter_column.includes(".")) {
41
- const p = s.filter_column.split(".");
42
+ const i = [], l = [], f = [], s = (o, a) => {
43
+ if (n || (n = {}), o.filter_is_m2m)
44
+ n[o.filter_column] = { _some: a };
45
+ else if (o.filter_column.includes(".")) {
46
+ const p = o.filter_column.split(".");
42
47
  let _ = a;
43
48
  for (let u = p.length - 1; u >= 1; u--) _ = { [p[u]]: _ };
44
- n[p[0]] = s.filter_via_many ? { _some: _ } : _;
49
+ n[p[0]] = o.filter_via_many ? { _some: _ } : _;
45
50
  } else
46
- n[s.filter_column] = a;
51
+ n[o.filter_column] = a;
47
52
  };
48
- for (const s of t.rules) {
49
- if ((d = t.skipParent) != null && d.call(t, s.parent_field)) continue;
50
- const a = t.parentValue(s.parent_field);
53
+ for (const o of t.rules) {
54
+ if ((d = t.skipParent) != null && d.call(t, o.parent_field)) continue;
55
+ const a = t.parentValue(o.parent_field);
51
56
  if (a != null && a !== "" && !(Array.isArray(a) && a.length === 0)) {
52
57
  let _ = a;
53
- if (s.value_map && typeof s.value_map == "object") {
54
- const y = s.value_map, h = (e) => y[String(e)] ?? s.value_map_default ?? e;
58
+ if (o.value_map && typeof o.value_map == "object") {
59
+ const y = o.value_map, m = (e) => y[String(e)] ?? o.value_map_default ?? e;
55
60
  _ = Array.isArray(a) ? [
56
61
  ...new Set(
57
62
  a.flatMap((e) => {
58
- const r = h(e);
63
+ const r = m(e);
59
64
  return Array.isArray(r) ? r : [r];
60
65
  })
61
66
  )
62
- ] : h(a);
67
+ ] : m(a);
63
68
  }
64
69
  const u = Array.isArray(_) ? { _in: _ } : { _eq: _ };
65
- i(s, s.filter_is_m2m ? { id: u } : u), o.push(String(s.parent_field));
70
+ s(o, o.filter_is_m2m ? { id: u } : u), i.push(String(o.parent_field));
66
71
  } else {
67
- c.push(String(s.parent_field)), s.show_all_if_no_parent === !1 && l.push(String(s.parent_field));
68
- const _ = s.value_map || (g = t.parentOptionFilter) == null ? void 0 : g.call(t, s.parent_field);
69
- _ && i(s, _);
72
+ l.push(String(o.parent_field)), o.show_all_if_no_parent === !1 && f.push(String(o.parent_field));
73
+ const _ = o.value_map || (h = t.parentOptionFilter) == null ? void 0 : h.call(t, o.parent_field);
74
+ _ && s(o, _);
70
75
  }
71
76
  }
72
- return { filter: n, satisfiedParents: o, unsatisfiedParents: c, missingRequiredParents: l };
77
+ return { filter: n, satisfiedParents: i, unsatisfiedParents: l, missingRequiredParents: f };
73
78
  }
74
- function x(t, n, o) {
75
- const c = (e) => n.some(
76
- (r) => r.many_collection === o && r.many_field === e && !r.junction_field || r.one_collection === o && r.one_field === e
77
- ), l = /* @__PURE__ */ new Map();
79
+ function z(t, n, i) {
80
+ const l = (e) => n.some(
81
+ (r) => r.many_collection === i && r.many_field === e && !r.junction_field || r.one_collection === i && r.one_field === e
82
+ ), f = /* @__PURE__ */ new Map();
78
83
  for (const e of t) {
79
84
  if (e.hidden) continue;
80
- const r = I(e.dependency_config);
81
- r.length && c(e.field) && l.set(e.field, r);
85
+ const r = q(e.dependency_config);
86
+ r.length && l(e.field) && f.set(e.field, r);
82
87
  }
83
- const i = new Set(l.keys());
84
- for (const e of l.values())
85
- for (const r of e) c(r.parent_field) && i.add(r.parent_field);
86
- const d = (e, r) => [...r].filter((f) => f !== e && (l.get(f) ?? []).some((m) => m.parent_field === e)), g = new Set(t.filter((e) => e.required).map((e) => e.field)), s = (e) => g.has(e) && (l.get(e) ?? []).some((r) => r.show_all_if_no_parent !== !0), a = new Set(
87
- [...i].filter((e) => d(e, i).length === 0 && !s(e))
88
- ), p = new Set([...i].filter((e) => !a.has(e))), _ = new Set(
89
- [...p].filter((e) => d(e, p).length > 0 || l.has(e))
88
+ const s = new Set(f.keys());
89
+ for (const e of f.values())
90
+ for (const r of e) l(r.parent_field) && s.add(r.parent_field);
91
+ const d = (e, r) => [...r].filter((c) => c !== e && (f.get(c) ?? []).some((g) => g.parent_field === e)), h = new Set(t.filter((e) => e.required).map((e) => e.field)), o = (e) => h.has(e) && (f.get(e) ?? []).some((r) => r.show_all_if_no_parent !== !0), a = new Set(
92
+ [...s].filter((e) => d(e, s).length === 0 && !o(e))
93
+ ), p = new Set([...s].filter((e) => !a.has(e))), _ = new Set(
94
+ [...p].filter((e) => d(e, p).length > 0 || f.has(e))
90
95
  ), u = [...p].filter((e) => {
91
96
  if (!_.has(e)) return !1;
92
- const r = d(e, i);
93
- return r.length === 0 || r.some((f) => p.has(f));
97
+ const r = d(e, s);
98
+ return r.length === 0 || r.some((c) => p.has(c));
94
99
  });
95
100
  if (u.length > 0) {
96
- i.clear();
97
- for (const e of u) i.add(e);
101
+ s.clear();
102
+ for (const e of u) s.add(e);
98
103
  }
99
- const y = [], h = new Set(i);
100
- for (; h.size; ) {
104
+ const y = [], m = new Set(s);
105
+ for (; m.size; ) {
101
106
  let e = null, r = Number.POSITIVE_INFINITY;
102
- for (const f of [...h].sort()) {
103
- const m = (l.get(f) ?? []).filter((S) => i.has(S.parent_field));
104
- if (m.filter(
107
+ for (const c of [...m].sort()) {
108
+ const g = (f.get(c) ?? []).filter((S) => s.has(S.parent_field));
109
+ if (g.filter(
105
110
  (S) => S.show_all_if_no_parent === !1 && !y.includes(S.parent_field)
106
111
  ).length > 0) continue;
107
112
  const A = new Set(
108
- m.map((S) => S.parent_field).filter((S) => !y.includes(S) && S !== f)
109
- ).size * 100 + m.length;
110
- A < r && (r = A, e = f);
113
+ g.map((S) => S.parent_field).filter((S) => !y.includes(S) && S !== c)
114
+ ).size * 100 + g.length;
115
+ A < r && (r = A, e = c);
111
116
  }
112
- e == null && (e = [...h].sort(
113
- (f, m) => {
117
+ e == null && (e = [...m].sort(
118
+ (c, g) => {
114
119
  var k, v;
115
- return (((k = l.get(f)) == null ? void 0 : k.length) ?? 0) - (((v = l.get(m)) == null ? void 0 : v.length) ?? 0);
120
+ return (((k = f.get(c)) == null ? void 0 : k.length) ?? 0) - (((v = f.get(g)) == null ? void 0 : v.length) ?? 0);
116
121
  }
117
- )[0]), y.push(e), h.delete(e);
122
+ )[0]), y.push(e), m.delete(e);
118
123
  }
119
124
  return y;
120
125
  }
121
- function J({
126
+ function W({
122
127
  cascadeRules: t,
123
128
  cascadeFilter: n,
124
- currentValue: o,
125
- relatedCollection: c,
126
- missingRequiredParents: l,
127
- onClear: i
129
+ currentValue: i,
130
+ relatedCollection: l,
131
+ missingRequiredParents: f,
132
+ onClear: s
128
133
  }) {
129
- const d = N(), g = JSON.stringify(n), s = b(void 0), a = b(i);
130
- a.current = i, w(() => {
131
- const e = s.current;
132
- s.current = g, e !== void 0 && e !== g && t.some((r) => r.clear_on_parent_change) && a.current();
133
- }, [g, t]);
134
- const p = b(null), _ = P(), u = _ == null ? void 0 : _.dirtyFields, y = (l ?? []).join(","), h = b(null);
134
+ const d = N(), h = JSON.stringify(n), o = b(void 0), a = b(s);
135
+ a.current = s, w(() => {
136
+ const e = o.current;
137
+ o.current = h, e !== void 0 && e !== h && t.some((r) => r.clear_on_parent_change) && a.current();
138
+ }, [h, t]);
139
+ const p = b(null), _ = P(), u = _ == null ? void 0 : _.dirtyFields, y = (f ?? []).join(","), m = b(null);
135
140
  return w(() => {
136
- if (o == null || o === "") return;
137
- const e = (l ?? []).filter(
138
- (f) => (u == null ? void 0 : u.has(f)) && t.some((m) => m.parent_field === f && m.clear_on_unavailable)
141
+ if (i == null || i === "") return;
142
+ const e = (f ?? []).filter(
143
+ (c) => (u == null ? void 0 : u.has(c)) && t.some((g) => g.parent_field === c && g.clear_on_unavailable)
139
144
  );
140
145
  if (e.length === 0) return;
141
- const r = `${String(o)}|${e.join(",")}`;
142
- h.current !== r && (h.current = r, a.current());
143
- }, [y, o, u, t]), w(() => {
144
- if (!n || Object.keys(n).length === 0 || !t.some((f) => f.clear_on_unavailable) || o == null || !c || !t.some(
145
- (f) => f.clear_on_unavailable && (u == null ? void 0 : u.has(f.parent_field))
146
+ const r = `${String(i)}|${e.join(",")}`;
147
+ m.current !== r && (m.current = r, a.current());
148
+ }, [y, i, u, t]), w(() => {
149
+ if (!n || Object.keys(n).length === 0 || !t.some((c) => c.clear_on_unavailable) || i == null || !l || !t.some(
150
+ (c) => c.clear_on_unavailable && (u == null ? void 0 : u.has(c.parent_field))
146
151
  )) return;
147
- const r = `${c}|${String(o)}|${g}`;
152
+ const r = `${l}|${String(i)}|${h}`;
148
153
  p.current !== r && (p.current = r, d.request(
149
- j(`/items/${c}`, {
150
- filter: JSON.stringify({ ...n, id: { _eq: o } }),
154
+ j(`/items/${l}`, {
155
+ filter: JSON.stringify({ ...n, id: { _eq: i } }),
151
156
  limit: 1,
152
157
  fields: "id"
153
158
  })
154
- ).then((f) => {
155
- (f.data ?? []).length === 0 && a.current();
159
+ ).then((c) => {
160
+ (c.data ?? []).length === 0 && a.current();
156
161
  }).catch(() => {
157
162
  p.current === r && (p.current = null);
158
163
  }));
159
164
  }, [
160
165
  n,
161
- g,
166
+ h,
162
167
  t,
163
168
  d,
164
- o,
165
- c,
169
+ i,
170
+ l,
166
171
  u
167
172
  ]), null;
168
173
  }
169
- function z(t) {
170
- const [n, o] = E(9999);
174
+ function B(t) {
175
+ const [n, i] = E(9999);
171
176
  return w(() => {
172
- const c = t.current;
173
- if (!c) return;
174
- o(c.getBoundingClientRect().width);
175
- const l = new ResizeObserver(([i]) => {
176
- o(i.contentRect.width);
177
+ const l = t.current;
178
+ if (!l) return;
179
+ i(l.getBoundingClientRect().width);
180
+ const f = new ResizeObserver(([s]) => {
181
+ i(s.contentRect.width);
177
182
  });
178
- return l.observe(c), () => l.disconnect();
183
+ return f.observe(l), () => f.disconnect();
179
184
  }, [t]), n;
180
185
  }
181
- function W(t, n) {
182
- const o = T(t), c = (o == null ? void 0 : o.col_span) ?? 0, l = [3, 4, 6, 12].includes(c) ? c : 12;
183
- return n < 480 ? 12 : n < 800 ? l <= 6 ? 6 : 12 : l;
186
+ function K(t, n) {
187
+ const i = T(t), l = (i == null ? void 0 : i.col_span) ?? 0, f = [3, 4, 6, 12].includes(l) ? l : 12;
188
+ return n < 480 ? 12 : n < 800 ? f <= 6 ? 6 : 12 : f;
184
189
  }
185
- function B(t) {
190
+ function R(t) {
186
191
  if (!t) return "";
187
192
  try {
188
193
  return new Date(String(t)).toISOString().slice(0, 16);
@@ -190,13 +195,13 @@ function B(t) {
190
195
  return "";
191
196
  }
192
197
  }
193
- const K = /* @__PURE__ */ new Set([
198
+ const U = /* @__PURE__ */ new Set([
194
199
  "id",
195
200
  "date_created",
196
201
  "date_updated",
197
202
  "user_created",
198
203
  "user_updated"
199
- ]), q = /* @__PURE__ */ new Set([
204
+ ]), D = /* @__PURE__ */ new Set([
200
205
  "__pipeline__",
201
206
  "__comments__",
202
207
  "__tasks__",
@@ -206,50 +211,44 @@ const K = /* @__PURE__ */ new Set([
206
211
  "__owners__",
207
212
  "__pdf__",
208
213
  "__subtitle__"
209
- ]), R = (t) => q.has(t) || t.startsWith("__widget_") && t.endsWith("__"), U = { created: [], updated: [], deleted: [] };
210
- function Y(t) {
214
+ ]), Y = (t) => D.has(t) || t.startsWith("__widget_") && t.endsWith("__"), F = { created: [], updated: [], deleted: [] };
215
+ function Q(t) {
211
216
  if (typeof t != "string") return null;
212
217
  const n = t.trim();
213
218
  if (!n) return null;
214
219
  if (n.startsWith("{") && /"blocks"\s*:/.test(n))
215
220
  try {
216
- const o = JSON.parse(n);
217
- if (Array.isArray(o.blocks)) {
218
- const c = [];
219
- for (const l of o.blocks) {
220
- const i = l.data ?? {};
221
- typeof i.text == "string" ? c.push(i.text) : Array.isArray(i.items) && c.push(
222
- i.items.map(
221
+ const i = JSON.parse(n);
222
+ if (Array.isArray(i.blocks)) {
223
+ const l = [];
224
+ for (const f of i.blocks) {
225
+ const s = f.data ?? {};
226
+ typeof s.text == "string" ? l.push(s.text) : Array.isArray(s.items) && l.push(
227
+ s.items.map(
223
228
  (d) => typeof d == "string" ? d : String((d == null ? void 0 : d.content) ?? "")
224
229
  ).filter(Boolean).join(" · ")
225
230
  );
226
231
  }
227
- return O(c.join(" ")).trim();
232
+ return O(l.join(" ")).trim();
228
233
  }
229
234
  } catch {
230
235
  }
231
236
  return /<[a-z][\s\S]*>/i.test(n) ? O(n).trim() : null;
232
237
  }
233
- function O(t) {
234
- if (typeof document < "u") {
235
- const n = document.createElement("div");
236
- return n.innerHTML = t, (n.textContent || "").replace(/\s+/g, " ");
237
- }
238
- return t.replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ");
239
- }
238
+ const O = I;
240
239
  export {
241
- J as CascadeEffectController,
242
- U as EMPTY_NESTED_OPS,
243
- q as SENTINEL_FIELDS,
244
- K as SYSTEM_FIELDS,
245
- M as applyDisplayTemplate,
246
- $ as buildCascadeFilter,
247
- I as getCascadeFilters,
248
- R as isSentinelKey,
240
+ W as CascadeEffectController,
241
+ F as EMPTY_NESTED_OPS,
242
+ D as SENTINEL_FIELDS,
243
+ U as SYSTEM_FIELDS,
244
+ L as applyDisplayTemplate,
245
+ M as buildCascadeFilter,
246
+ q as getCascadeFilters,
247
+ Y as isSentinelKey,
249
248
  T as parseJson,
250
- W as resolveColSpan,
251
- Y as richTextToPlain,
252
- x as seedQuickPickerSteps,
253
- B as toLocalDatetime,
254
- z as useContainerWidth
249
+ K as resolveColSpan,
250
+ Q as richTextToPlain,
251
+ z as seedQuickPickerSteps,
252
+ R as toLocalDatetime,
253
+ B as useContainerWidth
255
254
  };
@@ -0,0 +1,57 @@
1
+ import { evaluateNumeric as c } from "../../lib/expression.js";
2
+ const o = {
3
+ tinyint: 255,
4
+ smallint: 32767,
5
+ integer: 2147483647,
6
+ int: 2147483647,
7
+ bigInteger: Number.MAX_SAFE_INTEGER,
8
+ bigint: Number.MAX_SAFE_INTEGER
9
+ }, f = /* @__PURE__ */ new Set([
10
+ ...Object.keys(o),
11
+ "decimal",
12
+ "float",
13
+ "double",
14
+ "real",
15
+ "numeric",
16
+ "money",
17
+ "smallmoney",
18
+ "number"
19
+ ]);
20
+ function m(e) {
21
+ return e != null && Object.hasOwn(o, e);
22
+ }
23
+ function b(e, n = {}) {
24
+ const r = n.label ?? "Value";
25
+ if (e == null || typeof e == "string" && e.trim() === "")
26
+ return { ok: !0, value: null };
27
+ const i = typeof e == "number" ? e : Number(e);
28
+ if (Number.isNaN(i)) return { ok: !1, message: `${r} must be a number` };
29
+ const t = m(n.type) ? o[n.type] : Number.MAX_SAFE_INTEGER;
30
+ return !Number.isFinite(i) || Math.abs(i) > t ? { ok: !1, message: `${r} can't be more than ${t.toLocaleString("en-US")}` } : m(n.type) && !Number.isInteger(i) ? { ok: !1, message: `${r} must be a whole number` } : n.min !== void 0 && i < n.min ? {
31
+ ok: !1,
32
+ message: n.min === 0 ? `${r} can't be negative` : `${r} can't be below ${n.min}`
33
+ } : { ok: !0, value: i };
34
+ }
35
+ function g(e, n, r, i = {}) {
36
+ const t = { ...e, ...n };
37
+ for (const u of r)
38
+ e[u] != null && e[u] !== "" && (t[u] = e[u]);
39
+ for (const [u, s] of Object.entries(i)) {
40
+ const l = c(s, t);
41
+ l !== null && (t[u] = l);
42
+ }
43
+ return t;
44
+ }
45
+ function N(e, n, r) {
46
+ const i = {};
47
+ for (const [t, u] of Object.entries(e))
48
+ r.has(t) && (n && t !== "_change_reason" && String(u ?? "") === String(n[t] ?? "") || (i[t] = u));
49
+ return i;
50
+ }
51
+ export {
52
+ f as NUMBER_FIELD_TYPES,
53
+ N as changedRowFields,
54
+ b as checkNumberEntry,
55
+ m as isIntegerFieldType,
56
+ g as mergePendingQtyRow
57
+ };
@@ -0,0 +1,53 @@
1
+ import { titleCase as y } from "../../lib/utils.js";
2
+ function S(n, i) {
3
+ const r = /* @__PURE__ */ new Map();
4
+ for (const o of n) {
5
+ const s = i(o).trim().toLowerCase(), a = r.get(s);
6
+ a ? a.push(String(o.id)) : r.set(s, [String(o.id)]);
7
+ }
8
+ return [...r.values()].filter((o) => o.length > 1).flat();
9
+ }
10
+ const b = /* @__PURE__ */ new Set([
11
+ "id",
12
+ "sort",
13
+ "date_created",
14
+ "date_updated",
15
+ "user_created",
16
+ "user_updated",
17
+ "created_at",
18
+ "updated_at",
19
+ "created_by",
20
+ "updated_by"
21
+ ]), m = /(^|_)(system_id|code|number|no|key|name|type|status)$/i;
22
+ function p(n) {
23
+ if (n == null || typeof n == "object") return null;
24
+ const i = String(n).trim();
25
+ return i === "" ? null : i;
26
+ }
27
+ function w(n, i = []) {
28
+ const r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([...b, ...i]);
29
+ for (const s of n) {
30
+ if (s.length < 2) continue;
31
+ const a = [...new Set(s.flatMap((t) => Object.keys(t)))].filter(
32
+ (t) => !o.has(t) && !t.startsWith("_")
33
+ );
34
+ let e = null;
35
+ for (const t of a) {
36
+ const c = s.map((d) => p(d[t]));
37
+ if (c.some((d) => d === null)) continue;
38
+ const u = new Set(c).size;
39
+ if (u < 2) continue;
40
+ const f = m.test(t), l = s.some((d) => typeof d[t] == "string");
41
+ (!e || u > e.distinct || u === e.distinct && (f !== e.preferred ? f : l && !e.text)) && (e = { key: t, distinct: u, preferred: f, text: l });
42
+ }
43
+ for (const t of s) {
44
+ const c = String(t.id);
45
+ r.set(c, e ? `${y(e.key)}: ${p(t[e.key])}` : `#${c}`);
46
+ }
47
+ }
48
+ return r;
49
+ }
50
+ export {
51
+ S as collidingIds,
52
+ w as disambiguators
53
+ };