@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.
- package/README.md +195 -55
- package/dist/config/api.config.d.ts +14 -0
- package/dist/dismissible-client.es.js +208 -205
- package/dist/dismissible-client.umd.js +1 -1
- package/dist/hooks/useDismissibleItem.d.ts +14 -16
- package/dist/root.d.ts +5 -0
- package/package.json +16 -17
- package/CHANGELOG.md +0 -12
|
@@ -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 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
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var t of
|
|
10
|
-
|
|
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
|
|
13
|
+
var Q = (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
|
+
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
|
-
|
|
25
|
+
l(t.next(f));
|
|
26
26
|
} catch (d) {
|
|
27
27
|
o(d);
|
|
28
28
|
}
|
|
29
29
|
}, i = (f) => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
l(t.throw(f));
|
|
32
32
|
} catch (d) {
|
|
33
33
|
o(d);
|
|
34
34
|
}
|
|
35
|
-
},
|
|
36
|
-
|
|
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
|
|
40
|
-
const ge = /\{[^{}]+\}/g,
|
|
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
|
|
44
|
+
function Re() {
|
|
45
45
|
return Math.random().toString(36).slice(2, 11);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
let
|
|
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:
|
|
56
|
-
} =
|
|
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
|
-
|
|
65
|
+
l = Ee() ? l : void 0, r = ie(r);
|
|
66
66
|
const d = [];
|
|
67
|
-
function g(
|
|
67
|
+
function g(u, a) {
|
|
68
68
|
return $(this, null, function* () {
|
|
69
|
-
var
|
|
70
|
-
const
|
|
69
|
+
var ee;
|
|
70
|
+
const Z = a || {}, {
|
|
71
71
|
baseUrl: R,
|
|
72
|
-
fetch:
|
|
73
|
-
Request:
|
|
74
|
-
headers:
|
|
72
|
+
fetch: C = n,
|
|
73
|
+
Request: O = t,
|
|
74
|
+
headers: x,
|
|
75
75
|
params: v = {},
|
|
76
|
-
parseAs:
|
|
76
|
+
parseAs: j = "json",
|
|
77
77
|
querySerializer: S,
|
|
78
|
-
bodySerializer:
|
|
79
|
-
body:
|
|
80
|
-
middleware:
|
|
81
|
-
} =
|
|
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
|
|
94
|
-
R && (
|
|
95
|
-
let
|
|
96
|
-
S && (
|
|
97
|
-
const
|
|
98
|
-
|
|
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
|
-
|
|
105
|
-
),
|
|
104
|
+
oe(i, x, v.header)
|
|
105
|
+
), G = oe(
|
|
106
106
|
// with no body, we should not to set Content-Type
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
112
|
+
x,
|
|
113
113
|
v.header
|
|
114
|
-
), D = [...d, ...
|
|
114
|
+
), D = [...d, ...k], de = E(b(b({
|
|
115
115
|
redirect: "follow"
|
|
116
|
-
}, f),
|
|
117
|
-
body:
|
|
118
|
-
headers:
|
|
116
|
+
}, f), c), {
|
|
117
|
+
body: H,
|
|
118
|
+
headers: G
|
|
119
119
|
});
|
|
120
|
-
let
|
|
121
|
-
Se(
|
|
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
|
|
125
|
-
w in T || (T[w] =
|
|
124
|
+
for (const w in c)
|
|
125
|
+
w in T || (T[w] = c[w]);
|
|
126
126
|
if (D.length) {
|
|
127
|
-
|
|
128
|
-
baseUrl:
|
|
129
|
-
fetch:
|
|
130
|
-
parseAs:
|
|
131
|
-
querySerializer:
|
|
132
|
-
bodySerializer:
|
|
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:
|
|
138
|
+
schemaPath: u,
|
|
139
139
|
params: v,
|
|
140
|
-
options:
|
|
141
|
-
id:
|
|
140
|
+
options: L,
|
|
141
|
+
id: F
|
|
142
142
|
});
|
|
143
143
|
if (p)
|
|
144
|
-
if (p instanceof
|
|
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
|
|
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
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
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:
|
|
165
|
+
schemaPath: u,
|
|
166
166
|
params: v,
|
|
167
|
-
options:
|
|
168
|
-
id:
|
|
167
|
+
options: L,
|
|
168
|
+
id: F
|
|
169
169
|
});
|
|
170
|
-
if (
|
|
171
|
-
if (
|
|
172
|
-
p = void 0, m =
|
|
170
|
+
if (I) {
|
|
171
|
+
if (I instanceof Response) {
|
|
172
|
+
p = void 0, m = I;
|
|
173
173
|
break;
|
|
174
174
|
}
|
|
175
|
-
if (
|
|
176
|
-
p =
|
|
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:
|
|
193
|
+
schemaPath: u,
|
|
194
194
|
params: v,
|
|
195
|
-
options:
|
|
196
|
-
id:
|
|
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
|
|
210
|
-
let
|
|
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
|
-
|
|
212
|
+
K = JSON.parse(K);
|
|
213
213
|
} catch (w) {
|
|
214
214
|
}
|
|
215
|
-
return { error:
|
|
215
|
+
return { error: K, response: m };
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
return {
|
|
219
|
-
request(
|
|
220
|
-
return g(a, E(b({}, R), { method:
|
|
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(
|
|
224
|
-
return g(
|
|
223
|
+
GET(u, a) {
|
|
224
|
+
return g(u, E(b({}, a), { method: "GET" }));
|
|
225
225
|
},
|
|
226
226
|
/** Call a PUT endpoint */
|
|
227
|
-
PUT(
|
|
228
|
-
return g(
|
|
227
|
+
PUT(u, a) {
|
|
228
|
+
return g(u, E(b({}, a), { method: "PUT" }));
|
|
229
229
|
},
|
|
230
230
|
/** Call a POST endpoint */
|
|
231
|
-
POST(
|
|
232
|
-
return g(
|
|
231
|
+
POST(u, a) {
|
|
232
|
+
return g(u, E(b({}, a), { method: "POST" }));
|
|
233
233
|
},
|
|
234
234
|
/** Call a DELETE endpoint */
|
|
235
|
-
DELETE(
|
|
236
|
-
return g(
|
|
235
|
+
DELETE(u, a) {
|
|
236
|
+
return g(u, E(b({}, a), { method: "DELETE" }));
|
|
237
237
|
},
|
|
238
238
|
/** Call a OPTIONS endpoint */
|
|
239
|
-
OPTIONS(
|
|
240
|
-
return g(
|
|
239
|
+
OPTIONS(u, a) {
|
|
240
|
+
return g(u, E(b({}, a), { method: "OPTIONS" }));
|
|
241
241
|
},
|
|
242
242
|
/** Call a HEAD endpoint */
|
|
243
|
-
HEAD(
|
|
244
|
-
return g(
|
|
243
|
+
HEAD(u, a) {
|
|
244
|
+
return g(u, E(b({}, a), { method: "HEAD" }));
|
|
245
245
|
},
|
|
246
246
|
/** Call a PATCH endpoint */
|
|
247
|
-
PATCH(
|
|
248
|
-
return g(
|
|
247
|
+
PATCH(u, a) {
|
|
248
|
+
return g(u, E(b({}, a), { method: "PATCH" }));
|
|
249
249
|
},
|
|
250
250
|
/** Call a TRACE endpoint */
|
|
251
|
-
TRACE(
|
|
252
|
-
return g(
|
|
251
|
+
TRACE(u, a) {
|
|
252
|
+
return g(u, E(b({}, a), { method: "TRACE" }));
|
|
253
253
|
},
|
|
254
254
|
/** Register middleware */
|
|
255
|
-
use(...
|
|
256
|
-
for (const a of
|
|
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(...
|
|
265
|
-
for (const a of
|
|
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
|
|
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
|
|
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
|
|
291
|
-
n.push(
|
|
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
|
|
306
|
-
n.push(
|
|
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
|
|
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((
|
|
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(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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,
|
|
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, 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,
|
|
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,
|
|
384
|
+
t = t.replace(o, le(s, f, { style: l, explode: i }));
|
|
385
385
|
continue;
|
|
386
386
|
}
|
|
387
|
-
if (
|
|
388
|
-
t = t.replace(o, `;${
|
|
387
|
+
if (l === "matrix") {
|
|
388
|
+
t = t.replace(o, `;${B(s, f)}`);
|
|
389
389
|
continue;
|
|
390
390
|
}
|
|
391
|
-
t = t.replace(o,
|
|
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
|
|
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
|
|
422
|
+
function ie(e) {
|
|
423
423
|
return e.endsWith("/") ? e.substring(0, e.length - 1) : e;
|
|
424
424
|
}
|
|
425
|
-
const
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
451
|
+
}, fe = pe(
|
|
452
452
|
null
|
|
453
|
-
),
|
|
454
|
-
const e = we(
|
|
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
|
-
},
|
|
460
|
+
}, Ae = "dismissible", je = (e, r = {}) => {
|
|
461
|
+
var k;
|
|
461
462
|
const {
|
|
462
463
|
initialData: t,
|
|
463
464
|
enableCache: n = !0,
|
|
464
|
-
cachePrefix: o =
|
|
465
|
+
cachePrefix: o = Ae,
|
|
465
466
|
cacheExpiration: s
|
|
466
|
-
} = r, i =
|
|
467
|
+
} = r, i = $e(), { userId: l } = i, f = Y(() => ve({
|
|
467
468
|
baseUrl: i.baseUrl,
|
|
468
469
|
headers: {}
|
|
469
|
-
}), [i.baseUrl]), d =
|
|
470
|
+
}), [i.baseUrl]), d = Y(() => `${l}-${e}`, [l, e]), g = J({
|
|
470
471
|
enableCache: n,
|
|
471
472
|
cachePrefix: o,
|
|
472
473
|
cacheExpiration: s
|
|
473
|
-
}),
|
|
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
|
|
477
|
+
const c = ae(
|
|
477
478
|
d,
|
|
478
479
|
o,
|
|
479
480
|
s
|
|
480
481
|
);
|
|
481
|
-
if (
|
|
482
|
+
if (c) return c;
|
|
482
483
|
}
|
|
483
|
-
}), S =
|
|
484
|
+
}), S = V(() => $(null, null, function* () {
|
|
484
485
|
var y;
|
|
485
486
|
if (n) {
|
|
486
|
-
const h =
|
|
487
|
+
const h = ae(
|
|
487
488
|
d,
|
|
488
489
|
o,
|
|
489
490
|
s
|
|
490
491
|
);
|
|
491
492
|
if (h != null && h.dismissedAt) {
|
|
492
|
-
|
|
493
|
+
j(h), C(!1);
|
|
493
494
|
return;
|
|
494
495
|
}
|
|
495
496
|
}
|
|
496
497
|
(y = a.current) == null || y.abort();
|
|
497
|
-
const
|
|
498
|
-
a.current =
|
|
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:
|
|
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:
|
|
506
|
+
userId: l,
|
|
506
507
|
itemId: e
|
|
507
508
|
}
|
|
508
509
|
},
|
|
509
510
|
headers: h,
|
|
510
|
-
signal:
|
|
511
|
+
signal: c.signal
|
|
511
512
|
}
|
|
512
513
|
);
|
|
513
|
-
if (
|
|
514
|
+
if (G || !H)
|
|
514
515
|
throw new Error("Failed to fetch dismissible item");
|
|
515
|
-
|
|
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
|
-
|
|
520
|
+
x(
|
|
520
521
|
h instanceof Error ? h : new Error("Unknown error occurred")
|
|
521
522
|
);
|
|
522
523
|
} finally {
|
|
523
|
-
|
|
524
|
+
C(!1);
|
|
524
525
|
}
|
|
525
526
|
}), [
|
|
526
527
|
e,
|
|
527
|
-
|
|
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
|
-
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
}, [e, d, t, S]),
|
|
539
|
-
var
|
|
540
|
-
(
|
|
541
|
-
}, []),
|
|
542
|
-
const
|
|
543
|
-
(
|
|
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
|
|
550
|
-
|
|
550
|
+
const P = V(() => $(null, null, function* () {
|
|
551
|
+
x(null);
|
|
551
552
|
try {
|
|
552
|
-
const
|
|
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:
|
|
558
|
+
userId: l,
|
|
558
559
|
itemId: e
|
|
559
560
|
}
|
|
560
561
|
},
|
|
561
|
-
headers:
|
|
562
|
+
headers: c
|
|
562
563
|
}
|
|
563
564
|
);
|
|
564
565
|
if (h || !y)
|
|
565
566
|
throw new Error("Failed to dismiss item");
|
|
566
|
-
|
|
567
|
-
} catch (
|
|
568
|
-
throw
|
|
569
|
-
|
|
570
|
-
),
|
|
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
|
-
|
|
575
|
+
l,
|
|
575
576
|
d,
|
|
576
577
|
n,
|
|
577
578
|
o,
|
|
578
579
|
f,
|
|
579
580
|
i
|
|
580
|
-
]),
|
|
581
|
-
|
|
581
|
+
]), z = V(() => $(null, null, function* () {
|
|
582
|
+
x(null);
|
|
582
583
|
try {
|
|
583
|
-
const
|
|
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:
|
|
589
|
+
userId: l,
|
|
589
590
|
itemId: e
|
|
590
591
|
}
|
|
591
592
|
},
|
|
592
|
-
headers:
|
|
593
|
+
headers: c
|
|
593
594
|
}
|
|
594
595
|
);
|
|
595
596
|
if (h || !y)
|
|
596
597
|
throw new Error("Failed to restore item");
|
|
597
|
-
|
|
598
|
-
} catch (
|
|
599
|
-
throw
|
|
600
|
-
|
|
601
|
-
),
|
|
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
|
-
|
|
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
|
-
|
|
614
|
-
dismiss:
|
|
615
|
-
restore:
|
|
614
|
+
dismissedOn: (k = v == null ? void 0 : v.dismissedAt) != null ? k : null,
|
|
615
|
+
dismiss: P,
|
|
616
|
+
restore: z,
|
|
616
617
|
isLoading: R,
|
|
617
|
-
error:
|
|
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:
|
|
638
|
+
cachePrefix: l,
|
|
638
639
|
cacheExpiration: f,
|
|
639
640
|
ignoreErrors: d = !1
|
|
640
641
|
}) => {
|
|
641
|
-
const {
|
|
642
|
+
const { dismissedOn: g, isLoading: A, error: u, dismiss: a } = je(
|
|
642
643
|
e,
|
|
643
644
|
{
|
|
644
645
|
enableCache: i,
|
|
645
|
-
cachePrefix:
|
|
646
|
+
cachePrefix: l,
|
|
646
647
|
cacheExpiration: f
|
|
647
648
|
}
|
|
648
|
-
), [R,
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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 (
|
|
655
|
-
|
|
657
|
+
} catch (x) {
|
|
658
|
+
C(!1);
|
|
656
659
|
}
|
|
657
660
|
});
|
|
658
|
-
return
|
|
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:
|
|
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
|
-
}),
|
|
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 } =
|
|
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 =
|
|
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(
|
|
712
|
+
return /* @__PURE__ */ U(fe.Provider, { value: s, children: n });
|
|
710
713
|
};
|
|
711
714
|
export {
|
|
712
715
|
ke as Dismissible,
|
|
713
|
-
|
|
716
|
+
fe as DismissibleContext,
|
|
714
717
|
Fe as DismissibleProvider,
|
|
715
718
|
qe as getAuthHeaders,
|
|
716
719
|
He as resolveJwt,
|
|
717
|
-
|
|
720
|
+
$e as useDismissibleContext,
|
|
718
721
|
je as useDismissibleItem
|
|
719
722
|
};
|