@nivaro/react 0.3.112 → 0.3.113

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,20 +1,20 @@
1
- import { jsxs as d, jsx as h, Fragment as T } from "react/jsx-runtime";
2
- import { useQuery as C } from "@tanstack/react-query";
3
- import { Search as _, X as D, Loader2 as L } from "lucide-react";
4
- import { useState as v, useEffect as S } from "react";
5
- import { get as R } from "../../lib/commands.js";
6
- import { describeError as H } from "../../lib/error-message.js";
7
- import { numericIntlOptions as k } from "../../lib/format-value.js";
8
- import { cn as E, toLocalDateString as G, choiceLabel as F } from "../../lib/utils.js";
9
- const X = 200, K = 10, O = 200;
10
- function z(e) {
1
+ import { jsxs as d, jsx as h, Fragment as L } from "react/jsx-runtime";
2
+ import { useQuery as v } from "@tanstack/react-query";
3
+ import { Search as T, X as D, Loader2 as G } from "lucide-react";
4
+ import { useState as H, useEffect as y } from "react";
5
+ import { get as E } from "../../lib/commands.js";
6
+ import { describeError as O } from "../../lib/error-message.js";
7
+ import { numericIntlOptions as R } from "../../lib/format-value.js";
8
+ import { cn as A, toLocalDateString as q, choiceLabel as F } from "../../lib/utils.js";
9
+ const ne = 200, re = 10, U = 200;
10
+ function oe(e) {
11
11
  return [
12
12
  ...new Set(
13
13
  e.toLowerCase().split(/\s+/).map((t) => t.trim()).filter(Boolean)
14
14
  )
15
15
  ];
16
16
  }
17
- function q(e) {
17
+ function M(e) {
18
18
  if (!e.options) return {};
19
19
  if (typeof e.options == "string")
20
20
  try {
@@ -24,7 +24,7 @@ function q(e) {
24
24
  }
25
25
  return e.options;
26
26
  }
27
- const A = /* @__PURE__ */ new Set([
27
+ const $ = /* @__PURE__ */ new Set([
28
28
  "integer",
29
29
  "bigInteger",
30
30
  "decimal",
@@ -40,69 +40,69 @@ const A = /* @__PURE__ */ new Set([
40
40
  "double",
41
41
  "number"
42
42
  ]);
43
- function Z(e, t, a = {}) {
44
- const r = q(e);
45
- if (e.interface === "relation-path" && r.display === "presence")
43
+ function ie(e, t, r = {}) {
44
+ const n = M(e);
45
+ if (e.interface === "relation-path" && n.display === "presence")
46
46
  return [t != null && String(t).trim() !== "" ? "Yes" : "No"];
47
47
  if (t == null || t === "") return [];
48
48
  if (typeof t == "object") return [];
49
- const n = [String(t)];
50
- if (a.m2oLabel && n.push(a.m2oLabel), e.type === "boolean" && n.push(t ? "Yes" : "No"), e.type === "date" || e.type === "datetime")
49
+ const o = [String(t)];
50
+ if (r.m2oLabel && o.push(r.m2oLabel), e.type === "boolean" && o.push(t ? "Yes" : "No"), e.type === "date" || e.type === "datetime")
51
51
  try {
52
- n.push(G(t));
52
+ o.push(q(t));
53
53
  } catch {
54
54
  }
55
- const l = Array.isArray(r.choices) ? r.choices : [];
56
- for (const o of l)
57
- o && String(o.value) === String(t) && o.text != null && n.push(F(String(o.text)));
55
+ const l = Array.isArray(n.choices) ? n.choices : [];
56
+ for (const a of l)
57
+ a && String(a.value) === String(t) && a.text != null && o.push(F(String(a.text)));
58
58
  const i = Number(t);
59
- if ((A.has(e.type ?? "") || r.format === "currency") && String(t).trim() !== "" && Number.isFinite(i)) {
60
- n.push(new Intl.NumberFormat("en-US", { maximumFractionDigits: 20 }).format(i));
61
- const o = r.format;
59
+ if (($.has(e.type ?? "") || n.format === "currency") && String(t).trim() !== "" && Number.isFinite(i)) {
60
+ o.push(new Intl.NumberFormat("en-US", { maximumFractionDigits: 20 }).format(i));
61
+ const a = n.format;
62
62
  try {
63
- o === "currency" ? n.push(
63
+ a === "currency" ? o.push(
64
64
  i.toLocaleString("en-US", {
65
- ...k(r, "currency"),
66
- currency: r.currency || "USD"
65
+ ...R(n, "currency"),
66
+ currency: n.currency || "USD"
67
67
  })
68
- ) : o === "int" ? n.push(new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(i)) : (o === "decimal" || o === "number") && n.push(i.toLocaleString("en-US", k(r, "number")));
68
+ ) : a === "int" ? o.push(new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(i)) : (a === "decimal" || a === "number") && o.push(i.toLocaleString("en-US", R(n, "number")));
69
69
  } catch {
70
70
  }
71
71
  }
72
- return n;
72
+ return o;
73
73
  }
74
- function Q(e, t) {
74
+ function ae(e, t) {
75
75
  if (t.length === 0) return !0;
76
- const a = e.toLowerCase();
77
- return t.every((r) => a.includes(r));
76
+ const r = e.toLowerCase();
77
+ return t.every((n) => r.includes(n));
78
78
  }
79
- function ee(e, t) {
79
+ function le(e, t) {
80
80
  return t.matches || t.editing ? "show" : e.__prefilled ? "hide" : "dim";
81
81
  }
82
- function te(e, t, a = []) {
83
- const r = new Set(e.map((l) => String(l.id))), n = [];
84
- for (const l of [...t ?? [], ...a]) {
82
+ function se(e, t, r = []) {
83
+ const n = new Set(e.map((l) => String(l.id))), o = [];
84
+ for (const l of [...t ?? [], ...r]) {
85
85
  const i = String(l.id);
86
- l.id == null || r.has(i) || (r.add(i), n.push(l));
86
+ l.id == null || n.has(i) || (n.add(i), o.push(l));
87
87
  }
88
- return n;
88
+ return o;
89
89
  }
90
- function re(e, t) {
91
- const [a, r] = v(e);
92
- return S(() => {
93
- const n = setTimeout(() => r(e), t);
94
- return () => clearTimeout(n);
95
- }, [e, t]), a;
90
+ function ce(e, t) {
91
+ const [r, n] = H(e);
92
+ return y(() => {
93
+ const o = setTimeout(() => n(e), t);
94
+ return () => clearTimeout(o);
95
+ }, [e, t]), r;
96
96
  }
97
- function ne(e) {
98
- var n, l;
99
- const t = e.query.trim(), a = JSON.stringify(e.filter), r = C({
100
- queryKey: ["o2m-grid-search", e.collection, a, t, e.version],
97
+ function ue(e) {
98
+ var o, l;
99
+ const t = e.query.trim(), r = JSON.stringify(e.filter), n = v({
100
+ queryKey: ["o2m-grid-search", e.collection, r, t, e.version],
101
101
  queryFn: () => e.client.request(
102
- R(`/items/${e.collection}`, {
103
- filter: a,
102
+ E(`/items/${e.collection}`, {
103
+ filter: r,
104
104
  search: t,
105
- limit: O
105
+ limit: U
106
106
  })
107
107
  ).then((i) => ({
108
108
  rows: i.data ?? [],
@@ -117,101 +117,127 @@ function ne(e) {
117
117
  retry: !1
118
118
  });
119
119
  return {
120
- rows: e.enabled && t ? (n = r.data) == null ? void 0 : n.rows : void 0,
121
- total: e.enabled && t ? ((l = r.data) == null ? void 0 : l.total) ?? null : null,
122
- loading: e.enabled && t.length > 0 && r.isFetching,
123
- error: e.enabled && t ? r.error : null,
124
- retry: () => void r.refetch()
120
+ rows: e.enabled && t ? (o = n.data) == null ? void 0 : o.rows : void 0,
121
+ total: e.enabled && t ? ((l = n.data) == null ? void 0 : l.total) ?? null : null,
122
+ loading: e.enabled && t.length > 0 && n.isFetching,
123
+ error: e.enabled && t ? n.error : null,
124
+ retry: () => void n.refetch()
125
125
  };
126
126
  }
127
- function ie(e) {
128
- const t = JSON.stringify(e.filter), a = C({
127
+ function de(e) {
128
+ const t = JSON.stringify(e.filter), r = v({
129
129
  queryKey: ["o2m-grid-total", e.collection, t, e.version],
130
130
  queryFn: () => e.client.request(
131
- R(`/items/${e.collection}`, { filter: t, fields: "id", limit: 1 })
132
- ).then((r) => typeof r.total == "number" ? r.total : null),
131
+ E(`/items/${e.collection}`, { filter: t, fields: "id", limit: 1 })
132
+ ).then((n) => typeof n.total == "number" ? n.total : null),
133
133
  enabled: e.enabled,
134
134
  staleTime: 6e4,
135
- placeholderData: (r) => r,
135
+ placeholderData: (n) => n,
136
136
  retry: !1
137
137
  });
138
- return e.enabled ? a.data ?? null : null;
138
+ return e.enabled ? r.data ?? null : null;
139
139
  }
140
- const b = "nvr-grid-search", ae = `::highlight(${b}){background-color:#fde68a;color:#422006}.dark ::highlight(${b}){background-color:rgba(245,158,11,0.45);color:#fffbeb}`, p = /* @__PURE__ */ new Map();
141
- function U() {
140
+ const w = "nvr-grid-search", he = `::highlight(${w}){background-color:#fde68a;color:#422006}.dark ::highlight(${w}){background-color:rgba(245,158,11,0.45);color:#fffbeb}`, b = /* @__PURE__ */ new Map();
141
+ function K() {
142
142
  if (typeof window > "u") return null;
143
143
  const e = window.CSS, t = window.Highlight;
144
144
  return !(e != null && e.highlights) || !t ? null : { registry: e.highlights, Ctor: t };
145
145
  }
146
- function y() {
147
- const e = U();
146
+ function x() {
147
+ const e = K();
148
148
  if (!e) return;
149
- const t = [...p.values()].flat();
150
- t.length === 0 ? e.registry.delete(b) : e.registry.set(b, new e.Ctor(...t));
149
+ const t = [...b.values()].flat();
150
+ t.length === 0 ? e.registry.delete(w) : e.registry.set(w, new e.Ctor(...t));
151
151
  }
152
- function M(e, t, a = 2e3) {
153
- const r = [];
154
- if (t.length === 0 || typeof document > "u") return r;
155
- for (const n of e) {
156
- const l = document.createTreeWalker(n, NodeFilter.SHOW_TEXT);
152
+ function P(e, t, r = 2e3) {
153
+ const n = [];
154
+ if (t.length === 0 || typeof document > "u") return n;
155
+ for (const o of e) {
156
+ const l = document.createTreeWalker(o, NodeFilter.SHOW_TEXT);
157
157
  let i = l.nextNode();
158
158
  for (; i; ) {
159
159
  const s = i.data.toLowerCase();
160
- for (const o of t) {
161
- let c = s.indexOf(o);
160
+ for (const a of t) {
161
+ let c = s.indexOf(a);
162
162
  for (; c >= 0; ) {
163
163
  const m = document.createRange();
164
- if (m.setStart(i, c), m.setEnd(i, c + o.length), r.push(m), r.length >= a) return r;
165
- c = s.indexOf(o, c + o.length);
164
+ if (m.setStart(i, c), m.setEnd(i, c + a.length), n.push(m), n.length >= r) return n;
165
+ c = s.indexOf(a, c + a.length);
166
166
  }
167
167
  }
168
168
  i = l.nextNode();
169
169
  }
170
170
  }
171
- return r;
171
+ return n;
172
172
  }
173
- function oe(e, t, a, r) {
174
- S(() => {
175
- const n = t.current;
176
- if (!n || a.length === 0) {
177
- p.delete(e) && y();
173
+ function fe(e, t, r, n) {
174
+ y(() => {
175
+ const o = t.current;
176
+ if (!o || r.length === 0) {
177
+ b.delete(e) && x();
178
178
  return;
179
179
  }
180
- p.set(e, M(n.querySelectorAll(r), a)), y();
181
- }), S(
180
+ b.set(e, P(o.querySelectorAll(n), r)), x();
181
+ }), y(
182
182
  () => () => {
183
- p.delete(e) && y();
183
+ b.delete(e) && x();
184
184
  },
185
185
  [e]
186
186
  );
187
187
  }
188
+ const W = "Search these rows by any column. Shortcut: / while in the table. Esc clears.", Y = "data-grid-search-root", j = 'input, textarea, select, [contenteditable=""], [contenteditable="true"], [role="combobox"], [role="textbox"]';
189
+ let g = null, C = 0;
190
+ const I = (e) => {
191
+ g = e.target instanceof Element ? e.target : null;
192
+ };
193
+ function J(e, t = document) {
194
+ if (e.key !== "/" || e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey) return null;
195
+ const r = e.target instanceof Element ? e.target : null;
196
+ if (r != null && r.closest(j)) return null;
197
+ const o = (r && r !== t.body && r !== t.documentElement ? r : null) ?? (g != null && g.isConnected ? g : null);
198
+ return (o == null ? void 0 : o.closest(`[${Y}]`)) ?? null;
199
+ }
200
+ function me(e, t, r) {
201
+ y(() => {
202
+ if (!r || typeof document > "u") return;
203
+ C++ === 0 && document.addEventListener("pointerdown", I, !0);
204
+ const n = (o) => {
205
+ var i, s;
206
+ const l = e.current;
207
+ !l || J(o) !== l || (o.preventDefault(), (i = t.current) == null || i.focus(), (s = t.current) == null || s.select());
208
+ };
209
+ return document.addEventListener("keydown", n), () => {
210
+ document.removeEventListener("keydown", n), --C === 0 && document.removeEventListener("pointerdown", I, !0);
211
+ };
212
+ }, [r, e, t]);
213
+ }
188
214
  const f = (e) => e.toLocaleString("en-US");
189
- function le(e) {
215
+ function ge(e) {
190
216
  const {
191
217
  value: t,
192
- onChange: a,
193
- inputRef: r,
194
- shown: n,
218
+ onChange: r,
219
+ inputRef: n,
220
+ shown: o,
195
221
  total: l,
196
222
  loaded: i,
197
223
  loadedOf: s,
198
- searching: o,
224
+ searching: a,
199
225
  loading: c,
200
226
  error: m,
201
- onRetry: x,
202
- moreMatches: g,
203
- keptUnsaved: N,
204
- className: I
205
- } = e, w = m ? H(m, "Could not search the rest of the rows") : null;
227
+ onRetry: N,
228
+ moreMatches: p,
229
+ keptUnsaved: k,
230
+ className: _
231
+ } = e, S = m ? O(m, "Could not search the rest of the rows") : null;
206
232
  return /* @__PURE__ */ d(
207
233
  "div",
208
234
  {
209
- className: E("flex min-w-0 items-center gap-1.5 text-[11px]", I),
235
+ className: A("flex min-w-0 items-center gap-1.5 text-[11px]", _),
210
236
  "data-grid-search": "",
211
237
  children: [
212
238
  /* @__PURE__ */ d("div", { className: "relative flex items-center", children: [
213
239
  /* @__PURE__ */ h(
214
- _,
240
+ T,
215
241
  {
216
242
  className: "pointer-events-none absolute left-1.5 h-3 w-3 text-slate-400 dark:text-slate-500",
217
243
  "aria-hidden": "true"
@@ -220,16 +246,16 @@ function le(e) {
220
246
  /* @__PURE__ */ h(
221
247
  "input",
222
248
  {
223
- ref: r,
249
+ ref: n,
224
250
  type: "search",
225
251
  value: t,
226
- onChange: (u) => a(u.target.value),
252
+ onChange: (u) => r(u.target.value),
227
253
  onKeyDown: (u) => {
228
- u.key === "Escape" && (u.stopPropagation(), u.preventDefault(), t ? a("") : u.currentTarget.blur());
254
+ u.key === "Escape" && (u.stopPropagation(), u.preventDefault(), t ? r("") : u.currentTarget.blur());
229
255
  },
230
256
  "aria-label": "Search these rows",
231
257
  placeholder: `Search ${f(l)} rows`,
232
- "data-tip": "Find rows by any column’s text — press / in the table to jump here, Esc to clear",
258
+ "data-tip": W,
233
259
  className: "h-6 w-[190px] rounded border border-slate-200 bg-white pl-5 pr-5 text-[11px] text-slate-700 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-nvr-cyan dark:border-border dark:bg-background dark:text-slate-200 dark:placeholder:text-slate-500 [&::-webkit-search-cancel-button]:hidden"
234
260
  }
235
261
  ),
@@ -240,7 +266,7 @@ function le(e) {
240
266
  "aria-label": "Clear search",
241
267
  onClick: () => {
242
268
  var u;
243
- a(""), (u = r.current) == null || u.focus();
269
+ r(""), (u = n.current) == null || u.focus();
244
270
  },
245
271
  className: "absolute right-1 rounded p-px text-slate-400 hover:text-slate-700 dark:hover:text-slate-200",
246
272
  children: /* @__PURE__ */ h(D, { className: "h-3 w-3", "aria-hidden": "true" })
@@ -252,20 +278,20 @@ function le(e) {
252
278
  {
253
279
  className: "whitespace-nowrap tabular-nums text-slate-500 dark:text-slate-400",
254
280
  "aria-live": "polite",
255
- "data-grid-search-count": o ? n : void 0,
256
- children: o ? /* @__PURE__ */ d(T, { children: [
257
- f(n),
281
+ "data-grid-search-count": a ? o : void 0,
282
+ children: a ? /* @__PURE__ */ d(L, { children: [
283
+ f(o),
258
284
  " of ",
259
285
  f(l),
260
286
  " rows",
261
- N ? /* @__PURE__ */ d(
287
+ k ? /* @__PURE__ */ d(
262
288
  "span",
263
289
  {
264
290
  className: "ml-1 text-slate-400 dark:text-slate-500",
265
291
  "data-tip": "Unsaved rows stay in view while you search",
266
292
  children: [
267
293
  "· ",
268
- N,
294
+ k,
269
295
  " unsaved kept"
270
296
  ]
271
297
  }
@@ -284,36 +310,36 @@ function le(e) {
284
310
  ) : null
285
311
  }
286
312
  ),
287
- o && c && /* @__PURE__ */ d("span", { className: "inline-flex items-center gap-1 whitespace-nowrap text-slate-400 dark:text-slate-500", children: [
288
- /* @__PURE__ */ h(L, { className: "h-3 w-3 animate-spin", "aria-hidden": "true" }),
313
+ a && c && /* @__PURE__ */ d("span", { className: "inline-flex items-center gap-1 whitespace-nowrap text-slate-400 dark:text-slate-500", children: [
314
+ /* @__PURE__ */ h(G, { className: "h-3 w-3 animate-spin", "aria-hidden": "true" }),
289
315
  "Searching all rows…"
290
316
  ] }),
291
- o && !c && g != null && g > 0 && /* @__PURE__ */ d(
317
+ a && !c && p != null && p > 0 && /* @__PURE__ */ d(
292
318
  "span",
293
319
  {
294
320
  className: "whitespace-nowrap text-amber-700 dark:text-amber-300",
295
321
  "data-tip": "Only the first matches are shown — add a word to narrow the search",
296
322
  children: [
297
- f(g),
323
+ f(p),
298
324
  " more ",
299
- g === 1 ? "match" : "matches",
325
+ p === 1 ? "match" : "matches",
300
326
  " — narrow it"
301
327
  ]
302
328
  }
303
329
  ),
304
- o && !c && w && /* @__PURE__ */ d(
330
+ a && !c && S && /* @__PURE__ */ d(
305
331
  "span",
306
332
  {
307
333
  className: "inline-flex items-center gap-1 whitespace-nowrap text-amber-700 dark:text-amber-300",
308
- "data-tip": w.hint,
334
+ "data-tip": S.hint,
309
335
  role: "status",
310
336
  children: [
311
- w.title,
312
- x && /* @__PURE__ */ h(
337
+ S.title,
338
+ N && /* @__PURE__ */ h(
313
339
  "button",
314
340
  {
315
341
  type: "button",
316
- onClick: x,
342
+ onClick: N,
317
343
  className: "rounded px-1 font-medium underline decoration-dotted underline-offset-2 hover:text-amber-900 dark:hover:text-amber-100",
318
344
  children: "Retry"
319
345
  }
@@ -326,20 +352,24 @@ function le(e) {
326
352
  );
327
353
  }
328
354
  export {
329
- X as GRID_READ_LIMIT,
330
- b as GRID_SEARCH_HIGHLIGHT,
331
- ae as GRID_SEARCH_HIGHLIGHT_CSS,
332
- O as GRID_SEARCH_LIMIT,
333
- K as GRID_SEARCH_MIN_ROWS,
334
- le as GridSearchBox,
335
- Z as cellSearchTexts,
336
- te as extraSearchRows,
337
- M as matchRanges,
338
- ee as pendingRowVisibility,
339
- z as searchWords,
340
- Q as textMatchesWords,
341
- re as useDebouncedValue,
342
- ie as useGridChildTotal,
343
- oe as useGridSearchHighlight,
344
- ne as useGridServerSearch
355
+ ne as GRID_READ_LIMIT,
356
+ w as GRID_SEARCH_HIGHLIGHT,
357
+ he as GRID_SEARCH_HIGHLIGHT_CSS,
358
+ U as GRID_SEARCH_LIMIT,
359
+ re as GRID_SEARCH_MIN_ROWS,
360
+ Y as GRID_SEARCH_ROOT_ATTR,
361
+ W as GRID_SEARCH_TIP,
362
+ ge as GridSearchBox,
363
+ ie as cellSearchTexts,
364
+ se as extraSearchRows,
365
+ J as gridSearchShortcutRoot,
366
+ P as matchRanges,
367
+ le as pendingRowVisibility,
368
+ oe as searchWords,
369
+ ae as textMatchesWords,
370
+ ce as useDebouncedValue,
371
+ de as useGridChildTotal,
372
+ fe as useGridSearchHighlight,
373
+ me as useGridSearchShortcut,
374
+ ue as useGridServerSearch
345
375
  };