lisichatbot 1.2.6 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +51 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
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,6 @@ 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 = '12px'; // Add space between inputs
665
679
  minClone.setAttribute('data-field', field);
666
680
 
667
681
  const minInput = minClone.querySelector('[data-chat-input-element="input"]');
@@ -884,12 +898,15 @@ function validateMinMax(field, customConfig) {
884
898
  const minConstraint = customConfig.min !== undefined ? customConfig.min : 0;
885
899
  const maxConstraint = customConfig.max !== undefined ? customConfig.max : 100;
886
900
 
887
- // Helper to show error in div
901
+ // Helper to show error in div and clear data
888
902
  const showErrorDiv = (message) => {
889
903
  if (errorDiv) {
890
904
  errorDiv.textContent = message;
891
905
  errorDiv.style.display = 'block';
892
906
  }
907
+ // Clear the data when validation fails
908
+ delete chatState.data[field];
909
+ chatState.currentSelection = null;
893
910
  };
894
911
 
895
912
  // Helper to hide error div
@@ -921,6 +938,9 @@ function validateMinMax(field, customConfig) {
921
938
  // 2. Check if both are empty
922
939
  if (!minFilled && !maxFilled) {
923
940
  hideErrorDiv();
941
+ // Clear data when both empty
942
+ delete chatState.data[field];
943
+ chatState.currentSelection = null;
924
944
  disableNextButton();
925
945
  return { valid: false, error: null };
926
946
  }
@@ -1200,32 +1220,41 @@ async function handleNext() {
1200
1220
  const isCustomRange = Array.isArray(selectedValue);
1201
1221
 
1202
1222
  if (isCustomRange && customConfig) {
1203
- // Validate the custom range
1223
+ // Validate the custom range one more time before proceeding
1204
1224
  const validation = validateMinMax(field, customConfig);
1205
1225
 
1206
- if (!validation.valid && validation.error) {
1207
- // Show error as bot message
1208
- console.log(' ⚠️ Validation failed, showing error message');
1209
-
1210
- // Hide current inputs (options and range wrapper)
1211
- const optionsWrapper = document.querySelector('[data-chat-element="options-wrapper"]');
1212
- if (optionsWrapper) {
1213
- optionsWrapper.style.display = 'none';
1226
+ if (!validation.valid) {
1227
+ // If there's an error message, show it
1228
+ if (validation.error) {
1229
+ console.log(' ⚠️ Validation failed in handleNext, showing error message');
1230
+
1231
+ // Hide current inputs (options and range wrapper)
1232
+ const optionsWrapper = document.querySelector('[data-chat-element="options-wrapper"]');
1233
+ if (optionsWrapper) {
1234
+ optionsWrapper.style.display = 'none';
1235
+ }
1236
+
1237
+ const rangeWrapper = document.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
1238
+ if (rangeWrapper) {
1239
+ rangeWrapper.style.display = 'none';
1240
+ }
1241
+
1242
+ // Add error message as bot message
1243
+ addMessage(validation.error, 'bot', false, null);
1244
+
1245
+ // Re-display the same step with fresh inputs
1246
+ await showNextStep();
1247
+ } else {
1248
+ // No error message, just incomplete data - do nothing
1249
+ console.log(' ⚠️ Validation incomplete, waiting for user input');
1214
1250
  }
1215
1251
 
1216
- const rangeWrapper = document.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
1217
- if (rangeWrapper) {
1218
- rangeWrapper.style.display = 'none';
1219
- }
1220
-
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
1252
  return; // Stop here, don't proceed
1228
1253
  }
1254
+ } else if (customConfig && chatState.currentSelection && chatState.currentSelection.value === customConfig.value) {
1255
+ // User selected the custom option but hasn't entered valid min/max yet
1256
+ console.log(' ⚠️ Custom option selected but no valid range entered');
1257
+ return; // Stop here
1229
1258
  }
1230
1259
  }
1231
1260