@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/SectionsProvider.d.ts +10 -0
- package/dist/editeur/pont.d.ts +2 -0
- package/dist/editeur.js +197 -181
- package/dist/index.js +170 -164
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,163 +1,167 @@
|
|
|
1
|
-
import { jsx as x, jsxs as
|
|
2
|
-
import { useState as m, useRef as
|
|
3
|
-
import { appliquerAuxTextes as
|
|
4
|
-
import { adaptateurI18next as
|
|
5
|
-
const u = "lystech-edit",
|
|
6
|
-
function
|
|
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
|
|
8
|
+
const e = (r) => {
|
|
9
9
|
try {
|
|
10
|
-
window.localStorage.setItem(u,
|
|
10
|
+
window.localStorage.setItem(u, r);
|
|
11
11
|
} catch {
|
|
12
12
|
try {
|
|
13
|
-
window.sessionStorage.setItem(u,
|
|
13
|
+
window.sessionStorage.setItem(u, r);
|
|
14
14
|
} catch {
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return r;
|
|
18
18
|
};
|
|
19
19
|
try {
|
|
20
|
-
if (window.localStorage.getItem(
|
|
21
|
-
window.localStorage.removeItem(
|
|
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
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
const s =
|
|
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
|
-
),
|
|
38
|
+
), e(o);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
return
|
|
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
|
|
48
|
-
site:
|
|
49
|
-
page:
|
|
50
|
-
langue:
|
|
51
|
-
apiBaseUrl:
|
|
52
|
-
sectionsInitiales:
|
|
53
|
-
sourceTexte:
|
|
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:
|
|
55
|
+
children: h
|
|
56
56
|
}) {
|
|
57
|
-
const [
|
|
58
|
-
|
|
57
|
+
const [l, A] = m(
|
|
58
|
+
c ?? []
|
|
59
59
|
), [p, w] = m(
|
|
60
|
-
|
|
61
|
-
), [E, g] = m(0), [y,
|
|
62
|
-
|
|
63
|
-
if (!
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return fetch(
|
|
69
|
-
(
|
|
70
|
-
).then((
|
|
71
|
-
|
|
72
|
-
}).catch((
|
|
73
|
-
|
|
74
|
-
}), () =>
|
|
75
|
-
}, [
|
|
76
|
-
const I =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
),
|
|
84
|
-
site:
|
|
85
|
-
page:
|
|
86
|
-
langue:
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
}, [
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
let
|
|
98
|
-
return import("@lystech/sections/editeur").then((
|
|
99
|
-
|
|
100
|
-
jeton:
|
|
101
|
-
site:
|
|
102
|
-
apiBaseUrl:
|
|
103
|
-
pont:
|
|
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((
|
|
106
|
-
console.error("[lystech] éditeur indisponible:",
|
|
107
|
+
}).catch((b) => {
|
|
108
|
+
console.error("[lystech] éditeur indisponible:", b?.message ?? b);
|
|
107
109
|
}), () => {
|
|
108
|
-
|
|
110
|
+
f = !1, a?.();
|
|
109
111
|
};
|
|
110
|
-
}, [
|
|
111
|
-
const
|
|
112
|
+
}, [e, n]);
|
|
113
|
+
const N = v(
|
|
112
114
|
() => ({
|
|
113
|
-
site:
|
|
114
|
-
page:
|
|
115
|
-
langue:
|
|
116
|
-
apiBaseUrl:
|
|
117
|
-
sections:
|
|
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:
|
|
124
|
+
modeEdition: U,
|
|
125
|
+
declarerRepli: P
|
|
123
126
|
}),
|
|
124
127
|
[
|
|
125
|
-
t,
|
|
126
|
-
n,
|
|
127
128
|
e,
|
|
128
129
|
r,
|
|
129
|
-
|
|
130
|
+
t,
|
|
131
|
+
n,
|
|
132
|
+
l,
|
|
130
133
|
p,
|
|
131
134
|
I,
|
|
132
135
|
y,
|
|
133
136
|
j,
|
|
134
|
-
|
|
137
|
+
U,
|
|
138
|
+
P
|
|
135
139
|
]
|
|
136
140
|
);
|
|
137
|
-
return /* @__PURE__ */ x(
|
|
141
|
+
return /* @__PURE__ */ x(z.Provider, { value: N, children: h });
|
|
138
142
|
}
|
|
139
|
-
function
|
|
140
|
-
return
|
|
143
|
+
function L() {
|
|
144
|
+
return H(z);
|
|
141
145
|
}
|
|
142
|
-
const
|
|
143
|
-
function
|
|
144
|
-
site:
|
|
145
|
-
apiBaseUrl:
|
|
146
|
-
className:
|
|
147
|
-
mention:
|
|
148
|
-
connexion:
|
|
149
|
-
methodes:
|
|
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 =
|
|
152
|
-
if (!
|
|
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 (!
|
|
158
|
+
if (!A) {
|
|
155
159
|
p(!0);
|
|
156
160
|
try {
|
|
157
161
|
(await import("@lystech/sections/editeur")).monterConnexion({
|
|
158
|
-
site:
|
|
159
|
-
apiBaseUrl:
|
|
160
|
-
...
|
|
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__ */
|
|
190
|
+
return /* @__PURE__ */ J(
|
|
187
191
|
"div",
|
|
188
192
|
{
|
|
189
|
-
className:
|
|
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:
|
|
211
|
+
children: n
|
|
208
212
|
}
|
|
209
213
|
),
|
|
210
|
-
!s?.modeEdition && /* @__PURE__ */
|
|
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:
|
|
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
|
|
219
|
-
return !!
|
|
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(
|
|
222
|
-
if (Array.isArray(
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
return
|
|
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
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
239
|
-
for (const [r, o] of Object.entries(n))
|
|
240
|
-
o != null && (e[r] = o);
|
|
236
|
+
}
|
|
241
237
|
return e;
|
|
242
238
|
}
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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:
|
|
256
|
+
contenu: V(r.defaut, h),
|
|
251
257
|
publie: !!o?.data,
|
|
252
258
|
UID: o?.UID ?? null,
|
|
253
|
-
chargement:
|
|
254
|
-
ancrage: { "data-lystech-section":
|
|
259
|
+
chargement: t?.etat === "chargement",
|
|
260
|
+
ancrage: { "data-lystech-section": e }
|
|
255
261
|
};
|
|
256
262
|
}, [
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
t?.sections,
|
|
264
|
+
t?.langue,
|
|
265
|
+
t?.etat,
|
|
266
|
+
n,
|
|
267
|
+
e,
|
|
268
|
+
r.defaut
|
|
263
269
|
]);
|
|
264
270
|
}
|
|
265
|
-
function
|
|
266
|
-
const
|
|
267
|
-
return
|
|
268
|
-
const
|
|
269
|
-
(
|
|
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
|
|
272
|
-
items: (
|
|
273
|
-
...
|
|
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:
|
|
278
|
-
ancrage:
|
|
283
|
+
chargement: t?.etat === "chargement",
|
|
284
|
+
ancrage: n
|
|
279
285
|
} : {
|
|
280
|
-
items:
|
|
281
|
-
...C(
|
|
282
|
-
__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:
|
|
286
|
-
ancrage:
|
|
291
|
+
chargement: t?.etat === "chargement",
|
|
292
|
+
ancrage: n
|
|
287
293
|
};
|
|
288
|
-
}, [
|
|
294
|
+
}, [t?.sections, t?.langue, t?.etat, e, r?.defaut]);
|
|
289
295
|
}
|
|
290
296
|
export {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
};
|