@nivaro/react 0.3.70 → 0.3.71

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.
@@ -9,7 +9,7 @@ import { noteReplayEvent as _e, createReplayCheckoutState as De } from "../share
9
9
  import { emitReplayTap as Te, setReplayRecorderMode as N, registerReplayCapture as qe, clipEndOffset as Le, withClipKind as Pe } from "../shared/lib/replay-capture.js";
10
10
  import { instrumentConsole as Ne, instrumentRequests as Fe, redactSecrets as Me } from "../shared/lib/replay-context.js";
11
11
  import { instrumentSocket as Oe } from "../shared/lib/replay-socket.js";
12
- const Ue = "nivaro-react@0.3.70", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
12
+ const Ue = "nivaro-react@0.3.71", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
13
13
  function Be(n) {
14
14
  return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
15
15
  const u = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
@@ -1,15 +1,15 @@
1
- import { jsxs as i, jsx as e, Fragment as J } from "react/jsx-runtime";
1
+ import { jsxs as i, jsx as e, Fragment as D } from "react/jsx-runtime";
2
2
  import { useQueryClient as be, useQuery as ee } from "@tanstack/react-query";
3
- import { Clock as we, Download as ye, Loader2 as te, Upload as de, X as le, Plus as Ke, File as fe, FileVideo as Pe, FileAudio as Oe, FileText as oe, FileSpreadsheet as Qe, FileCode as Ee } from "lucide-react";
4
- import { useId as ce, useState as L, useRef as Ne, useEffect as G } from "react";
3
+ import { Clock as we, Download as ye, Loader2 as te, Upload as de, X as le, Plus as Pe, File as fe, FileVideo as Oe, FileAudio as Qe, FileText as oe, FileSpreadsheet as Ee, FileCode as Te } from "lucide-react";
4
+ import { useId as ce, useState as $, useRef as Ne, useEffect as H } from "react";
5
5
  import { useNivaroClient as me, useGridFlush as ve, useParentDraft as ke } from "../../context.js";
6
6
  import { useFileHealth as _e } from "../../hooks/useFileHealth.js";
7
7
  import { get as se, post as xe, del as ge } from "../../lib/commands.js";
8
- import { cn as ue, formatDateTime as Te } from "../../lib/utils.js";
8
+ import { cn as ue, formatDateTime as Ae } from "../../lib/utils.js";
9
9
  import { useFileDownloadStats as Fe, FileDownloadCount as Re } from "./FileDownloadCount.js";
10
10
  import { useOnceVisible as Ce, useFileUsage as $e, FileUsageChip as Le } from "./FileUsage.js";
11
11
  import { useFileDownload as qe } from "./file-download.js";
12
- import { useM2MStaging as Ae } from "./M2MStagingContext.js";
12
+ import { useM2MStaging as Me } from "./M2MStagingContext.js";
13
13
  function he(s) {
14
14
  var y;
15
15
  const a = ((s == null ? void 0 : s.title) ?? "").trim(), N = ((s == null ? void 0 : s.filename_download) ?? "").trim();
@@ -21,22 +21,22 @@ function ne(s) {
21
21
  return s ? s < 1024 ? `${s} B` : s < 1024 * 1024 ? `${(s / 1024).toFixed(1)} KB` : `${(s / (1024 * 1024)).toFixed(1)} MB` : null;
22
22
  }
23
23
  function Ue(s) {
24
- return s ? Te(s) : null;
24
+ return s ? Ae(s) : null;
25
25
  }
26
- function Me(s) {
26
+ function Be(s) {
27
27
  return !!s && s.startsWith("image/");
28
28
  }
29
- function Be(s, a) {
30
- return s ? s.startsWith("video/") ? /* @__PURE__ */ e(Pe, { className: a, strokeWidth: 1.5 }) : s.startsWith("audio/") ? /* @__PURE__ */ e(Oe, { className: a, strokeWidth: 1.5 }) : s === "application/pdf" ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.startsWith("text/") ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.includes("spreadsheet") || s.includes("excel") || s === "text/csv" ? /* @__PURE__ */ e(Qe, { className: a, strokeWidth: 1.5 }) : s.includes("wordprocessing") || s.includes("msword") ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.includes("json") || s.includes("javascript") || s.includes("typescript") || s.includes("xml") ? /* @__PURE__ */ e(Ee, { className: a, strokeWidth: 1.5 }) : /* @__PURE__ */ e(fe, { className: a, strokeWidth: 1.5 }) : /* @__PURE__ */ e(fe, { className: a, strokeWidth: 1.5 });
29
+ function Ve(s, a) {
30
+ return s ? s.startsWith("video/") ? /* @__PURE__ */ e(Oe, { className: a, strokeWidth: 1.5 }) : s.startsWith("audio/") ? /* @__PURE__ */ e(Qe, { className: a, strokeWidth: 1.5 }) : s === "application/pdf" ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.startsWith("text/") ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.includes("spreadsheet") || s.includes("excel") || s === "text/csv" ? /* @__PURE__ */ e(Ee, { className: a, strokeWidth: 1.5 }) : s.includes("wordprocessing") || s.includes("msword") ? /* @__PURE__ */ e(oe, { className: a, strokeWidth: 1.5 }) : s.includes("json") || s.includes("javascript") || s.includes("typescript") || s.includes("xml") ? /* @__PURE__ */ e(Te, { className: a, strokeWidth: 1.5 }) : /* @__PURE__ */ e(fe, { className: a, strokeWidth: 1.5 }) : /* @__PURE__ */ e(fe, { className: a, strokeWidth: 1.5 });
31
31
  }
32
- function X({
32
+ function J({
33
33
  url: s,
34
34
  type: a,
35
35
  filename: N,
36
36
  size: p = "md"
37
37
  }) {
38
38
  const y = p === "sm" ? "h-10 w-10" : p === "lg" ? "h-20 w-20" : "h-14 w-14";
39
- return Me(a) ? /* @__PURE__ */ e(
39
+ return Be(a) ? /* @__PURE__ */ e(
40
40
  "img",
41
41
  {
42
42
  src: s,
@@ -44,11 +44,11 @@ function X({
44
44
  "data-file-thumb": !0,
45
45
  className: ue(y, "object-cover rounded shrink-0"),
46
46
  loading: "lazy",
47
- onError: (j) => {
48
- j.target.style.display = "none";
47
+ onError: (S) => {
48
+ S.target.style.display = "none";
49
49
  }
50
50
  }
51
- ) : /* @__PURE__ */ e("div", { className: ue(y, "flex items-center justify-center rounded bg-slate-100 shrink-0"), children: Be(a, p === "sm" ? "h-4 w-4" : "h-6 w-6") });
51
+ ) : /* @__PURE__ */ e("div", { className: ue(y, "flex items-center justify-center rounded bg-slate-100 shrink-0"), children: Ve(a, p === "sm" ? "h-4 w-4" : "h-6 w-6") });
52
52
  }
53
53
  function Se({
54
54
  selected: s,
@@ -57,9 +57,9 @@ function Se({
57
57
  onClose: p,
58
58
  getUrl: y
59
59
  }) {
60
- const j = me(), [x, _] = L(""), { data: F = [], isLoading: c } = ee({
60
+ const S = me(), [x, _] = $(""), { data: F = [], isLoading: u } = ee({
61
61
  queryKey: ["file-browser", x],
62
- queryFn: () => j.request(
62
+ queryFn: () => S.request(
63
63
  se("/files", {
64
64
  limit: "60",
65
65
  sort: "-uploaded_on",
@@ -98,9 +98,9 @@ function Se({
98
98
  }
99
99
  ) }),
100
100
  /* @__PURE__ */ i("div", { className: "overflow-y-auto flex-1 p-3", children: [
101
- c && /* @__PURE__ */ e("div", { className: "flex justify-center py-6", children: /* @__PURE__ */ e(te, { className: "h-5 w-5 animate-spin text-slate-300" }) }),
102
- !c && F.length === 0 && /* @__PURE__ */ e("p", { className: "text-center text-[12px] text-slate-400 py-6", children: "No files found" }),
103
- !c && F.length > 0 && /* @__PURE__ */ e("div", { className: "grid grid-cols-5 gap-2", children: F.map((d) => {
101
+ u && /* @__PURE__ */ e("div", { className: "flex justify-center py-6", children: /* @__PURE__ */ e(te, { className: "h-5 w-5 animate-spin text-slate-300" }) }),
102
+ !u && F.length === 0 && /* @__PURE__ */ e("p", { className: "text-center text-[12px] text-slate-400 py-6", children: "No files found" }),
103
+ !u && F.length > 0 && /* @__PURE__ */ e("div", { className: "grid grid-cols-5 gap-2", children: F.map((d) => {
104
104
  const g = s.includes(d.id);
105
105
  return /* @__PURE__ */ i(
106
106
  "button",
@@ -114,7 +114,7 @@ function Se({
114
114
  children: [
115
115
  /* @__PURE__ */ i("div", { className: "relative", children: [
116
116
  /* @__PURE__ */ e(
117
- X,
117
+ J,
118
118
  {
119
119
  url: y(d.id),
120
120
  type: d.type,
@@ -157,86 +157,86 @@ function Se({
157
157
  ] })
158
158
  ] });
159
159
  }
160
- function st({
160
+ function nt({
161
161
  value: s,
162
162
  onChange: a,
163
163
  disabled: N,
164
164
  allowUpload: p = !0,
165
165
  allowPick: y = !0,
166
- showUsage: j = !0,
166
+ showUsage: S = !0,
167
167
  showDownloads: x = !0
168
168
  }) {
169
- var D, V, H;
170
- const _ = me(), F = be(), c = ve(), d = ce(), [g, W] = L(!1), [q, U] = L(!1), [f, P] = L(null), [Z, A] = L(null), b = Ne(null), r = !f && s ? String(s) : null, v = (m) => _.fileUrl(m), z = qe(), h = ke(), K = ((D = h == null ? void 0 : h.draft) == null ? void 0 : D.id) != null ? String(h.draft.id) : null, [Y, R] = Ce(!!r), C = $e(
169
+ var Q, Y, V;
170
+ const _ = me(), F = be(), u = ve(), d = ce(), [g, j] = $(!1), [L, q] = $(!1), [f, K] = $(null), [G, A] = $(null), b = Ne(null), r = !f && s ? String(s) : null, v = (c) => _.fileUrl(c), W = qe(), h = ke(), z = ((Q = h == null ? void 0 : h.draft) == null ? void 0 : Q.id) != null ? String(h.draft.id) : null, [X, R] = Ce(!!r), C = $e(
171
171
  h == null ? void 0 : h.collection,
172
- K,
172
+ z,
173
173
  r ? [r] : [],
174
- R && j
174
+ R && S
175
175
  ), M = Fe(
176
176
  h == null ? void 0 : h.collection,
177
- K,
177
+ z,
178
178
  r ? [r] : [],
179
179
  R && x
180
180
  );
181
- G(() => {
181
+ H(() => {
182
182
  if (!f) {
183
183
  A(null);
184
184
  return;
185
185
  }
186
- const m = URL.createObjectURL(f);
187
- return A(m), () => URL.revokeObjectURL(m);
188
- }, [f]), G(() => {
189
- if (!(!c || !f))
190
- return c.register(d, async () => {
191
- const m = await _.upload(f);
192
- a(m.id), P(null), F.invalidateQueries({ queryKey: ["file-browser"] });
193
- }), () => c.unregister(d);
194
- }, [c, f, d, _, a, F]);
186
+ const c = URL.createObjectURL(f);
187
+ return A(c), () => URL.revokeObjectURL(c);
188
+ }, [f]), H(() => {
189
+ if (!(!u || !f))
190
+ return u.register(d, async () => {
191
+ const c = await _.upload(f);
192
+ a(c.id), K(null), F.invalidateQueries({ queryKey: ["file-browser"] });
193
+ }), () => u.unregister(d);
194
+ }, [u, f, d, _, a, F]);
195
195
  const k = _e([r]), { data: n, isLoading: B } = ee({
196
196
  queryKey: ["file-meta", r],
197
- queryFn: () => _.request(se(`/files/${r}/meta`)).then((m) => m.data ?? null),
197
+ queryFn: () => _.request(se(`/files/${r}/meta`)).then((c) => c.data ?? null),
198
198
  enabled: !!r,
199
199
  staleTime: 6e4
200
200
  });
201
- async function Q(m) {
201
+ async function O(c) {
202
202
  var I;
203
- const O = (I = m.target.files) == null ? void 0 : I[0];
204
- if (O)
205
- if (b.current && (b.current.value = ""), c)
206
- P(O);
203
+ const P = (I = c.target.files) == null ? void 0 : I[0];
204
+ if (P)
205
+ if (b.current && (b.current.value = ""), u)
206
+ K(P);
207
207
  else {
208
- U(!0), window.dispatchEvent(
209
- new CustomEvent("nvr:upload-state", { detail: { name: O.name, state: "start" } })
208
+ q(!0), window.dispatchEvent(
209
+ new CustomEvent("nvr:upload-state", { detail: { name: P.name, state: "start" } })
210
210
  );
211
211
  try {
212
- const ie = await _.upload(O);
212
+ const ie = await _.upload(P);
213
213
  a(ie.id), F.invalidateQueries({ queryKey: ["file-browser"] });
214
214
  } catch {
215
215
  } finally {
216
- U(!1), window.dispatchEvent(
217
- new CustomEvent("nvr:upload-state", { detail: { name: O.name, state: "done" } })
216
+ q(!1), window.dispatchEvent(
217
+ new CustomEvent("nvr:upload-state", { detail: { name: P.name, state: "done" } })
218
218
  );
219
219
  }
220
220
  }
221
221
  }
222
- function ae(m) {
223
- P(null), a(m), W(!1);
222
+ function ae(c) {
223
+ K(null), a(c), j(!1);
224
224
  }
225
- function S() {
226
- P(null), a(null);
225
+ function U() {
226
+ K(null), a(null);
227
227
  }
228
- const u = !!f;
228
+ const m = !!f;
229
229
  return /* @__PURE__ */ i("div", { className: "relative", children: [
230
- u || !!r ? /* @__PURE__ */ i(
230
+ m || !!r ? /* @__PURE__ */ i(
231
231
  "div",
232
232
  {
233
- ref: Y,
233
+ ref: X,
234
234
  className: "flex items-center gap-2 rounded-lg border border-slate-200 p-2 bg-slate-50",
235
235
  children: [
236
- u ? /* @__PURE__ */ e(
237
- X,
236
+ m ? /* @__PURE__ */ e(
237
+ J,
238
238
  {
239
- url: Z ?? "",
239
+ url: G ?? "",
240
240
  type: f.type || null,
241
241
  filename: f.name,
242
242
  size: "sm"
@@ -248,11 +248,11 @@ function st({
248
248
  {
249
249
  href: `${v(r)}?download=1`,
250
250
  download: (n == null ? void 0 : n.filename_download) || !0,
251
- onClick: z(`${v(r)}?download=1`, n == null ? void 0 : n.filename_download),
251
+ onClick: W(`${v(r)}?download=1`, n == null ? void 0 : n.filename_download),
252
252
  title: "Download",
253
253
  className: "shrink-0",
254
254
  children: /* @__PURE__ */ e(
255
- X,
255
+ J,
256
256
  {
257
257
  url: v(r),
258
258
  type: (n == null ? void 0 : n.type) ?? null,
@@ -265,9 +265,9 @@ function st({
265
265
  ),
266
266
  /* @__PURE__ */ i("div", { className: "flex-1 min-w-0", children: [
267
267
  /* @__PURE__ */ i("div", { className: "flex items-center gap-1", children: [
268
- u && /* @__PURE__ */ e(we, { className: "h-3 w-3 text-amber-400 shrink-0" }),
269
- /* @__PURE__ */ e("p", { "data-file-name": !0, className: "text-[12px] font-medium text-slate-700 truncate", children: u ? f.name : he(n) || r }),
270
- !u && (k.verdict(r) ?? !!(n != null && n.missing_at)) && /* @__PURE__ */ e(
268
+ m && /* @__PURE__ */ e(we, { className: "h-3 w-3 text-amber-400 shrink-0" }),
269
+ /* @__PURE__ */ e("p", { "data-file-name": !0, className: "text-[12px] font-medium text-slate-700 truncate", children: m ? f.name : he(n) || r }),
270
+ !m && (k.verdict(r) ?? !!(n != null && n.missing_at)) && /* @__PURE__ */ e(
271
271
  "span",
272
272
  {
273
273
  className: "shrink-0 rounded bg-red-500/10 px-1.5 py-0.5 text-[9.5px] font-semibold uppercase tracking-wide text-red-600 dark:text-red-400",
@@ -276,11 +276,11 @@ function st({
276
276
  }
277
277
  )
278
278
  ] }),
279
- /* @__PURE__ */ e("div", { className: "flex flex-wrap items-center gap-x-2 mt-0.5", children: u ? /* @__PURE__ */ i(J, { children: [
279
+ /* @__PURE__ */ e("div", { className: "flex flex-wrap items-center gap-x-2 mt-0.5", children: m ? /* @__PURE__ */ i(D, { children: [
280
280
  f.type && /* @__PURE__ */ e("span", { className: "text-[10px] text-slate-400", children: f.type }),
281
281
  /* @__PURE__ */ e("span", { className: "text-[10px] text-slate-400", children: ne(f.size) }),
282
282
  /* @__PURE__ */ e("span", { className: "text-[10px] text-amber-500", children: "Pending upload" })
283
- ] }) : /* @__PURE__ */ i(J, { children: [
283
+ ] }) : /* @__PURE__ */ i(D, { children: [
284
284
  (n == null ? void 0 : n.type) && /* @__PURE__ */ e("span", { className: "text-[10px] text-slate-400", children: n.type }),
285
285
  (n == null ? void 0 : n.filesize) != null && /* @__PURE__ */ e("span", { className: "text-[10px] text-slate-400", children: ne(n.filesize) }),
286
286
  (n == null ? void 0 : n.uploaded_on) && /* @__PURE__ */ e("span", { className: "text-[10px] text-slate-400", children: Ue(n.uploaded_on) }),
@@ -290,22 +290,22 @@ function st({
290
290
  ] })
291
291
  ] }) })
292
292
  ] }),
293
- j && !u && r && /* @__PURE__ */ e(
293
+ S && !m && r && /* @__PURE__ */ e(
294
294
  Le,
295
295
  {
296
296
  fileId: r,
297
- uses: (V = C.data) == null ? void 0 : V[r],
297
+ uses: (Y = C.data) == null ? void 0 : Y[r],
298
298
  loading: C.isLoading,
299
299
  collection: h == null ? void 0 : h.collection,
300
- itemId: K
300
+ itemId: z
301
301
  }
302
302
  ),
303
- x && !u && r && /* @__PURE__ */ e(Re, { fileId: r, stat: (H = M.data) == null ? void 0 : H[r] }),
304
- !u && r && /* @__PURE__ */ e(
303
+ x && !m && r && /* @__PURE__ */ e(Re, { fileId: r, stat: (V = M.data) == null ? void 0 : V[r] }),
304
+ !m && r && /* @__PURE__ */ e(
305
305
  "a",
306
306
  {
307
307
  href: `${v(r)}?download=1`,
308
- onClick: z(`${v(r)}?download=1`, n == null ? void 0 : n.filename_download),
308
+ onClick: W(`${v(r)}?download=1`, n == null ? void 0 : n.filename_download),
309
309
  title: "Download",
310
310
  className: "shrink-0 text-slate-400 hover:text-nvr-cyan p-0.5",
311
311
  children: /* @__PURE__ */ e(ye, { className: "h-3.5 w-3.5" })
@@ -316,36 +316,36 @@ function st({
316
316
  "button",
317
317
  {
318
318
  type: "button",
319
- onClick: () => W(!0),
319
+ onClick: () => j(!0),
320
320
  className: "h-6 px-2 rounded border border-slate-200 text-[11px] text-slate-600 hover:border-slate-400",
321
321
  children: "Replace"
322
322
  }
323
323
  ),
324
- p && /* @__PURE__ */ i(J, { children: [
324
+ p && /* @__PURE__ */ i(D, { children: [
325
325
  /* @__PURE__ */ i(
326
326
  "button",
327
327
  {
328
328
  type: "button",
329
329
  onClick: () => {
330
- var m;
331
- return (m = b.current) == null ? void 0 : m.click();
330
+ var c;
331
+ return (c = b.current) == null ? void 0 : c.click();
332
332
  },
333
- disabled: q,
333
+ disabled: L,
334
334
  className: "h-6 px-2 rounded border border-slate-200 text-[11px] text-slate-600 hover:border-slate-400 disabled:opacity-40 flex items-center gap-1",
335
335
  children: [
336
- q ? /* @__PURE__ */ e(te, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3 w-3" }),
336
+ L ? /* @__PURE__ */ e(te, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3 w-3" }),
337
337
  "Upload"
338
338
  ]
339
339
  }
340
340
  ),
341
- /* @__PURE__ */ e("input", { ref: b, type: "file", className: "hidden", onChange: Q })
341
+ /* @__PURE__ */ e("input", { ref: b, type: "file", className: "hidden", onChange: O })
342
342
  ] }),
343
343
  /* @__PURE__ */ e(
344
344
  "button",
345
345
  {
346
346
  type: "button",
347
347
  "aria-label": "Remove file",
348
- onClick: S,
348
+ onClick: U,
349
349
  className: "text-slate-300 hover:text-red-400 p-0.5",
350
350
  children: /* @__PURE__ */ e(le, { className: "h-3.5 w-3.5" })
351
351
  }
@@ -359,29 +359,29 @@ function st({
359
359
  {
360
360
  type: "button",
361
361
  disabled: N,
362
- onClick: () => W(!0),
362
+ onClick: () => j(!0),
363
363
  className: "flex h-9 flex-1 items-center gap-2 rounded-md border border-dashed border-slate-300 px-3 text-[12px] text-slate-400 hover:border-slate-400 hover:text-slate-600 disabled:opacity-40 transition-colors",
364
364
  children: "Select file…"
365
365
  }
366
366
  ),
367
- p && !N && /* @__PURE__ */ i(J, { children: [
367
+ p && !N && /* @__PURE__ */ i(D, { children: [
368
368
  /* @__PURE__ */ i(
369
369
  "button",
370
370
  {
371
371
  type: "button",
372
372
  onClick: () => {
373
- var m;
374
- return (m = b.current) == null ? void 0 : m.click();
373
+ var c;
374
+ return (c = b.current) == null ? void 0 : c.click();
375
375
  },
376
- disabled: q,
376
+ disabled: L,
377
377
  className: "flex h-9 items-center gap-1.5 rounded-md border border-dashed border-slate-300 px-3 text-[12px] text-slate-400 hover:border-slate-400 hover:text-slate-600 disabled:opacity-40 transition-colors",
378
378
  children: [
379
- q ? /* @__PURE__ */ e(te, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3.5 w-3.5" }),
379
+ L ? /* @__PURE__ */ e(te, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3.5 w-3.5" }),
380
380
  "Upload"
381
381
  ]
382
382
  }
383
383
  ),
384
- /* @__PURE__ */ e("input", { ref: b, type: "file", className: "hidden", onChange: Q })
384
+ /* @__PURE__ */ e("input", { ref: b, type: "file", className: "hidden", onChange: O })
385
385
  ] })
386
386
  ] }),
387
387
  g && /* @__PURE__ */ e(
@@ -395,7 +395,7 @@ function st({
395
395
  selected: r ? [r] : [],
396
396
  multi: !1,
397
397
  onSelect: ae,
398
- onClose: () => W(!1),
398
+ onClose: () => j(!1),
399
399
  getUrl: v
400
400
  }
401
401
  )
@@ -403,62 +403,62 @@ function st({
403
403
  )
404
404
  ] });
405
405
  }
406
- function nt({
406
+ function at({
407
407
  relation: s,
408
408
  parentId: a,
409
409
  allRelations: N,
410
410
  disabled: p,
411
411
  allowUpload: y = !0,
412
- allowPick: j = !0,
412
+ allowPick: S = !0,
413
413
  pendingSave: x = !1,
414
414
  showUsage: _ = !0,
415
415
  showDownloads: F = !0
416
416
  }) {
417
- const c = me(), d = be(), g = ve(), W = ce(), q = ce(), U = Ae(), [f, P] = L(!1), [Z, A] = L(!1), [b, r] = L([]), v = Ne(null), [z, h] = L([]), [K, Y] = L(/* @__PURE__ */ new Set()), R = s.junction_field ?? "", C = s.many_field ?? "", M = s.one_field ?? `${s.many_collection}.${R}`, k = a === "new", n = (t) => c.fileUrl(t), B = qe();
418
- G(() => () => {
417
+ const u = me(), d = be(), g = ve(), j = ce(), L = ce(), q = Me(), [f, K] = $(!1), [G, A] = $(!1), [b, r] = $([]), v = Ne(null), [W, h] = $([]), [z, X] = $(/* @__PURE__ */ new Set()), R = s.junction_field ?? "", C = s.many_field ?? "", M = s.one_field ?? `${s.many_collection}.${R}`, k = a === "new", n = (t) => u.fileUrl(t), B = qe();
418
+ H(() => () => {
419
419
  r((t) => (t.forEach((l) => URL.revokeObjectURL(l.url)), []));
420
- }, []), G(() => {
420
+ }, []), H(() => {
421
421
  if (!g || !b.length || x) return;
422
422
  const t = b;
423
- return g.register(W, async () => {
423
+ return g.register(j, async () => {
424
424
  for (const l of t) {
425
- const o = await c.upload(l.file);
425
+ const o = await u.upload(l.file);
426
426
  URL.revokeObjectURL(l.url), await re(o.id);
427
427
  }
428
428
  r([]), d.invalidateQueries({ queryKey: ["file-browser"] });
429
- }), () => g.unregister(W);
430
- }, [g, b, W, x]), G(() => {
429
+ }), () => g.unregister(j);
430
+ }, [g, b, j, x]), H(() => {
431
431
  if (!g || !x) return;
432
- if (!(z.length > 0 || K.size > 0 || b.length > 0)) {
433
- g.unregister(q);
432
+ if (!(W.length > 0 || z.size > 0 || b.length > 0)) {
433
+ g.unregister(L);
434
434
  return;
435
435
  }
436
- const l = z, o = new Set(K), w = b;
437
- return g.register(q, async () => {
436
+ const l = W, o = new Set(z), w = b;
437
+ return g.register(L, async () => {
438
438
  const pe = [];
439
439
  for (const E of w) {
440
- const T = await c.upload(E.file);
440
+ const T = await u.upload(E.file);
441
441
  URL.revokeObjectURL(E.url), pe.push(T.id);
442
442
  }
443
443
  for (const E of [...l, ...pe])
444
- await c.request(
444
+ await u.request(
445
445
  xe(`/items/${s.many_collection}`, {
446
446
  [C]: a,
447
447
  [R]: E
448
448
  })
449
449
  );
450
450
  for (const E of o) {
451
- const T = Q.find((ze) => String(ze[R]) === E);
452
- T != null && T.id && await c.request(ge(`/items/${s.many_collection}/${T.id}`));
451
+ const T = O.find((Ke) => String(Ke[R]) === E);
452
+ T != null && T.id && await u.request(ge(`/items/${s.many_collection}/${T.id}`));
453
453
  }
454
- h([]), Y(/* @__PURE__ */ new Set()), r([]), d.invalidateQueries({
454
+ h([]), X(/* @__PURE__ */ new Set()), r([]), d.invalidateQueries({
455
455
  queryKey: ["m2m-items", s.many_collection, C, a]
456
456
  }), d.invalidateQueries({ queryKey: ["file-browser"] });
457
- }), () => g.unregister(q);
458
- }, [g, x, z, K, b, q]);
459
- const { data: Q = [] } = ee({
457
+ }), () => g.unregister(L);
458
+ }, [g, x, W, z, b, L]);
459
+ const { data: O = [] } = ee({
460
460
  queryKey: ["m2m-items", s.many_collection, C, a],
461
- queryFn: () => c.request(
461
+ queryFn: () => u.request(
462
462
  se(`/items/${s.many_collection}`, {
463
463
  filter: JSON.stringify({ [C]: { _eq: a } }),
464
464
  limit: "200",
@@ -467,64 +467,64 @@ function nt({
467
467
  ).then((t) => t.data ?? []),
468
468
  enabled: !!a && !k,
469
469
  staleTime: 3e4
470
- }), ae = k && U ? U.getStagedLinks(M) : [], S = Q.map((t) => String(t[R])), u = k ? ae : x ? [...S.filter((t) => !K.has(t)), ...z] : S, $ = ke(), [D, V] = Ce(S.length > 0), H = $e(
471
- $ == null ? void 0 : $.collection,
470
+ }), ae = k && q ? q.getStagedLinks(M) : [], U = O.map((t) => String(t[R])), m = k ? ae : x ? [...U.filter((t) => !z.has(t)), ...W] : U, Z = ke(), Q = (Z == null ? void 0 : Z.collection) ?? s.one_collection ?? null, [Y, V] = Ce(U.length > 0), c = $e(
471
+ Q,
472
472
  k ? null : a,
473
- S,
473
+ U,
474
474
  V && _
475
- ), m = Fe(
476
- $ == null ? void 0 : $.collection,
475
+ ), P = Fe(
476
+ Q,
477
477
  k ? null : a,
478
- S,
478
+ U,
479
479
  V && F
480
- ), O = _e(u), { data: I = {} } = ee({
481
- queryKey: ["files-meta", ...u.sort()],
480
+ ), I = _e(m), { data: ie = {} } = ee({
481
+ queryKey: ["files-meta", ...m.sort()],
482
482
  queryFn: async () => {
483
- if (!u.length) return {};
484
- const t = await c.request(
483
+ if (!m.length) return {};
484
+ const t = await u.request(
485
485
  se("/files", {
486
- filter: JSON.stringify({ id: { _in: u } }),
487
- limit: String(u.length),
486
+ filter: JSON.stringify({ id: { _in: m } }),
487
+ limit: String(m.length),
488
488
  fields: "id,filename_download,title,type,filesize,uploaded_on,uploaded_by_name,missing_at"
489
489
  })
490
490
  ).then((o) => o.data ?? []), l = {};
491
491
  for (const o of t) l[o.id] = o;
492
492
  return l;
493
493
  },
494
- enabled: u.length > 0,
494
+ enabled: m.length > 0,
495
495
  staleTime: 6e4
496
496
  });
497
- async function ie(t) {
498
- if (k && U) {
499
- U.unstageLink(M, t);
497
+ async function je(t) {
498
+ if (k && q) {
499
+ q.unstageLink(M, t);
500
500
  return;
501
501
  }
502
502
  if (x) {
503
- z.includes(t) ? h((o) => o.filter((w) => w !== t)) : Y((o) => /* @__PURE__ */ new Set([...o, t]));
503
+ W.includes(t) ? h((o) => o.filter((w) => w !== t)) : X((o) => /* @__PURE__ */ new Set([...o, t]));
504
504
  return;
505
505
  }
506
- const l = Q.find((o) => String(o[R]) === t);
507
- l != null && l.id && (await c.request(ge(`/items/${s.many_collection}/${l.id}`)), d.invalidateQueries({ queryKey: ["m2m-items", s.many_collection, C, a] }));
506
+ const l = O.find((o) => String(o[R]) === t);
507
+ l != null && l.id && (await u.request(ge(`/items/${s.many_collection}/${l.id}`)), d.invalidateQueries({ queryKey: ["m2m-items", s.many_collection, C, a] }));
508
508
  }
509
509
  async function re(t) {
510
- if (!u.includes(t)) {
511
- if (k && U) {
512
- U.stageLink(M, t);
510
+ if (!m.includes(t)) {
511
+ if (k && q) {
512
+ q.stageLink(M, t);
513
513
  return;
514
514
  }
515
515
  if (x) {
516
516
  h((l) => l.includes(t) ? l : [...l, t]);
517
517
  return;
518
518
  }
519
- await c.request(
519
+ await u.request(
520
520
  xe(`/items/${s.many_collection}`, { [C]: a, [R]: t })
521
521
  ), d.invalidateQueries({ queryKey: ["m2m-items", s.many_collection, C, a] });
522
522
  }
523
523
  }
524
- function je(t) {
524
+ function We(t) {
525
525
  URL.revokeObjectURL(t), r((l) => l.filter((o) => o.url !== t));
526
526
  }
527
- async function We(t) {
527
+ async function ze(t) {
528
528
  const l = Array.from(t.target.files ?? []);
529
529
  if (l.length)
530
530
  if (v.current && (v.current.value = ""), g) {
@@ -534,7 +534,7 @@ function nt({
534
534
  A(!0);
535
535
  try {
536
536
  for (const o of l) {
537
- const w = await c.upload(o);
537
+ const w = await u.upload(o);
538
538
  await re(w.id);
539
539
  }
540
540
  d.invalidateQueries({ queryKey: ["file-browser"] });
@@ -545,10 +545,10 @@ function nt({
545
545
  }
546
546
  }
547
547
  return /* @__PURE__ */ i("div", { className: "space-y-2", children: [
548
- (u.length > 0 || b.length > 0) && /* @__PURE__ */ i("div", { ref: D, className: "flex flex-col gap-1.5", children: [
549
- u.map((t) => {
548
+ (m.length > 0 || b.length > 0) && /* @__PURE__ */ i("div", { ref: Y, className: "flex flex-col gap-1.5", children: [
549
+ m.map((t) => {
550
550
  var o, w;
551
- const l = I[t];
551
+ const l = ie[t];
552
552
  return /* @__PURE__ */ i(
553
553
  "div",
554
554
  {
@@ -563,7 +563,7 @@ function nt({
563
563
  title: "Download",
564
564
  className: "shrink-0",
565
565
  children: /* @__PURE__ */ e(
566
- X,
566
+ J,
567
567
  {
568
568
  url: n(t),
569
569
  type: (l == null ? void 0 : l.type) ?? null,
@@ -596,7 +596,7 @@ function nt({
596
596
  ] })
597
597
  ] })
598
598
  ] }),
599
- (O.verdict(t) ?? !!(l != null && l.missing_at)) && /* @__PURE__ */ e(
599
+ (I.verdict(t) ?? !!(l != null && l.missing_at)) && /* @__PURE__ */ e(
600
600
  "span",
601
601
  {
602
602
  className: "shrink-0 self-center rounded bg-red-500/10 px-1.5 py-0.5 text-[9.5px] font-semibold uppercase tracking-wide text-red-600 dark:text-red-400",
@@ -604,17 +604,17 @@ function nt({
604
604
  children: "file missing"
605
605
  }
606
606
  ),
607
- _ && !k && S.includes(t) && /* @__PURE__ */ e(
607
+ _ && !k && U.includes(t) && /* @__PURE__ */ e(
608
608
  Le,
609
609
  {
610
610
  fileId: t,
611
- uses: (o = H.data) == null ? void 0 : o[t],
612
- loading: H.isLoading,
613
- collection: $ == null ? void 0 : $.collection,
611
+ uses: (o = c.data) == null ? void 0 : o[t],
612
+ loading: c.isLoading,
613
+ collection: Q,
614
614
  itemId: a
615
615
  }
616
616
  ),
617
- F && !k && S.includes(t) && /* @__PURE__ */ e(Re, { fileId: t, stat: (w = m.data) == null ? void 0 : w[t] }),
617
+ F && !k && U.includes(t) && /* @__PURE__ */ e(Re, { fileId: t, stat: (w = P.data) == null ? void 0 : w[t] }),
618
618
  /* @__PURE__ */ e(
619
619
  "a",
620
620
  {
@@ -630,7 +630,7 @@ function nt({
630
630
  {
631
631
  type: "button",
632
632
  "aria-label": "Remove file",
633
- onClick: () => ie(t),
633
+ onClick: () => je(t),
634
634
  className: "text-slate-300 hover:text-red-400 p-0.5 shrink-0",
635
635
  children: /* @__PURE__ */ e(le, { className: "h-3.5 w-3.5" })
636
636
  }
@@ -646,7 +646,7 @@ function nt({
646
646
  className: "flex items-center gap-2 rounded-lg border border-amber-200 p-2 bg-amber-50/50",
647
647
  children: [
648
648
  /* @__PURE__ */ e(
649
- X,
649
+ J,
650
650
  {
651
651
  url: t.url,
652
652
  type: t.file.type || null,
@@ -670,7 +670,7 @@ function nt({
670
670
  {
671
671
  type: "button",
672
672
  "aria-label": "Remove file",
673
- onClick: () => je(t.url),
673
+ onClick: () => We(t.url),
674
674
  className: "text-slate-300 hover:text-red-400 p-0.5 shrink-0",
675
675
  children: /* @__PURE__ */ e(le, { className: "h-3.5 w-3.5" })
676
676
  }
@@ -681,15 +681,15 @@ function nt({
681
681
  ))
682
682
  ] }),
683
683
  !p && /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
684
- j && /* @__PURE__ */ i("div", { className: "relative", children: [
684
+ S && /* @__PURE__ */ i("div", { className: "relative", children: [
685
685
  /* @__PURE__ */ i(
686
686
  "button",
687
687
  {
688
688
  type: "button",
689
- onClick: () => P((t) => !t),
689
+ onClick: () => K((t) => !t),
690
690
  className: "flex h-8 items-center gap-1.5 rounded border border-dashed border-slate-300 px-3 text-[12px] text-slate-400 hover:border-slate-400 hover:text-slate-600 transition-colors",
691
691
  children: [
692
- /* @__PURE__ */ e(Ke, { className: "h-3.5 w-3.5" }),
692
+ /* @__PURE__ */ e(Pe, { className: "h-3.5 w-3.5" }),
693
693
  "Add existing…"
694
694
  ]
695
695
  }
@@ -702,17 +702,17 @@ function nt({
702
702
  children: /* @__PURE__ */ e(
703
703
  Se,
704
704
  {
705
- selected: u,
705
+ selected: m,
706
706
  multi: !0,
707
707
  onSelect: (t) => re(t),
708
- onClose: () => P(!1),
708
+ onClose: () => K(!1),
709
709
  getUrl: n
710
710
  }
711
711
  )
712
712
  }
713
713
  )
714
714
  ] }),
715
- y && /* @__PURE__ */ i(J, { children: [
715
+ y && /* @__PURE__ */ i(D, { children: [
716
716
  /* @__PURE__ */ i(
717
717
  "button",
718
718
  {
@@ -721,10 +721,10 @@ function nt({
721
721
  var t;
722
722
  return (t = v.current) == null ? void 0 : t.click();
723
723
  },
724
- disabled: Z,
724
+ disabled: G,
725
725
  className: "flex h-8 items-center gap-1.5 rounded border border-dashed border-slate-300 px-3 text-[12px] text-slate-400 hover:border-slate-400 hover:text-slate-600 disabled:opacity-40 transition-colors",
726
726
  children: [
727
- Z ? /* @__PURE__ */ e(te, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3.5 w-3.5" }),
727
+ G ? /* @__PURE__ */ e(te, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(de, { className: "h-3.5 w-3.5" }),
728
728
  "Upload…"
729
729
  ]
730
730
  }
@@ -736,7 +736,7 @@ function nt({
736
736
  type: "file",
737
737
  multiple: !0,
738
738
  className: "hidden",
739
- onChange: We
739
+ onChange: ze
740
740
  }
741
741
  )
742
742
  ] })
@@ -744,7 +744,7 @@ function nt({
744
744
  ] });
745
745
  }
746
746
  export {
747
- nt as FileM2MField,
748
- st as FilePickerField,
747
+ at as FileM2MField,
748
+ nt as FilePickerField,
749
749
  he as fileDisplayName
750
750
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.70",
3
+ "version": "0.3.71",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",