@abyss-project/commons-front-core 18.0.0 → 18.1.1

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,595 +0,0 @@
1
- import { jsxs as p, Fragment as U, jsx as r } from "react/jsx-runtime";
2
- import { useState as h, useCallback as k, useEffect as T, useLayoutEffect as te, useId as S, useRef as ne, createContext as oe, useContext as q, useMemo as z } from "react";
3
- import O from "@mui/material/Button";
4
- import G from "@mui/material/Switch";
5
- import { styled as f } from "@mui/material/styles";
6
- import { t as R, w, p as d, d as D, D as _, S as M, a as P, u as C, b as J, h as ie, M as se, c as ae } from "./Surface-dziv23sf.js";
7
- import { useQuery as re, useMutation as ce } from "@tanstack/react-query";
8
- import { AbyssCore as W } from "@abyss-project/main";
9
- import { createPortal as de } from "react-dom";
10
- import le from "@mui/material/GlobalStyles";
11
- import ue from "@mui/material/Link";
12
- const it = "2026-11-03", x = "abyssCookieConsent", Q = 183, fe = Q * 24 * 60 * 60 * 1e3, me = Q * 24 * 60 * 60, ge = "/", ye = "Lax", pe = (e) => btoa(JSON.stringify(e)), he = (e) => {
13
- try {
14
- const t = JSON.parse(atob(decodeURIComponent(e)));
15
- return typeof t.a != "boolean" || typeof t.m != "boolean" || typeof t.d != "string" || typeof t.v != "string" ? null : t;
16
- } catch {
17
- return null;
18
- }
19
- }, X = (e, t, o = Date.now()) => {
20
- if (e.v !== t)
21
- return !1;
22
- const n = new Date(e.d).getTime();
23
- return Number.isNaN(n) ? !1 : o - n < fe;
24
- }, ke = () => typeof window > "u" ? !1 : window.location.protocol === "https:", Z = (e, t) => {
25
- const o = [
26
- `Path=${ge}`,
27
- `Max-Age=${t}`,
28
- `SameSite=${ye}`
29
- ];
30
- return e.domain && o.push(`Domain=${e.domain}`), ke() && o.push("Secure"), o.join("; ");
31
- }, be = () => {
32
- if (typeof document > "u")
33
- return null;
34
- const e = document.cookie.split(";").map((t) => t.trim()).find((t) => t.startsWith(`${x}=`));
35
- return e ? he(e.slice(x.length + 1)) : null;
36
- }, B = (e, t = {}) => {
37
- typeof document > "u" || (document.cookie = `${x}=${pe(
38
- e
39
- )}; ${Z(t, me)}`);
40
- }, ve = (e = {}) => {
41
- typeof document > "u" || (document.cookie = `${x}=; ${Z(e, 0)}`);
42
- };
43
- var $ = /* @__PURE__ */ ((e) => (e.NOOP = "noop", e.ADOPT_DB = "adopt-db", e.PUSH_COOKIE = "push-cookie", e))($ || {});
44
- const H = (e) => ({
45
- essentials: !0,
46
- analytics: e.analytics,
47
- marketing: e.marketing,
48
- decidedAt: typeof e.decidedAt == "string" ? e.decidedAt : new Date(e.decidedAt).toISOString(),
49
- consentVersion: e.consentVersion
50
- }), Ae = (e, t) => {
51
- if (!e && !t)
52
- return { action: "noop", value: null };
53
- if (!e && t)
54
- return { action: "adopt-db", value: H(t) };
55
- if (e && !t)
56
- return { action: "push-cookie", value: e };
57
- const o = new Date(e.decidedAt).getTime(), n = new Date(
58
- typeof t.decidedAt == "string" ? t.decidedAt : t.decidedAt.toISOString()
59
- ).getTime();
60
- return n > o ? { action: "adopt-db", value: H(t) } : o > n ? { action: "push-cookie", value: e } : { action: "noop", value: e };
61
- }, Se = (e) => ({
62
- essentials: !0,
63
- analytics: e.a,
64
- marketing: e.m,
65
- decidedAt: e.d,
66
- consentVersion: e.v
67
- }), j = (e) => ({
68
- a: e.analytics,
69
- m: e.marketing,
70
- d: e.decidedAt,
71
- v: e.consentVersion
72
- }), Ce = (e) => {
73
- const t = be();
74
- return !t || !X(t, e) ? null : Se(t);
75
- }, we = (e) => {
76
- const [t, o] = h(
77
- () => Ce(e.consentVersion)
78
- ), n = re({
79
- queryKey: ["cookie-consent", "me"],
80
- queryFn: async () => (await W.sdk.user.cookieConsent.get()).data.consent,
81
- enabled: e.isAuthenticated,
82
- retry: !1,
83
- refetchOnWindowFocus: !1
84
- }), s = ce({
85
- mutationFn: async (i) => (await W.sdk.user.cookieConsent.upsert({
86
- analytics: i.analytics,
87
- marketing: i.marketing,
88
- decidedAt: i.decidedAt,
89
- consentVersion: i.consentVersion
90
- })).data.consent
91
- }), a = k(
92
- (i) => {
93
- B(j(i), { domain: e.domain }), o(i), e.isAuthenticated && s.mutate(i);
94
- },
95
- [e.domain, e.isAuthenticated, s]
96
- );
97
- T(() => {
98
- if (!e.isAuthenticated || n.isLoading || n.isError)
99
- return;
100
- const i = n.data ?? null, g = i !== null && X(
101
- {
102
- a: i.analytics,
103
- m: i.marketing,
104
- // `String`, never `toISOString()`: an unreadable date must read as no choice, not throw.
105
- d: String(i.decidedAt),
106
- v: i.consentVersion
107
- },
108
- e.consentVersion
109
- ), m = Ae(t, g ? i : null);
110
- m.action === $.ADOPT_DB && m.value ? (B(j(m.value), { domain: e.domain }), o(m.value)) : m.action === $.PUSH_COOKIE && m.value && s.mutate(m.value);
111
- }, [e.isAuthenticated, n.isLoading, n.isError, n.data]);
112
- const l = k(() => {
113
- a({
114
- essentials: !0,
115
- analytics: !0,
116
- marketing: !0,
117
- decidedAt: (/* @__PURE__ */ new Date()).toISOString(),
118
- consentVersion: e.consentVersion
119
- });
120
- }, [e.consentVersion, a]), c = k(() => {
121
- a({
122
- essentials: !0,
123
- analytics: !1,
124
- marketing: !1,
125
- decidedAt: (/* @__PURE__ */ new Date()).toISOString(),
126
- consentVersion: e.consentVersion
127
- });
128
- }, [e.consentVersion, a]), u = k(
129
- (i) => {
130
- a({
131
- essentials: !0,
132
- analytics: i.analytics,
133
- marketing: i.marketing,
134
- decidedAt: (/* @__PURE__ */ new Date()).toISOString(),
135
- consentVersion: e.consentVersion
136
- });
137
- },
138
- [e.consentVersion, a]
139
- ), y = k(() => {
140
- ve({ domain: e.domain }), o(null);
141
- }, [e.domain]);
142
- return {
143
- consent: t,
144
- isResolved: t !== null,
145
- acceptAll: l,
146
- rejectAll: c,
147
- save: u,
148
- reset: y
149
- };
150
- }, Me = "https://abyss-project.fr/cgu", F = "--abyss-toast-clearance", v = "--abyss-cookie-banner-modal-clearance", A = "data-abyss-cookie-banner-host", xe = () => {
151
- const e = Array.from(document.body.children).filter(
152
- (t) => t instanceof HTMLElement && t.classList.contains("MuiModal-root") && !t.classList.contains("MuiModal-hidden") && !t.classList.contains("MuiPopover-root")
153
- );
154
- for (let t = e.length - 1; t >= 0; t -= 1) {
155
- const o = e[t], n = o.querySelector('[aria-modal="true"]');
156
- if (n !== null)
157
- return { host: o, surface: n };
158
- }
159
- return null;
160
- }, Te = () => {
161
- const [e] = h(
162
- () => typeof document > "u" ? null : document.createElement("div")
163
- ), [t, o] = h(null);
164
- return te(() => {
165
- if (e === null)
166
- return;
167
- let n = null;
168
- const s = /* @__PURE__ */ new WeakSet(), a = () => {
169
- Array.from(document.body.children).forEach((i) => {
170
- i.classList.contains("MuiModal-root") && !s.has(i) && (s.add(i), l.observe(i, {
171
- attributes: !0,
172
- attributeFilter: ["class"]
173
- }));
174
- });
175
- const c = xe(), u = (c == null ? void 0 : c.host) ?? null, y = (c == null ? void 0 : c.surface) ?? document.body;
176
- e.parentNode !== y && y.appendChild(e), e.removeAttribute("aria-hidden"), u !== n && (n == null || n.removeAttribute(A), u == null || u.setAttribute(A, ""), n = u, o(u));
177
- }, l = new MutationObserver(a);
178
- return l.observe(document.body, { childList: !0 }), a(), () => {
179
- l.disconnect(), n == null || n.removeAttribute(A), e.remove();
180
- };
181
- }, [e]), { container: e, modalHost: t };
182
- }, K = f(O)(({ theme: e }) => R(e)), Oe = f("div")(({ theme: e }) => {
183
- const { space: t, elevations: o, durations: n, easings: s } = e.design;
184
- return {
185
- position: "fixed",
186
- zIndex: e.zIndex.snackbar,
187
- // Clear of the home indicator or gesture bar of a native webview (0 elsewhere).
188
- bottom: w(M.Bottom, t[6]),
189
- right: d(t[6]),
190
- width: 420,
191
- maxWidth: `calc(100vw - ${d(2 * t[6])})`,
192
- "& > *": {
193
- boxShadow: o.overlay,
194
- animation: `cookie-consent-in ${n.slow}ms ${s.sheet}`
195
- },
196
- "@keyframes cookie-consent-in": {
197
- from: { opacity: 0, transform: `translateY(${d(t[3])})` },
198
- to: { opacity: 1, transform: "translateY(0)" }
199
- },
200
- "@media (prefers-reduced-motion: reduce)": {
201
- "& > *": { animation: "none" }
202
- },
203
- [D.down(_.Tablet)]: {
204
- bottom: w(M.Bottom, t[3]),
205
- right: w(M.Right, t[3]),
206
- left: w(M.Left, t[3]),
207
- width: "auto",
208
- maxWidth: "none"
209
- }
210
- };
211
- }), Re = f("h2")(({ theme: e }) => ({
212
- margin: 0,
213
- fontSize: d(e.design.typeScale.sectionTitle),
214
- fontWeight: P.semibold,
215
- color: e.design.tokens["text.primary"]
216
- })), Ie = f("p")(({ theme: e }) => ({
217
- margin: `${d(e.design.space[2])} 0 0`,
218
- fontSize: d(e.design.typeScale.body),
219
- color: e.design.tokens["text.secondary"]
220
- })), Ee = f(ue)(({ theme: e }) => ({
221
- alignSelf: "flex-start",
222
- marginTop: d(e.design.space[3]),
223
- fontSize: d(e.design.typeScale.body),
224
- color: e.design.tokens["accent.text"]
225
- })), $e = f("div")(({ theme: e }) => ({
226
- display: "flex",
227
- gap: d(e.design.space[2]),
228
- marginTop: d(e.design.space[4]),
229
- "& > *": { flex: 1 }
230
- })), De = f(O)(({ theme: e }) => ({
231
- ...R(e),
232
- marginTop: d(e.design.space[2]),
233
- color: e.design.tokens["text.secondary"]
234
- }));
235
- function _e({ api: e }) {
236
- const t = C(), { acceptAll: o, rejectAll: n, openPreferences: s } = e, a = S(), l = S(), c = ne(null), { container: u, modalHost: y } = Te();
237
- return T(() => {
238
- const i = c.current;
239
- if (i === null)
240
- return;
241
- const g = document.documentElement, m = () => {
242
- const L = Number.parseFloat(getComputedStyle(i).bottom), N = d(
243
- i.getBoundingClientRect().height + (Number.isNaN(L) ? 0 : L)
244
- );
245
- g.style.setProperty(F, N), y === null ? g.style.removeProperty(v) : g.style.setProperty(v, N);
246
- };
247
- m();
248
- const b = typeof ResizeObserver > "u" ? null : new ResizeObserver(m);
249
- return b == null || b.observe(i), window.addEventListener("resize", m), () => {
250
- b == null || b.disconnect(), window.removeEventListener("resize", m), g.style.removeProperty(F), g.style.removeProperty(v);
251
- };
252
- }, [y]), u === null ? null : de(
253
- /* @__PURE__ */ p(U, { children: [
254
- /* @__PURE__ */ r(
255
- le,
256
- {
257
- styles: {
258
- // A dialog or a sheet: the root of the modal is the box they are laid out in.
259
- [`body > [${A}]`]: {
260
- bottom: `var(${v}, 0px)`
261
- },
262
- // A drawer's paper is fixed to the viewport, not laid out in the root: shorten it too.
263
- [`body > [${A}] > .MuiDrawer-paper`]: {
264
- maxHeight: `calc(100% - var(${v}, 0px))`
265
- },
266
- [`body > [${A}] > .MuiDrawer-paperAnchorBottom`]: {
267
- bottom: `var(${v}, 0px)`
268
- }
269
- }
270
- }
271
- ),
272
- /* @__PURE__ */ r(Oe, { ref: c, children: /* @__PURE__ */ p(
273
- J,
274
- {
275
- padding: 4,
276
- role: "dialog",
277
- "aria-modal": !1,
278
- "aria-labelledby": a,
279
- "aria-describedby": l,
280
- children: [
281
- /* @__PURE__ */ r(Re, { id: a, children: t.formatRichMessage({ id: "cookies.banner.title" }) }),
282
- /* @__PURE__ */ r(Ie, { id: l, children: t.formatRichMessage({ id: "cookies.banner.description" }) }),
283
- /* @__PURE__ */ r(
284
- Ee,
285
- {
286
- href: Me,
287
- rel: "noreferrer",
288
- underline: "hover",
289
- children: t.formatRichMessage({ id: "cookies.banner.privacy-link" })
290
- }
291
- ),
292
- /* @__PURE__ */ p($e, { children: [
293
- /* @__PURE__ */ r(K, { variant: "contained", onClick: o, children: t.formatRichMessage({ id: "cookies.action.accept-all" }) }),
294
- /* @__PURE__ */ r(K, { variant: "outlined", onClick: n, children: t.formatRichMessage({ id: "cookies.action.reject-all" }) })
295
- ] }),
296
- /* @__PURE__ */ r(
297
- De,
298
- {
299
- variant: "text",
300
- size: "small",
301
- fullWidth: !0,
302
- onClick: s,
303
- children: t.formatRichMessage({ id: "cookies.action.configure" })
304
- }
305
- )
306
- ]
307
- }
308
- ) })
309
- ] }),
310
- u
311
- );
312
- }
313
- const Pe = f("div")(({ theme: e }) => {
314
- const { tokens: t, space: o } = e.design;
315
- return {
316
- display: "flex",
317
- alignItems: "center",
318
- justifyContent: "space-between",
319
- gap: d(o[6]),
320
- minWidth: 0,
321
- paddingTop: d(o[3]),
322
- paddingBottom: d(o[3]),
323
- "& + &": { borderTop: ie(t["border.subtle"]) },
324
- [D.down(_.Tablet)]: {
325
- flexDirection: "column",
326
- alignItems: "stretch",
327
- gap: d(o[3])
328
- }
329
- };
330
- }), Ve = f("div")(({ theme: e }) => ({
331
- display: "flex",
332
- flexDirection: "column",
333
- gap: d(e.design.space[1]),
334
- flex: "1 1 auto",
335
- minWidth: 0,
336
- overflowWrap: "anywhere"
337
- })), Le = f("label")(({ theme: e }) => ({
338
- fontSize: d(e.design.typeScale.body),
339
- fontWeight: P.medium,
340
- color: e.design.tokens["text.primary"]
341
- })), Ne = f("div")(({ theme: e }) => ({
342
- fontSize: d(e.design.typeScale.small),
343
- lineHeight: e.typography.body2.lineHeight,
344
- color: e.design.tokens["text.secondary"]
345
- })), ze = f("div")({
346
- display: "flex",
347
- flex: "none",
348
- alignItems: "center",
349
- justifyContent: "flex-end",
350
- maxWidth: "100%",
351
- [D.down(_.Tablet)]: {
352
- justifyContent: "flex-start"
353
- }
354
- });
355
- function ee({
356
- label: e,
357
- description: t,
358
- control: o,
359
- htmlFor: n
360
- }) {
361
- const s = S(), a = `${s}-label`, l = t !== void 0 ? `${s}-description` : void 0;
362
- return /* @__PURE__ */ p(
363
- Pe,
364
- {
365
- role: "group",
366
- "aria-labelledby": a,
367
- "aria-describedby": l,
368
- children: [
369
- /* @__PURE__ */ p(Ve, { children: [
370
- /* @__PURE__ */ r(
371
- Le,
372
- {
373
- id: a,
374
- htmlFor: n,
375
- as: n === void 0 ? "span" : "label",
376
- children: e
377
- }
378
- ),
379
- t !== void 0 && /* @__PURE__ */ r(Ne, { id: l, children: t })
380
- ] }),
381
- /* @__PURE__ */ r(ze, { children: o })
382
- ]
383
- }
384
- );
385
- }
386
- const Y = f(O)(({ theme: e }) => R(e)), We = f("span")(({ theme: e }) => ({
387
- fontSize: d(e.design.typeScale.small),
388
- color: e.design.tokens["text.secondary"],
389
- whiteSpace: "nowrap"
390
- })), Be = f("div")(({ theme: e }) => ({
391
- display: "flex",
392
- alignItems: "center",
393
- gap: d(e.design.space[2])
394
- }));
395
- function I({
396
- category: e,
397
- checked: t,
398
- locked: o = !1,
399
- onChange: n
400
- }) {
401
- const s = C(), a = S();
402
- return /* @__PURE__ */ r(
403
- ee,
404
- {
405
- label: s.formatRichMessage({
406
- id: `cookies.category.${e}.title`
407
- }),
408
- description: s.formatRichMessage({
409
- id: `cookies.category.${e}.description`
410
- }),
411
- htmlFor: a,
412
- control: /* @__PURE__ */ p(Be, { children: [
413
- o && /* @__PURE__ */ r(We, { children: s.formatRichMessage({
414
- id: "cookies.category.essentials.always-on"
415
- }) }),
416
- /* @__PURE__ */ r(
417
- G,
418
- {
419
- id: a,
420
- checked: t,
421
- disabled: o,
422
- onChange: (l, c) => n == null ? void 0 : n(c)
423
- }
424
- )
425
- ] })
426
- }
427
- );
428
- }
429
- function He({
430
- api: e,
431
- open: t,
432
- onClose: o
433
- }) {
434
- const n = C(), { consent: s, save: a } = e, [l, c] = h(!1), [u, y] = h(!1), i = (s == null ? void 0 : s.analytics) ?? !1, g = (s == null ? void 0 : s.marketing) ?? !1;
435
- T(() => {
436
- t && (c(i), y(g));
437
- }, [t, i, g]);
438
- const m = () => {
439
- a({ analytics: l, marketing: u }), o();
440
- };
441
- return /* @__PURE__ */ p(
442
- se,
443
- {
444
- open: t,
445
- onClose: o,
446
- size: ae.Small,
447
- title: n.formatRichMessage({ id: "cookies.configure.title" }),
448
- actions: /* @__PURE__ */ p(U, { children: [
449
- /* @__PURE__ */ r(Y, { variant: "text", onClick: o, children: n.formatRichMessage({ id: "cookies.action.cancel" }) }),
450
- /* @__PURE__ */ r(Y, { variant: "contained", onClick: m, children: n.formatRichMessage({ id: "cookies.action.save" }) })
451
- ] }),
452
- children: [
453
- /* @__PURE__ */ r(I, { category: "essentials", checked: !0, locked: !0 }),
454
- /* @__PURE__ */ r(
455
- I,
456
- {
457
- category: "analytics",
458
- checked: l,
459
- onChange: c
460
- }
461
- ),
462
- /* @__PURE__ */ r(
463
- I,
464
- {
465
- category: "marketing",
466
- checked: u,
467
- onChange: y
468
- }
469
- )
470
- ]
471
- }
472
- );
473
- }
474
- const V = oe(null), je = () => {
475
- const e = q(V);
476
- if (!e)
477
- throw new Error(
478
- "useAbyssCookieConsent must be used inside <AbyssCookieConsentProvider>"
479
- );
480
- return e;
481
- }, st = () => q(V), at = ({ children: e, consentVersion: t, isAuthenticated: o, domain: n, renderBanner: s }) => {
482
- const a = we({ isAuthenticated: o, consentVersion: t, domain: n }), [l, c] = h(!1), u = k(() => c(!0), []), y = k(() => c(!1), []), i = z(
483
- () => ({ ...a, openPreferences: u }),
484
- [a, u]
485
- ), g = z(() => i.isResolved || l ? null : s ? s(i) : /* @__PURE__ */ r(_e, { api: i }), [i, l, s]);
486
- return /* @__PURE__ */ p(V.Provider, { value: i, children: [
487
- e,
488
- g,
489
- /* @__PURE__ */ r(
490
- He,
491
- {
492
- api: i,
493
- open: l,
494
- onClose: y
495
- }
496
- )
497
- ] });
498
- }, Fe = f(O)(({ theme: e }) => R(e)), Ke = f("h2")(({ theme: e }) => ({
499
- margin: `0 0 ${d(e.design.space[2])}`,
500
- fontSize: d(e.design.typeScale.sectionTitle),
501
- fontWeight: P.semibold,
502
- color: e.design.tokens["text.primary"]
503
- })), Ye = f("div")(({ theme: e }) => ({
504
- display: "flex",
505
- marginTop: d(e.design.space[3])
506
- }));
507
- function E({
508
- category: e,
509
- checked: t,
510
- locked: o = !1,
511
- onChange: n
512
- }) {
513
- const s = C(), a = S();
514
- return /* @__PURE__ */ r(
515
- ee,
516
- {
517
- label: s.formatRichMessage({
518
- id: `cookies.category.${e}.title`
519
- }),
520
- description: s.formatRichMessage({
521
- id: `cookies.category.${e}.description`
522
- }),
523
- htmlFor: a,
524
- control: /* @__PURE__ */ r(
525
- G,
526
- {
527
- id: a,
528
- checked: t,
529
- disabled: o,
530
- onChange: (l, c) => n == null ? void 0 : n(c)
531
- }
532
- )
533
- }
534
- );
535
- }
536
- function rt() {
537
- const e = C(), { consent: t, save: o } = je(), [n, s] = h((t == null ? void 0 : t.analytics) ?? !1), [a, l] = h((t == null ? void 0 : t.marketing) ?? !1), c = t == null ? void 0 : t.analytics, u = t == null ? void 0 : t.marketing;
538
- return T(() => {
539
- c !== void 0 && s(c), u !== void 0 && l(u);
540
- }, [c, u]), /* @__PURE__ */ p(J, { padding: 4, children: [
541
- /* @__PURE__ */ r(Ke, { children: e.formatRichMessage({ id: "cookies.configure.title" }) }),
542
- /* @__PURE__ */ r(E, { category: "essentials", checked: !0, locked: !0 }),
543
- /* @__PURE__ */ r(
544
- E,
545
- {
546
- category: "analytics",
547
- checked: n,
548
- onChange: s
549
- }
550
- ),
551
- /* @__PURE__ */ r(
552
- E,
553
- {
554
- category: "marketing",
555
- checked: a,
556
- onChange: l
557
- }
558
- ),
559
- /* @__PURE__ */ r(Ye, { children: /* @__PURE__ */ r(
560
- Fe,
561
- {
562
- variant: "contained",
563
- onClick: () => o({ analytics: n, marketing: a }),
564
- children: e.formatRichMessage({ id: "cookies.action.save" })
565
- }
566
- ) })
567
- ] });
568
- }
569
- export {
570
- at as A,
571
- _e as C,
572
- Me as D,
573
- $ as R,
574
- ee as S,
575
- F as T,
576
- st as a,
577
- He as b,
578
- rt as c,
579
- we as d,
580
- it as e,
581
- x as f,
582
- Q as g,
583
- fe as h,
584
- me as i,
585
- ge as j,
586
- ye as k,
587
- pe as l,
588
- he as m,
589
- X as n,
590
- ve as o,
591
- Ae as p,
592
- be as r,
593
- je as u,
594
- B as w
595
- };