lisichatbot 1.3.0 → 1.3.2

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 +94 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -656,6 +656,13 @@ function renderMinMaxInputs(field, customConfig, existingData) {
656
656
  return;
657
657
  }
658
658
 
659
+ // Remove existing rangeWrapper if it exists (for edit flow)
660
+ const existingRangeWrapper = elements.messages.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
661
+ if (existingRangeWrapper) {
662
+ console.log(' 🗑️ Removing existing rangeWrapper for re-render');
663
+ existingRangeWrapper.remove();
664
+ }
665
+
659
666
  // Create wrapper for min/max
660
667
  const rangeWrapper = document.createElement('div');
661
668
  rangeWrapper.setAttribute('data-chat-element', 'range-wrapper');
@@ -1080,7 +1087,7 @@ function validateMinMax(field, customConfig) {
1080
1087
  // TEXT/NUMBER INPUT RENDERING
1081
1088
  // =============================================================================
1082
1089
 
1083
- function renderTextInput(field, inputType = 'text') {
1090
+ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1084
1091
  if (!elements.messages) return;
1085
1092
 
1086
1093
  // Determine input type attribute value
@@ -1098,6 +1105,17 @@ function renderTextInput(field, inputType = 'text') {
1098
1105
  // Get existing data for this field (for pre-filling when editing)
1099
1106
  const existingValue = chatState.data[field];
1100
1107
  console.log(`📝 Pre-filling ${field}:`, existingValue);
1108
+
1109
+ // Check if validation should be applied (only if input has min/max defined)
1110
+ const hasValidation = inputType === 'number' &&
1111
+ (inputConfig.min !== undefined || inputConfig.max !== undefined);
1112
+
1113
+ if (hasValidation) {
1114
+ console.log(` 🔍 Validation enabled for ${field}:`, {
1115
+ min: inputConfig.min,
1116
+ max: inputConfig.max
1117
+ });
1118
+ }
1101
1119
 
1102
1120
  // Clone existing input element
1103
1121
  const clone = existingInput.cloneNode(true);
@@ -1114,17 +1132,46 @@ function renderTextInput(field, inputType = 'text') {
1114
1132
  inputElement.setAttribute('data-field', field);
1115
1133
  inputElement.name = field;
1116
1134
 
1135
+ // Set min/max attributes if validation enabled
1136
+ if (hasValidation) {
1137
+ if (inputConfig.min !== undefined) {
1138
+ inputElement.min = inputConfig.min;
1139
+ }
1140
+ if (inputConfig.max !== undefined) {
1141
+ inputElement.max = inputConfig.max;
1142
+ }
1143
+ }
1144
+
1117
1145
  // Pre-fill value if it exists
1118
1146
  if (existingValue !== undefined && existingValue !== null) {
1119
1147
  inputElement.value = existingValue;
1120
1148
  console.log(` ✅ Pre-filled with: ${existingValue}`);
1149
+
1150
+ // If validation enabled, validate the pre-filled value
1151
+ if (hasValidation) {
1152
+ const value = parseFloat(existingValue);
1153
+ const min = inputConfig.min;
1154
+ const max = inputConfig.max;
1155
+
1156
+ let isValid = !isNaN(value);
1157
+ if (isValid && min !== undefined && value < min) isValid = false;
1158
+ if (isValid && max !== undefined && value > max) isValid = false;
1159
+
1160
+ if (isValid) {
1161
+ enableNextButton();
1162
+ console.log(` ✅ Pre-filled value is valid: ${value}`);
1163
+ } else {
1164
+ disableNextButton();
1165
+ console.log(` ❌ Pre-filled value is invalid: ${value}`);
1166
+ }
1167
+ }
1121
1168
  } else {
1122
1169
  inputElement.value = '';
1123
1170
  }
1124
1171
 
1125
1172
  inputElement.type = inputType === 'number' ? 'number' : 'text';
1126
1173
 
1127
- // Add input event to enable Next button when user types
1174
+ // Add input event handler
1128
1175
  inputElement.oninput = (e) => {
1129
1176
  const value = inputType === 'number' ? parseFloat(e.target.value) : e.target.value;
1130
1177
 
@@ -1132,11 +1179,36 @@ function renderTextInput(field, inputType = 'text') {
1132
1179
  chatState.data[field] = value;
1133
1180
  chatState.currentSelection = { field, value, name: value };
1134
1181
 
1135
- // Enable Next button if there's a value
1136
- if (value !== '' && value !== null && !isNaN(value)) {
1137
- enableNextButton();
1182
+ // Apply validation ONLY if min/max defined at input level
1183
+ if (hasValidation) {
1184
+ const min = inputConfig.min;
1185
+ const max = inputConfig.max;
1186
+
1187
+ // Check if value is valid
1188
+ let isValid = true;
1189
+ let errorMessage = '';
1190
+
1191
+ if (value === '' || isNaN(value)) {
1192
+ isValid = false;
1193
+ errorMessage = 'Please enter a valid number';
1194
+ } else if (min !== undefined && value < min) {
1195
+ isValid = false;
1196
+ errorMessage = `Value must be at least ${min}`;
1197
+ } else if (max !== undefined && value > max) {
1198
+ isValid = false;
1199
+ errorMessage = `Value must be at most ${max}`;
1200
+ }
1201
+
1202
+ if (isValid) {
1203
+ enableNextButton();
1204
+ console.log(` ✅ Number input valid: ${value}`);
1205
+ } else {
1206
+ disableNextButton();
1207
+ console.log(` ❌ Number input invalid: ${errorMessage}`);
1208
+ }
1138
1209
  } else {
1139
- disableNextButton();
1210
+ // No validation - just log
1211
+ console.log(` 📝 Input updated: ${value} (no validation)`);
1140
1212
  }
1141
1213
  };
1142
1214
  }
@@ -1499,13 +1571,21 @@ async function showNextStep() {
1499
1571
 
1500
1572
  if (inputType === 'text' || inputType === 'number') {
1501
1573
  // Render text or number input
1502
- renderTextInput(nextStep.input.field, inputType);
1574
+ renderTextInput(nextStep.input.field, inputType, nextStep.input);
1503
1575
 
1504
- // Disable Next button initially (enabled when user types)
1505
- if (inputRequired) {
1576
+ // Check if validation is enabled (number input with min/max defined)
1577
+ const hasValidation = inputType === 'number' &&
1578
+ (nextStep.input.min !== undefined || nextStep.input.max !== undefined);
1579
+
1580
+ // Initial Next button state
1581
+ if (inputRequired || hasValidation) {
1582
+ // Disable if input is required OR has validation rules
1506
1583
  disableNextButton();
1584
+ console.log(' 🔒 Next button disabled initially (input required or validation enabled)');
1507
1585
  } else {
1586
+ // Enable if optional and no validation
1508
1587
  enableNextButton();
1588
+ console.log(' 🔓 Next button enabled (optional input, no validation)');
1509
1589
  }
1510
1590
  } else if (inputType === 'multi-select-color') {
1511
1591
  // Render color options with color blocks
@@ -1540,7 +1620,7 @@ async function showNextStep() {
1540
1620
  }
1541
1621
  }
1542
1622
  } else {
1543
- // Auto-advance for steps without input
1623
+ // No input - always auto-advance (nextButtonDisplay only controls button visibility)
1544
1624
  setTimeout(() => {
1545
1625
  chatState.step++;
1546
1626
 
@@ -1557,11 +1637,12 @@ async function showNextStep() {
1557
1637
 
1558
1638
  // Handle nextButtonDisplay - default is true
1559
1639
  const showNextButton = nextStep.nextButtonDisplay !== false;
1560
- if (elements.nextButton) {
1640
+ if (elements.nextBtn) {
1561
1641
  if (showNextButton) {
1562
- elements.nextButton.style.display = '';
1642
+ elements.nextBtn.style.display = '';
1643
+ console.log(' 👁️ Next button shown (nextButtonDisplay: true or undefined)');
1563
1644
  } else {
1564
- elements.nextButton.style.display = 'none';
1645
+ elements.nextBtn.style.display = 'none';
1565
1646
  console.log(' 🙈 Next button hidden (nextButtonDisplay: false)');
1566
1647
  }
1567
1648
  }