@lystech/sections 0.1.0 → 0.3.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/README.md +109 -55
- package/dist/SectionsProvider.d.ts +78 -0
- package/dist/SignatureLystech.d.ts +9 -0
- package/dist/editeur/Connexion.d.ts +6 -0
- package/dist/editeur/Editeur.d.ts +6 -0
- package/dist/editeur/TexteEnPlace.d.ts +7 -0
- package/dist/editeur/api.d.ts +39 -0
- package/dist/editeur/champs.d.ts +9 -0
- package/dist/editeur/index.d.ts +20 -0
- package/dist/editeur/pont.d.ts +28 -0
- package/dist/editeur/styles.d.ts +2 -0
- package/dist/editeur.js +1208 -0
- package/dist/index.d.ts +18 -108
- package/dist/index.js +259 -82
- package/dist/morceaux/sourceTexte-BMPMpNg9.js +71 -0
- package/dist/sourceTexte.d.ts +34 -0
- package/dist/types.d.ts +41 -0
- package/dist/useSection.d.ts +50 -0
- package/package.json +14 -6
- package/dist/index.umd.cjs +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LES ATTRIBUTS À POSER SUR LE CONTENEUR DE LA SECTION.
|
|
3
|
+
*
|
|
4
|
+
* L'éditeur doit pouvoir retrouver, DANS LA PAGE, le rectangle qui correspond
|
|
5
|
+
* à un bloc — pour l'encadrer et y poser un bouton. Il n'existe aucun moyen
|
|
6
|
+
* fiable de le deviner : deux sections peuvent afficher les mêmes mots, et un
|
|
7
|
+
* site est libre de sa structure. Le site le dit donc explicitement, en
|
|
8
|
+
* étalant ces attributs sur son élément :
|
|
9
|
+
*
|
|
10
|
+
* const { contenu, ancrage } = useSection("tarifs", { defaut });
|
|
11
|
+
* return <section {...ancrage}>…</section>;
|
|
12
|
+
*
|
|
13
|
+
* Hors mode édition, c'est un attribut `data-` inerte : aucun poids, aucun
|
|
14
|
+
* effet, aucun style.
|
|
15
|
+
*/
|
|
16
|
+
export type AncrageEdition = {
|
|
17
|
+
"data-lystech-section": string;
|
|
18
|
+
};
|
|
19
|
+
export type ResultatSection<T> = {
|
|
20
|
+
/** Le contenu à afficher : aperçu, sinon publié, sinon défaut. */
|
|
21
|
+
contenu: T;
|
|
22
|
+
/** Vrai quand le contenu vient du serveur, faux quand c'est le défaut. */
|
|
23
|
+
publie: boolean;
|
|
24
|
+
/** L'identifiant de la section — nécessaire à l'édition. */
|
|
25
|
+
UID: string | null;
|
|
26
|
+
chargement: boolean;
|
|
27
|
+
/** À étaler sur le conteneur pour que l'éditeur puisse le situer. */
|
|
28
|
+
ancrage: AncrageEdition;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Le contenu d'un type de bloc sur la page courante.
|
|
32
|
+
*
|
|
33
|
+
* Le cas visé est celui d'un site DÉJÀ DESSINÉ : un bloc par type et par page,
|
|
34
|
+
* dont on veut rendre les mots et les images modifiables — pas un constructeur
|
|
35
|
+
* de pages. Pour des blocs répétables, voir `useSectionList`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useSection<T extends object>(blockType: string, options: {
|
|
38
|
+
defaut: T;
|
|
39
|
+
}): ResultatSection<T>;
|
|
40
|
+
/** Plusieurs blocs du même type, dans l'ordre choisi par le client. */
|
|
41
|
+
export declare function useSectionList<T extends object>(blockType: string, options?: {
|
|
42
|
+
defaut?: T[];
|
|
43
|
+
}): {
|
|
44
|
+
items: Array<T & {
|
|
45
|
+
__uid: string;
|
|
46
|
+
}>;
|
|
47
|
+
publie: boolean;
|
|
48
|
+
chargement: boolean;
|
|
49
|
+
ancrage: AncrageEdition;
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lystech/sections",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Contenu de site editable par le client — lecture legere, edition chargee a la demande.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
13
|
-
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./editeur": {
|
|
15
|
+
"types": "./dist/editeur/index.d.ts",
|
|
16
|
+
"import": "./dist/editeur.js"
|
|
14
17
|
}
|
|
15
18
|
},
|
|
16
|
-
"
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
17
23
|
"scripts": {
|
|
18
24
|
"build": "tsc -b && vite build",
|
|
19
25
|
"dev": "vite build --watch"
|
|
@@ -31,5 +37,7 @@
|
|
|
31
37
|
"vite": "^7.0.0",
|
|
32
38
|
"vite-plugin-dts": "^4.5.4"
|
|
33
39
|
},
|
|
34
|
-
"publishConfig": {
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
35
43
|
}
|
package/dist/index.umd.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s.LystechSections={},s.jsxRuntime,s.React))})(this,(function(s,a,c){"use strict";const y=c.createContext(null),j="https://api.lystech.ca/api";function A({site:t,page:n,langue:e="fr",apiBaseUrl:o=j,children:r}){const[i,l]=c.useState([]),[S,h]=c.useState("chargement"),[E,P]=c.useState(0),b=c.useRef(null);c.useEffect(()=>{if(!t||!n)return;b.current?.abort();const f=new AbortController;return b.current=f,h("chargement"),fetch(`${o}/site-sections/public/${encodeURIComponent(t)}/${encodeURIComponent(n)}`,{signal:f.signal}).then(u=>u.ok?u.json():Promise.reject(new Error(String(u.status)))).then(u=>{f.signal.aborted||(l(Array.isArray(u)?u:[]),h("pret"))}).catch(u=>{f.signal.aborted||u?.name==="AbortError"||h("erreur")}),()=>f.abort()},[t,n,o,E]);const R=c.useMemo(()=>({site:t,langue:e,sections:i,etat:S,recharger:()=>P(f=>f+1)}),[t,e,i,S]);return a.jsx(y.Provider,{value:R,children:r})}function m(){return c.useContext(y)}function g(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).every(n=>/^[a-z]{2}(-[A-Za-z]{2})?$/.test(n))}function d(t,n){if(Array.isArray(t))return t.map(e=>d(e,n));if(g(t)){const e=t,o=n.slice(0,2);return e[n]??e[o]??Object.values(e).find(i=>i!=null)??""}if(t&&typeof t=="object"){const e={};for(const[o,r]of Object.entries(t))e[o]=d(r,n);return e}return t}function p(t,n){if(!n||typeof n!="object"||Array.isArray(n))return t;const e={...t};for(const[o,r]of Object.entries(n))r!=null&&(e[o]=r);return e}function x(t,n){const e=m();return c.useMemo(()=>{const o=e?.sections.find(l=>l.blockType===t),r=o?.data??null,i=r?d(r,e?.langue??"fr"):null;return{contenu:p(n.defaut,i),publie:!!r,UID:o?.UID??null,chargement:e?.etat==="chargement"}},[e?.sections,e?.langue,e?.etat,t,n.defaut])}function C(t,n){const e=m();return c.useMemo(()=>{const o=(e?.sections??[]).filter(r=>r.blockType===t);return o.length===0?{items:(n?.defaut??[]).map((r,i)=>({...r,__uid:`defaut-${i}`})),publie:!1,chargement:e?.etat==="chargement"}:{items:o.map(r=>({...d(r.data??{},e?.langue??"fr"),__uid:r.UID})),publie:!0,chargement:e?.etat==="chargement"}},[e?.sections,e?.langue,e?.etat,t,n?.defaut])}s.SectionsProvider=A,s.useSection=x,s.useSectionList=C,s.useSectionsContext=m,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|