@lystech/sections 0.8.0 → 0.9.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.
@@ -0,0 +1,112 @@
1
+ import { jsxs as m, Fragment as S, jsx as n } from "react/jsx-runtime";
2
+ import { useState as d, useEffect as g } from "react";
3
+ import { C as b } from "./constantes-BAdpe1ss.js";
4
+ import { useSectionsContext as C } from "../index.js";
5
+ const v = "lystech-peut-editer", I = `
6
+ .lystech-crayon-edition {
7
+ position: fixed; z-index: 2147482000;
8
+ bottom: calc(16px + env(safe-area-inset-bottom, 0px));
9
+ width: 56px; height: 56px; border-radius: 50%; border: 0; padding: 0;
10
+ display: grid; place-items: center; cursor: pointer;
11
+ background: #16181d; color: #fff;
12
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
13
+ -webkit-tap-highlight-color: transparent;
14
+ }
15
+ .lystech-crayon-edition--gauche { left: calc(16px + env(safe-area-inset-left, 0px)); }
16
+ .lystech-crayon-edition--droite { right: calc(16px + env(safe-area-inset-right, 0px)); }
17
+ .lystech-crayon-edition:hover { background: #3ba58d; color: #06120e; }
18
+ .lystech-crayon-edition:focus-visible { outline: 3px solid #3ba58d; outline-offset: 3px; }
19
+ .lystech-crayon-edition[aria-busy="true"] { opacity: .7; cursor: progress; }
20
+ .lystech-crayon-edition svg { width: 22px; height: 22px; }
21
+ .lystech-crayon-edition__bulle {
22
+ position: fixed; z-index: 2147482000; max-width: min(280px, calc(100vw - 32px));
23
+ bottom: calc(80px + env(safe-area-inset-bottom, 0px));
24
+ padding: 8px 12px; border-radius: 10px; background: #16181d; color: #fff;
25
+ font: 500 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
26
+ }
27
+ @media print { .lystech-crayon-edition, .lystech-crayon-edition__bulle { display: none; } }
28
+ `;
29
+ function L({
30
+ connecte: a,
31
+ peutEditer: s,
32
+ coin: u = "gauche",
33
+ libelle: p = "Modifier le site"
34
+ }) {
35
+ const e = C(), [w, r] = d(s ?? null), [h, f] = d(!1), [y, c] = d(null), l = !!e && a && !e.modeEdition && !e.modeApercu && !!e.site;
36
+ if (g(() => {
37
+ if (s !== void 0) {
38
+ r(s);
39
+ return;
40
+ }
41
+ if (!l || !e) return;
42
+ const o = v + ":" + e.site;
43
+ try {
44
+ const t = window.sessionStorage.getItem(o);
45
+ if (t === "1" || t === "0") {
46
+ r(t === "1");
47
+ return;
48
+ }
49
+ } catch {
50
+ }
51
+ let i = !0;
52
+ return e.appelSession("/site-sections/session-edition/acces/" + encodeURIComponent(e.site)).then((t) => t.ok ? t.json() : null).then((t) => {
53
+ if (!i || !t) return;
54
+ const x = t.peutEditer === !0;
55
+ if (r(x), t.connecte)
56
+ try {
57
+ window.sessionStorage.setItem(o, x ? "1" : "0");
58
+ } catch {
59
+ }
60
+ }).catch(() => {
61
+ }), () => {
62
+ i = !1;
63
+ };
64
+ }, [l, s, e?.site]), g(() => {
65
+ if (!(a || !e?.site))
66
+ try {
67
+ window.sessionStorage.removeItem(v + ":" + e.site);
68
+ } catch {
69
+ }
70
+ }, [a, e?.site]), !l || !w || !e) return null;
71
+ const k = async () => {
72
+ if (!h) {
73
+ f(!0), c(null);
74
+ try {
75
+ const o = await e.appelSession("/site-sections/session-edition/jeton/" + encodeURIComponent(e.site), { method: "POST" }), i = await o.json().catch(() => null);
76
+ if (!o.ok || !i?.token) {
77
+ c(i?.error ?? "Impossible d'ouvrir l'édition. Réessayez."), o.status === 403 && r(!1);
78
+ return;
79
+ }
80
+ e.entrerEnEdition(i.token);
81
+ } catch {
82
+ c("Pas de connexion au serveur. Vérifiez Internet et réessayez.");
83
+ } finally {
84
+ f(!1);
85
+ }
86
+ }
87
+ };
88
+ return /* @__PURE__ */ m(S, { children: [
89
+ /* @__PURE__ */ n("style", { children: I }),
90
+ /* @__PURE__ */ n(
91
+ "button",
92
+ {
93
+ type: "button",
94
+ className: `lystech-crayon-edition lystech-crayon-edition--${u} ${b}`,
95
+ onClick: () => {
96
+ k();
97
+ },
98
+ "aria-label": p,
99
+ title: p,
100
+ "aria-busy": h,
101
+ children: /* @__PURE__ */ m("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
102
+ /* @__PURE__ */ n("path", { d: "M12 20h9" }),
103
+ /* @__PURE__ */ n("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" })
104
+ ] })
105
+ }
106
+ ),
107
+ y && /* @__PURE__ */ n("p", { role: "alert", className: `lystech-crayon-edition__bulle ${b}`, style: u === "gauche" ? { left: 16 } : { right: 16 }, children: y })
108
+ ] });
109
+ }
110
+ export {
111
+ L as default
112
+ };