@dismissible/react-client 1.0.0 → 2.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.
- package/CHANGELOG.md +30 -0
- package/README.md +55 -195
- package/dist/config/api.config.d.ts +0 -14
- package/dist/dismissible-client.es.js +205 -208
- package/dist/dismissible-client.umd.js +1 -1
- package/dist/hooks/useDismissibleItem.d.ts +16 -14
- package/dist/root.d.ts +0 -5
- package/package.json +17 -16
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
var he = Object.defineProperty, me = Object.defineProperties;
|
|
2
2
|
var ye = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
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) => {
|
|
6
6
|
for (var t in r || (r = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var t of
|
|
10
|
-
|
|
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]);
|
|
11
11
|
return e;
|
|
12
12
|
}, E = (e, r) => me(e, ye(r));
|
|
13
|
-
var
|
|
13
|
+
var G = (e, r) => {
|
|
14
14
|
var t = {};
|
|
15
15
|
for (var n in e)
|
|
16
|
-
|
|
17
|
-
if (e != null &&
|
|
18
|
-
for (var n of
|
|
19
|
-
r.indexOf(n) < 0 &&
|
|
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]);
|
|
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
|
-
|
|
25
|
+
c(t.next(f));
|
|
26
26
|
} catch (d) {
|
|
27
27
|
o(d);
|
|
28
28
|
}
|
|
29
29
|
}, i = (f) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
c(t.throw(f));
|
|
32
32
|
} catch (d) {
|
|
33
33
|
o(d);
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
35
|
+
}, c = (f) => f.done ? n(f.value) : Promise.resolve(f.value).then(s, i);
|
|
36
|
+
c((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
|
|
40
|
-
const ge = /\{[^{}]+\}/g,
|
|
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 = () => {
|
|
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
|
|
44
|
+
function Ee() {
|
|
45
45
|
return Math.random().toString(36).slice(2, 11);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
let
|
|
47
|
+
function Re(e) {
|
|
48
|
+
let j = 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:
|
|
56
|
-
} =
|
|
55
|
+
requestInitExt: c = void 0
|
|
56
|
+
} = j, f = G(j, [
|
|
57
57
|
"baseUrl",
|
|
58
58
|
"Request",
|
|
59
59
|
"fetch",
|
|
@@ -62,23 +62,23 @@ function ve(e) {
|
|
|
62
62
|
"headers",
|
|
63
63
|
"requestInitExt"
|
|
64
64
|
]);
|
|
65
|
-
|
|
65
|
+
c = ve() ? c : void 0, r = oe(r);
|
|
66
66
|
const d = [];
|
|
67
|
-
function g(
|
|
67
|
+
function g(l, a) {
|
|
68
68
|
return $(this, null, function* () {
|
|
69
|
-
var
|
|
70
|
-
const
|
|
69
|
+
var Z;
|
|
70
|
+
const Y = a || {}, {
|
|
71
71
|
baseUrl: R,
|
|
72
|
-
fetch:
|
|
73
|
-
Request:
|
|
74
|
-
headers:
|
|
72
|
+
fetch: x = n,
|
|
73
|
+
Request: I = t,
|
|
74
|
+
headers: C,
|
|
75
75
|
params: v = {},
|
|
76
|
-
parseAs:
|
|
76
|
+
parseAs: A = "json",
|
|
77
77
|
querySerializer: S,
|
|
78
|
-
bodySerializer:
|
|
79
|
-
body:
|
|
80
|
-
middleware:
|
|
81
|
-
} =
|
|
78
|
+
bodySerializer: k = s != null ? s : xe,
|
|
79
|
+
body: F,
|
|
80
|
+
middleware: u = []
|
|
81
|
+
} = Y, y = G(Y, [
|
|
82
82
|
"baseUrl",
|
|
83
83
|
"fetch",
|
|
84
84
|
"Request",
|
|
@@ -90,58 +90,58 @@ function ve(e) {
|
|
|
90
90
|
"body",
|
|
91
91
|
"middleware"
|
|
92
92
|
]);
|
|
93
|
-
let
|
|
94
|
-
R && (
|
|
95
|
-
let
|
|
96
|
-
S && (
|
|
97
|
-
const
|
|
98
|
-
|
|
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,
|
|
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
|
-
|
|
105
|
-
),
|
|
104
|
+
se(i, C, v.header)
|
|
105
|
+
), fe = se(
|
|
106
106
|
// with no body, we should not to set Content-Type
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
P === void 0 || // if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
108
|
+
P instanceof FormData ? {} : {
|
|
109
109
|
"Content-Type": "application/json"
|
|
110
110
|
},
|
|
111
111
|
i,
|
|
112
|
-
|
|
112
|
+
C,
|
|
113
113
|
v.header
|
|
114
|
-
), D = [...d, ...
|
|
114
|
+
), D = [...d, ...u], de = E(b(b({
|
|
115
115
|
redirect: "follow"
|
|
116
|
-
}, f),
|
|
117
|
-
body:
|
|
118
|
-
headers:
|
|
116
|
+
}, f), y), {
|
|
117
|
+
body: P,
|
|
118
|
+
headers: fe
|
|
119
119
|
});
|
|
120
|
-
let
|
|
121
|
-
Se(
|
|
120
|
+
let L, N, T = new I(
|
|
121
|
+
Se(l, { baseUrl: h, params: v, querySerializer: H }),
|
|
122
122
|
de
|
|
123
123
|
), m;
|
|
124
|
-
for (const w in
|
|
125
|
-
w in T || (T[w] =
|
|
124
|
+
for (const w in y)
|
|
125
|
+
w in T || (T[w] = y[w]);
|
|
126
126
|
if (D.length) {
|
|
127
|
-
|
|
128
|
-
baseUrl:
|
|
129
|
-
fetch:
|
|
130
|
-
parseAs:
|
|
131
|
-
querySerializer:
|
|
132
|
-
bodySerializer:
|
|
127
|
+
L = Ee(), N = Object.freeze({
|
|
128
|
+
baseUrl: h,
|
|
129
|
+
fetch: x,
|
|
130
|
+
parseAs: A,
|
|
131
|
+
querySerializer: H,
|
|
132
|
+
bodySerializer: k
|
|
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:
|
|
138
|
+
schemaPath: l,
|
|
139
139
|
params: v,
|
|
140
|
-
options:
|
|
141
|
-
id:
|
|
140
|
+
options: N,
|
|
141
|
+
id: L
|
|
142
142
|
});
|
|
143
143
|
if (p)
|
|
144
|
-
if (p instanceof
|
|
144
|
+
if (p instanceof I)
|
|
145
145
|
T = p;
|
|
146
146
|
else if (p instanceof Response) {
|
|
147
147
|
m = p;
|
|
@@ -152,28 +152,28 @@ function ve(e) {
|
|
|
152
152
|
}
|
|
153
153
|
if (!m) {
|
|
154
154
|
try {
|
|
155
|
-
m = yield
|
|
155
|
+
m = yield x(T, c);
|
|
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
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
160
|
+
const M = D[q];
|
|
161
|
+
if (M && typeof M == "object" && typeof M.onError == "function") {
|
|
162
|
+
const O = yield M.onError({
|
|
163
163
|
request: T,
|
|
164
164
|
error: p,
|
|
165
|
-
schemaPath:
|
|
165
|
+
schemaPath: l,
|
|
166
166
|
params: v,
|
|
167
|
-
options:
|
|
168
|
-
id:
|
|
167
|
+
options: N,
|
|
168
|
+
id: L
|
|
169
169
|
});
|
|
170
|
-
if (
|
|
171
|
-
if (
|
|
172
|
-
p = void 0, m =
|
|
170
|
+
if (O) {
|
|
171
|
+
if (O instanceof Response) {
|
|
172
|
+
p = void 0, m = O;
|
|
173
173
|
break;
|
|
174
174
|
}
|
|
175
|
-
if (
|
|
176
|
-
p =
|
|
175
|
+
if (O instanceof Error) {
|
|
176
|
+
p = O;
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
179
179
|
throw new Error("onError: must return new Response() or instance of Error");
|
|
@@ -190,10 +190,10 @@ function ve(e) {
|
|
|
190
190
|
const q = yield p.onResponse({
|
|
191
191
|
request: T,
|
|
192
192
|
response: m,
|
|
193
|
-
schemaPath:
|
|
193
|
+
schemaPath: l,
|
|
194
194
|
params: v,
|
|
195
|
-
options:
|
|
196
|
-
id:
|
|
195
|
+
options: N,
|
|
196
|
+
id: L
|
|
197
197
|
});
|
|
198
198
|
if (q) {
|
|
199
199
|
if (!(q instanceof Response))
|
|
@@ -206,54 +206,54 @@ function ve(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
|
|
210
|
-
let
|
|
209
|
+
return A === "stream" ? { data: m.body, response: m } : { data: yield m[A](), response: m };
|
|
210
|
+
let B = yield m.text();
|
|
211
211
|
try {
|
|
212
|
-
|
|
212
|
+
B = JSON.parse(B);
|
|
213
213
|
} catch (w) {
|
|
214
214
|
}
|
|
215
|
-
return { error:
|
|
215
|
+
return { error: B, response: m };
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
return {
|
|
219
|
-
request(
|
|
220
|
-
return g(a, E(b({}, R), { method:
|
|
219
|
+
request(l, a, R) {
|
|
220
|
+
return g(a, E(b({}, R), { method: l.toUpperCase() }));
|
|
221
221
|
},
|
|
222
222
|
/** Call a GET endpoint */
|
|
223
|
-
GET(
|
|
224
|
-
return g(
|
|
223
|
+
GET(l, a) {
|
|
224
|
+
return g(l, E(b({}, a), { method: "GET" }));
|
|
225
225
|
},
|
|
226
226
|
/** Call a PUT endpoint */
|
|
227
|
-
PUT(
|
|
228
|
-
return g(
|
|
227
|
+
PUT(l, a) {
|
|
228
|
+
return g(l, E(b({}, a), { method: "PUT" }));
|
|
229
229
|
},
|
|
230
230
|
/** Call a POST endpoint */
|
|
231
|
-
POST(
|
|
232
|
-
return g(
|
|
231
|
+
POST(l, a) {
|
|
232
|
+
return g(l, E(b({}, a), { method: "POST" }));
|
|
233
233
|
},
|
|
234
234
|
/** Call a DELETE endpoint */
|
|
235
|
-
DELETE(
|
|
236
|
-
return g(
|
|
235
|
+
DELETE(l, a) {
|
|
236
|
+
return g(l, E(b({}, a), { method: "DELETE" }));
|
|
237
237
|
},
|
|
238
238
|
/** Call a OPTIONS endpoint */
|
|
239
|
-
OPTIONS(
|
|
240
|
-
return g(
|
|
239
|
+
OPTIONS(l, a) {
|
|
240
|
+
return g(l, E(b({}, a), { method: "OPTIONS" }));
|
|
241
241
|
},
|
|
242
242
|
/** Call a HEAD endpoint */
|
|
243
|
-
HEAD(
|
|
244
|
-
return g(
|
|
243
|
+
HEAD(l, a) {
|
|
244
|
+
return g(l, E(b({}, a), { method: "HEAD" }));
|
|
245
245
|
},
|
|
246
246
|
/** Call a PATCH endpoint */
|
|
247
|
-
PATCH(
|
|
248
|
-
return g(
|
|
247
|
+
PATCH(l, a) {
|
|
248
|
+
return g(l, E(b({}, a), { method: "PATCH" }));
|
|
249
249
|
},
|
|
250
250
|
/** Call a TRACE endpoint */
|
|
251
|
-
TRACE(
|
|
252
|
-
return g(
|
|
251
|
+
TRACE(l, a) {
|
|
252
|
+
return g(l, E(b({}, a), { method: "TRACE" }));
|
|
253
253
|
},
|
|
254
254
|
/** Register middleware */
|
|
255
|
-
use(...
|
|
256
|
-
for (const a of
|
|
255
|
+
use(...l) {
|
|
256
|
+
for (const a of l)
|
|
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 ve(e) {
|
|
|
261
261
|
}
|
|
262
262
|
},
|
|
263
263
|
/** Unregister middleware */
|
|
264
|
-
eject(...
|
|
265
|
-
for (const a of
|
|
264
|
+
eject(...l) {
|
|
265
|
+
for (const a of l) {
|
|
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
|
|
272
|
+
function _(e, r, t) {
|
|
273
273
|
if (r == null)
|
|
274
274
|
return "";
|
|
275
275
|
if (typeof r == "object")
|
|
@@ -278,7 +278,7 @@ function B(e, r, t) {
|
|
|
278
278
|
);
|
|
279
279
|
return `${e}=${(t == null ? void 0 : t.allowReserved) === !0 ? r : encodeURIComponent(r)}`;
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function ce(e, r, t) {
|
|
282
282
|
if (!r || typeof r != "object")
|
|
283
283
|
return "";
|
|
284
284
|
const n = [], o = {
|
|
@@ -287,8 +287,8 @@ function le(e, r, t) {
|
|
|
287
287
|
matrix: ";"
|
|
288
288
|
}[t.style] || "&";
|
|
289
289
|
if (t.style !== "deepObject" && t.explode === !1) {
|
|
290
|
-
for (const
|
|
291
|
-
n.push(
|
|
290
|
+
for (const c in r)
|
|
291
|
+
n.push(c, t.allowReserved === !0 ? r[c] : encodeURIComponent(r[c]));
|
|
292
292
|
const i = n.join(",");
|
|
293
293
|
switch (t.style) {
|
|
294
294
|
case "form":
|
|
@@ -302,17 +302,17 @@ function le(e, r, t) {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
for (const i in r) {
|
|
305
|
-
const
|
|
306
|
-
n.push(
|
|
305
|
+
const c = t.style === "deepObject" ? `${e}[${i}]` : i;
|
|
306
|
+
n.push(_(c, 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
|
|
311
|
+
function le(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((
|
|
315
|
+
const s = { form: ",", spaceDelimited: "%20", pipeDelimited: "|" }[t.style] || ",", i = (t.allowReserved === !0 ? r : r.map((c) => encodeURIComponent(c))).join(s);
|
|
316
316
|
switch (t.style) {
|
|
317
317
|
case "simple":
|
|
318
318
|
return i;
|
|
@@ -328,10 +328,10 @@ function ue(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(
|
|
331
|
+
t.style === "simple" || t.style === "label" ? o.push(t.allowReserved === !0 ? s : encodeURIComponent(s)) : o.push(_(e, s, t));
|
|
332
332
|
return t.style === "label" || t.style === "matrix" ? `${n}${o.join(n)}` : o.join(n);
|
|
333
333
|
}
|
|
334
|
-
function
|
|
334
|
+
function ne(e) {
|
|
335
335
|
return function(t) {
|
|
336
336
|
const n = [];
|
|
337
337
|
if (t && typeof t == "object")
|
|
@@ -342,7 +342,7 @@ function se(e) {
|
|
|
342
342
|
if (s.length === 0)
|
|
343
343
|
continue;
|
|
344
344
|
n.push(
|
|
345
|
-
|
|
345
|
+
le(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 se(e) {
|
|
|
353
353
|
}
|
|
354
354
|
if (typeof s == "object") {
|
|
355
355
|
n.push(
|
|
356
|
-
|
|
356
|
+
ce(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 se(e) {
|
|
|
362
362
|
);
|
|
363
363
|
continue;
|
|
364
364
|
}
|
|
365
|
-
n.push(
|
|
365
|
+
n.push(_(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,
|
|
376
|
-
if (s.endsWith("*") && (i = !0, s = s.substring(0, s.length - 1)), s.startsWith(".") ? (
|
|
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)
|
|
377
377
|
continue;
|
|
378
378
|
const f = r[s];
|
|
379
379
|
if (Array.isArray(f)) {
|
|
380
|
-
t = t.replace(o,
|
|
380
|
+
t = t.replace(o, le(s, f, { style: c, explode: i }));
|
|
381
381
|
continue;
|
|
382
382
|
}
|
|
383
383
|
if (typeof f == "object") {
|
|
384
|
-
t = t.replace(o,
|
|
384
|
+
t = t.replace(o, ce(s, f, { style: c, explode: i }));
|
|
385
385
|
continue;
|
|
386
386
|
}
|
|
387
|
-
if (
|
|
388
|
-
t = t.replace(o, `;${
|
|
387
|
+
if (c === "matrix") {
|
|
388
|
+
t = t.replace(o, `;${_(s, f)}`);
|
|
389
389
|
continue;
|
|
390
390
|
}
|
|
391
|
-
t = t.replace(o,
|
|
391
|
+
t = t.replace(o, c === "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
|
|
406
|
+
function se(...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 oe(...e) {
|
|
|
419
419
|
}
|
|
420
420
|
return r;
|
|
421
421
|
}
|
|
422
|
-
function
|
|
422
|
+
function oe(e) {
|
|
423
423
|
return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
|
|
424
424
|
}
|
|
425
|
-
const
|
|
425
|
+
const ie = (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 ae = (e, r, t) => {
|
|
|
431
431
|
} catch (n) {
|
|
432
432
|
return null;
|
|
433
433
|
}
|
|
434
|
-
},
|
|
434
|
+
}, V = (e, r, t) => {
|
|
435
435
|
try {
|
|
436
436
|
const n = `${t}_${e}`, o = {
|
|
437
437
|
data: r,
|
|
@@ -441,91 +441,90 @@ const ae = (e, r, t) => {
|
|
|
441
441
|
} catch (n) {
|
|
442
442
|
console.warn("Failed to cache dismissible item:", n);
|
|
443
443
|
}
|
|
444
|
-
},
|
|
444
|
+
}, ae = (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
|
-
},
|
|
451
|
+
}, ue = pe(
|
|
452
452
|
null
|
|
453
|
-
),
|
|
454
|
-
const e = we(
|
|
453
|
+
), Ae = () => {
|
|
454
|
+
const e = we(ue);
|
|
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
|
-
},
|
|
461
|
-
var k;
|
|
460
|
+
}, $e = "dismissible", je = (e, r = {}) => {
|
|
462
461
|
const {
|
|
463
462
|
initialData: t,
|
|
464
463
|
enableCache: n = !0,
|
|
465
|
-
cachePrefix: o =
|
|
464
|
+
cachePrefix: o = $e,
|
|
466
465
|
cacheExpiration: s
|
|
467
|
-
} = r, i =
|
|
466
|
+
} = r, i = Ae(), { userId: c } = i, f = X(() => Re({
|
|
468
467
|
baseUrl: i.baseUrl,
|
|
469
468
|
headers: {}
|
|
470
|
-
}), [i.baseUrl]), d =
|
|
469
|
+
}), [i.baseUrl]), d = X(() => `${c}-${e}`, [c, e]), g = W({
|
|
471
470
|
enableCache: n,
|
|
472
471
|
cachePrefix: o,
|
|
473
472
|
cacheExpiration: s
|
|
474
|
-
}),
|
|
473
|
+
}), j = W(e), l = W(d), a = W(null), [R, x] = z(!1), [I, C] = z(), [v, A] = z(() => {
|
|
475
474
|
if (t) return t;
|
|
476
475
|
if (n) {
|
|
477
|
-
const
|
|
476
|
+
const u = ie(
|
|
478
477
|
d,
|
|
479
478
|
o,
|
|
480
479
|
s
|
|
481
480
|
);
|
|
482
|
-
if (
|
|
481
|
+
if (u) return u;
|
|
483
482
|
}
|
|
484
|
-
}), S =
|
|
483
|
+
}), S = K(() => $(null, null, function* () {
|
|
485
484
|
var y;
|
|
486
485
|
if (n) {
|
|
487
|
-
const h =
|
|
486
|
+
const h = ie(
|
|
488
487
|
d,
|
|
489
488
|
o,
|
|
490
489
|
s
|
|
491
490
|
);
|
|
492
491
|
if (h != null && h.dismissedAt) {
|
|
493
|
-
|
|
492
|
+
A(h), x(!1);
|
|
494
493
|
return;
|
|
495
494
|
}
|
|
496
495
|
}
|
|
497
496
|
(y = a.current) == null || y.abort();
|
|
498
|
-
const
|
|
499
|
-
a.current =
|
|
497
|
+
const u = new AbortController();
|
|
498
|
+
a.current = u, x(!0), C(void 0);
|
|
500
499
|
try {
|
|
501
|
-
const h = yield i.getAuthHeaders(), { data: H, error:
|
|
500
|
+
const h = yield i.getAuthHeaders(), { data: H, error: P } = yield f.GET(
|
|
502
501
|
"/v1/users/{userId}/items/{itemId}",
|
|
503
502
|
{
|
|
504
503
|
params: {
|
|
505
504
|
path: {
|
|
506
|
-
userId:
|
|
505
|
+
userId: c,
|
|
507
506
|
itemId: e
|
|
508
507
|
}
|
|
509
508
|
},
|
|
510
509
|
headers: h,
|
|
511
|
-
signal:
|
|
510
|
+
signal: u.signal
|
|
512
511
|
}
|
|
513
512
|
);
|
|
514
|
-
if (
|
|
513
|
+
if (P || !H)
|
|
515
514
|
throw new Error("Failed to fetch dismissible item");
|
|
516
|
-
|
|
515
|
+
A(H.data), n && V(d, H.data, o);
|
|
517
516
|
} catch (h) {
|
|
518
517
|
if (h instanceof Error && h.name === "AbortError")
|
|
519
518
|
return;
|
|
520
|
-
|
|
519
|
+
C(
|
|
521
520
|
h instanceof Error ? h : new Error("Unknown error occurred")
|
|
522
521
|
);
|
|
523
522
|
} finally {
|
|
524
|
-
|
|
523
|
+
x(!1);
|
|
525
524
|
}
|
|
526
525
|
}), [
|
|
527
526
|
e,
|
|
528
|
-
|
|
527
|
+
c,
|
|
529
528
|
d,
|
|
530
529
|
n,
|
|
531
530
|
o,
|
|
@@ -533,77 +532,77 @@ const ae = (e, r, t) => {
|
|
|
533
532
|
f,
|
|
534
533
|
i
|
|
535
534
|
]);
|
|
536
|
-
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
}, [e, d, t, S]),
|
|
540
|
-
var
|
|
541
|
-
(
|
|
542
|
-
}, []),
|
|
543
|
-
const
|
|
544
|
-
(
|
|
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 = {
|
|
545
544
|
enableCache: n,
|
|
546
545
|
cachePrefix: o,
|
|
547
546
|
cacheExpiration: s
|
|
548
547
|
}, S());
|
|
549
548
|
}, [n, o, s, d, S]);
|
|
550
|
-
const
|
|
551
|
-
|
|
549
|
+
const k = K(() => $(null, null, function* () {
|
|
550
|
+
C(void 0);
|
|
552
551
|
try {
|
|
553
|
-
const
|
|
552
|
+
const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.DELETE(
|
|
554
553
|
"/v1/users/{userId}/items/{itemId}",
|
|
555
554
|
{
|
|
556
555
|
params: {
|
|
557
556
|
path: {
|
|
558
|
-
userId:
|
|
557
|
+
userId: c,
|
|
559
558
|
itemId: e
|
|
560
559
|
}
|
|
561
560
|
},
|
|
562
|
-
headers:
|
|
561
|
+
headers: u
|
|
563
562
|
}
|
|
564
563
|
);
|
|
565
564
|
if (h || !y)
|
|
566
565
|
throw new Error("Failed to dismiss item");
|
|
567
|
-
|
|
568
|
-
} catch (
|
|
569
|
-
throw
|
|
570
|
-
|
|
571
|
-
),
|
|
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;
|
|
572
571
|
}
|
|
573
572
|
}), [
|
|
574
573
|
e,
|
|
575
|
-
|
|
574
|
+
c,
|
|
576
575
|
d,
|
|
577
576
|
n,
|
|
578
577
|
o,
|
|
579
578
|
f,
|
|
580
579
|
i
|
|
581
|
-
]),
|
|
582
|
-
|
|
580
|
+
]), F = K(() => $(null, null, function* () {
|
|
581
|
+
C(void 0);
|
|
583
582
|
try {
|
|
584
|
-
const
|
|
583
|
+
const u = yield i.getAuthHeaders(), { data: y, error: h } = yield f.POST(
|
|
585
584
|
"/v1/users/{userId}/items/{itemId}",
|
|
586
585
|
{
|
|
587
586
|
params: {
|
|
588
587
|
path: {
|
|
589
|
-
userId:
|
|
588
|
+
userId: c,
|
|
590
589
|
itemId: e
|
|
591
590
|
}
|
|
592
591
|
},
|
|
593
|
-
headers:
|
|
592
|
+
headers: u
|
|
594
593
|
}
|
|
595
594
|
);
|
|
596
595
|
if (h || !y)
|
|
597
596
|
throw new Error("Failed to restore item");
|
|
598
|
-
|
|
599
|
-
} catch (
|
|
600
|
-
throw
|
|
601
|
-
|
|
602
|
-
),
|
|
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;
|
|
603
602
|
}
|
|
604
603
|
}), [
|
|
605
604
|
e,
|
|
606
|
-
|
|
605
|
+
c,
|
|
607
606
|
d,
|
|
608
607
|
n,
|
|
609
608
|
o,
|
|
@@ -611,11 +610,11 @@ const ae = (e, r, t) => {
|
|
|
611
610
|
i
|
|
612
611
|
]);
|
|
613
612
|
return {
|
|
614
|
-
|
|
615
|
-
dismiss:
|
|
616
|
-
restore:
|
|
613
|
+
dismissedAt: v == null ? void 0 : v.dismissedAt,
|
|
614
|
+
dismiss: k,
|
|
615
|
+
restore: F,
|
|
617
616
|
isLoading: R,
|
|
618
|
-
error:
|
|
617
|
+
error: I,
|
|
619
618
|
item: v
|
|
620
619
|
};
|
|
621
620
|
}, 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(
|
|
@@ -635,35 +634,33 @@ const ae = (e, r, t) => {
|
|
|
635
634
|
ErrorComponent: o = Te,
|
|
636
635
|
DismissButtonComponent: s = Ue,
|
|
637
636
|
enableCache: i,
|
|
638
|
-
cachePrefix:
|
|
637
|
+
cachePrefix: c,
|
|
639
638
|
cacheExpiration: f,
|
|
640
639
|
ignoreErrors: d = !1
|
|
641
640
|
}) => {
|
|
642
|
-
const {
|
|
641
|
+
const { dismissedAt: g, isLoading: j, error: l, dismiss: a } = je(
|
|
643
642
|
e,
|
|
644
643
|
{
|
|
645
644
|
enableCache: i,
|
|
646
|
-
cachePrefix:
|
|
645
|
+
cachePrefix: c,
|
|
647
646
|
cacheExpiration: f
|
|
648
647
|
}
|
|
649
|
-
), [R,
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const O = () => $(null, null, function* () {
|
|
654
|
-
C(!0);
|
|
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);
|
|
655
652
|
try {
|
|
656
653
|
yield a(), t == null || t();
|
|
657
|
-
} catch (
|
|
658
|
-
|
|
654
|
+
} catch (A) {
|
|
655
|
+
x(!1);
|
|
659
656
|
}
|
|
660
657
|
});
|
|
661
|
-
return
|
|
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: [
|
|
662
659
|
/* @__PURE__ */ U("div", { className: "dismissible-content", children: r }),
|
|
663
660
|
s ? /* @__PURE__ */ U(
|
|
664
661
|
s,
|
|
665
662
|
{
|
|
666
|
-
onDismiss:
|
|
663
|
+
onDismiss: v,
|
|
667
664
|
ariaLabel: `Dismiss ${e}`
|
|
668
665
|
}
|
|
669
666
|
) : null
|
|
@@ -681,7 +678,7 @@ const ae = (e, r, t) => {
|
|
|
681
678
|
}), qe = (e) => $(null, null, function* () {
|
|
682
679
|
const r = yield He(e);
|
|
683
680
|
return r ? { Authorization: `Bearer ${r}` } : {};
|
|
684
|
-
}),
|
|
681
|
+
}), Ie = (e) => {
|
|
685
682
|
try {
|
|
686
683
|
const r = new URL(e), t = r.hostname === "localhost" || r.hostname === "127.0.0.1" || r.hostname === "[::1]", n = r.protocol === "https:";
|
|
687
684
|
return { isSecure: n || t, isLocalhost: t, isHttps: n };
|
|
@@ -694,11 +691,11 @@ const ae = (e, r, t) => {
|
|
|
694
691
|
baseUrl: t,
|
|
695
692
|
children: n
|
|
696
693
|
}) => {
|
|
697
|
-
const { isSecure: o } =
|
|
694
|
+
const { isSecure: o } = Ie(t);
|
|
698
695
|
o || console.warn(
|
|
699
696
|
`[dismissible] Insecure baseUrl "${t}". Use https:// in production (or localhost for development). JWT tokens may be exposed over insecure connections.`
|
|
700
697
|
);
|
|
701
|
-
const s =
|
|
698
|
+
const s = X(
|
|
702
699
|
() => ({
|
|
703
700
|
userId: e,
|
|
704
701
|
jwt: r,
|
|
@@ -709,14 +706,14 @@ const ae = (e, r, t) => {
|
|
|
709
706
|
}),
|
|
710
707
|
[e, r, t]
|
|
711
708
|
);
|
|
712
|
-
return /* @__PURE__ */ U(
|
|
709
|
+
return /* @__PURE__ */ U(ue.Provider, { value: s, children: n });
|
|
713
710
|
};
|
|
714
711
|
export {
|
|
715
712
|
ke as Dismissible,
|
|
716
|
-
|
|
713
|
+
ue as DismissibleContext,
|
|
717
714
|
Fe as DismissibleProvider,
|
|
718
715
|
qe as getAuthHeaders,
|
|
719
716
|
He as resolveJwt,
|
|
720
|
-
|
|
717
|
+
Ae as useDismissibleContext,
|
|
721
718
|
je as useDismissibleItem
|
|
722
719
|
};
|