@lystech/sections 0.4.4 → 0.4.6

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