@lystech/sections 0.4.5 → 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.
@@ -25,6 +25,16 @@ type Contexte = {
25
25
  poserApercu: (blockType: string, data: Record<string, unknown> | null) => void;
26
26
  /** Vrai quand un jeton d'édition est actif. Faux pour tout visiteur. */
27
27
  modeEdition: boolean;
28
+ /**
29
+ * CE QUE LE SITE AFFICHE QUAND RIEN N'EST PUBLIÉ.
30
+ *
31
+ * Chaque `useSection` déclare ici son repli. L'éditeur s'en sert pour
32
+ * ouvrir un formulaire DÉJÀ REMPLI : sans ça, un bloc jamais publié
33
+ * s'ouvrait sur des champs vides devant une page pleine de valeurs, et il
34
+ * fallait tout retaper — ou pire, enregistrer des blancs par-dessus ce qui
35
+ * marchait.
36
+ */
37
+ declarerRepli: (blockType: string, defaut: unknown) => void;
28
38
  };
29
39
  export declare function SectionsProvider({ site, page, langue, apiBaseUrl, sectionsInitiales, sourceTexte, pagesPartagees, children, }: {
30
40
  /** Sous-domaine de l'organisation (ex. « armoise »). */
@@ -8,6 +8,8 @@ export type PontEdition = {
8
8
  * blocs marques a la main.
9
9
  */
10
10
  sourceTexte?: SourceTexte | undefined;
11
+ /** Ce que le site affiche par defaut, par type de bloc. */
12
+ replis?: Record<string, unknown> | undefined;
11
13
  /** Sous-domaine de l'organisation — affiché, jamais envoyé. */
12
14
  site: string;
13
15
  /** La page courante. Mise à jour par le fournisseur. */
package/dist/editeur.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as e, jsxs as f, Fragment as re } from "react/jsx-runtime";
2
2
  import { createRoot as ae } from "react-dom/client";
3
- import { useState as O, useRef as j, useEffect as G, useCallback as W, useMemo as te } from "react";
3
+ import { useState as M, useRef as X, useEffect as G, useCallback as W, useMemo as te } from "react";
4
4
  function fe({
5
5
  jeton: n,
6
6
  site: t,
@@ -78,7 +78,7 @@ function ye({
78
78
  surJeton: r,
79
79
  surFermer: a
80
80
  }) {
81
- const [d, l] = O({ nom: "repos" }), b = (v) => {
81
+ const [d, l] = M({ nom: "repos" }), b = (v) => {
82
82
  switch (v) {
83
83
  case "auth/popup-blocked":
84
84
  return "Votre navigateur a bloqué la fenêtre de connexion. Autorisez les fenêtres pour ce site, puis réessayez.";
@@ -94,25 +94,25 @@ function ye({
94
94
  default:
95
95
  return "La connexion a échoué. Réessayez dans un instant.";
96
96
  }
97
- }, o = async (v, E = !1) => {
98
- const D = await fetch(t + "/site-sections/edit-login/third-party", {
97
+ }, o = async (v, S = !1) => {
98
+ const P = await fetch(t + "/site-sections/edit-login/third-party", {
99
99
  method: "POST",
100
100
  headers: { "Content-Type": "application/json" },
101
101
  body: JSON.stringify({
102
102
  site: n,
103
103
  token: v,
104
104
  tokenType: "firebase",
105
- demanderAcces: E
105
+ demanderAcces: S
106
106
  })
107
107
  });
108
- if (D.status === 429) {
108
+ if (P.status === 429) {
109
109
  l({
110
110
  nom: "erreur",
111
111
  texte: "Trop de tentatives. Réessayez dans quelques minutes."
112
112
  });
113
113
  return;
114
114
  }
115
- const y = await D.json().catch(() => null);
115
+ const y = await P.json().catch(() => null);
116
116
  if (y?.ok && y?.token) {
117
117
  r(y.token);
118
118
  return;
@@ -148,13 +148,13 @@ function ye({
148
148
  }, i = async (v) => {
149
149
  l({ nom: "envoi", quoi: v });
150
150
  try {
151
- const [{ initializeApp: E, getApps: D }, y] = await Promise.all([
151
+ const [{ initializeApp: S, getApps: P }, y] = await Promise.all([
152
152
  import("./morceaux/index.esm-B4AB50RA.js"),
153
153
  import("./morceaux/index.esm-B4hL1FOE.js")
154
- ]), q = D().find((M) => M.name === "lystech-edition") ?? E(ge, "lystech-edition"), U = v === "google" ? new y.GoogleAuthProvider() : new y.FacebookAuthProvider(), C = await (await y.signInWithPopup(y.getAuth(q), U)).user.getIdToken();
155
- await o(C);
156
- } catch (E) {
157
- l({ nom: "erreur", texte: b(String(E?.code ?? "")) });
154
+ ]), q = P().find((O) => O.name === "lystech-edition") ?? S(ge, "lystech-edition"), U = v === "google" ? new y.GoogleAuthProvider() : new y.FacebookAuthProvider(), E = await (await y.signInWithPopup(y.getAuth(q), U)).user.getIdToken();
155
+ await o(E);
156
+ } catch (S) {
157
+ l({ nom: "erreur", texte: b(String(S?.code ?? "")) });
158
158
  }
159
159
  }, h = d.nom === "envoi";
160
160
  return /* @__PURE__ */ e("div", { className: "voile", role: "dialog", "aria-modal": "true", "aria-label": "Modifier ce site", children: /* @__PURE__ */ f("div", { className: "fenetre", children: [
@@ -336,7 +336,7 @@ function ne({ champ: n, valeur: t, changer: s }) {
336
336
  function se({ champ: n, valeur: t, changer: s, langue: r }) {
337
337
  if (n.type === "list") {
338
338
  const a = Array.isArray(t) ? t : [], d = n.of ?? [], l = (b, o, i) => {
339
- const h = a.map((v, E) => E === b ? { ...v, [o]: i } : v);
339
+ const h = a.map((v, S) => S === b ? { ...v, [o]: i } : v);
340
340
  s(h);
341
341
  };
342
342
  return /* @__PURE__ */ f("div", { className: "champ", children: [
@@ -463,20 +463,20 @@ function Ee({
463
463
  actif: t,
464
464
  surModification: s
465
465
  }) {
466
- const r = j(/* @__PURE__ */ new Map()), a = j(null), [d, l] = O(null), b = j(n);
466
+ const r = X(/* @__PURE__ */ new Map()), a = X(null), [d, l] = M(null), b = X(n);
467
467
  b.current = n;
468
- const o = j(s);
468
+ const o = X(s);
469
469
  return o.current = s, G(() => {
470
470
  if (!t) return;
471
471
  const i = b.current.langueCourante(), h = Ce(b.current.dictionnaire(i)), v = () => {
472
472
  r.current = Ne(h);
473
473
  };
474
474
  v();
475
- let E;
476
- const D = new MutationObserver(() => {
477
- a.current || (clearTimeout(E), E = setTimeout(v, 250));
475
+ let S;
476
+ const P = new MutationObserver(() => {
477
+ a.current || (clearTimeout(S), S = setTimeout(v, 250));
478
478
  });
479
- D.observe(document.body, { childList: !0, subtree: !0 });
479
+ P.observe(document.body, { childList: !0, subtree: !0 });
480
480
  const y = "outline:2px dashed rgba(59,165,141,.85);outline-offset:3px;border-radius:3px;cursor:text;", q = (p) => {
481
481
  const c = p.target;
482
482
  !(c instanceof HTMLElement) || a.current || r.current.has(c) && (c.dataset.lysStyleAvant || (c.dataset.lysStyleAvant = c.getAttribute("style") ?? ""), c.setAttribute(
@@ -502,7 +502,7 @@ function Ee({
502
502
  ), p.focus();
503
503
  const _ = window.getSelection(), Q = document.createRange();
504
504
  Q.selectNodeContents(p), _?.removeAllRanges(), _?.addRange(Q);
505
- }, C = async (p) => {
505
+ }, E = async (p) => {
506
506
  const c = a.current;
507
507
  if (!c) return;
508
508
  a.current = null;
@@ -515,12 +515,12 @@ function Ee({
515
515
  }
516
516
  const Q = b.current.langueCourante();
517
517
  b.current.poser(Q, c.ns, c.chemin, x), await o.current(c.ns, c.chemin, Q, x);
518
- }, M = (p) => {
518
+ }, O = (p) => {
519
519
  const c = p.target;
520
520
  if (!(c instanceof HTMLElement)) return;
521
521
  if (a.current) {
522
522
  if (a.current.el === c) return;
523
- C(!1);
523
+ E(!1);
524
524
  }
525
525
  const x = r.current.get(c);
526
526
  if (x) {
@@ -535,21 +535,21 @@ function Ee({
535
535
  y: p.clientY
536
536
  });
537
537
  }
538
- }, S = (p) => {
539
- a.current && (p.key === "Escape" ? (p.preventDefault(), C(!0)) : p.key === "Enter" && !p.shiftKey && (p.preventDefault(), C(!1)));
538
+ }, z = (p) => {
539
+ a.current && (p.key === "Escape" ? (p.preventDefault(), E(!0)) : p.key === "Enter" && !p.shiftKey && (p.preventDefault(), E(!1)));
540
540
  }, L = () => {
541
- a.current && C(!1);
541
+ a.current && E(!1);
542
542
  };
543
- document.addEventListener("mouseover", q, !0), document.addEventListener("mouseout", U, !0), document.addEventListener("click", M, !0);
543
+ document.addEventListener("mouseover", q, !0), document.addEventListener("mouseout", U, !0), document.addEventListener("click", O, !0);
544
544
  const V = (p) => {
545
545
  if (!a.current) return;
546
546
  const c = p.inputType;
547
- (c === "insertParagraph" || c === "insertLineBreak") && (p.preventDefault(), C(!1));
547
+ (c === "insertParagraph" || c === "insertLineBreak") && (p.preventDefault(), E(!1));
548
548
  };
549
- return document.addEventListener("beforeinput", V, !0), document.addEventListener("keydown", S, !0), document.addEventListener("focusout", L, !0), window.__lysChoisir = (p, c) => {
549
+ return document.addEventListener("beforeinput", V, !0), document.addEventListener("keydown", z, !0), document.addEventListener("focusout", L, !0), window.__lysChoisir = (p, c) => {
550
550
  l(null), I(c, p);
551
551
  }, () => {
552
- clearTimeout(E), D.disconnect(), document.removeEventListener("mouseover", q, !0), document.removeEventListener("mouseout", U, !0), document.removeEventListener("click", M, !0), document.removeEventListener("beforeinput", V, !0), document.removeEventListener("keydown", S, !0), document.removeEventListener("focusout", L, !0), a.current && C(!0), delete window.__lysChoisir;
552
+ clearTimeout(S), P.disconnect(), document.removeEventListener("mouseover", q, !0), document.removeEventListener("mouseout", U, !0), document.removeEventListener("click", O, !0), document.removeEventListener("beforeinput", V, !0), document.removeEventListener("keydown", z, !0), document.removeEventListener("focusout", L, !0), a.current && E(!0), delete window.__lysChoisir;
553
553
  };
554
554
  }, [t]), d ? /* @__PURE__ */ f(
555
555
  "div",
@@ -593,7 +593,7 @@ function oe(n, t) {
593
593
  return JSON.stringify(n ?? {}) === JSON.stringify(t ?? {});
594
594
  }
595
595
  function Se({ api: n, pont: t }) {
596
- const [s, r] = O([]), [a, d] = O([]), [l, b] = O(t.page), [o, i] = O(null), [h, v] = O({}), [E, D] = O(!1), [y, q] = O(() => {
596
+ const [s, r] = M([]), [a, d] = M([]), [l, b] = M(t.page), [o, i] = M(null), [h, v] = M({}), [S, P] = M(!1), [y, q] = M(() => {
597
597
  try {
598
598
  return window.localStorage.getItem(ee) === "circuler" ? "circuler" : "modifier";
599
599
  } catch {
@@ -606,11 +606,11 @@ function Se({ api: n, pont: t }) {
606
606
  } catch {
607
607
  }
608
608
  return m;
609
- }), [I, C] = O(!1), [M, S] = O(
609
+ }), [I, E] = M(!1), [O, z] = M(
610
610
  null
611
611
  );
612
612
  G(() => (t.surChangementDePage = (u) => {
613
- b(u), i(null), D(!1);
613
+ b(u), i(null), P(!1);
614
614
  }, () => {
615
615
  t.surChangementDePage = void 0;
616
616
  }), [t]);
@@ -622,7 +622,7 @@ function Se({ api: n, pont: t }) {
622
622
  ]), g = [...u, ...m];
623
623
  return d(g), g;
624
624
  } catch {
625
- return S({
625
+ return z({
626
626
  ton: "erreur",
627
627
  texte: "Impossible de lire le contenu du site."
628
628
  }), [];
@@ -636,11 +636,11 @@ function Se({ api: n, pont: t }) {
636
636
  const V = W(
637
637
  (u, m) => {
638
638
  let g = null, A = -1;
639
- for (const P of s) {
640
- const k = Z.exec(P.blockType);
641
- if (!k || k[1] !== u) continue;
642
- const w = k[2];
643
- (w === "" || m === w || m.startsWith(w + ".")) && w.length > A && (g = P, A = w.length);
639
+ for (const k of s) {
640
+ const w = Z.exec(k.blockType);
641
+ if (!w || w[1] !== u) continue;
642
+ const C = w[2];
643
+ (C === "" || m === C || m.startsWith(C + ".")) && C.length > A && (g = k, A = C.length);
644
644
  }
645
645
  if (!g) return null;
646
646
  const N = Z.exec(g.blockType)?.[2] ?? "", T = N ? m.slice(N.length + 1) : m;
@@ -663,28 +663,28 @@ function Se({ api: n, pont: t }) {
663
663
  async (u, m, g, A) => {
664
664
  const N = V(u, m);
665
665
  if (!N) {
666
- S({
666
+ z({
667
667
  ton: "erreur",
668
668
  texte: `Ce texte (${u}:${m}) n'appartient à aucun bloc déclaré.`
669
669
  });
670
670
  return;
671
671
  }
672
- const T = a.find((z) => z.blockType === N.bloc.blockType), P = T?.draft ?? T?.data ?? {}, k = P[N.champ], w = N.bloc.fields.find((z) => z.key === N.champ), B = (
672
+ const T = a.find((D) => D.blockType === N.bloc.blockType), k = T?.draft ?? T?.data ?? {}, w = k[N.champ], C = N.bloc.fields.find((D) => D.key === N.champ), B = (
673
673
  /* `!declare.localized` et non `=== false` : un champ non traduit
674
674
  OMET la cle plutot que de la mettre a faux. Tester l'egalite
675
675
  stricte ne se declenchait donc jamais. */
676
- w && !w.localized ? A : k && typeof k == "object" && !Array.isArray(k) ? { ...k, [g]: A } : { [g]: A }
677
- ), X = { ...P, [N.champ]: B };
676
+ C && !C.localized ? A : w && typeof w == "object" && !Array.isArray(w) ? { ...w, [g]: A } : { [g]: A }
677
+ ), j = { ...k, [N.champ]: B };
678
678
  try {
679
679
  if (T?.UID)
680
- await n.enregistrerBrouillon(T.UID, X);
680
+ await n.enregistrerBrouillon(T.UID, j);
681
681
  else {
682
- const z = N.bloc.pages?.[0] ?? l;
683
- await n.creer(z, N.bloc.blockType, X);
682
+ const D = N.bloc.pages?.[0] ?? l;
683
+ await n.creer(D, N.bloc.blockType, j);
684
684
  }
685
- await L(), S(null);
685
+ await L(), z(null);
686
686
  } catch {
687
- S({
687
+ z({
688
688
  ton: "erreur",
689
689
  texte: "Enregistrement impossible. Votre texte est toujours à l'écran."
690
690
  });
@@ -693,26 +693,26 @@ function Se({ api: n, pont: t }) {
693
693
  [n, V, l, L, a]
694
694
  ), Q = async () => {
695
695
  if (!x.length) return;
696
- C(!0), S(null);
696
+ E(!0), z(null);
697
697
  const u = x.length;
698
698
  try {
699
699
  for (const m of x) await n.publier(m.UID);
700
700
  await L();
701
701
  for (const m of x) t.poserApercu(m.blockType, null);
702
- t.recharger(), S({
702
+ t.recharger(), z({
703
703
  ton: "ok",
704
704
  texte: u === 1 ? "Publié. Vos visiteurs le voient maintenant." : `${u} modifications publiées.`
705
705
  });
706
706
  } catch {
707
- S({
707
+ z({
708
708
  ton: "erreur",
709
709
  texte: "La publication a échoué. Rien n'a été mis en ligne."
710
710
  });
711
711
  } finally {
712
- C(!1);
712
+ E(!1);
713
713
  }
714
714
  }, le = async () => {
715
- C(!0);
715
+ E(!0);
716
716
  try {
717
717
  const u = x.map((g) => g.blockType);
718
718
  for (const g of x) await n.annuler(g.UID);
@@ -725,43 +725,47 @@ function Se({ api: n, pont: t }) {
725
725
  t.sourceTexte
726
726
  );
727
727
  }
728
- S({
728
+ z({
729
729
  ton: "info",
730
730
  texte: "Modifications abandonnées. On est revenu à ce qui est en ligne."
731
731
  });
732
732
  } finally {
733
- C(!1);
733
+ E(!1);
734
734
  }
735
735
  }, ue = (u) => {
736
- const m = a.find((P) => P.blockType === u), g = m?.draft ?? m?.data ?? {}, A = p(u), N = Z.exec(u), T = {};
736
+ const m = a.find((k) => k.blockType === u), g = m?.draft ?? m?.data ?? {}, A = p(u), N = Z.exec(u), T = {};
737
+ if (!N) {
738
+ const k = t.replis?.[u];
739
+ k && typeof k == "object" && !Array.isArray(k) && Object.assign(T, k);
740
+ }
737
741
  if (N && A && t.sourceTexte) {
738
- const P = N[1], k = N[2], w = t.sourceTexte.langues(), B = {};
739
- for (const z of w)
740
- B[z] = t.sourceTexte.dictionnaire(z)[P] ?? {};
741
- const X = t.sourceTexte.langueCourante();
742
- for (const z of A.fields) {
743
- const J = k ? k + "." + z.key : z.key;
744
- if (!z.localized) {
745
- const Y = B[X]?.[J] ?? w.map((R) => B[R]?.[J]).find((R) => typeof R == "string");
746
- typeof Y == "string" && (T[z.key] = Y);
742
+ const k = N[1], w = N[2], C = t.sourceTexte.langues(), B = {};
743
+ for (const D of C)
744
+ B[D] = t.sourceTexte.dictionnaire(D)[k] ?? {};
745
+ const j = t.sourceTexte.langueCourante();
746
+ for (const D of A.fields) {
747
+ const J = w ? w + "." + D.key : D.key;
748
+ if (!D.localized) {
749
+ const Y = B[j]?.[J] ?? C.map((R) => B[R]?.[J]).find((R) => typeof R == "string");
750
+ typeof Y == "string" && (T[D.key] = Y);
747
751
  continue;
748
752
  }
749
753
  const K = {};
750
- for (const Y of w) {
754
+ for (const Y of C) {
751
755
  const R = B[Y]?.[J];
752
756
  typeof R == "string" && (K[Y] = R);
753
757
  }
754
- Object.keys(K).length && (T[z.key] = K);
758
+ Object.keys(K).length && (T[D.key] = K);
755
759
  }
756
760
  }
757
- for (const [P, k] of Object.entries(g)) {
758
- const w = T[P], B = k && typeof k == "object" && !Array.isArray(k) && w && typeof w == "object" && !Array.isArray(w);
759
- T[P] = B ? { ...w, ...k } : k;
761
+ for (const [k, w] of Object.entries(g)) {
762
+ const C = T[k], B = w && typeof w == "object" && !Array.isArray(w) && C && typeof C == "object" && !Array.isArray(C);
763
+ T[k] = B ? { ...C, ...w } : w;
760
764
  }
761
- v(T), i(u), D(!1), S(null);
765
+ v(T), i(u), P(!1), z(null);
762
766
  }, de = (u, m) => v((g) => ({ ...g, [u]: m })), pe = async () => {
763
767
  if (o) {
764
- C(!0);
768
+ E(!0);
765
769
  try {
766
770
  const u = a.find((g) => g.blockType === o);
767
771
  if (u?.UID) await n.enregistrerBrouillon(u.UID, h);
@@ -777,14 +781,14 @@ function Se({ api: n, pont: t }) {
777
781
  t.sourceTexte
778
782
  );
779
783
  }
780
- Z.test(o) || t.poserApercu(o, h), S({
784
+ Z.test(o) || t.poserApercu(o, h), z({
781
785
  ton: "ok",
782
786
  texte: "Enregistré. Rien n'a encore changé pour vos visiteurs."
783
787
  });
784
788
  } catch {
785
- S({ ton: "erreur", texte: "L'enregistrement a échoué." });
789
+ z({ ton: "erreur", texte: "L'enregistrement a échoué." });
786
790
  } finally {
787
- C(!1);
791
+ E(!1);
788
792
  }
789
793
  }
790
794
  }, me = () => {
@@ -797,7 +801,7 @@ function Se({ api: n, pont: t }) {
797
801
  } catch {
798
802
  }
799
803
  window.location.reload();
800
- }, F = o ? p(o) : void 0, H = !o && !E;
804
+ }, F = o ? p(o) : void 0, H = !o && !S;
801
805
  return /* @__PURE__ */ f("div", { className: "calque", children: [
802
806
  /* @__PURE__ */ e(
803
807
  "div",
@@ -855,7 +859,7 @@ function Se({ api: n, pont: t }) {
855
859
  {
856
860
  type: "button",
857
861
  className: "bouton bouton--icone bouton--discret",
858
- onClick: () => D(!0),
862
+ onClick: () => P(!0),
859
863
  title: "Tous les contenus",
860
864
  "aria-label": "Tous les contenus",
861
865
  children: "⋮"
@@ -873,8 +877,8 @@ function Se({ api: n, pont: t }) {
873
877
  }
874
878
  )
875
879
  ] }),
876
- M && H && /* @__PURE__ */ e("div", { className: "flottant", children: /* @__PURE__ */ e("p", { className: "message message--" + M.ton, children: M.texte }) }),
877
- E && /* @__PURE__ */ f("div", { className: "panneau", role: "dialog", "aria-label": "Tous les contenus", children: [
880
+ O && H && /* @__PURE__ */ e("div", { className: "flottant", children: /* @__PURE__ */ e("p", { className: "message message--" + O.ton, children: O.texte }) }),
881
+ S && /* @__PURE__ */ f("div", { className: "panneau", role: "dialog", "aria-label": "Tous les contenus", children: [
878
882
  /* @__PURE__ */ f("div", { className: "panneau__tete", children: [
879
883
  /* @__PURE__ */ f("div", { style: { flex: 1 }, children: [
880
884
  /* @__PURE__ */ e("h2", { className: "panneau__titre", children: "Tous les contenus" }),
@@ -885,7 +889,7 @@ function Se({ api: n, pont: t }) {
885
889
  {
886
890
  type: "button",
887
891
  className: "bouton bouton--icone bouton--discret",
888
- onClick: () => D(!1),
892
+ onClick: () => P(!1),
889
893
  "aria-label": "Fermer",
890
894
  children: "✕"
891
895
  }
@@ -935,7 +939,7 @@ function Se({ api: n, pont: t }) {
935
939
  )
936
940
  ] }),
937
941
  /* @__PURE__ */ f("div", { className: "panneau__corps", children: [
938
- M && /* @__PURE__ */ e("p", { className: "message message--" + M.ton, children: M.texte }),
942
+ O && /* @__PURE__ */ e("p", { className: "message message--" + O.ton, children: O.texte }),
939
943
  F.fields.map((u) => /* @__PURE__ */ e(
940
944
  se,
941
945
  {
@@ -1355,7 +1359,7 @@ input:focus, select:focus, textarea:focus {
1355
1359
  discrete le reste du temps — c'est le geste qu'on fait une fois. */
1356
1360
  .bouton--sortie { color: var(--texte-doux); background: transparent; border-color: transparent; }
1357
1361
  .bouton--sortie:hover { background: rgba(217, 119, 106, 0.16); color: var(--danger); }
1358
- `, Pe = "lystech-editeur-hote", Me = "lystech-connexion-hote";
1362
+ `, Pe = "lystech-editeur-hote", Oe = "lystech-connexion-hote";
1359
1363
  function ie(n) {
1360
1364
  document.getElementById(n)?.remove();
1361
1365
  const t = document.createElement("div");
@@ -1380,7 +1384,7 @@ function Be({
1380
1384
  methodes: s,
1381
1385
  surJeton: r
1382
1386
  }) {
1383
- const { hote: a, point: d } = ie(Me), l = ae(d), b = () => o();
1387
+ const { hote: a, point: d } = ie(Oe), l = ae(d), b = () => o();
1384
1388
  l.render(
1385
1389
  /* @__PURE__ */ e(
1386
1390
  ye,
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.5",
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",