wineater-bot 3.0.6 → 3.0.7
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/wineater-chatbot.mjs +550 -530
- package/dist/wineater-chatbot.umd.js +72 -57
- package/package.json +1 -1
- package/src/js/i18n.js +3 -0
- package/src/js/widget-styles.js +37 -28
- package/src/js/widget.js +104 -76
package/package.json
CHANGED
package/src/js/i18n.js
CHANGED
|
@@ -45,6 +45,7 @@ class Translator {
|
|
|
45
45
|
barSendButton: "Envoyer",
|
|
46
46
|
barResetButton: "Réinitialiser",
|
|
47
47
|
barName: "Nom du bar",
|
|
48
|
+
barNotesPlaceholder: "Entrez vos souhaits ici...",
|
|
48
49
|
},
|
|
49
50
|
es: {
|
|
50
51
|
welcomeMessage: "¿Qué vas a comer? Cuéntame tu plato y te recomendaré el maridaje perfecto.",
|
|
@@ -86,6 +87,7 @@ class Translator {
|
|
|
86
87
|
barSendButton: "Enviar",
|
|
87
88
|
barResetButton: "Reiniciar",
|
|
88
89
|
barName: "Nombre del bar",
|
|
90
|
+
barNotesPlaceholder: "Agrega tus comentarios aquí...",
|
|
89
91
|
},
|
|
90
92
|
en: {
|
|
91
93
|
welcomeMessage: "What are you planning to eat? Share your dish and I'll recommend the perfect wine pairing for your meal.",
|
|
@@ -127,6 +129,7 @@ class Translator {
|
|
|
127
129
|
barSendButton: "Send",
|
|
128
130
|
barResetButton: "Reset",
|
|
129
131
|
barName: "Bar Name",
|
|
132
|
+
barNotesPlaceholder: "Add your wishes here...",
|
|
130
133
|
},
|
|
131
134
|
de: {
|
|
132
135
|
welcomeMessage: "Was möchten Sie essen? Beschreiben Sie Ihr Gericht und ich empfehle Ihnen den perfekten Wein dazu.",
|
package/src/js/widget-styles.js
CHANGED
|
@@ -352,45 +352,54 @@ const widgetStyles = `
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
/* Кнопка "Отправить" для бар-версии */
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
cursor: pointer;
|
|
362
|
-
font-size: 16px;
|
|
363
|
-
transition: all 0.2s ease;
|
|
364
|
-
text-align:center;
|
|
365
|
-
margin-top: 16px;
|
|
355
|
+
|
|
356
|
+
#bar-controls {
|
|
357
|
+
display: flex;
|
|
358
|
+
align-items: stretch; /* или center, если нужно выравнивать */
|
|
359
|
+
gap: 8px;
|
|
360
|
+
margin-top: 16px;
|
|
366
361
|
}
|
|
367
362
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
363
|
+
/* Задаем одной высотой и одинаковыми отступами */
|
|
364
|
+
#bar-controls input,
|
|
365
|
+
#bar-controls button {
|
|
366
|
+
height: 44px; /* или 48px, как вам нравится */
|
|
367
|
+
line-height: 44px; /* чтобы текст по вертикали выровнялся */
|
|
368
|
+
box-sizing: border-box; /* подстраховка, чтобы высота учитывала бордер */
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/* Чтобы кнопка и инпут смотрелись схоже по высоте */
|
|
372
|
+
#bar-notes-input {
|
|
373
|
+
flex: 1;
|
|
374
|
+
padding: 0 12px; /* уберите или уменьшите вертикальные padding’и */
|
|
375
|
+
border: 1px solid #ccc;
|
|
376
|
+
border-radius: 6px;
|
|
377
|
+
font-size: 14px;
|
|
378
|
+
outline: none;
|
|
371
379
|
}
|
|
372
380
|
|
|
373
|
-
/*
|
|
381
|
+
/* Кнопки – чуть меняем паддинги, чтобы не «лезли» за высоту */
|
|
382
|
+
#bar-send-button,
|
|
374
383
|
#bar-reset-button {
|
|
375
|
-
|
|
384
|
+
padding: 0 20px; /* а по вертикали пусть высота сама регулируется через height */
|
|
385
|
+
border-radius: 6px;
|
|
376
386
|
background: linear-gradient(90deg, #7B2BEB, #0044FF);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
transition: all 0.2s ease;
|
|
383
|
-
margin-top: 16px; /* или подстройте под свой макет */
|
|
384
|
-
margin-left: 12px; /* чтобы отступить от кнопки "Отправить" */
|
|
387
|
+
font-size: 14px;
|
|
388
|
+
cursor: pointer;
|
|
389
|
+
white-space: nowrap;
|
|
390
|
+
color: white;
|
|
391
|
+
border: none;
|
|
385
392
|
}
|
|
386
393
|
|
|
387
|
-
|
|
388
|
-
|
|
394
|
+
/* При желании hover-эффект сохранить: */
|
|
395
|
+
#bar-send-button:hover,
|
|
389
396
|
#bar-reset-button:hover {
|
|
390
|
-
|
|
391
|
-
|
|
397
|
+
transform: scale(1.05);
|
|
398
|
+
box-shadow: 0 4px 8px rgba(123, 43, 235, 0.15);
|
|
392
399
|
}
|
|
393
400
|
|
|
401
|
+
|
|
402
|
+
|
|
394
403
|
.hidden {
|
|
395
404
|
display: none;
|
|
396
405
|
}
|
package/src/js/widget.js
CHANGED
|
@@ -118,21 +118,27 @@ export class WineWidget {
|
|
|
118
118
|
|
|
119
119
|
<div id="wine-placeholder"></div>
|
|
120
120
|
|
|
121
|
+
<div id="loading-indicator" class="hidden">
|
|
122
|
+
<div id="typing-indicator" class="typing-indicator">
|
|
123
|
+
<span></span><span></span><span></span>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
121
127
|
<!-- Кнопки для отправки и сброса -->
|
|
122
|
-
<div id="bar-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
<div id="bar-controls">
|
|
129
|
+
<input
|
|
130
|
+
type="text"
|
|
131
|
+
id="bar-notes-input"
|
|
132
|
+
placeholder="${translator.translate('barNotesPlaceholder')}"
|
|
133
|
+
/>
|
|
134
|
+
<button id="bar-send-button">
|
|
135
|
+
${translator.translate('barSendButton')}
|
|
136
|
+
</button>
|
|
137
|
+
<button id="bar-reset-button" class="hidden">
|
|
138
|
+
${translator.translate('barResetButton')}
|
|
139
|
+
</button>
|
|
140
|
+
</div>
|
|
130
141
|
|
|
131
|
-
<div id="loading-indicator" class="hidden">
|
|
132
|
-
<div id="typing-indicator" class="typing-indicator">
|
|
133
|
-
<span></span><span></span><span></span>
|
|
134
|
-
</div>
|
|
135
|
-
</div>
|
|
136
142
|
</div>
|
|
137
143
|
</div>
|
|
138
144
|
`;
|
|
@@ -309,75 +315,97 @@ export class WineWidget {
|
|
|
309
315
|
}
|
|
310
316
|
}
|
|
311
317
|
addEventListenersBarVersion() {
|
|
312
|
-
//
|
|
318
|
+
// Теперь плитки блюд появятся только после renderDishGroups()
|
|
313
319
|
const tileElements = document.querySelectorAll('.dish-tile');
|
|
314
|
-
tileElements.forEach(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
320
|
+
tileElements.forEach(tile => {
|
|
321
|
+
tile.addEventListener('click', () => {
|
|
322
|
+
tile.classList.toggle('selected');
|
|
323
|
+
});
|
|
318
324
|
});
|
|
319
|
-
|
|
320
|
-
// Собираем все .dish-grid
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
//
|
|
324
|
-
const sendButton
|
|
325
|
-
const resetButton
|
|
325
|
+
|
|
326
|
+
// Собираем все группы (или все .dish-grid)
|
|
327
|
+
const dishGroups = document.querySelectorAll('.dish-group');
|
|
328
|
+
|
|
329
|
+
// Находим элементы управления
|
|
330
|
+
const sendButton = document.getElementById('bar-send-button');
|
|
331
|
+
const resetButton = document.getElementById('bar-reset-button');
|
|
332
|
+
const notesInput = document.getElementById('bar-notes-input');
|
|
326
333
|
const winePlaceholder = document.getElementById('wine-placeholder');
|
|
327
|
-
|
|
328
|
-
if (!sendButton || !resetButton || !winePlaceholder) return;
|
|
329
|
-
|
|
330
|
-
// Нажатие
|
|
334
|
+
|
|
335
|
+
if (!sendButton || !resetButton || !notesInput || !winePlaceholder) return;
|
|
336
|
+
|
|
337
|
+
// Нажатие "Отправить"
|
|
331
338
|
sendButton.addEventListener('click', async () => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
339
|
+
dishGroups.forEach(g => g.classList.add('hidden'));
|
|
340
|
+
this.showLoadingIndicator();
|
|
341
|
+
|
|
342
|
+
// 1) Собираем выбранные блюда
|
|
343
|
+
const selectedDishes = [];
|
|
344
|
+
document.querySelectorAll('.dish-tile.selected').forEach(tile => {
|
|
345
|
+
selectedDishes.push(tile.dataset.dish);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// 2) Берём пожелания (notes)
|
|
349
|
+
const notes = notesInput.value.trim(); // не стираем и не скрываем поле
|
|
350
|
+
|
|
351
|
+
// 3) Формируем запрос
|
|
352
|
+
const queryParts = [];
|
|
353
|
+
if (selectedDishes.length > 0) {
|
|
354
|
+
queryParts.push(`Dishes: ${selectedDishes.join(', ')}`);
|
|
355
|
+
}
|
|
356
|
+
if (notes) {
|
|
357
|
+
queryParts.push(`Notes: ${notes}`);
|
|
358
|
+
}
|
|
359
|
+
const finalQuery = queryParts.join('; ');
|
|
360
|
+
|
|
361
|
+
console.log('Final query =>', finalQuery);
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
// 4) Делаете запрос к API
|
|
365
|
+
const results = await this.api.getWineRecommendationsSearch(finalQuery);
|
|
366
|
+
|
|
367
|
+
// 5) Скрываем группы блюд (если хотите, чтобы больше не мешались)
|
|
368
|
+
|
|
369
|
+
// 6) Отображаем результаты
|
|
370
|
+
if (results && results.length > 0) {
|
|
371
|
+
this.displayResults(results, true);
|
|
372
|
+
} else {
|
|
373
|
+
this.displayNoResultsMessage();
|
|
362
374
|
}
|
|
375
|
+
|
|
376
|
+
// 7) Показываем кнопку «Сбросить»
|
|
377
|
+
resetButton.classList.remove('hidden');
|
|
378
|
+
|
|
379
|
+
// 8) Кнопку «Отправить» НЕ скрываем — оставляем!
|
|
380
|
+
// ...никакого sendButton.classList.add('hidden')
|
|
381
|
+
} catch (error) {
|
|
382
|
+
console.error('Error while fetching bar recommendations:', error);
|
|
383
|
+
this.displayErrorMessage();
|
|
384
|
+
} finally {
|
|
385
|
+
this.hideLoadingIndicator();
|
|
386
|
+
}
|
|
363
387
|
});
|
|
364
|
-
|
|
365
|
-
// Нажатие
|
|
388
|
+
|
|
389
|
+
// Нажатие "Сбросить"
|
|
366
390
|
resetButton.addEventListener('click', () => {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
391
|
+
// 1) Показываем все группы (блюда)
|
|
392
|
+
dishGroups.forEach(g => g.classList.remove('hidden'));
|
|
393
|
+
|
|
394
|
+
// 2) Снимаем выделение с плиток
|
|
395
|
+
tileElements.forEach(tile => tile.classList.remove('selected'));
|
|
396
|
+
|
|
397
|
+
// 3) Очищаем результаты
|
|
398
|
+
winePlaceholder.innerHTML = '';
|
|
399
|
+
|
|
400
|
+
// 4) Прячем кнопку «Сбросить»
|
|
401
|
+
resetButton.classList.add('hidden');
|
|
402
|
+
|
|
403
|
+
notesInput.value = '';
|
|
404
|
+
|
|
405
|
+
// 5) Инпут с пожеланиями НЕ трогаем — пусть остается, пользователь может менять
|
|
406
|
+
// notesInput.value = ''; // Если захотите — можете раскомментить, чтобы тоже сбрасывать
|
|
407
|
+
|
|
408
|
+
// 6) «Отправить» и дальше на месте, не меняется
|
|
381
409
|
});
|
|
382
|
-
|
|
410
|
+
}
|
|
383
411
|
}
|