@bebranded/bb-contents 1.0.123 → 1.0.124

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.
Files changed (2) hide show
  1. package/bb-contents.js +38 -11
  2. package/package.json +1 -1
package/bb-contents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * BeBranded Contents
3
3
  * Contenus additionnels français pour Webflow
4
- * @version 1.0.123
4
+ * @version 1.0.124
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -32,11 +32,11 @@
32
32
  window._bbContentsInitialized = true;
33
33
 
34
34
  // Log de démarrage simple (une seule fois)
35
- console.log('bb-contents | v1.0.123');
35
+ console.log('bb-contents | v1.0.124');
36
36
 
37
37
  // Configuration
38
38
  const config = {
39
- version: '1.0.123',
39
+ version: '1.0.124',
40
40
  debug: false, // Debug désactivé pour rendu propre
41
41
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
42
42
  youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
@@ -1261,7 +1261,6 @@
1261
1261
  elements.forEach(function(element) {
1262
1262
  if (element.bbProcessed || element.hasAttribute('data-bb-country-select-processed')) return;
1263
1263
  if (element.tagName !== 'SELECT') {
1264
- bbContents.utils.log('bb-country-select doit être utilisé sur un élément <select>');
1265
1264
  return;
1266
1265
  }
1267
1266
  element.bbProcessed = true;
@@ -1291,11 +1290,21 @@
1291
1290
  defaultCountry = self.findCountry(element.value);
1292
1291
  }
1293
1292
 
1294
- // Trier les pays : préférés en haut
1293
+ // Trier les pays : préférés en haut dans l'ordre exact spécifié
1295
1294
  let sortedCountries = self.countries.slice();
1296
1295
  if (preferredCountries.length > 0) {
1297
- sortedCountries = sortedCountries.filter(function(c) {
1298
- return preferredCountries.indexOf(c.alpha2) !== -1;
1296
+ // Créer un map pour l'ordre des préférés
1297
+ const preferredOrder = {};
1298
+ preferredCountries.forEach(function(code, index) {
1299
+ preferredOrder[code] = index;
1300
+ });
1301
+ // Trier : préférés dans l'ordre exact, puis les autres
1302
+ sortedCountries = preferredCountries.map(function(code) {
1303
+ return self.countries.find(function(c) {
1304
+ return c.alpha2 === code;
1305
+ });
1306
+ }).filter(function(c) {
1307
+ return c !== undefined;
1299
1308
  }).concat(sortedCountries.filter(function(c) {
1300
1309
  return preferredCountries.indexOf(c.alpha2) === -1;
1301
1310
  }));
@@ -1327,6 +1336,9 @@
1327
1336
  trigger.innerHTML = '<div style="display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;"><span class="bb-country-flag" style="flex-shrink: 0;">' + selectedFlag + '</span><span class="bb-country-name" style="flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">' + bbContents.utils.sanitize(selectedName) + '</span></div><svg width="16" height="16" viewBox="0 0 16 16" fill="none" style="flex-shrink: 0; transition: transform 0.2s;"><path d="M4 6L8 10L12 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
1328
1337
  trigger.style.cssText = 'display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; background: white; cursor: pointer; font-size: inherit; font-family: inherit; color: inherit; transition: border-color 0.2s; box-sizing: border-box;';
1329
1338
 
1339
+ // Variable pour stocker le pays sélectionné (pour chaque instance)
1340
+ let currentSelectedCountry = defaultCountry;
1341
+
1330
1342
  // Créer le popover
1331
1343
  const popover = document.createElement('div');
1332
1344
  popover.className = 'bb-country-select-popover';
@@ -1364,7 +1376,7 @@
1364
1376
  }
1365
1377
 
1366
1378
  list.innerHTML = countries.map(function(country) {
1367
- const isSelected = selectedCountry && selectedCountry.alpha2 === country.alpha2;
1379
+ const isSelected = currentSelectedCountry && currentSelectedCountry.alpha2 === country.alpha2;
1368
1380
  return '<div class="bb-country-item" data-country="' + country.alpha2 + '" role="option" aria-selected="' + (isSelected ? 'true' : 'false') + '" style="display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; font-size: inherit; font-family: inherit; transition: background-color 0.15s;' + (isSelected ? ' background-color: #f3f4f6;' : '') + '"><img src="https://hatscripts.github.io/circle-flags/flags/' + country.alpha2.toLowerCase() + '.svg" alt="' + bbContents.utils.sanitize(country.name[language]) + '" style="width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex-shrink: 0;"><span>' + bbContents.utils.sanitize(country.name[language]) + '</span></div>';
1369
1381
  }).join('');
1370
1382
 
@@ -1453,12 +1465,28 @@
1453
1465
  });
1454
1466
  if (!country) return;
1455
1467
 
1468
+ // Mettre à jour le pays sélectionné
1469
+ currentSelectedCountry = country;
1470
+
1456
1471
  // Mettre à jour l'affichage
1457
1472
  flagSpan.innerHTML = '<img src="https://hatscripts.github.io/circle-flags/flags/' + country.alpha2.toLowerCase() + '.svg" alt="' + bbContents.utils.sanitize(country.name[language]) + '" style="width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex-shrink: 0;">';
1458
1473
  nameSpan.textContent = country.name[language];
1459
1474
 
1460
- // Mettre à jour le select natif
1461
- element.value = country.alpha2;
1475
+ // Mettre à jour le select natif avec le nom du pays (pas le code ISO)
1476
+ const countryName = country.name[language];
1477
+ element.value = countryName;
1478
+ // Mettre aussi le texte de l'option
1479
+ const existingOption = Array.from(element.options).find(function(opt) {
1480
+ return opt.value === countryName;
1481
+ });
1482
+ if (!existingOption) {
1483
+ // Créer l'option si elle n'existe pas
1484
+ const newOption = document.createElement('option');
1485
+ newOption.value = countryName;
1486
+ newOption.textContent = countryName;
1487
+ element.innerHTML = '';
1488
+ element.appendChild(newOption);
1489
+ }
1462
1490
  const changeEvent = new Event('change', { bubbles: true });
1463
1491
  element.dispatchEvent(changeEvent);
1464
1492
 
@@ -1478,7 +1506,6 @@
1478
1506
  wrapper.setAttribute('data-bb-country-select-processed', 'true');
1479
1507
  });
1480
1508
 
1481
- bbContents.utils.log('Module CountrySelect initialisé:', elements.length, 'éléments');
1482
1509
  }
1483
1510
  },
1484
1511
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.123",
3
+ "version": "1.0.124",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {