lisichatbot 2.0.2 → 2.0.4
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 +53 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -580,7 +580,19 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
580
580
|
// ✅ Initial tag render if pre-filled (edit mode)
|
|
581
581
|
if (selectedValues.size > 0) {
|
|
582
582
|
renderTags(field, options, tagsContainer, tagTemplateClone, optionsContainer);
|
|
583
|
+
|
|
584
|
+
// ✅ NEW: Set currentSelection for pre-filled data so user message shows
|
|
585
|
+
chatState.currentSelection = {
|
|
586
|
+
field,
|
|
587
|
+
value: existingData,
|
|
588
|
+
name: existingData.map(v => {
|
|
589
|
+
const opt = options.find(o => o.value === v);
|
|
590
|
+
return opt ? opt.name : v;
|
|
591
|
+
}).join(', ')
|
|
592
|
+
};
|
|
593
|
+
|
|
583
594
|
console.log(` ✅ Pre-filled ${selectedValues.size} selections, Next button enabled`);
|
|
595
|
+
console.log(` 📝 Set currentSelection.name: "${chatState.currentSelection.name}"`);
|
|
584
596
|
}
|
|
585
597
|
|
|
586
598
|
elements.messages.appendChild(clone);
|
|
@@ -1056,18 +1068,37 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
1056
1068
|
}
|
|
1057
1069
|
} else {
|
|
1058
1070
|
// Regular option selected
|
|
1059
|
-
|
|
1071
|
+
// ✅ Try to find the matching option by value
|
|
1072
|
+
let selectedOption = options.find(o =>
|
|
1060
1073
|
JSON.stringify(o.value !== undefined ? o.value : o) === JSON.stringify(existingData)
|
|
1061
1074
|
);
|
|
1062
1075
|
|
|
1076
|
+
// ✅ If not found and existingData is a primitive, try direct match
|
|
1077
|
+
if (!selectedOption && (typeof existingData === 'string' || typeof existingData === 'number')) {
|
|
1078
|
+
selectedOption = options.find(o => o === existingData || o.value === existingData);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
let displayName;
|
|
1082
|
+
if (selectedOption) {
|
|
1083
|
+
displayName = selectedOption.name || selectedOption;
|
|
1084
|
+
} else {
|
|
1085
|
+
// Fallback to existingData if option not found
|
|
1086
|
+
displayName = existingData;
|
|
1087
|
+
console.warn(` ⚠️ Could not find matching option for value:`, existingData);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1063
1090
|
chatState.currentSelection = {
|
|
1064
1091
|
field,
|
|
1065
1092
|
value: existingData,
|
|
1066
|
-
name:
|
|
1093
|
+
name: displayName
|
|
1067
1094
|
};
|
|
1068
1095
|
|
|
1069
1096
|
enableNextButton();
|
|
1070
1097
|
console.log(` ✅ Pre-selected option found - Next button enabled`);
|
|
1098
|
+
console.log(` Field: "${field}"`);
|
|
1099
|
+
console.log(` Value:`, existingData);
|
|
1100
|
+
console.log(` Display name: "${displayName}"`);
|
|
1101
|
+
console.log(` 📝 Set chatState.currentSelection:`, chatState.currentSelection);
|
|
1071
1102
|
}
|
|
1072
1103
|
}
|
|
1073
1104
|
}
|
|
@@ -3183,6 +3214,26 @@ async function showNextStep() {
|
|
|
3183
3214
|
console.log(` ⏱️ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
|
|
3184
3215
|
|
|
3185
3216
|
setTimeout(() => {
|
|
3217
|
+
// ✅ NEW: Add user message if there's a currentSelection (pre-filled value)
|
|
3218
|
+
if (chatState.currentSelection && chatState.currentSelection.name) {
|
|
3219
|
+
const prefix = nextStep.input?.selectedInputPrefix || '';
|
|
3220
|
+
const suffix = nextStep.input?.selectedInputSuffix || '';
|
|
3221
|
+
let displayName = chatState.currentSelection.name;
|
|
3222
|
+
|
|
3223
|
+
if (prefix) displayName = `${prefix} ${displayName}`;
|
|
3224
|
+
if (suffix) displayName = `${displayName} ${suffix}`;
|
|
3225
|
+
|
|
3226
|
+
console.log(`📝 Adding user message for auto-advance: "${displayName}"`);
|
|
3227
|
+
addMessage(displayName, 'user', false, chatState.step);
|
|
3228
|
+
|
|
3229
|
+
chatState.history.push({
|
|
3230
|
+
step: chatState.step,
|
|
3231
|
+
field: chatState.currentSelection.field,
|
|
3232
|
+
value: chatState.currentSelection.value,
|
|
3233
|
+
displayName: displayName
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3186
3237
|
// ✅ NEW: Find next accessible step
|
|
3187
3238
|
chatState.step = findNextAccessibleStep(chatState.step);
|
|
3188
3239
|
updateEditIcons();
|