@lystech/sections 0.3.0 → 0.4.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/dist/index.js CHANGED
@@ -1,74 +1,86 @@
1
- import { jsx as S, jsxs as L, Fragment as F } from "react/jsx-runtime";
2
- import { useState as h, useRef as P, useEffect as x, useCallback as O, useMemo as _, useContext as M, createContext as N } from "react";
3
- import { appliquerAuxTextes as T } from "./morceaux/sourceTexte-BMPMpNg9.js";
4
- import { adaptateurI18next as rt } from "./morceaux/sourceTexte-BMPMpNg9.js";
5
- const d = "lystech-edit", k = N(null), q = "https://api.lystech.ca/api";
6
- function H() {
1
+ import { jsx as x, jsxs as U, Fragment as T } from "react/jsx-runtime";
2
+ import { useState as m, useRef as D, useEffect as b, useCallback as O, useMemo as _, useContext as M, createContext as N } from "react";
3
+ import { appliquerAuxTextes as q } from "./morceaux/sourceTexte-BMPMpNg9.js";
4
+ import { adaptateurI18next as ot } from "./morceaux/sourceTexte-BMPMpNg9.js";
5
+ const u = "lystech-edit", P = "lystech-edit-sortie", J = N(null), H = "https://api.lystech.ca/api";
6
+ function W() {
7
7
  if (typeof window > "u") return null;
8
8
  const t = (n) => {
9
9
  try {
10
- window.sessionStorage.setItem(d, n);
10
+ window.localStorage.setItem(u, n);
11
11
  } catch {
12
+ try {
13
+ window.sessionStorage.setItem(u, n);
14
+ } catch {
15
+ }
12
16
  }
13
17
  return n;
14
18
  };
15
19
  try {
20
+ if (window.localStorage.getItem(P)) {
21
+ window.localStorage.removeItem(P), window.localStorage.removeItem(u);
22
+ try {
23
+ window.sessionStorage.removeItem(u);
24
+ } catch {
25
+ }
26
+ return null;
27
+ }
16
28
  const n = window.location.hash.replace(/^#/, "");
17
- if (n.includes(d + "=")) {
18
- const c = new URLSearchParams(n), o = c.get(d);
19
- if (o) {
20
- c.delete(d);
21
- const i = c.toString();
29
+ if (n.includes(u + "=")) {
30
+ const o = new URLSearchParams(n), c = o.get(u);
31
+ if (c) {
32
+ o.delete(u);
33
+ const s = o.toString();
22
34
  return window.history.replaceState(
23
35
  {},
24
36
  "",
25
- window.location.pathname + window.location.search + (i ? "#" + i : "")
26
- ), t(o);
37
+ window.location.pathname + window.location.search + (s ? "#" + s : "")
38
+ ), t(c);
27
39
  }
28
40
  }
29
- const e = new URL(window.location.href), r = e.searchParams.get(d);
30
- return r ? (e.searchParams.delete(d), window.history.replaceState({}, "", e.toString()), t(r)) : window.sessionStorage.getItem(d);
41
+ const e = new URL(window.location.href), r = e.searchParams.get(u);
42
+ return r ? (e.searchParams.delete(u), window.history.replaceState({}, "", e.toString()), t(r)) : window.localStorage.getItem(u) ?? window.sessionStorage.getItem(u);
31
43
  } catch {
32
44
  return null;
33
45
  }
34
46
  }
35
- function X({
47
+ function Y({
36
48
  site: t,
37
49
  page: n,
38
50
  langue: e = "fr",
39
- apiBaseUrl: r = q,
40
- sectionsInitiales: c,
41
- sourceTexte: o,
42
- pagesPartagees: i,
43
- children: m
51
+ apiBaseUrl: r = H,
52
+ sectionsInitiales: o,
53
+ sourceTexte: c,
54
+ pagesPartagees: s,
55
+ children: f
44
56
  }) {
45
- const [u, g] = h(
46
- c ?? []
47
- ), [w, p] = h(
48
- c?.length ? "pret" : "chargement"
49
- ), [y, A] = h(0), [R, J] = h({}), [U, $] = h(!1), D = P(null);
50
- x(() => {
57
+ const [d, S] = m(
58
+ o ?? []
59
+ ), [p, w] = m(
60
+ o?.length ? "pret" : "chargement"
61
+ ), [E, g] = m(0), [y, $] = m({}), [R, z] = m(!1), L = D(null);
62
+ b(() => {
51
63
  if (!t || !n) return;
52
- D.current?.abort();
64
+ L.current?.abort();
53
65
  const a = new AbortController();
54
- D.current = a, p("chargement");
55
- const f = r + "/site-sections/public/" + encodeURIComponent(t) + "/" + encodeURIComponent([n, ...i ?? []].join(","));
56
- return fetch(f, { signal: a.signal }).then(
57
- (s) => s.ok ? s.json() : Promise.reject(new Error(String(s.status)))
58
- ).then((s) => {
59
- a.signal.aborted || (g(Array.isArray(s) ? s : []), p("pret"));
60
- }).catch((s) => {
61
- a.signal.aborted || s?.name === "AbortError" || p("erreur");
66
+ L.current = a, w("chargement");
67
+ const h = r + "/site-sections/public/" + encodeURIComponent(t) + "/" + encodeURIComponent([n, ...s ?? []].join(","));
68
+ return fetch(h, { signal: a.signal }).then(
69
+ (i) => i.ok ? i.json() : Promise.reject(new Error(String(i.status)))
70
+ ).then((i) => {
71
+ a.signal.aborted || (S(Array.isArray(i) ? i : []), w("pret"));
72
+ }).catch((i) => {
73
+ a.signal.aborted || i?.name === "AbortError" || w("erreur");
62
74
  }), () => a.abort();
63
- }, [t, n, r, y, (i ?? []).join(",")]);
64
- const E = O(() => A((a) => a + 1), []);
65
- x(() => {
66
- !o || !u.length || T(u, o);
67
- }, [u, o]);
75
+ }, [t, n, r, E, (s ?? []).join(",")]);
76
+ const I = O(() => g((a) => a + 1), []);
77
+ b(() => {
78
+ !c || !d.length || q(d, c);
79
+ }, [d, c]);
68
80
  const j = O(
69
- (a, f) => J((s) => ({ ...s, [a]: f })),
81
+ (a, h) => $((i) => ({ ...i, [a]: h })),
70
82
  []
71
- ), l = P({
83
+ ), l = D({
72
84
  site: t,
73
85
  page: n,
74
86
  langue: e,
@@ -77,89 +89,91 @@ function X({
77
89
  recharger: () => {
78
90
  }
79
91
  });
80
- l.current.site = t, l.current.page = n, l.current.langue = e, l.current.poserApercu = j, l.current.sourceTexte = o, l.current.recharger = E, x(() => {
92
+ l.current.site = t, l.current.page = n, l.current.langue = e, l.current.poserApercu = j, l.current.sourceTexte = c, l.current.recharger = I, b(() => {
81
93
  l.current.surChangementDePage?.(n);
82
- }, [n]), x(() => {
83
- const a = H();
94
+ }, [n]), b(() => {
95
+ const a = W();
84
96
  if (!a) return;
85
- let f = !0, s;
86
- return import("@lystech/sections/editeur").then((b) => {
87
- f && ($(!0), s = b.monterEditeur({
97
+ let h = !0, i;
98
+ return import("@lystech/sections/editeur").then((A) => {
99
+ h && (z(!0), i = A.monterEditeur({
88
100
  jeton: a,
89
101
  site: t,
90
102
  apiBaseUrl: r,
91
103
  pont: l.current
92
104
  }));
93
- }).catch((b) => {
94
- console.error("[lystech] éditeur indisponible:", b?.message ?? b);
105
+ }).catch((A) => {
106
+ console.error("[lystech] éditeur indisponible:", A?.message ?? A);
95
107
  }), () => {
96
- f = !1, s?.();
108
+ h = !1, i?.();
97
109
  };
98
110
  }, [t, r]);
99
- const z = _(
111
+ const F = _(
100
112
  () => ({
101
113
  site: t,
102
114
  page: n,
103
115
  langue: e,
104
116
  apiBaseUrl: r,
105
- sections: u,
106
- etat: w,
107
- recharger: E,
108
- apercu: R,
117
+ sections: d,
118
+ etat: p,
119
+ recharger: I,
120
+ apercu: y,
109
121
  poserApercu: j,
110
- modeEdition: U
122
+ modeEdition: R
111
123
  }),
112
124
  [
113
125
  t,
114
126
  n,
115
127
  e,
116
128
  r,
117
- u,
118
- w,
119
- E,
120
- R,
129
+ d,
130
+ p,
131
+ I,
132
+ y,
121
133
  j,
122
- U
134
+ R
123
135
  ]
124
136
  );
125
- return /* @__PURE__ */ S(k.Provider, { value: z, children: m });
137
+ return /* @__PURE__ */ x(J.Provider, { value: F, children: f });
126
138
  }
127
- function I() {
128
- return M(k);
139
+ function v() {
140
+ return M(J);
129
141
  }
130
- const W = "https://api.lystech.ca/api", v = "lystech-edit";
131
- function Y({
142
+ const Z = "https://api.lystech.ca/api", k = "lystech-edit";
143
+ function B({
132
144
  site: t,
133
145
  apiBaseUrl: n,
134
146
  className: e,
135
147
  mention: r = "Réalisé avec Lystech",
136
- connexion: c = "Connexion"
148
+ connexion: o = "Connexion",
149
+ methodes: c
137
150
  }) {
138
- const o = I(), i = t ?? o?.site ?? "", m = n ?? o?.apiBaseUrl ?? W, [u, g] = h(!1);
139
- if (!i) return null;
151
+ const s = v(), f = t ?? s?.site ?? "", d = n ?? s?.apiBaseUrl ?? Z, [S, p] = m(!1);
152
+ if (!f) return null;
140
153
  const w = async () => {
141
- if (!u) {
142
- g(!0);
154
+ if (!S) {
155
+ p(!0);
143
156
  try {
144
157
  (await import("@lystech/sections/editeur")).monterConnexion({
145
- site: i,
146
- apiBaseUrl: m,
147
- surJeton: (A) => {
158
+ site: f,
159
+ apiBaseUrl: d,
160
+ ...c ? { methodes: c } : {},
161
+ surJeton: (y) => {
148
162
  try {
149
- window.sessionStorage.setItem(v, A);
163
+ window.localStorage.removeItem("lystech-edit-sortie"), window.localStorage.setItem(k, y);
150
164
  } catch {
151
- window.location.hash = v + "=" + encodeURIComponent(A);
165
+ window.location.hash = k + "=" + encodeURIComponent(y);
152
166
  }
153
167
  window.location.reload();
154
168
  }
155
169
  });
156
- } catch (y) {
157
- console.error("[lystech] connexion indisponible:", y?.message ?? y);
170
+ } catch (g) {
171
+ console.error("[lystech] connexion indisponible:", g?.message ?? g);
158
172
  } finally {
159
- g(!1);
173
+ p(!1);
160
174
  }
161
175
  }
162
- }, p = {
176
+ }, E = {
163
177
  color: "inherit",
164
178
  font: "inherit",
165
179
  background: "none",
@@ -169,7 +183,7 @@ function Y({
169
183
  textDecoration: "underline",
170
184
  textUnderlineOffset: "0.2em"
171
185
  };
172
- return /* @__PURE__ */ L(
186
+ return /* @__PURE__ */ U(
173
187
  "div",
174
188
  {
175
189
  className: e,
@@ -183,7 +197,7 @@ function Y({
183
197
  lineHeight: 1.5
184
198
  },
185
199
  children: [
186
- /* @__PURE__ */ S(
200
+ /* @__PURE__ */ x(
187
201
  "a",
188
202
  {
189
203
  href: "https://lystech.ca",
@@ -193,49 +207,49 @@ function Y({
193
207
  children: r
194
208
  }
195
209
  ),
196
- !o?.modeEdition && /* @__PURE__ */ L(F, { children: [
197
- /* @__PURE__ */ S("span", { "aria-hidden": "true", children: "·" }),
198
- /* @__PURE__ */ S("button", { type: "button", style: p, onClick: w, children: u ? "…" : c })
210
+ !s?.modeEdition && /* @__PURE__ */ U(T, { children: [
211
+ /* @__PURE__ */ x("span", { "aria-hidden": "true", children: "·" }),
212
+ /* @__PURE__ */ x("button", { type: "button", style: E, onClick: w, children: S ? "…" : o })
199
213
  ] })
200
214
  ]
201
215
  }
202
216
  );
203
217
  }
204
- function Z(t) {
218
+ function G(t) {
205
219
  return !!t && typeof t == "object" && !Array.isArray(t) && Object.keys(t).every((n) => /^[a-z]{2}(-[A-Za-z]{2})?$/.test(n));
206
220
  }
207
221
  function C(t, n) {
208
222
  if (Array.isArray(t)) return t.map((e) => C(e, n));
209
- if (Z(t)) {
223
+ if (G(t)) {
210
224
  const e = t, r = n.slice(0, 2);
211
- return e[n] ?? e[r] ?? Object.values(e).find((o) => o != null) ?? "";
225
+ return e[n] ?? e[r] ?? Object.values(e).find((c) => c != null) ?? "";
212
226
  }
213
227
  if (t && typeof t == "object") {
214
228
  const e = {};
215
- for (const [r, c] of Object.entries(t))
216
- e[r] = C(c, n);
229
+ for (const [r, o] of Object.entries(t))
230
+ e[r] = C(o, n);
217
231
  return e;
218
232
  }
219
233
  return t;
220
234
  }
221
- function G(t, n) {
235
+ function K(t, n) {
222
236
  if (!n || typeof n != "object" || Array.isArray(n))
223
237
  return t;
224
238
  const e = { ...t };
225
- for (const [r, c] of Object.entries(n))
226
- c != null && (e[r] = c);
239
+ for (const [r, o] of Object.entries(n))
240
+ o != null && (e[r] = o);
227
241
  return e;
228
242
  }
229
- function B(t, n) {
230
- const e = I(), r = e?.apercu?.[t];
243
+ function tt(t, n) {
244
+ const e = v(), r = e?.apercu?.[t];
231
245
  return _(() => {
232
- const c = e?.sections.find(
233
- (m) => m.blockType === t
234
- ), o = r ?? c?.data ?? null, i = o ? C(o, e?.langue ?? "fr") : null;
246
+ const o = e?.sections.find(
247
+ (f) => f.blockType === t
248
+ ), c = r ?? o?.data ?? null, s = c ? C(c, e?.langue ?? "fr") : null;
235
249
  return {
236
- contenu: G(n.defaut, i),
237
- publie: !!c?.data,
238
- UID: c?.UID ?? null,
250
+ contenu: K(n.defaut, s),
251
+ publie: !!o?.data,
252
+ UID: o?.UID ?? null,
239
253
  chargement: e?.etat === "chargement",
240
254
  ancrage: { "data-lystech-section": t }
241
255
  };
@@ -248,24 +262,24 @@ function B(t, n) {
248
262
  n.defaut
249
263
  ]);
250
264
  }
251
- function tt(t, n) {
252
- const e = I();
265
+ function et(t, n) {
266
+ const e = v();
253
267
  return _(() => {
254
- const r = { "data-lystech-section": t }, c = (e?.sections ?? []).filter(
255
- (o) => o.blockType === t
268
+ const r = { "data-lystech-section": t }, o = (e?.sections ?? []).filter(
269
+ (c) => c.blockType === t
256
270
  );
257
- return c.length === 0 ? {
258
- items: (n?.defaut ?? []).map((o, i) => ({
259
- ...o,
260
- __uid: `defaut-${i}`
271
+ return o.length === 0 ? {
272
+ items: (n?.defaut ?? []).map((c, s) => ({
273
+ ...c,
274
+ __uid: `defaut-${s}`
261
275
  })),
262
276
  publie: !1,
263
277
  chargement: e?.etat === "chargement",
264
278
  ancrage: r
265
279
  } : {
266
- items: c.map((o) => ({
267
- ...C(o.data ?? {}, e?.langue ?? "fr"),
268
- __uid: o.UID
280
+ items: o.map((c) => ({
281
+ ...C(c.data ?? {}, e?.langue ?? "fr"),
282
+ __uid: c.UID
269
283
  })),
270
284
  publie: !0,
271
285
  chargement: e?.etat === "chargement",
@@ -274,11 +288,11 @@ function tt(t, n) {
274
288
  }, [e?.sections, e?.langue, e?.etat, t, n?.defaut]);
275
289
  }
276
290
  export {
277
- X as SectionsProvider,
278
- Y as SignatureLystech,
279
- rt as adaptateurI18next,
280
- T as appliquerAuxTextes,
281
- B as useSection,
282
- tt as useSectionList,
283
- I as useSectionsContext
291
+ Y as SectionsProvider,
292
+ B as SignatureLystech,
293
+ ot as adaptateurI18next,
294
+ q as appliquerAuxTextes,
295
+ tt as useSection,
296
+ et as useSectionList,
297
+ v as useSectionsContext
284
298
  };
@@ -0,0 +1,29 @@
1
+ import { r as e } from "./index.esm-Bd0PBW01.js";
2
+ import { F as o, S as t, D as n, _, a as v, b as m, c as A, d as g, e as S, f as d, g as b, h as l, i as F, j as c, k as E, l as f, m as C, n as L, o as D, p as N, q as O, s as x } from "./index.esm-Bd0PBW01.js";
3
+ var s = "firebase", a = "12.19.0";
4
+ e(s, a, "app");
5
+ export {
6
+ o as FirebaseError,
7
+ t as SDK_VERSION,
8
+ n as _DEFAULT_ENTRY_NAME,
9
+ _ as _addComponent,
10
+ v as _addOrOverwriteComponent,
11
+ m as _apps,
12
+ A as _clearComponents,
13
+ g as _components,
14
+ S as _getProvider,
15
+ d as _isFirebaseApp,
16
+ b as _isFirebaseServerApp,
17
+ l as _isFirebaseServerAppSettings,
18
+ F as _registerComponent,
19
+ c as _removeServiceInstance,
20
+ E as _serverApps,
21
+ f as deleteApp,
22
+ C as getApp,
23
+ L as getApps,
24
+ D as initializeApp,
25
+ N as initializeServerApp,
26
+ O as onLog,
27
+ e as registerVersion,
28
+ x as setLogLevel
29
+ };