lisichatbot 1.4.3 → 1.4.5
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 +1 -1
- package/src/index.js +59 -37
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -610,7 +610,7 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
610
610
|
el.onclick = (e) => {
|
|
611
611
|
e.stopPropagation();
|
|
612
612
|
e.preventDefault();
|
|
613
|
-
handleOptionClick(el, field, isSingleSelect);
|
|
613
|
+
handleOptionClick(el, field, isSingleSelect, options); // ✅ Pass options
|
|
614
614
|
};
|
|
615
615
|
});
|
|
616
616
|
|
|
@@ -739,7 +739,7 @@ function renderColorOptions(options, field) {
|
|
|
739
739
|
el.onclick = (e) => {
|
|
740
740
|
e.stopPropagation();
|
|
741
741
|
e.preventDefault();
|
|
742
|
-
handleOptionClick(el, field, false);
|
|
742
|
+
handleOptionClick(el, field, false, options); // ✅ Pass options
|
|
743
743
|
};
|
|
744
744
|
});
|
|
745
745
|
|
|
@@ -1555,7 +1555,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1555
1555
|
// OPTION CLICK HANDLER USING CUSTOM ATTRIBUTES
|
|
1556
1556
|
// =============================================================================
|
|
1557
1557
|
|
|
1558
|
-
function handleOptionClick(element, field, isSingleSelect) {
|
|
1558
|
+
function handleOptionClick(element, field, isSingleSelect, options) {
|
|
1559
1559
|
const now = Date.now();
|
|
1560
1560
|
const lastClick = element.getAttribute('data-last-click');
|
|
1561
1561
|
if (lastClick && (now - parseInt(lastClick)) < 300) {
|
|
@@ -1648,6 +1648,12 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
1648
1648
|
} else {
|
|
1649
1649
|
const isChecked = !element.classList.contains('cf-checked');
|
|
1650
1650
|
|
|
1651
|
+
console.log(`Multi-select "${optionName}":`, {
|
|
1652
|
+
isChecked,
|
|
1653
|
+
currentData: chatState.data[field],
|
|
1654
|
+
valueToToggle: value
|
|
1655
|
+
});
|
|
1656
|
+
|
|
1651
1657
|
if (isChecked) {
|
|
1652
1658
|
element.classList.add('cf-checked');
|
|
1653
1659
|
element.style.setProperty('background-color', config.selectedBackground, 'important');
|
|
@@ -1667,33 +1673,67 @@ function handleOptionClick(element, field, isSingleSelect) {
|
|
|
1667
1673
|
chatState.data[field].push(value);
|
|
1668
1674
|
}
|
|
1669
1675
|
|
|
1670
|
-
console.log(`✅ Added "${optionName}"
|
|
1676
|
+
console.log(`✅ Added "${optionName}"`);
|
|
1677
|
+
console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
1671
1678
|
} else {
|
|
1672
1679
|
element.classList.remove('cf-checked');
|
|
1673
1680
|
element.style.setProperty('background-color', 'transparent', 'important');
|
|
1674
1681
|
if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
|
|
1675
1682
|
if (input) input.checked = false;
|
|
1676
1683
|
|
|
1684
|
+
console.log(` BEFORE filter - chatState.data.${field}:`, chatState.data[field]);
|
|
1685
|
+
|
|
1677
1686
|
if (Array.isArray(chatState.data[field])) {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1687
|
+
const beforeLength = chatState.data[field].length;
|
|
1688
|
+
chatState.data[field] = chatState.data[field].filter(v => {
|
|
1689
|
+
const match = JSON.stringify(v) === JSON.stringify(value);
|
|
1690
|
+
console.log(` Comparing:`, {
|
|
1691
|
+
arrayValue: v,
|
|
1692
|
+
clickedValue: value,
|
|
1693
|
+
stringifiedArray: JSON.stringify(v),
|
|
1694
|
+
stringifiedClick: JSON.stringify(value),
|
|
1695
|
+
match: match,
|
|
1696
|
+
keep: !match
|
|
1697
|
+
});
|
|
1698
|
+
return !match;
|
|
1699
|
+
});
|
|
1700
|
+
const afterLength = chatState.data[field].length;
|
|
1701
|
+
console.log(` AFTER filter - removed ${beforeLength - afterLength} items`);
|
|
1681
1702
|
}
|
|
1682
1703
|
|
|
1683
|
-
console.log(`❌ Removed "${optionName}"
|
|
1704
|
+
console.log(`❌ Removed "${optionName}"`);
|
|
1705
|
+
console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
1684
1706
|
}
|
|
1685
1707
|
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1708
|
+
// ✅ FIX: Build currentSelection from actual data array, not DOM elements
|
|
1709
|
+
// The DOM might have duplicate/old elements that still have cf-checked class
|
|
1710
|
+
if (!chatState.data[field] || chatState.data[field].length === 0) {
|
|
1711
|
+
// No selections
|
|
1712
|
+
chatState.currentSelection = null;
|
|
1713
|
+
console.log(`📊 No selections - currentSelection set to null`);
|
|
1714
|
+
} else {
|
|
1715
|
+
// Build name from actual data array by finding matching options
|
|
1716
|
+
const selectedNames = chatState.data[field].map(val => {
|
|
1717
|
+
// Find the option config that matches this value
|
|
1718
|
+
const matchingOption = options.find(opt => {
|
|
1719
|
+
const optValue = opt.value !== undefined ? opt.value : opt;
|
|
1720
|
+
return JSON.stringify(optValue) === JSON.stringify(val);
|
|
1721
|
+
});
|
|
1722
|
+
return matchingOption ? (matchingOption.name || matchingOption) : val;
|
|
1723
|
+
}).join(', ');
|
|
1724
|
+
|
|
1725
|
+
chatState.currentSelection = {
|
|
1726
|
+
field,
|
|
1727
|
+
value: chatState.data[field],
|
|
1728
|
+
name: selectedNames || 'None selected'
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
console.log(`📊 Final state after toggle:`, {
|
|
1732
|
+
field,
|
|
1733
|
+
dataValue: chatState.data[field],
|
|
1734
|
+
currentSelectionName: chatState.currentSelection.name
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1697
1737
|
}
|
|
1698
1738
|
|
|
1699
1739
|
enableNextButton();
|
|
@@ -1815,21 +1855,6 @@ async function handleNext() {
|
|
|
1815
1855
|
}
|
|
1816
1856
|
}
|
|
1817
1857
|
|
|
1818
|
-
// ✅ FIX: Remove old user message for this step (if exists)
|
|
1819
|
-
// This handles cases where user edits and changes/deselects their answer
|
|
1820
|
-
const existingUserMessage = elements.messages.querySelector(
|
|
1821
|
-
`[data-chat-element="user-message-wrapper"][data-chat-step="${chatState.step}"]`
|
|
1822
|
-
);
|
|
1823
|
-
if (existingUserMessage) {
|
|
1824
|
-
existingUserMessage.remove();
|
|
1825
|
-
console.log(` 🗑️ Removed old user message for step ${chatState.step}`);
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
// ✅ FIX: Remove from history for this step
|
|
1829
|
-
chatState.history = chatState.history.filter(h => h.step !== chatState.step);
|
|
1830
|
-
console.log(` 🗑️ Cleared history for step ${chatState.step}`);
|
|
1831
|
-
|
|
1832
|
-
// ✅ Only add new user message if there's a selection
|
|
1833
1858
|
if (chatState.currentSelection) {
|
|
1834
1859
|
const inputConfig = currentStep.input || {};
|
|
1835
1860
|
const valueType = inputConfig.selectedInputValueType;
|
|
@@ -1849,7 +1874,6 @@ async function handleNext() {
|
|
|
1849
1874
|
if (suffix) displayName = `${displayName} ${suffix}`;
|
|
1850
1875
|
|
|
1851
1876
|
addMessage(displayName, 'user', false, chatState.step);
|
|
1852
|
-
console.log(` ✅ Added new user message: "${displayName}"`);
|
|
1853
1877
|
|
|
1854
1878
|
chatState.history.push({
|
|
1855
1879
|
step: chatState.step,
|
|
@@ -1857,8 +1881,6 @@ async function handleNext() {
|
|
|
1857
1881
|
value: chatState.currentSelection.value,
|
|
1858
1882
|
name: displayName
|
|
1859
1883
|
});
|
|
1860
|
-
} else {
|
|
1861
|
-
console.log(` ℹ️ No selection - no user message added (deselected or optional empty)`);
|
|
1862
1884
|
}
|
|
1863
1885
|
|
|
1864
1886
|
chatState.currentSelection = null;
|