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