pagery-edition 1.1.1 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pagery-edition",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Composants d'édition en ligne pour les sites clients Pagery",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -4,7 +4,6 @@
4
4
  "use client";
5
5
 
6
6
  import { useCallback, useEffect, useRef, useState } from "react";
7
- // @ts-expect-error react-dom types manquants
8
7
  import { createPortal } from "react-dom";
9
8
  import { useEdition } from "./ContexteEdition";
10
9
 
@@ -16,12 +15,17 @@ type PropsTexteEditable = {
16
15
  href?: string;
17
16
  classeAccent?: string;
18
17
  motAccent?: string;
18
+ sautLigneAccent?: boolean;
19
19
  };
20
20
 
21
- // Applique l'accent sur le motAccent dans le texte
22
- function rendreAccent(texte: string, motAccent: string, classeAccent: string): string {
21
+ // Applique l'accent sur le motAccent dans le texte + saut de ligne optionnel
22
+ function rendreAccent(texte: string, motAccent: string, classeAccent: string, sautLigne: boolean): string {
23
23
  if (!motAccent || !classeAccent) return texte;
24
- return texte.replace(motAccent, `<span class="${classeAccent}">${motAccent}</span>`);
24
+ const accentHtml = `<span class="${classeAccent}">${motAccent}</span>`;
25
+ if (sautLigne) {
26
+ return texte.replace(motAccent, `<br/>${accentHtml}`);
27
+ }
28
+ return texte.replace(motAccent, accentHtml);
25
29
  }
26
30
 
27
31
  // Styles inline de la barre d'outils
@@ -184,6 +188,7 @@ export function TexteEditable({
184
188
  href,
185
189
  classeAccent = "",
186
190
  motAccent = "",
191
+ sautLigneAccent = false,
187
192
  }: PropsTexteEditable) {
188
193
  const { modeEdition, contenus, modifierTexte } = useEdition();
189
194
  const refElement = useRef<HTMLElement>(null);
@@ -206,7 +211,6 @@ export function TexteEditable({
206
211
  const barre = document.querySelector("[data-barre-outils]");
207
212
  if (barre?.contains(cible)) return;
208
213
  if (refElement.current) {
209
- refElement.current.textContent = texteOriginal.current;
210
214
  refElement.current.contentEditable = "false";
211
215
  setEnEdition(false);
212
216
  }
@@ -219,7 +223,8 @@ export function TexteEditable({
219
223
  if (!modeEdition || enEdition || !refElement.current) return;
220
224
  const el = refElement.current;
221
225
  texteOriginal.current = texte;
222
- el.textContent = texte;
226
+ // Garder le HTML avec l'accent visible pendant l'édition
227
+ // (ne pas écraser avec textContent)
223
228
  el.contentEditable = "true";
224
229
  el.focus();
225
230
  setEnEdition(true);
@@ -235,7 +240,8 @@ export function TexteEditable({
235
240
  const sauvegarder = useCallback(async () => {
236
241
  if (!refElement.current) return;
237
242
  const el = refElement.current;
238
- const nouveauTexte = el.textContent || "";
243
+ // Extraire le texte brut (sans HTML)
244
+ const nouveauTexte = (el.textContent || "").replace(/\s+/g, " ").trim();
239
245
  el.contentEditable = "false";
240
246
  setEnEdition(false);
241
247
  if (nouveauTexte !== texteOriginal.current) {
@@ -259,7 +265,7 @@ export function TexteEditable({
259
265
 
260
266
  // Accent : appliqué au rendu via motAccent (pas de marqueur dans le texte)
261
267
  const aAccent = motAccent && classeAccent && texte.includes(motAccent);
262
- const htmlRendu = aAccent ? rendreAccent(texte, motAccent, classeAccent) : texte;
268
+ const htmlRendu = aAccent ? rendreAccent(texte, motAccent, classeAccent, sautLigneAccent) : texte;
263
269
  const doitRendreHtml = aAccent || texte.includes("<");
264
270
 
265
271
  // Mode normal