lisichatbot 1.2.6 ā 1.2.8
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 +100 -30
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -282,6 +282,10 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
282
282
|
// Create wrapper to hold all options
|
|
283
283
|
const optionsWrapper = document.createElement('div');
|
|
284
284
|
optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
|
|
285
|
+
optionsWrapper.style.display = 'flex';
|
|
286
|
+
optionsWrapper.style.flexDirection = 'column';
|
|
287
|
+
optionsWrapper.style.alignItems = 'flex-start'; // Don't stretch options
|
|
288
|
+
optionsWrapper.style.gap = '8px';
|
|
285
289
|
|
|
286
290
|
// Clone and fill option element for each option
|
|
287
291
|
options.forEach((option, index) => {
|
|
@@ -396,6 +400,10 @@ function renderColorOptions(options, field) {
|
|
|
396
400
|
// Create wrapper to hold all options
|
|
397
401
|
const optionsWrapper = document.createElement('div');
|
|
398
402
|
optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
|
|
403
|
+
optionsWrapper.style.display = 'flex';
|
|
404
|
+
optionsWrapper.style.flexDirection = 'column';
|
|
405
|
+
optionsWrapper.style.alignItems = 'flex-start'; // Don't stretch options
|
|
406
|
+
optionsWrapper.style.gap = '8px';
|
|
399
407
|
|
|
400
408
|
// Clone and fill option element for each option
|
|
401
409
|
options.forEach((option, index) => {
|
|
@@ -514,6 +522,10 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
514
522
|
// Create wrapper to hold all options
|
|
515
523
|
const optionsWrapper = document.createElement('div');
|
|
516
524
|
optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
|
|
525
|
+
optionsWrapper.style.display = 'flex';
|
|
526
|
+
optionsWrapper.style.flexDirection = 'column';
|
|
527
|
+
optionsWrapper.style.alignItems = 'flex-start'; // Don't stretch options
|
|
528
|
+
optionsWrapper.style.gap = '8px';
|
|
517
529
|
|
|
518
530
|
// Render regular options
|
|
519
531
|
options.forEach((option, index) => {
|
|
@@ -649,6 +661,9 @@ function renderMinMaxInputs(field, customConfig, existingData) {
|
|
|
649
661
|
rangeWrapper.setAttribute('data-chat-element', 'range-wrapper');
|
|
650
662
|
rangeWrapper.setAttribute('data-field', field);
|
|
651
663
|
rangeWrapper.style.marginBottom = '16px'; // Add space below wrapper
|
|
664
|
+
rangeWrapper.style.display = 'flex';
|
|
665
|
+
rangeWrapper.style.gap = '16px'; // Gap between min and max
|
|
666
|
+
rangeWrapper.style.flexWrap = 'wrap';
|
|
652
667
|
|
|
653
668
|
// Check if should show min/max (custom option selected)
|
|
654
669
|
// Data is stored as array [min, max]
|
|
@@ -661,7 +676,9 @@ function renderMinMaxInputs(field, customConfig, existingData) {
|
|
|
661
676
|
// Clone and setup min input
|
|
662
677
|
const minClone = minTemplate.cloneNode(true);
|
|
663
678
|
minClone.style.display = '';
|
|
664
|
-
minClone.style.marginRight = '
|
|
679
|
+
minClone.style.marginRight = '16px'; // Gap between min and max
|
|
680
|
+
minClone.style.width = 'auto'; // Don't stretch
|
|
681
|
+
minClone.style.flex = '0 0 auto'; // Don't grow or shrink
|
|
665
682
|
minClone.setAttribute('data-field', field);
|
|
666
683
|
|
|
667
684
|
const minInput = minClone.querySelector('[data-chat-input-element="input"]');
|
|
@@ -682,6 +699,8 @@ function renderMinMaxInputs(field, customConfig, existingData) {
|
|
|
682
699
|
// Clone and setup max input
|
|
683
700
|
const maxClone = maxTemplate.cloneNode(true);
|
|
684
701
|
maxClone.style.display = '';
|
|
702
|
+
maxClone.style.width = 'auto'; // Don't stretch
|
|
703
|
+
maxClone.style.flex = '0 0 auto'; // Don't grow or shrink
|
|
685
704
|
maxClone.setAttribute('data-field', field);
|
|
686
705
|
|
|
687
706
|
const maxInput = maxClone.querySelector('[data-chat-input-element="input"]');
|
|
@@ -870,11 +889,16 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
870
889
|
}
|
|
871
890
|
|
|
872
891
|
function validateMinMax(field, customConfig) {
|
|
892
|
+
console.log(`\nš === VALIDATING MIN/MAX for field: ${field} ===`);
|
|
893
|
+
|
|
873
894
|
const minInput = document.querySelector(`[data-field="${field}"][data-input-type="min"] [data-chat-input-element="input"]`);
|
|
874
895
|
const maxInput = document.querySelector(`[data-field="${field}"][data-input-type="max"] [data-chat-input-element="input"]`);
|
|
875
896
|
const errorDiv = document.querySelector(`[data-chat-element="range-error"][data-field="${field}"]`);
|
|
876
897
|
|
|
877
|
-
if (!minInput || !maxInput)
|
|
898
|
+
if (!minInput || !maxInput) {
|
|
899
|
+
console.log('ā Min or Max input not found');
|
|
900
|
+
return { valid: false, error: null };
|
|
901
|
+
}
|
|
878
902
|
|
|
879
903
|
const minValue = parseFloat(minInput.value);
|
|
880
904
|
const maxValue = parseFloat(maxInput.value);
|
|
@@ -884,12 +908,24 @@ function validateMinMax(field, customConfig) {
|
|
|
884
908
|
const minConstraint = customConfig.min !== undefined ? customConfig.min : 0;
|
|
885
909
|
const maxConstraint = customConfig.max !== undefined ? customConfig.max : 100;
|
|
886
910
|
|
|
887
|
-
|
|
911
|
+
console.log(`š Input values:
|
|
912
|
+
Min input value: "${minInput.value}" (filled: ${minFilled}, parsed: ${minValue})
|
|
913
|
+
Max input value: "${maxInput.value}" (filled: ${maxFilled}, parsed: ${maxValue})`);
|
|
914
|
+
|
|
915
|
+
console.log(`š Constraints:
|
|
916
|
+
Min constraint: >= ${minConstraint}
|
|
917
|
+
Max constraint: <= ${maxConstraint}`);
|
|
918
|
+
|
|
919
|
+
// Helper to show error in div and clear data
|
|
888
920
|
const showErrorDiv = (message) => {
|
|
889
921
|
if (errorDiv) {
|
|
890
922
|
errorDiv.textContent = message;
|
|
891
923
|
errorDiv.style.display = 'block';
|
|
892
924
|
}
|
|
925
|
+
// Clear the data when validation fails
|
|
926
|
+
delete chatState.data[field];
|
|
927
|
+
chatState.currentSelection = null;
|
|
928
|
+
console.log(`šļø Data cleared for field: ${field}`);
|
|
893
929
|
};
|
|
894
930
|
|
|
895
931
|
// Helper to hide error div
|
|
@@ -905,7 +941,7 @@ function validateMinMax(field, customConfig) {
|
|
|
905
941
|
if (minFilled && !maxFilled) {
|
|
906
942
|
const error = config.customRangeErrors.maxRequired;
|
|
907
943
|
showErrorDiv(error);
|
|
908
|
-
console.log(
|
|
944
|
+
console.log(`ā FAIL: Only min filled`);
|
|
909
945
|
disableNextButton();
|
|
910
946
|
return { valid: false, error };
|
|
911
947
|
}
|
|
@@ -913,7 +949,7 @@ function validateMinMax(field, customConfig) {
|
|
|
913
949
|
if (!minFilled && maxFilled) {
|
|
914
950
|
const error = config.customRangeErrors.minRequired;
|
|
915
951
|
showErrorDiv(error);
|
|
916
|
-
console.log(
|
|
952
|
+
console.log(`ā FAIL: Only max filled`);
|
|
917
953
|
disableNextButton();
|
|
918
954
|
return { valid: false, error };
|
|
919
955
|
}
|
|
@@ -921,6 +957,9 @@ function validateMinMax(field, customConfig) {
|
|
|
921
957
|
// 2. Check if both are empty
|
|
922
958
|
if (!minFilled && !maxFilled) {
|
|
923
959
|
hideErrorDiv();
|
|
960
|
+
delete chatState.data[field];
|
|
961
|
+
chatState.currentSelection = null;
|
|
962
|
+
console.log(`ā¹ļø Both empty - waiting for input`);
|
|
924
963
|
disableNextButton();
|
|
925
964
|
return { valid: false, error: null };
|
|
926
965
|
}
|
|
@@ -929,37 +968,43 @@ function validateMinMax(field, customConfig) {
|
|
|
929
968
|
if (isNaN(minValue) || isNaN(maxValue)) {
|
|
930
969
|
const error = config.customRangeErrors.bothRequired;
|
|
931
970
|
showErrorDiv(error);
|
|
932
|
-
console.log(
|
|
971
|
+
console.log(`ā FAIL: Invalid numbers (min: ${minValue}, max: ${maxValue})`);
|
|
933
972
|
disableNextButton();
|
|
934
973
|
return { valid: false, error };
|
|
935
974
|
}
|
|
936
975
|
|
|
937
976
|
// 4. Check min constraint
|
|
977
|
+
console.log(`š Checking: ${minValue} < ${minConstraint}?`);
|
|
938
978
|
if (minValue < minConstraint) {
|
|
939
979
|
const error = config.customRangeErrors.minBelowConstraint.replace('{min}', minConstraint);
|
|
940
980
|
showErrorDiv(error);
|
|
941
|
-
console.log(
|
|
981
|
+
console.log(`ā FAIL: Min (${minValue}) < constraint (${minConstraint})`);
|
|
942
982
|
disableNextButton();
|
|
943
983
|
return { valid: false, error };
|
|
944
984
|
}
|
|
985
|
+
console.log(`ā
PASS: Min (${minValue}) >= constraint (${minConstraint})`);
|
|
945
986
|
|
|
946
987
|
// 5. Check max constraint
|
|
988
|
+
console.log(`š Checking: ${maxValue} > ${maxConstraint}?`);
|
|
947
989
|
if (maxValue > maxConstraint) {
|
|
948
990
|
const error = config.customRangeErrors.maxAboveConstraint.replace('{max}', maxConstraint);
|
|
949
991
|
showErrorDiv(error);
|
|
950
|
-
console.log(
|
|
992
|
+
console.log(`ā FAIL: Max (${maxValue}) > constraint (${maxConstraint})`);
|
|
951
993
|
disableNextButton();
|
|
952
994
|
return { valid: false, error };
|
|
953
995
|
}
|
|
996
|
+
console.log(`ā
PASS: Max (${maxValue}) <= constraint (${maxConstraint})`);
|
|
954
997
|
|
|
955
998
|
// 6. Check min < max
|
|
999
|
+
console.log(`š Checking: ${minValue} >= ${maxValue}?`);
|
|
956
1000
|
if (minValue >= maxValue) {
|
|
957
1001
|
const error = config.customRangeErrors.minGreaterThanMax;
|
|
958
1002
|
showErrorDiv(error);
|
|
959
|
-
console.log(
|
|
1003
|
+
console.log(`ā FAIL: Min (${minValue}) >= Max (${maxValue})`);
|
|
960
1004
|
disableNextButton();
|
|
961
1005
|
return { valid: false, error };
|
|
962
1006
|
}
|
|
1007
|
+
console.log(`ā
PASS: Min (${minValue}) < Max (${maxValue})`);
|
|
963
1008
|
|
|
964
1009
|
// All valid! Hide error and save data as array
|
|
965
1010
|
hideErrorDiv();
|
|
@@ -972,7 +1017,11 @@ function validateMinMax(field, customConfig) {
|
|
|
972
1017
|
name: `${minValue}-${maxValue}`
|
|
973
1018
|
};
|
|
974
1019
|
|
|
975
|
-
console.log(
|
|
1020
|
+
console.log(`ā
ā
ā
ALL VALIDATION PASSED!`);
|
|
1021
|
+
console.log(`š¾ Data saved: chatState.data.${field} = [${minValue}, ${maxValue}]`);
|
|
1022
|
+
console.log(`š¾ Current selection: ${minValue}-${maxValue}`);
|
|
1023
|
+
console.log(`š¢ Next button: ENABLED\n`);
|
|
1024
|
+
|
|
976
1025
|
enableNextButton();
|
|
977
1026
|
return { valid: true, error: null };
|
|
978
1027
|
}
|
|
@@ -1195,37 +1244,58 @@ async function handleNext() {
|
|
|
1195
1244
|
const field = currentStep.input.field;
|
|
1196
1245
|
const customConfig = currentStep.input.custom;
|
|
1197
1246
|
|
|
1247
|
+
console.log(`\nšÆ === HANDLE NEXT: Checking single-select-custom validation ===`);
|
|
1248
|
+
console.log(`Field: ${field}`);
|
|
1249
|
+
console.log(`Custom config:`, customConfig);
|
|
1250
|
+
|
|
1198
1251
|
// Check if custom range was selected (data is array)
|
|
1199
1252
|
const selectedValue = chatState.data[field];
|
|
1200
1253
|
const isCustomRange = Array.isArray(selectedValue);
|
|
1201
1254
|
|
|
1255
|
+
console.log(`Selected value:`, selectedValue);
|
|
1256
|
+
console.log(`Is custom range (array)? ${isCustomRange}`);
|
|
1257
|
+
|
|
1202
1258
|
if (isCustomRange && customConfig) {
|
|
1203
|
-
// Validate the custom range
|
|
1259
|
+
// Validate the custom range one more time before proceeding
|
|
1260
|
+
console.log(`š Running final validation before proceeding...`);
|
|
1204
1261
|
const validation = validateMinMax(field, customConfig);
|
|
1205
1262
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1263
|
+
console.log(`Validation result:`, validation);
|
|
1264
|
+
|
|
1265
|
+
if (!validation.valid) {
|
|
1266
|
+
// If there's an error message, show it
|
|
1267
|
+
if (validation.error) {
|
|
1268
|
+
console.log(' ā ļø Validation failed in handleNext, showing error message');
|
|
1269
|
+
|
|
1270
|
+
// Hide current inputs (options and range wrapper)
|
|
1271
|
+
const optionsWrapper = document.querySelector('[data-chat-element="options-wrapper"]');
|
|
1272
|
+
if (optionsWrapper) {
|
|
1273
|
+
optionsWrapper.style.display = 'none';
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
const rangeWrapper = document.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
|
|
1277
|
+
if (rangeWrapper) {
|
|
1278
|
+
rangeWrapper.style.display = 'none';
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// Add error message as bot message
|
|
1282
|
+
addMessage(validation.error, 'bot', false, null);
|
|
1283
|
+
|
|
1284
|
+
// Re-display the same step with fresh inputs
|
|
1285
|
+
await showNextStep();
|
|
1286
|
+
} else {
|
|
1287
|
+
// No error message, just incomplete data - do nothing
|
|
1288
|
+
console.log(' ā ļø Validation incomplete, waiting for user input');
|
|
1219
1289
|
}
|
|
1220
1290
|
|
|
1221
|
-
// Add error message as bot message
|
|
1222
|
-
addMessage(validation.error, 'bot', false, null);
|
|
1223
|
-
|
|
1224
|
-
// Re-display the same step with fresh inputs
|
|
1225
|
-
await showNextStep();
|
|
1226
|
-
|
|
1227
1291
|
return; // Stop here, don't proceed
|
|
1228
1292
|
}
|
|
1293
|
+
|
|
1294
|
+
console.log('ā
Validation passed, proceeding to next step');
|
|
1295
|
+
} else if (customConfig && chatState.currentSelection && chatState.currentSelection.value === customConfig.value) {
|
|
1296
|
+
// User selected the custom option but hasn't entered valid min/max yet
|
|
1297
|
+
console.log(' ā ļø Custom option selected but no valid range entered');
|
|
1298
|
+
return; // Stop here
|
|
1229
1299
|
}
|
|
1230
1300
|
}
|
|
1231
1301
|
|