@dismissible/react-client 1.0.0-canary.4.a9fb4a5 → 1.0.0

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,59 +1,59 @@
1
1
  var he = Object.defineProperty, me = Object.defineProperties;
2
2
  var ye = Object.getOwnPropertyDescriptors;
3
- var J = Object.getOwnPropertySymbols;
4
- var te = Object.prototype.hasOwnProperty, re = Object.prototype.propertyIsEnumerable;
5
- var ee = (e, r, t) => r in e ? he(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, b = (e, r) => {
3
+ var M = Object.getOwnPropertySymbols;
4
+ var re = Object.prototype.hasOwnProperty, ne = Object.prototype.propertyIsEnumerable;
5
+ var te = (e, r, t) => r in e ? he(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, b = (e, r) => {
6
6
  for (var t in r || (r = {}))
7
- te.call(r, t) && ee(e, t, r[t]);
8
- if (J)
9
- for (var t of J(r))
10
- re.call(r, t) && ee(e, t, r[t]);
7
+ re.call(r, t) && te(e, t, r[t]);
8
+ if (M)
9
+ for (var t of M(r))
10
+ ne.call(r, t) && te(e, t, r[t]);
11
11
  return e;
12
12
  }, E = (e, r) => me(e, ye(r));
13
- var G = (e, r) => {
13
+ var Q = (e, r) => {
14
14
  var t = {};
15
15
  for (var n in e)
16
- te.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
17
- if (e != null && J)
18
- for (var n of J(e))
19
- r.indexOf(n) < 0 && re.call(e, n) && (t[n] = e[n]);
16
+ re.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
17
+ if (e != null && M)
18
+ for (var n of M(e))
19
+ r.indexOf(n) < 0 && ne.call(e, n) && (t[n] = e[n]);
20
20
  return t;
21
21
  };
22
22
  var $ = (e, r, t) => new Promise((n, o) => {
23
23
  var s = (f) => {
24
24
  try {
25
- c(t.next(f));
25
+ l(t.next(f));
26
26
  } catch (d) {
27
27
  o(d);
28
28
  }
29
29
  }, i = (f) => {
30
30
  try {
31
- c(t.throw(f));
31
+ l(t.throw(f));
32
32
  } catch (d) {
33
33
  o(d);
34
34
  }
35
- }, c = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(s, i);
36
- c((t = t.apply(e, r)).next());
35
+ }, l = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(s, i);
36
+ l((t = t.apply(e, r)).next());
37
37
  });
38
38
  import { jsx as U, jsxs as be } from "react/jsx-runtime";
39
- import { createContext as pe, useContext as we, useMemo as X, useRef as W, useState as z, useCallback as K, useEffect as Q } from "react";
40
- const ge = /\{[^{}]+\}/g, ve = () => {
39
+ import { createContext as pe, useContext as we, useMemo as Y, useRef as J, useState as W, useCallback as V, useEffect as _ } from "react";
40
+ const ge = /\{[^{}]+\}/g, Ee = () => {
41
41
  var e, r;
42
42
  return typeof process == "object" && Number.parseInt((r = (e = process == null ? void 0 : process.versions) == null ? void 0 : e.node) == null ? void 0 : r.substring(0, 2)) >= 18 && process.versions.undici;
43
43
  };
44
- function Ee() {
44
+ function Re() {
45
45
  return Math.random().toString(36).slice(2, 11);
46
46
  }
47
- function Re(e) {
48
- let j = b({}, e), {
47
+ function ve(e) {
48
+ let A = b({}, e), {
49
49
  baseUrl: r = "",
50
50
  Request: t = globalThis.Request,
51
51
  fetch: n = globalThis.fetch,
52
52
  querySerializer: o,
53
53
  bodySerializer: s,
54
54
  headers: i,
55
- requestInitExt: c = void 0
56
- } = j, f = G(j, [
55
+ requestInitExt: l = void 0
56
+ } = A, f = Q(A, [
57
57
  "baseUrl",
58
58
  "Request",
59
59
  "fetch",
@@ -62,23 +62,23 @@ function Re(e) {
62
62
  "headers",
63
63
  "requestInitExt"
64
64
  ]);
65
- c = ve() ? c : void 0, r = oe(r);
65
+ l = Ee() ? l : void 0, r = ie(r);
66
66
  const d = [];
67
- function g(l, a) {
67
+ function g(u, a) {
68
68
  return $(this, null, function* () {
69
- var Z;
70
- const Y = a || {}, {
69
+ var ee;
70
+ const Z = a || {}, {
71
71
  baseUrl: R,
72
- fetch: x = n,
73
- Request: I = t,
74
- headers: C,
72
+ fetch: C = n,
73
+ Request: O = t,
74
+ headers: x,
75
75
  params: v = {},
76
- parseAs: A = "json",
76
+ parseAs: j = "json",
77
77
  querySerializer: S,
78
- bodySerializer: k = s != null ? s : xe,
79
- body: F,
80
- middleware: u = []
81
- } = Y, y = G(Y, [
78
+ bodySerializer: P = s != null ? s : xe,
79
+ body: z,
80
+ middleware: k = []
81
+ } = Z, c = Q(Z, [
82
82
  "baseUrl",
83
83
  "fetch",
84
84
  "Request",
@@ -90,58 +90,58 @@ function Re(e) {
90
90
  "body",
91
91
  "middleware"
92
92
  ]);
93
- let h = r;
94
- R && (h = (Z = oe(R)) != null ? Z : r);
95
- let H = typeof o == "function" ? o : ne(o);
96
- S && (H = typeof S == "function" ? S : ne(b(b({}, typeof o == "object" ? o : {}), S)));
97
- const P = F === void 0 ? void 0 : k(
98
- F,
93
+ let y = r;
94
+ R && (y = (ee = ie(R)) != null ? ee : r);
95
+ let h = typeof o == "function" ? o : se(o);
96
+ S && (h = typeof S == "function" ? S : se(b(b({}, typeof o == "object" ? o : {}), S)));
97
+ const H = z === void 0 ? void 0 : P(
98
+ z,
99
99
  // Note: we declare mergeHeaders() both here and below because it’s a bit of a chicken-or-egg situation:
100
100
  // bodySerializer() needs all headers so we aren’t dropping ones set by the user, however,
101
101
  // the result of this ALSO sets the lowest-priority content-type header. So we re-merge below,
102
102
  // setting the content-type at the very beginning to be overwritten.
103
103
  // Lastly, based on the way headers work, it’s not a simple “present-or-not” check becauase null intentionally un-sets headers.
104
- se(i, C, v.header)
105
- ), fe = se(
104
+ oe(i, x, v.header)
105
+ ), G = oe(
106
106
  // with no body, we should not to set Content-Type
107
- P === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
108
- P instanceof FormData ? {} : {
107
+ H === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
108
+ H instanceof FormData ? {} : {
109
109
  "Content-Type": "application/json"
110
110
  },
111
111
  i,
112
- C,
112
+ x,
113
113
  v.header
114
- ), D = [...d, ...u], de = E(b(b({
114
+ ), D = [...d, ...k], de = E(b(b({
115
115
  redirect: "follow"
116
- }, f), y), {
117
- body: P,
118
- headers: fe
116
+ }, f), c), {
117
+ body: H,
118
+ headers: G
119
119
  });
120
- let L, N, T = new I(
121
- Se(l, { baseUrl: h, params: v, querySerializer: H }),
120
+ let F, L, T = new O(
121
+ Se(u, { baseUrl: y, params: v, querySerializer: h }),
122
122
  de
123
123
  ), m;
124
- for (const w in y)
125
- w in T || (T[w] = y[w]);
124
+ for (const w in c)
125
+ w in T || (T[w] = c[w]);
126
126
  if (D.length) {
127
- L = Ee(), N = Object.freeze({
128
- baseUrl: h,
129
- fetch: x,
130
- parseAs: A,
131
- querySerializer: H,
132
- bodySerializer: k
127
+ F = Re(), L = Object.freeze({
128
+ baseUrl: y,
129
+ fetch: C,
130
+ parseAs: j,
131
+ querySerializer: h,
132
+ bodySerializer: P
133
133
  });
134
134
  for (const w of D)
135
135
  if (w && typeof w == "object" && typeof w.onRequest == "function") {
136
136
  const p = yield w.onRequest({
137
137
  request: T,
138
- schemaPath: l,
138
+ schemaPath: u,
139
139
  params: v,
140
- options: N,
141
- id: L
140
+ options: L,
141
+ id: F
142
142
  });
143
143
  if (p)
144
- if (p instanceof I)
144
+ if (p instanceof O)
145
145
  T = p;
146
146
  else if (p instanceof Response) {
147
147
  m = p;
@@ -152,28 +152,28 @@ function Re(e) {
152
152
  }
153
153
  if (!m) {
154
154
  try {
155
- m = yield x(T, c);
155
+ m = yield C(T, l);
156
156
  } catch (w) {
157
157
  let p = w;
158
158
  if (D.length)
159
159
  for (let q = D.length - 1; q >= 0; q--) {
160
- const M = D[q];
161
- if (M && typeof M == "object" && typeof M.onError == "function") {
162
- const O = yield M.onError({
160
+ const N = D[q];
161
+ if (N && typeof N == "object" && typeof N.onError == "function") {
162
+ const I = yield N.onError({
163
163
  request: T,
164
164
  error: p,
165
- schemaPath: l,
165
+ schemaPath: u,
166
166
  params: v,
167
- options: N,
168
- id: L
167
+ options: L,
168
+ id: F
169
169
  });
170
- if (O) {
171
- if (O instanceof Response) {
172
- p = void 0, m = O;
170
+ if (I) {
171
+ if (I instanceof Response) {
172
+ p = void 0, m = I;
173
173
  break;
174
174
  }
175
- if (O instanceof Error) {
176
- p = O;
175
+ if (I instanceof Error) {
176
+ p = I;
177
177
  continue;
178
178
  }
179
179
  throw new Error("onError: must return new Response() or instance of Error");
@@ -190,10 +190,10 @@ function Re(e) {
190
190
  const q = yield p.onResponse({
191
191
  request: T,
192
192
  response: m,
193
- schemaPath: l,
193
+ schemaPath: u,
194
194
  params: v,
195
- options: N,
196
- id: L
195
+ options: L,
196
+ id: F
197
197
  });
198
198
  if (q) {
199
199
  if (!(q instanceof Response))
@@ -206,54 +206,54 @@ function Re(e) {
206
206
  if (m.status === 204 || T.method === "HEAD" || m.headers.get("Content-Length") === "0")
207
207
  return m.ok ? { data: void 0, response: m } : { error: void 0, response: m };
208
208
  if (m.ok)
209
- return A === "stream" ? { data: m.body, response: m } : { data: yield m[A](), response: m };
210
- let B = yield m.text();
209
+ return j === "stream" ? { data: m.body, response: m } : { data: yield m[j](), response: m };
210
+ let K = yield m.text();
211
211
  try {
212
- B = JSON.parse(B);
212
+ K = JSON.parse(K);
213
213
  } catch (w) {
214
214
  }
215
- return { error: B, response: m };
215
+ return { error: K, response: m };
216
216
  });
217
217
  }
218
218
  return {
219
- request(l, a, R) {
220
- return g(a, E(b({}, R), { method: l.toUpperCase() }));
219
+ request(u, a, R) {
220
+ return g(a, E(b({}, R), { method: u.toUpperCase() }));
221
221
  },
222
222
  /** Call a GET endpoint */
223
- GET(l, a) {
224
- return g(l, E(b({}, a), { method: "GET" }));
223
+ GET(u, a) {
224
+ return g(u, E(b({}, a), { method: "GET" }));
225
225
  },
226
226
  /** Call a PUT endpoint */
227
- PUT(l, a) {
228
- return g(l, E(b({}, a), { method: "PUT" }));
227
+ PUT(u, a) {
228
+ return g(u, E(b({}, a), { method: "PUT" }));
229
229
  },
230
230
  /** Call a POST endpoint */
231
- POST(l, a) {
232
- return g(l, E(b({}, a), { method: "POST" }));
231
+ POST(u, a) {
232
+ return g(u, E(b({}, a), { method: "POST" }));
233
233
  },
234
234
  /** Call a DELETE endpoint */
235
- DELETE(l, a) {
236
- return g(l, E(b({}, a), { method: "DELETE" }));
235
+ DELETE(u, a) {
236
+ return g(u, E(b({}, a), { method: "DELETE" }));
237
237
  },
238
238
  /** Call a OPTIONS endpoint */
239
- OPTIONS(l, a) {
240
- return g(l, E(b({}, a), { method: "OPTIONS" }));
239
+ OPTIONS(u, a) {
240
+ return g(u, E(b({}, a), { method: "OPTIONS" }));
241
241
  },
242
242
  /** Call a HEAD endpoint */
243
- HEAD(l, a) {
244
- return g(l, E(b({}, a), { method: "HEAD" }));
243
+ HEAD(u, a) {
244
+ return g(u, E(b({}, a), { method: "HEAD" }));
245
245
  },
246
246
  /** Call a PATCH endpoint */
247
- PATCH(l, a) {
248
- return g(l, E(b({}, a), { method: "PATCH" }));
247
+ PATCH(u, a) {
248
+ return g(u, E(b({}, a), { method: "PATCH" }));
249
249
  },
250
250
  /** Call a TRACE endpoint */
251
- TRACE(l, a) {
252
- return g(l, E(b({}, a), { method: "TRACE" }));
251
+ TRACE(u, a) {
252
+ return g(u, E(b({}, a), { method: "TRACE" }));
253
253
  },
254
254
  /** Register middleware */
255
- use(...l) {
256
- for (const a of l)
255
+ use(...u) {
256
+ for (const a of u)
257
257
  if (a) {
258
258
  if (typeof a != "object" || !("onRequest" in a || "onResponse" in a || "onError" in a))
259
259
  throw new Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");
@@ -261,15 +261,15 @@ function Re(e) {
261
261
  }
262
262
  },
263
263
  /** Unregister middleware */
264
- eject(...l) {
265
- for (const a of l) {
264
+ eject(...u) {
265
+ for (const a of u) {
266
266
  const R = d.indexOf(a);
267
267
  R !== -1 && d.splice(R, 1);
268
268
  }
269
269
  }
270
270
  };
271
271
  }
272
- function _(e, r, t) {
272
+ function B(e, r, t) {
273
273
  if (r == null)
274
274
  return "";
275
275
  if (typeof r == "object")
@@ -278,7 +278,7 @@ function _(e, r, t) {
278
278
  );
279
279
  return `${e}=${(t == null ? void 0 : t.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
280
280
  }
281
- function ce(e, r, t) {
281
+ function le(e, r, t) {
282
282
  if (!r || typeof r != "object")
283
283
  return "";
284
284
  const n = [], o = {
@@ -287,8 +287,8 @@ function ce(e, r, t) {
287
287
  matrix: ";"
288
288
  }[t.style] || "&";
289
289
  if (t.style !== "deepObject" && t.explode === !1) {
290
- for (const c in r)
291
- n.push(c, t.allowReserved === !0 ? r[c] : encodeURIComponent(r[c]));
290
+ for (const l in r)
291
+ n.push(l, t.allowReserved === !0 ? r[l] : encodeURIComponent(r[l]));
292
292
  const i = n.join(",");
293
293
  switch (t.style) {
294
294
  case "form":
@@ -302,17 +302,17 @@ function ce(e, r, t) {
302
302
  }
303
303
  }
304
304
  for (const i in r) {
305
- const c = t.style === "deepObject" ? `${e}[${i}]` : i;
306
- n.push(_(c, r[i], t));
305
+ const l = t.style === "deepObject" ? `${e}[${i}]` : i;
306
+ n.push(B(l, r[i], t));
307
307
  }
308
308
  const s = n.join(o);
309
309
  return t.style === "label" || t.style === "matrix" ? `${o}${s}` : s;
310
310
  }
311
- function le(e, r, t) {
311
+ function ue(e, r, t) {
312
312
  if (!Array.isArray(r))
313
313
  return "";
314
314
  if (t.explode === !1) {
315
- const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[t.style] || ",", i = (t.allowReserved === !0 ? r : r.map((c) => encodeURIComponent(c))).join(s);
315
+ const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[t.style] || ",", i = (t.allowReserved === !0 ? r : r.map((l) => encodeURIComponent(l))).join(s);
316
316
  switch (t.style) {
317
317
  case "simple":
318
318
  return i;
@@ -328,10 +328,10 @@ function le(e, r, t) {
328
328
  }
329
329
  const n = { simple: ",", label: ".", matrix: ";" }[t.style] || "&", o = [];
330
330
  for (const s of r)
331
- t.style === "simple" || t.style === "label" ? o.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : o.push(_(e, s, t));
331
+ t.style === "simple" || t.style === "label" ? o.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : o.push(B(e, s, t));
332
332
  return t.style === "label" || t.style === "matrix" ? `${n}${o.join(n)}` : o.join(n);
333
333
  }
334
- function ne(e) {
334
+ function se(e) {
335
335
  return function(t) {
336
336
  const n = [];
337
337
  if (t && typeof t == "object")
@@ -342,7 +342,7 @@ function ne(e) {
342
342
  if (s.length === 0)
343
343
  continue;
344
344
  n.push(
345
- le(o, s, E(b({
345
+ ue(o, s, E(b({
346
346
  style: "form",
347
347
  explode: !0
348
348
  }, e == null ? void 0 : e.array), {
@@ -353,7 +353,7 @@ function ne(e) {
353
353
  }
354
354
  if (typeof s == "object") {
355
355
  n.push(
356
- ce(o, s, E(b({
356
+ le(o, s, E(b({
357
357
  style: "deepObject",
358
358
  explode: !0
359
359
  }, e == null ? void 0 : e.object), {
@@ -362,7 +362,7 @@ function ne(e) {
362
362
  );
363
363
  continue;
364
364
  }
365
- n.push(_(o, s, e));
365
+ n.push(B(o, s, e));
366
366
  }
367
367
  }
368
368
  return n.join("&");
@@ -372,23 +372,23 @@ function Ce(e, r) {
372
372
  var n;
373
373
  let t = e;
374
374
  for (const o of (n = e.match(ge)) != null ? n : []) {
375
- let s = o.substring(1, o.length - 1), i = !1, c = "simple";
376
- if (s.endsWith("*") && (i = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (c = "label", s = s.substring(1)) : s.startsWith(";") && (c = "matrix", s = s.substring(1)), !r || r[s] === void 0 || r[s] === null)
375
+ let s = o.substring(1, o.length - 1), i = !1, l = "simple";
376
+ if (s.endsWith("*") && (i = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (l = "label", s = s.substring(1)) : s.startsWith(";") && (l = "matrix", s = s.substring(1)), !r || r[s] === void 0 || r[s] === null)
377
377
  continue;
378
378
  const f = r[s];
379
379
  if (Array.isArray(f)) {
380
- t = t.replace(o, le(s, f, { style: c, explode: i }));
380
+ t = t.replace(o, ue(s, f, { style: l, explode: i }));
381
381
  continue;
382
382
  }
383
383
  if (typeof f == "object") {
384
- t = t.replace(o, ce(s, f, { style: c, explode: i }));
384
+ t = t.replace(o, le(s, f, { style: l, explode: i }));
385
385
  continue;
386
386
  }
387
- if (c === "matrix") {
388
- t = t.replace(o, `;${_(s, f)}`);
387
+ if (l === "matrix") {
388
+ t = t.replace(o, `;${B(s, f)}`);
389
389
  continue;
390
390
  }
391
- t = t.replace(o, c === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
391
+ t = t.replace(o, l === "label" ? `.${encodeURIComponent(f)}` : encodeURIComponent(f));
392
392
  }
393
393
  return t;
394
394
  }
@@ -403,7 +403,7 @@ function Se(e, r) {
403
403
  let n = r.querySerializer((s = r.params.query) != null ? s : {});
404
404
  return n.startsWith("?") && (n = n.substring(1)), n && (t += `?${n}`), t;
405
405
  }
406
- function se(...e) {
406
+ function oe(...e) {
407
407
  const r = new Headers();
408
408
  for (const t of e) {
409
409
  if (!t || typeof t != "object")
@@ -419,10 +419,10 @@ function se(...e) {
419
419
  }
420
420
  return r;
421
421
  }
422
- function oe(e) {
422
+ function ie(e) {
423
423
  return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
424
424
  }
425
- const ie = (e, r, t) => {
425
+ const ae = (e, r, t) => {
426
426
  try {
427
427
  const n = `${r}_${e}`, o = localStorage.getItem(n);
428
428
  if (!o) return null;
@@ -431,7 +431,7 @@ const ie = (e, r, t) => {
431
431
  } catch (n) {
432
432
  return null;
433
433
  }
434
- }, V = (e, r, t) => {
434
+ }, X = (e, r, t) => {
435
435
  try {
436
436
  const n = `${t}_${e}`, o = {
437
437
  data: r,
@@ -441,90 +441,91 @@ const ie = (e, r, t) => {
441
441
  } catch (n) {
442
442
  console.warn("Failed to cache dismissible item:", n);
443
443
  }
444
- }, ae = (e, r) => {
444
+ }, ce = (e, r) => {
445
445
  try {
446
446
  const t = `${r}_${e}`;
447
447
  localStorage.removeItem(t);
448
448
  } catch (t) {
449
449
  console.warn("Failed to remove cached dismissible item:", t);
450
450
  }
451
- }, ue = pe(
451
+ }, fe = pe(
452
452
  null
453
- ), Ae = () => {
454
- const e = we(ue);
453
+ ), $e = () => {
454
+ const e = we(fe);
455
455
  if (!e)
456
456
  throw new Error(
457
457
  "useDismissibleContext must be used within a DismissibleProvider"
458
458
  );
459
459
  return e;
460
- }, $e = "dismissible", je = (e, r = {}) => {
460
+ }, Ae = "dismissible", je = (e, r = {}) => {
461
+ var k;
461
462
  const {
462
463
  initialData: t,
463
464
  enableCache: n = !0,
464
- cachePrefix: o = $e,
465
+ cachePrefix: o = Ae,
465
466
  cacheExpiration: s
466
- } = r, i = Ae(), { userId: c } = i, f = X(() => Re({
467
+ } = r, i = $e(), { userId: l } = i, f = Y(() => ve({
467
468
  baseUrl: i.baseUrl,
468
469
  headers: {}
469
- }), [i.baseUrl]), d = X(() => `${c}-${e}`, [c, e]), g = W({
470
+ }), [i.baseUrl]), d = Y(() => `${l}-${e}`, [l, e]), g = J({
470
471
  enableCache: n,
471
472
  cachePrefix: o,
472
473
  cacheExpiration: s
473
- }), j = W(e), l = W(d), a = W(null), [R, x] = z(!1), [I, C] = z(), [v, A] = z(() => {
474
+ }), A = J(e), u = J(d), a = J(null), [R, C] = W(!1), [O, x] = W(null), [v, j] = W(() => {
474
475
  if (t) return t;
475
476
  if (n) {
476
- const u = ie(
477
+ const c = ae(
477
478
  d,
478
479
  o,
479
480
  s
480
481
  );
481
- if (u) return u;
482
+ if (c) return c;
482
483
  }
483
- }), S = K(() => $(null, null, function* () {
484
+ }), S = V(() => $(null, null, function* () {
484
485
  var y;
485
486
  if (n) {
486
- const h = ie(
487
+ const h = ae(
487
488
  d,
488
489
  o,
489
490
  s
490
491
  );
491
492
  if (h != null && h.dismissedAt) {
492
- A(h), x(!1);
493
+ j(h), C(!1);
493
494
  return;
494
495
  }
495
496
  }
496
497
  (y = a.current) == null || y.abort();
497
- const u = new AbortController();
498
- a.current = u, x(!0), C(void 0);
498
+ const c = new AbortController();
499
+ a.current = c, C(!0), x(null);
499
500
  try {
500
- const h = yield i.getAuthHeaders(), { data: H, error: P } = yield f.GET(
501
+ const h = yield i.getAuthHeaders(), { data: H, error: G } = yield f.GET(
501
502
  "/v1/users/{userId}/items/{itemId}",
502
503
  {
503
504
  params: {
504
505
  path: {
505
- userId: c,
506
+ userId: l,
506
507
  itemId: e
507
508
  }
508
509
  },
509
510
  headers: h,
510
- signal: u.signal
511
+ signal: c.signal
511
512
  }
512
513
  );
513
- if (P || !H)
514
+ if (G || !H)
514
515
  throw new Error("Failed to fetch dismissible item");
515
- A(H.data), n && V(d, H.data, o);
516
+ j(H.data), n && X(d, H.data, o);
516
517
  } catch (h) {
517
518
  if (h instanceof Error && h.name === "AbortError")
518
519
  return;
519
- C(
520
+ x(
520
521
  h instanceof Error ? h : new Error("Unknown error occurred")
521
522
  );
522
523
  } finally {
523
- x(!1);
524
+ C(!1);
524
525
  }
525
526
  }), [
526
527
  e,
527
- c,
528
+ l,
528
529
  d,
529
530
  n,
530
531
  o,
@@ -532,77 +533,77 @@ const ie = (e, r, t) => {
532
533
  f,
533
534
  i
534
535
  ]);
535
- Q(() => {
536
- const u = j.current !== e, y = l.current !== d;
537
- u || y ? (j.current = e, l.current = d, S()) : t || S();
538
- }, [e, d, t, S]), Q(() => () => {
539
- var u;
540
- (u = a.current) == null || u.abort();
541
- }, []), Q(() => {
542
- const u = g.current;
543
- (u.enableCache !== n || u.cachePrefix !== o || u.cacheExpiration !== s) && (u.cachePrefix !== o && ae(d, u.cachePrefix), !n && u.enableCache && ae(d, u.cachePrefix), g.current = {
536
+ _(() => {
537
+ const c = A.current !== e, y = u.current !== d;
538
+ c || y ? (A.current = e, u.current = d, S()) : t || S();
539
+ }, [e, d, t, S]), _(() => () => {
540
+ var c;
541
+ (c = a.current) == null || c.abort();
542
+ }, []), _(() => {
543
+ const c = g.current;
544
+ (c.enableCache !== n || c.cachePrefix !== o || c.cacheExpiration !== s) && (c.cachePrefix !== o && ce(d, c.cachePrefix), !n && c.enableCache && ce(d, c.cachePrefix), g.current = {
544
545
  enableCache: n,
545
546
  cachePrefix: o,
546
547
  cacheExpiration: s
547
548
  }, S());
548
549
  }, [n, o, s, d, S]);
549
- const k = K(() => $(null, null, function* () {
550
- C(void 0);
550
+ const P = V(() => $(null, null, function* () {
551
+ x(null);
551
552
  try {
552
- const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.DELETE(
553
+ const c = yield i.getAuthHeaders(), { data: y, error: h } = yield f.DELETE(
553
554
  "/v1/users/{userId}/items/{itemId}",
554
555
  {
555
556
  params: {
556
557
  path: {
557
- userId: c,
558
+ userId: l,
558
559
  itemId: e
559
560
  }
560
561
  },
561
- headers: u
562
+ headers: c
562
563
  }
563
564
  );
564
565
  if (h || !y)
565
566
  throw new Error("Failed to dismiss item");
566
- A(y.data), n && V(d, y.data, o);
567
- } catch (u) {
568
- throw C(
569
- u instanceof Error ? u : new Error("Failed to dismiss item")
570
- ), u;
567
+ j(y.data), n && X(d, y.data, o);
568
+ } catch (c) {
569
+ throw x(
570
+ c instanceof Error ? c : new Error("Failed to dismiss item")
571
+ ), c;
571
572
  }
572
573
  }), [
573
574
  e,
574
- c,
575
+ l,
575
576
  d,
576
577
  n,
577
578
  o,
578
579
  f,
579
580
  i
580
- ]), F = K(() => $(null, null, function* () {
581
- C(void 0);
581
+ ]), z = V(() => $(null, null, function* () {
582
+ x(null);
582
583
  try {
583
- const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.POST(
584
+ const c = yield i.getAuthHeaders(), { data: y, error: h } = yield f.POST(
584
585
  "/v1/users/{userId}/items/{itemId}",
585
586
  {
586
587
  params: {
587
588
  path: {
588
- userId: c,
589
+ userId: l,
589
590
  itemId: e
590
591
  }
591
592
  },
592
- headers: u
593
+ headers: c
593
594
  }
594
595
  );
595
596
  if (h || !y)
596
597
  throw new Error("Failed to restore item");
597
- A(y.data), n && V(d, y.data, o);
598
- } catch (u) {
599
- throw C(
600
- u instanceof Error ? u : new Error("Failed to restore item")
601
- ), u;
598
+ j(y.data), n && X(d, y.data, o);
599
+ } catch (c) {
600
+ throw x(
601
+ c instanceof Error ? c : new Error("Failed to restore item")
602
+ ), c;
602
603
  }
603
604
  }), [
604
605
  e,
605
- c,
606
+ l,
606
607
  d,
607
608
  n,
608
609
  o,
@@ -610,11 +611,11 @@ const ie = (e, r, t) => {
610
611
  i
611
612
  ]);
612
613
  return {
613
- dismissedAt: v == null ? void 0 : v.dismissedAt,
614
- dismiss: k,
615
- restore: F,
614
+ dismissedOn: (k = v == null ? void 0 : v.dismissedAt) != null ? k : null,
615
+ dismiss: P,
616
+ restore: z,
616
617
  isLoading: R,
617
- error: I,
618
+ error: O,
618
619
  item: v
619
620
  };
620
621
  }, De = () => /* @__PURE__ */ U("div", { className: "dismissible-loading", "aria-live": "polite", children: "Loading..." }), Te = () => /* @__PURE__ */ U("div", { className: "dismissible-error", role: "alert", children: "Unable to load content. Please try again later." }), Ue = ({ onDismiss: e, ariaLabel: r }) => /* @__PURE__ */ U(
@@ -634,33 +635,35 @@ const ie = (e, r, t) => {
634
635
  ErrorComponent: o = Te,
635
636
  DismissButtonComponent: s = Ue,
636
637
  enableCache: i,
637
- cachePrefix: c,
638
+ cachePrefix: l,
638
639
  cacheExpiration: f,
639
640
  ignoreErrors: d = !1
640
641
  }) => {
641
- const { dismissedAt: g, isLoading: j, error: l, dismiss: a } = je(
642
+ const { dismissedOn: g, isLoading: A, error: u, dismiss: a } = je(
642
643
  e,
643
644
  {
644
645
  enableCache: i,
645
- cachePrefix: c,
646
+ cachePrefix: l,
646
647
  cacheExpiration: f
647
648
  }
648
- ), [R, x] = z(!1), [I, C] = z(e);
649
- e !== I && (C(e), x(!1));
650
- const v = () => $(null, null, function* () {
651
- x(!0);
649
+ ), [R, C] = W(!1);
650
+ _(() => {
651
+ C(!1);
652
+ }, [e]);
653
+ const O = () => $(null, null, function* () {
654
+ C(!0);
652
655
  try {
653
656
  yield a(), t == null || t();
654
- } catch (A) {
655
- x(!1);
657
+ } catch (x) {
658
+ C(!1);
656
659
  }
657
660
  });
658
- return j && n ? /* @__PURE__ */ U(n, { itemId: e }) : j && !n ? null : l && o && !d ? /* @__PURE__ */ U(o, { itemId: e, error: l }) : g || R ? null : /* @__PURE__ */ be("div", { className: "dismissible-container", children: [
661
+ return A && n ? /* @__PURE__ */ U(n, { itemId: e }) : A && !n ? null : u && o && !d ? /* @__PURE__ */ U(o, { itemId: e, error: u }) : g || R ? null : /* @__PURE__ */ be("div", { className: "dismissible-container", children: [
659
662
  /* @__PURE__ */ U("div", { className: "dismissible-content", children: r }),
660
663
  s ? /* @__PURE__ */ U(
661
664
  s,
662
665
  {
663
- onDismiss: v,
666
+ onDismiss: O,
664
667
  ariaLabel: `Dismiss ${e}`
665
668
  }
666
669
  ) : null
@@ -678,7 +681,7 @@ const ie = (e, r, t) => {
678
681
  }), qe = (e) => $(null, null, function* () {
679
682
  const r = yield He(e);
680
683
  return r ? { Authorization: `Bearer ${r}` } : {};
681
- }), Ie = (e) => {
684
+ }), Oe = (e) => {
682
685
  try {
683
686
  const r = new URL(e), t = r.hostname === "localhost" || r.hostname === "127.0.0.1" || r.hostname === "[::1]", n = r.protocol === "https:";
684
687
  return { isSecure: n || t, isLocalhost: t, isHttps: n };
@@ -691,11 +694,11 @@ const ie = (e, r, t) => {
691
694
  baseUrl: t,
692
695
  children: n
693
696
  }) => {
694
- const { isSecure: o } = Ie(t);
697
+ const { isSecure: o } = Oe(t);
695
698
  o || console.warn(
696
699
  `[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`
697
700
  );
698
- const s = X(
701
+ const s = Y(
699
702
  () => ({
700
703
  userId: e,
701
704
  jwt: r,
@@ -706,14 +709,14 @@ const ie = (e, r, t) => {
706
709
  }),
707
710
  [e, r, t]
708
711
  );
709
- return /* @__PURE__ */ U(ue.Provider, { value: s, children: n });
712
+ return /* @__PURE__ */ U(fe.Provider, { value: s, children: n });
710
713
  };
711
714
  export {
712
715
  ke as Dismissible,
713
- ue as DismissibleContext,
716
+ fe as DismissibleContext,
714
717
  Fe as DismissibleProvider,
715
718
  qe as getAuthHeaders,
716
719
  He as resolveJwt,
717
- Ae as useDismissibleContext,
720
+ $e as useDismissibleContext,
718
721
  je as useDismissibleItem
719
722
  };