leiho 1.0.0-beta.13 → 1.0.0-rc.10
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 +41 -1
- package/bin/leiho.js +16 -2
- package/dist/leiho-bridge.js +198 -25
- package/gallery.css +74 -0
- package/package.json +17 -4
- package/src/ai-ready.js +488 -0
- package/src/attrs.js +5 -1
- package/src/content.js +15 -3
- package/src/html.js +212 -0
- package/src/index.js +197 -24
- package/src/seo.js +196 -0
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ import { field, block } from 'leiho';
|
|
|
70
70
|
<section {...block(page, 'sections', i, 'Hero')}>…</section>
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
`field(page, 'intro', { html: true })` adds `data-leiho-apply="html"`; `{ refresh: true }` adds `data-leiho-refresh="save"`. They are pure functions: use them in server components and at build time. In plain HTML, write the attributes below by hand.
|
|
73
|
+
`field(page, 'intro', { html: true })` adds `data-leiho-apply="html"`; `{ gallery: true }` adds `data-leiho-apply="gallery"`; `{ refresh: true }` adds `data-leiho-refresh="save"`. They are pure functions: use them in server components and at build time. In plain HTML, write the attributes below by hand.
|
|
74
74
|
|
|
75
75
|
```html
|
|
76
76
|
<main data-wp-post="12">
|
|
@@ -86,6 +86,7 @@ import { field, block } from 'leiho';
|
|
|
86
86
|
| `data-wp-post="{id}"` | Container: WordPress post ID of the fields inside |
|
|
87
87
|
| `data-wp-field="{path}"` | Editable element: ACF field name, `_title` or `_thumbnail`; dotted paths (`cards.0.title`, `contact.address`) reach into repeaters, flexible content and groups |
|
|
88
88
|
| `data-leiho-apply="html"` | The value contains markup: inject filtered HTML instead of text |
|
|
89
|
+
| `data-leiho-apply="gallery"` | Gallery field: one child per image; the preview rebuilds the children from the first one (its markup and classes are kept) |
|
|
89
90
|
| `data-leiho-refresh="save"` | No live preview; the editor reloads the page after saving |
|
|
90
91
|
| `data-leiho-section="Label"` | Names a section in the editor's Structure tree |
|
|
91
92
|
| `data-leiho-layout="sections.2"` | Binds a section to a flexible content row, so editors can add, move, duplicate and remove it |
|
|
@@ -95,6 +96,23 @@ import { field, block } from 'leiho';
|
|
|
95
96
|
|
|
96
97
|
**Always render annotated elements, even when their value is empty.** An element that isn't in the page can't be filled in live.
|
|
97
98
|
|
|
99
|
+
### Galleries
|
|
100
|
+
|
|
101
|
+
```astro
|
|
102
|
+
---
|
|
103
|
+
import 'leiho/gallery.css'; // optional default: automatic grid of squares
|
|
104
|
+
---
|
|
105
|
+
<ul class="leiho-gallery" {...field(page, 'photos', { gallery: true })}>
|
|
106
|
+
{page.fields.photos.map((photo) => <li><img src={photo.url} alt={photo.alt} loading="lazy" /></li>)}
|
|
107
|
+
</ul>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`leiho/gallery.css` also styles WordPress's Gallery block (`.wp-block-gallery`) in a post body. Variables: `--leiho-gallery-min` (200px), `--leiho-gallery-gap`, `--leiho-gallery-radius`, `--leiho-gallery-ratio`.
|
|
111
|
+
|
|
112
|
+
### Draft preview
|
|
113
|
+
|
|
114
|
+
A draft has no page on a static site yet. The editor loads the page of a published entry of the same type and the bridge (version 6) re-binds it to the draft (`data-wp-post` is rewritten, empty values apply), so editors see the draft in the real layout before publishing. Nothing to do on your side.
|
|
115
|
+
|
|
98
116
|
Header, footer and `<section>` elements are detected as sections automatically; explicit `data-leiho-section` / `data-leiho-layout` annotations take precedence.
|
|
99
117
|
|
|
100
118
|
## Allow framing
|
|
@@ -107,6 +125,28 @@ Content-Security-Policy: frame-ancestors 'self' https://your-wordpress.example
|
|
|
107
125
|
|
|
108
126
|
and must not send `X-Frame-Options: DENY` or `SAMEORIGIN`.
|
|
109
127
|
|
|
128
|
+
## Search engines and AI assistants
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import { leihoGraph, jsonLd, seoMeta } from 'leiho/seo';
|
|
132
|
+
// One schema.org graph per page: site, organization, breadcrumbs, and the
|
|
133
|
+
// item's own nodes (item.seo.jsonld, computed by the plugin).
|
|
134
|
+
const graph = leihoGraph( { url, item, site: { url: 'https://example.com', name: 'Example' }, breadcrumbs } );
|
|
135
|
+
const tag = `<script type="application/ld+json">${ jsonLd( graph ) }</script>`;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
After a static build, every page as Markdown (`page.md`), `llms.txt`, `llms-full.txt` and `sitemap.xml` with `hreflang`:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import { aiReady } from 'leiho/ai-ready'; // Astro integration
|
|
142
|
+
import { buildAiFiles } from 'leiho/ai-ready'; // or call it yourself
|
|
143
|
+
await buildAiFiles( { dir: 'dist', site: 'https://example.com' } );
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npx leiho ai-ready --site https://example.com --dir dist
|
|
148
|
+
```
|
|
149
|
+
|
|
110
150
|
## Protocol
|
|
111
151
|
|
|
112
152
|
Messages are `{ ns: 'leiho', type, … }`, sent with an explicit `targetOrigin` and checked against `event.origin`.
|
package/bin/leiho.js
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* npx leiho types [--url https://cms.example.com] [--out src/leiho.d.ts]
|
|
6
6
|
* npx leiho pull [--url https://cms.example.com] [--out .leiho/content.json]
|
|
7
|
+
* npx leiho ai-ready --site https://example.com [--dir dist] [--locales en,fr]
|
|
7
8
|
*
|
|
8
9
|
* L'adresse du CMS et le jeton se lisent aussi dans LEIHO_URL et LEIHO_TOKEN.
|
|
9
10
|
*/
|
|
10
11
|
import fs from 'node:fs/promises';
|
|
11
12
|
import path from 'node:path';
|
|
12
13
|
import { exportUrl, loadLeihoContent } from '../src/content.js';
|
|
14
|
+
import { buildAiFiles } from '../src/ai-ready.js';
|
|
13
15
|
|
|
14
16
|
const [ command, ...rest ] = process.argv.slice( 2 );
|
|
15
17
|
const args = {};
|
|
@@ -43,10 +45,22 @@ async function pull() {
|
|
|
43
45
|
console.log( 'leiho: ' + data.items.length + ' items (' + source + ') in ' + out );
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
// Après un build statique : pages en Markdown, llms.txt, llms-full.txt, sitemap.xml.
|
|
49
|
+
async function aiReady() {
|
|
50
|
+
await buildAiFiles( {
|
|
51
|
+
dir: args.dir || 'dist',
|
|
52
|
+
site: args.site || process.env.SITE_URL,
|
|
53
|
+
locales: args.locales ? args.locales.split( ',' ) : undefined,
|
|
54
|
+
exclude: args.exclude ? args.exclude.split( ',' ) : undefined,
|
|
55
|
+
sitemap: args.sitemap !== 'false',
|
|
56
|
+
logger: { info: ( message ) => console.log( 'leiho: ' + message ) },
|
|
57
|
+
} );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const commands = { types, pull, 'ai-ready': aiReady };
|
|
47
61
|
|
|
48
62
|
if ( ! commands[ command ] ) {
|
|
49
|
-
console.log( 'Usage: leiho <types|pull> [--url https://cms.example.com] [--out file] [--token …]' );
|
|
63
|
+
console.log( 'Usage: leiho <types|pull> [--url https://cms.example.com] [--out file] [--token …]\n leiho ai-ready --site https://example.com [--dir dist] [--locales en,fr] [--exclude /drafts] [--sitemap false]' );
|
|
50
64
|
process.exit( command ? 1 : 0 );
|
|
51
65
|
}
|
|
52
66
|
|
package/dist/leiho-bridge.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* leiho-bridge
|
|
2
|
+
* leiho-bridge v6 — standalone (auto-init).
|
|
3
3
|
* Généré par bridge/build.js depuis src/index.js — ne pas éditer à la main.
|
|
4
4
|
*
|
|
5
5
|
* Chargement recommandé (le bridge ne sert qu'à l'éditeur) :
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* leiho
|
|
19
|
+
* leiho v6 — pont postMessage entre un site et l'éditeur Leiho.
|
|
20
20
|
*
|
|
21
21
|
* Fonctionne avec n'importe quel front : HTML statique, Astro, Next.js, Remix,
|
|
22
22
|
* React (SPA ou rendu serveur), Vue/Nuxt, Svelte/SvelteKit.
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
* data-wp-post="12" conteneur : ID du contenu WordPress
|
|
38
38
|
* data-wp-field="chemin" élément éditable (chemins pointés : cartes.0.titre)
|
|
39
39
|
* data-leiho-apply="html" la valeur est du HTML (balisage interne conservé)
|
|
40
|
+
* data-leiho-apply="gallery" galerie : un enfant par image, sur le modèle du premier
|
|
40
41
|
* data-leiho-section="Libellé" section logique (arbre de structure)
|
|
41
42
|
* data-leiho-layout="sections.2" section portée par une ligne de flexible content
|
|
42
43
|
* data-leiho-refresh="save" pas d'aperçu instantané, rechargement après enregistrement
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
*/
|
|
57
58
|
|
|
58
59
|
const NS = 'leiho';
|
|
59
|
-
const VERSION =
|
|
60
|
+
const VERSION = 6;
|
|
60
61
|
const HOVER_CLASS = 'leiho-hover';
|
|
61
62
|
const MANAGED_CLASS = 'leiho-managed-hover';
|
|
62
63
|
const CLOAK_CLASS = 'leiho-cloak';
|
|
@@ -115,6 +116,17 @@
|
|
|
115
116
|
/** Valeurs d'aperçu en cours : "postId:path" -> { value, fieldType }. */
|
|
116
117
|
const overrides = new Map();
|
|
117
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Brouillon montré dans la page d'un autre contenu du même type (il n'a
|
|
121
|
+
* pas encore de page sur le site) : id de la page modèle -> id du
|
|
122
|
+
* brouillon. Réappliqué à chaque collecte (un re-render remet l'id
|
|
123
|
+
* d'origine), oublié au changement de page.
|
|
124
|
+
*/
|
|
125
|
+
const adoptions = new Map();
|
|
126
|
+
|
|
127
|
+
/** Galerie -> modèle d'un élément (premier enfant d'origine). */
|
|
128
|
+
const galleryTemplates = new WeakMap();
|
|
129
|
+
|
|
118
130
|
/** Dernière collecte : champs et sections présents dans le DOM. */
|
|
119
131
|
let fields = new Map();
|
|
120
132
|
let sections = [];
|
|
@@ -207,7 +219,17 @@
|
|
|
207
219
|
return { post: postIdOf( el ) || null, path: parts.slice( 0, -1 ).join( '.' ), index };
|
|
208
220
|
}
|
|
209
221
|
|
|
222
|
+
function applyAdoptions() {
|
|
223
|
+
adoptions.forEach( ( to, from ) => {
|
|
224
|
+
document.querySelectorAll( '[data-wp-post="' + from + '"]' ).forEach( ( el ) => {
|
|
225
|
+
el.setAttribute( 'data-wp-post', to );
|
|
226
|
+
el.setAttribute( 'data-leiho-adopted', from );
|
|
227
|
+
} );
|
|
228
|
+
} );
|
|
229
|
+
}
|
|
230
|
+
|
|
210
231
|
function collect() {
|
|
232
|
+
applyAdoptions();
|
|
211
233
|
const nextFields = new Map();
|
|
212
234
|
const nextSections = [];
|
|
213
235
|
|
|
@@ -292,22 +314,68 @@
|
|
|
292
314
|
* Application des valeurs
|
|
293
315
|
* ------------------------------------------------------------------ */
|
|
294
316
|
|
|
317
|
+
// Liste blanche : seul ce qu'un texte riche contient passe. Une liste noire
|
|
318
|
+
// laisse toujours une porte (noscript, svg/math, schémas d'URL exotiques).
|
|
319
|
+
const ALLOWED_TAGS = new Set( [
|
|
320
|
+
'A', 'ABBR', 'B', 'BLOCKQUOTE', 'BR', 'CAPTION', 'CITE', 'CODE', 'DD', 'DEL', 'DIV', 'DL', 'DT', 'EM', 'FIGCAPTION',
|
|
321
|
+
'FIGURE', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HR', 'I', 'IMG', 'INS', 'KBD', 'LI', 'MARK', 'OL', 'P', 'PRE', 'Q',
|
|
322
|
+
'S', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'TABLE', 'TBODY', 'TD', 'TFOOT', 'TH', 'THEAD', 'TR', 'U', 'UL',
|
|
323
|
+
] );
|
|
324
|
+
// Hors liste blanche et retirées avec leur contenu (code, documents imbriqués).
|
|
325
|
+
const DROPPED_TAGS = new Set( [ ...BANNED_TAGS.map( ( t ) => t.toUpperCase() ), 'NOSCRIPT', 'NOEMBED', 'NOFRAMES', 'TEMPLATE', 'SVG', 'MATH', 'XMP', 'TEXTAREA', 'TITLE', 'SELECT', 'OBJECT' ] );
|
|
326
|
+
const ALLOWED_ATTRS = new Set( [ 'href', 'src', 'alt', 'title', 'class', 'width', 'height', 'target', 'rel', 'colspan', 'rowspan', 'lang', 'dir', 'start', 'reversed', 'loading', 'decoding', 'srcset', 'sizes', 'id', 'style' ] );
|
|
327
|
+
|
|
328
|
+
/** Adresse sûre : http(s), mailto, tel ou relative. */
|
|
329
|
+
function safeUrl( value ) {
|
|
330
|
+
const url = String( null == value ? '' : value ).replace( /[\u0000-\u0020\u007f-\u009f]/g, '' );
|
|
331
|
+
const scheme = url.match( /^([a-z][a-z0-9+.-]*):/i );
|
|
332
|
+
return ! scheme || /^(https?|mailto|tel)$/i.test( scheme[ 1 ] ) ? String( value ) : '';
|
|
333
|
+
}
|
|
334
|
+
|
|
295
335
|
function sanitizeHtml( html ) {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
} else if ( ( 'href' === name || 'src' === name || 'xlink:href' === name ) && 0 === value.indexOf( 'javascript:' ) ) {
|
|
306
|
-
el.removeAttribute( attr.name );
|
|
336
|
+
const source = new DOMParser().parseFromString( '<body>' + String( null == html ? '' : html ) + '</body>', 'text/html' ).body;
|
|
337
|
+
const clean = ( node, into ) => {
|
|
338
|
+
node.childNodes.forEach( ( child ) => {
|
|
339
|
+
if ( child.nodeType === Node.TEXT_NODE ) {
|
|
340
|
+
into.appendChild( document.createTextNode( child.nodeValue ) );
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if ( child.nodeType !== Node.ELEMENT_NODE ) {
|
|
344
|
+
return;
|
|
307
345
|
}
|
|
346
|
+
if ( ! ALLOWED_TAGS.has( child.tagName ) ) {
|
|
347
|
+
// Balise inconnue : son texte reste, sauf pour ce qui n'en a pas à montrer.
|
|
348
|
+
if ( ! DROPPED_TAGS.has( child.tagName.toUpperCase() ) ) {
|
|
349
|
+
clean( child, into );
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const el = document.createElement( child.tagName );
|
|
354
|
+
[ ...child.attributes ].forEach( ( a ) => {
|
|
355
|
+
const name = a.name.toLowerCase();
|
|
356
|
+
if ( ! ALLOWED_ATTRS.has( name ) ) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if ( 'href' === name || 'src' === name ) {
|
|
360
|
+
const url = safeUrl( a.value );
|
|
361
|
+
if ( url ) {
|
|
362
|
+
el.setAttribute( name, url );
|
|
363
|
+
}
|
|
364
|
+
} else if ( 'srcset' === name ) {
|
|
365
|
+
if ( ! /(^|,)\s*[a-z][a-z0-9+.-]*:/i.test( a.value ) || a.value.split( ',' ).every( ( part ) => safeUrl( part.trim().split( /\s+/ )[ 0 ] ) ) ) {
|
|
366
|
+
el.setAttribute( name, a.value );
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
el.setAttribute( name, a.value );
|
|
370
|
+
}
|
|
371
|
+
} );
|
|
372
|
+
clean( child, el );
|
|
373
|
+
into.appendChild( el );
|
|
308
374
|
} );
|
|
309
|
-
}
|
|
310
|
-
|
|
375
|
+
};
|
|
376
|
+
const out = document.createElement( 'div' );
|
|
377
|
+
clean( source, out );
|
|
378
|
+
return out.innerHTML;
|
|
311
379
|
}
|
|
312
380
|
|
|
313
381
|
/**
|
|
@@ -326,16 +394,96 @@
|
|
|
326
394
|
}
|
|
327
395
|
}
|
|
328
396
|
|
|
329
|
-
|
|
330
|
-
|
|
397
|
+
/**
|
|
398
|
+
* @param {Element} el Élément annoté.
|
|
399
|
+
* @param {*} value Valeur du champ.
|
|
400
|
+
* @param {string} fieldType Type de champ.
|
|
401
|
+
* @param {boolean} explicit Valeur changée par l'utilisateur pendant cette
|
|
402
|
+
* édition (fieldUpdate), pas seulement chargée.
|
|
403
|
+
*/
|
|
404
|
+
/** Élément de galerie par défaut quand la galerie du site est vide. */
|
|
405
|
+
function defaultGalleryItem( el ) {
|
|
406
|
+
const item = document.createElement( 'UL' === el.tagName || 'OL' === el.tagName ? 'li' : 'figure' );
|
|
407
|
+
const img = document.createElement( 'img' );
|
|
408
|
+
img.setAttribute( 'loading', 'lazy' );
|
|
409
|
+
img.setAttribute( 'alt', '' );
|
|
410
|
+
item.appendChild( img );
|
|
411
|
+
return item;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function fillGalleryItem( node, image ) {
|
|
415
|
+
const img = 'IMG' === node.tagName ? node : node.querySelector( 'img' );
|
|
416
|
+
if ( img ) {
|
|
417
|
+
img.setAttribute( 'src', safeUrl( image.url || '' ) );
|
|
418
|
+
img.removeAttribute( 'srcset' );
|
|
419
|
+
img.removeAttribute( 'sizes' );
|
|
420
|
+
img.setAttribute( 'alt', image.alt || '' );
|
|
421
|
+
[ 'width', 'height' ].forEach( ( dim ) => {
|
|
422
|
+
if ( image[ dim ] ) {
|
|
423
|
+
img.setAttribute( dim, String( Number( image[ dim ] ) || '' ) );
|
|
424
|
+
} else {
|
|
425
|
+
img.removeAttribute( dim );
|
|
426
|
+
}
|
|
427
|
+
} );
|
|
428
|
+
}
|
|
429
|
+
// Lien vers l'image (visionneuse du site) : vers la nouvelle image.
|
|
430
|
+
const link = 'A' === node.tagName ? node : node.querySelector( 'a[href]' );
|
|
431
|
+
if ( link && image.url ) {
|
|
432
|
+
link.setAttribute( 'href', safeUrl( image.url ) );
|
|
433
|
+
}
|
|
434
|
+
const caption = node.querySelector( 'figcaption' );
|
|
435
|
+
if ( caption ) {
|
|
436
|
+
setText( caption, image.caption || '' );
|
|
437
|
+
}
|
|
438
|
+
return node;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Galerie : un enfant par image, cloné sur le premier enfant d'origine
|
|
443
|
+
* (le balisage et les classes du site restent les siens).
|
|
444
|
+
*/
|
|
445
|
+
function applyGallery( el, value, explicit ) {
|
|
446
|
+
const images = ( Array.isArray( value ) ? value : [] ).filter( ( image ) => image && 'object' === typeof image );
|
|
447
|
+
// Jamais remplie : le site montre peut-être des images de repli.
|
|
448
|
+
if ( ! images.length && ! explicit ) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
let template = galleryTemplates.get( el );
|
|
452
|
+
if ( ! template ) {
|
|
453
|
+
template = el.firstElementChild ? el.firstElementChild.cloneNode( true ) : defaultGalleryItem( el );
|
|
454
|
+
galleryTemplates.set( el, template );
|
|
455
|
+
}
|
|
456
|
+
const wanted = images.map( ( image ) => safeUrl( image.url || '' ) );
|
|
457
|
+
const current = [ ...el.children ].map( ( child ) => {
|
|
458
|
+
const img = 'IMG' === child.tagName ? child : child.querySelector( 'img' );
|
|
459
|
+
return img ? img.getAttribute( 'src' ) : null;
|
|
460
|
+
} );
|
|
461
|
+
if ( wanted.length === current.length && wanted.every( ( url, i ) => url === current[ i ] ) ) {
|
|
462
|
+
return; // Déjà à jour : pas de mutation, pas de boucle avec l'observateur.
|
|
463
|
+
}
|
|
464
|
+
el.replaceChildren( ...images.map( ( image ) => fillGalleryItem( template.cloneNode( true ), image ) ) );
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function applyToElement( el, value, fieldType, explicit ) {
|
|
468
|
+
if ( 'gallery' === fieldType || 'gallery' === attr( el, 'apply' ) ) {
|
|
469
|
+
applyGallery( el, value, explicit );
|
|
470
|
+
} else if ( 'image' === fieldType ) {
|
|
471
|
+
const url = value && 'object' === typeof value ? value.url || '' : value || '';
|
|
472
|
+
// Champ jamais rempli : le front affiche souvent une image de repli
|
|
473
|
+
// (src, srcset ou fond CSS du gabarit). On n'y touche pas, sauf si
|
|
474
|
+
// l'utilisateur vient de vider le champ.
|
|
475
|
+
if ( ! url && ! explicit ) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const src = safeUrl( url );
|
|
331
479
|
const img = 'IMG' === el.tagName ? el : el.querySelector( 'img' );
|
|
332
480
|
if ( img ) {
|
|
333
|
-
if ( img.getAttribute( 'src' ) !==
|
|
334
|
-
img.setAttribute( 'src',
|
|
481
|
+
if ( img.getAttribute( 'src' ) !== src ) {
|
|
482
|
+
img.setAttribute( 'src', src );
|
|
335
483
|
img.removeAttribute( 'srcset' );
|
|
336
484
|
}
|
|
337
485
|
} else {
|
|
338
|
-
el.style.backgroundImage =
|
|
486
|
+
el.style.backgroundImage = src ? 'url("' + src.replace( /["\\\n]/g, '' ) + '")' : '';
|
|
339
487
|
}
|
|
340
488
|
} else if ( 'color_picker' === fieldType ) {
|
|
341
489
|
el.style.setProperty( attr( el, 'style' ) || 'color', value || '' );
|
|
@@ -343,7 +491,7 @@
|
|
|
343
491
|
const link = 'A' === el.tagName ? el : el.querySelector( 'a' );
|
|
344
492
|
const data = value && 'object' === typeof value ? value : { url: value };
|
|
345
493
|
if ( link ) {
|
|
346
|
-
link.setAttribute( 'href', data.url || '' );
|
|
494
|
+
link.setAttribute( 'href', safeUrl( data.url || '' ) );
|
|
347
495
|
if ( data.target ) {
|
|
348
496
|
link.setAttribute( 'target', data.target );
|
|
349
497
|
} else {
|
|
@@ -369,7 +517,11 @@
|
|
|
369
517
|
overrides.forEach( ( item, key ) => {
|
|
370
518
|
const entry = fields.get( key );
|
|
371
519
|
if ( entry && ! entry.refresh ) {
|
|
372
|
-
|
|
520
|
+
// Page d'un autre contenu montrée pour un brouillon : ses images et
|
|
521
|
+
// galeries ne sont pas des images de repli, une valeur vide s'applique.
|
|
522
|
+
entry.els.forEach( ( el ) =>
|
|
523
|
+
applyToElement( el, item.value, item.fieldType, !! item.explicit || !! el.closest( '[data-leiho-adopted]' ) )
|
|
524
|
+
);
|
|
373
525
|
}
|
|
374
526
|
} );
|
|
375
527
|
} finally {
|
|
@@ -423,6 +575,7 @@
|
|
|
423
575
|
// précédente ne concernent plus rien.
|
|
424
576
|
currentUrl = window.location.href;
|
|
425
577
|
overrides.clear();
|
|
578
|
+
adoptions.clear();
|
|
426
579
|
}
|
|
427
580
|
collect();
|
|
428
581
|
applyOverrides();
|
|
@@ -505,6 +658,9 @@
|
|
|
505
658
|
} catch ( e ) {
|
|
506
659
|
return;
|
|
507
660
|
}
|
|
661
|
+
if ( ! /^https?:$/.test( url.protocol ) ) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
508
664
|
send( { type: 'navigate', href: url.href, path: url.pathname, external: url.origin !== window.location.origin } );
|
|
509
665
|
return;
|
|
510
666
|
}
|
|
@@ -544,7 +700,7 @@
|
|
|
544
700
|
}
|
|
545
701
|
|
|
546
702
|
window.addEventListener( 'message', ( event ) => {
|
|
547
|
-
if ( event.origin !== wpOrigin || ! event.data || event.data.ns !== NS ) {
|
|
703
|
+
if ( event.origin !== wpOrigin || event.source !== window.parent || ! event.data || event.data.ns !== NS ) {
|
|
548
704
|
return;
|
|
549
705
|
}
|
|
550
706
|
const data = event.data;
|
|
@@ -560,8 +716,25 @@
|
|
|
560
716
|
applyOverrides();
|
|
561
717
|
uncloak();
|
|
562
718
|
} else if ( 'fieldUpdate' === data.type ) {
|
|
563
|
-
overrides.set( data.postId + ':' + data.path, { value: data.value, fieldType: data.fieldType } );
|
|
719
|
+
overrides.set( data.postId + ':' + data.path, { value: data.value, fieldType: data.fieldType, explicit: true } );
|
|
564
720
|
applyOverrides();
|
|
721
|
+
} else if ( 'ping' === data.type ) {
|
|
722
|
+
// L'éditeur n'a pas reçu notre annonce (chargement concurrent) : on la
|
|
723
|
+
// refait. Page encore en chargement : start() l'enverra.
|
|
724
|
+
if ( 'loading' === document.readyState ) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
collect();
|
|
728
|
+
announce();
|
|
729
|
+
} else if ( 'adopt' === data.type ) {
|
|
730
|
+
const from = String( data.from );
|
|
731
|
+
const to = String( data.to );
|
|
732
|
+
if ( /^\d+$/.test( from ) && /^\d+$/.test( to ) && from !== to ) {
|
|
733
|
+
adoptions.set( from, to );
|
|
734
|
+
overrides.clear();
|
|
735
|
+
collect();
|
|
736
|
+
announce();
|
|
737
|
+
}
|
|
565
738
|
} else if ( 'focusField' === data.type ) {
|
|
566
739
|
const entry = fields.get( data.postId + ':' + data.path );
|
|
567
740
|
if ( entry && entry.els[ 0 ] ) {
|
package/gallery.css
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* leiho/gallery.css — rendu par défaut des galeries Leiho, à importer si on
|
|
3
|
+
* veut (import 'leiho/gallery.css') ou à copier et adapter.
|
|
4
|
+
*
|
|
5
|
+
* Une grille automatique de carrés : autant de colonnes que la largeur en
|
|
6
|
+
* permet (200 px minimum), photos recadrées au centre. Une photo seule garde
|
|
7
|
+
* son format. Aucun réglage côté éditeur : le site décide.
|
|
8
|
+
*
|
|
9
|
+
* Couvre les deux galeries :
|
|
10
|
+
* - un champ galerie rendu dans un .leiho-gallery (ul, ol ou div, un
|
|
11
|
+
* enfant par image) ;
|
|
12
|
+
* - le bloc Galerie du contenu (figure.wp-block-gallery), tel que
|
|
13
|
+
* WordPress et Leiho l'écrivent.
|
|
14
|
+
*
|
|
15
|
+
* Variables : --leiho-gallery-min (200px), --leiho-gallery-gap (10px),
|
|
16
|
+
* --leiho-gallery-radius (12px), --leiho-gallery-ratio (1).
|
|
17
|
+
*/
|
|
18
|
+
.leiho-gallery,
|
|
19
|
+
.wp-block-gallery,
|
|
20
|
+
.blocks-gallery-grid {
|
|
21
|
+
display: grid;
|
|
22
|
+
grid-template-columns: repeat(auto-fill, minmax(min(var(--leiho-gallery-min, 200px), 100%), 1fr));
|
|
23
|
+
gap: var(--leiho-gallery-gap, 10px);
|
|
24
|
+
margin-left: 0;
|
|
25
|
+
margin-right: 0;
|
|
26
|
+
padding: 0;
|
|
27
|
+
list-style: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.wp-block-gallery .blocks-gallery-grid {
|
|
31
|
+
display: contents;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.leiho-gallery > *,
|
|
35
|
+
.wp-block-gallery > figure,
|
|
36
|
+
.blocks-gallery-item {
|
|
37
|
+
margin: 0;
|
|
38
|
+
min-width: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.leiho-gallery img,
|
|
42
|
+
.wp-block-gallery img {
|
|
43
|
+
display: block;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 100%;
|
|
46
|
+
aspect-ratio: var(--leiho-gallery-ratio, 1);
|
|
47
|
+
object-fit: cover;
|
|
48
|
+
border-radius: var(--leiho-gallery-radius, 12px);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.leiho-gallery figcaption,
|
|
52
|
+
.wp-block-gallery figure figcaption {
|
|
53
|
+
margin-top: 6px;
|
|
54
|
+
font-size: 0.875em;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Légende de la galerie entière : sur toute la largeur. */
|
|
58
|
+
.wp-block-gallery > figcaption,
|
|
59
|
+
.blocks-gallery-caption {
|
|
60
|
+
grid-column: 1 / -1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Une seule photo : pleine largeur, à son format. */
|
|
64
|
+
.leiho-gallery:has(> :only-child),
|
|
65
|
+
.wp-block-gallery:has(> figure:only-of-type) {
|
|
66
|
+
grid-template-columns: minmax(0, 1fr);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.leiho-gallery > :only-child img,
|
|
70
|
+
.wp-block-gallery > figure:only-of-type img {
|
|
71
|
+
height: auto;
|
|
72
|
+
aspect-ratio: auto;
|
|
73
|
+
object-fit: contain;
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leiho",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"description": "Pont postMessage de l'éditeur visuel Leiho : rend n'importe quel site (React, Next.js, Remix, Vite, Nuxt, SvelteKit, Astro, HTML) éditable depuis WordPress. Zéro dépendance, inactif hors de l'éditeur.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wordpress",
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
"remix",
|
|
14
14
|
"vite",
|
|
15
15
|
"nuxt",
|
|
16
|
-
"sveltekit"
|
|
16
|
+
"sveltekit",
|
|
17
|
+
"llms.txt",
|
|
18
|
+
"json-ld",
|
|
19
|
+
"seo"
|
|
17
20
|
],
|
|
18
21
|
"license": "GPL-2.0-or-later",
|
|
19
22
|
"author": "Pixelers (https://pixelers.fr)",
|
|
@@ -34,7 +37,14 @@
|
|
|
34
37
|
},
|
|
35
38
|
"./attrs": {
|
|
36
39
|
"import": "./src/attrs.js"
|
|
37
|
-
}
|
|
40
|
+
},
|
|
41
|
+
"./seo": {
|
|
42
|
+
"import": "./src/seo.js"
|
|
43
|
+
},
|
|
44
|
+
"./ai-ready": {
|
|
45
|
+
"import": "./src/ai-ready.js"
|
|
46
|
+
},
|
|
47
|
+
"./gallery.css": "./gallery.css"
|
|
38
48
|
},
|
|
39
49
|
"scripts": {
|
|
40
50
|
"build": "node build.js",
|
|
@@ -44,9 +54,12 @@
|
|
|
44
54
|
"src",
|
|
45
55
|
"dist",
|
|
46
56
|
"bin",
|
|
57
|
+
"gallery.css",
|
|
47
58
|
"README.md"
|
|
48
59
|
],
|
|
49
|
-
"sideEffects":
|
|
60
|
+
"sideEffects": [
|
|
61
|
+
"*.css"
|
|
62
|
+
],
|
|
50
63
|
"repository": {
|
|
51
64
|
"type": "git",
|
|
52
65
|
"url": "git+https://github.com/pixelersagency/leiho.git",
|