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