lisichatbot 2.0.3 → 2.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +79 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -36,6 +36,7 @@ let config = {
36
36
  enableAnimations: true,
37
37
  showCancelButton: false, // ✅ NEW: Control cancel button visibility
38
38
  nextButtonText: null, // ✅ NEW: Global next button text (null = use original)
39
+ localeString: null, // ✅ NEW: Locale for number formatting (e.g., 'nb-NO', 'en-US')
39
40
  customRangeErrors: {
40
41
  minRequired: 'Minimum value is required',
41
42
  maxRequired: 'Maximum value is required',
@@ -1068,18 +1069,37 @@ function renderCustomSelectOptions(options, field, customConfig) {
1068
1069
  }
1069
1070
  } else {
1070
1071
  // Regular option selected
1071
- const selectedOption = options.find(o =>
1072
+ // Try to find the matching option by value
1073
+ let selectedOption = options.find(o =>
1072
1074
  JSON.stringify(o.value !== undefined ? o.value : o) === JSON.stringify(existingData)
1073
1075
  );
1074
1076
 
1077
+ // ✅ If not found and existingData is a primitive, try direct match
1078
+ if (!selectedOption && (typeof existingData === 'string' || typeof existingData === 'number')) {
1079
+ selectedOption = options.find(o => o === existingData || o.value === existingData);
1080
+ }
1081
+
1082
+ let displayName;
1083
+ if (selectedOption) {
1084
+ displayName = selectedOption.name || selectedOption;
1085
+ } else {
1086
+ // Fallback to existingData if option not found
1087
+ displayName = existingData;
1088
+ console.warn(` ⚠️ Could not find matching option for value:`, existingData);
1089
+ }
1090
+
1075
1091
  chatState.currentSelection = {
1076
1092
  field,
1077
1093
  value: existingData,
1078
- name: selectedOption ? (selectedOption.name || selectedOption) : existingData
1094
+ name: displayName
1079
1095
  };
1080
1096
 
1081
1097
  enableNextButton();
1082
1098
  console.log(` ✅ Pre-selected option found - Next button enabled`);
1099
+ console.log(` Field: "${field}"`);
1100
+ console.log(` Value:`, existingData);
1101
+ console.log(` Display name: "${displayName}"`);
1102
+ console.log(` 📝 Set chatState.currentSelection:`, chatState.currentSelection);
1083
1103
  }
1084
1104
  }
1085
1105
  }
@@ -1595,9 +1615,21 @@ function validateMinMax(field, customConfig, showErrors = false) {
1595
1615
 
1596
1616
  let displayName = `${minValue}-${maxValue}`;
1597
1617
  if (valueType === 'arrayRange') {
1598
- const formattedMin = minValue.toLocaleString();
1599
- const formattedMax = maxValue.toLocaleString();
1600
- displayName = `${formattedMin} - ${formattedMax}`;
1618
+ // NEW: Check if both values are 0
1619
+ if (minValue === 0 && maxValue === 0) {
1620
+ const formattedZero = config.localeString
1621
+ ? (0).toLocaleString(config.localeString)
1622
+ : (0).toLocaleString();
1623
+ displayName = formattedZero;
1624
+ } else {
1625
+ const formattedMin = config.localeString
1626
+ ? minValue.toLocaleString(config.localeString)
1627
+ : minValue.toLocaleString();
1628
+ const formattedMax = config.localeString
1629
+ ? maxValue.toLocaleString(config.localeString)
1630
+ : maxValue.toLocaleString();
1631
+ displayName = `${formattedMin} - ${formattedMax}`;
1632
+ }
1601
1633
  }
1602
1634
 
1603
1635
  if (prefix) displayName = `${prefix} ${displayName}`;
@@ -2144,9 +2176,22 @@ async function handleNext() {
2144
2176
 
2145
2177
  if (valueType === 'arrayRange' && Array.isArray(chatState.currentSelection.value)) {
2146
2178
  const [min, max] = chatState.currentSelection.value;
2147
- const formattedMin = min.toLocaleString();
2148
- const formattedMax = max.toLocaleString();
2149
- displayName = `${formattedMin} - ${formattedMax}`;
2179
+
2180
+ // NEW: Check if both values are 0
2181
+ if (min === 0 && max === 0) {
2182
+ const formattedZero = config.localeString
2183
+ ? (0).toLocaleString(config.localeString)
2184
+ : (0).toLocaleString();
2185
+ displayName = formattedZero;
2186
+ } else {
2187
+ const formattedMin = config.localeString
2188
+ ? min.toLocaleString(config.localeString)
2189
+ : min.toLocaleString();
2190
+ const formattedMax = config.localeString
2191
+ ? max.toLocaleString(config.localeString)
2192
+ : max.toLocaleString();
2193
+ displayName = `${formattedMin} - ${formattedMax}`;
2194
+ }
2150
2195
  }
2151
2196
 
2152
2197
  if (prefix) displayName = `${prefix} ${displayName}`;
@@ -3197,10 +3242,33 @@ async function showNextStep() {
3197
3242
  setTimeout(() => {
3198
3243
  // ✅ NEW: Add user message if there's a currentSelection (pre-filled value)
3199
3244
  if (chatState.currentSelection && chatState.currentSelection.name) {
3200
- const prefix = nextStep.input?.selectedInputPrefix || '';
3201
- const suffix = nextStep.input?.selectedInputSuffix || '';
3245
+ const inputConfig = nextStep.input || {};
3246
+ const valueType = inputConfig.selectedInputValueType;
3247
+ const prefix = inputConfig.selectedInputPrefix || '';
3248
+ const suffix = inputConfig.selectedInputSuffix || '';
3202
3249
  let displayName = chatState.currentSelection.name;
3203
3250
 
3251
+ // ✅ NEW: Format arrayRange values with locale
3252
+ if (valueType === 'arrayRange' && Array.isArray(chatState.currentSelection.value)) {
3253
+ const [min, max] = chatState.currentSelection.value;
3254
+
3255
+ // ✅ Check if both values are 0
3256
+ if (min === 0 && max === 0) {
3257
+ const formattedZero = config.localeString
3258
+ ? (0).toLocaleString(config.localeString)
3259
+ : (0).toLocaleString();
3260
+ displayName = formattedZero;
3261
+ } else {
3262
+ const formattedMin = config.localeString
3263
+ ? min.toLocaleString(config.localeString)
3264
+ : min.toLocaleString();
3265
+ const formattedMax = config.localeString
3266
+ ? max.toLocaleString(config.localeString)
3267
+ : max.toLocaleString();
3268
+ displayName = `${formattedMin} - ${formattedMax}`;
3269
+ }
3270
+ }
3271
+
3204
3272
  if (prefix) displayName = `${prefix} ${displayName}`;
3205
3273
  if (suffix) displayName = `${displayName} ${suffix}`;
3206
3274
 
@@ -3388,6 +3456,7 @@ function init(flowName, flowConfig, options = {}) {
3388
3456
  autoAdvanceDelay: config.autoAdvanceDelay,
3389
3457
  showCancelButton: config.showCancelButton,
3390
3458
  nextButtonText: config.nextButtonText || 'not set',
3459
+ localeString: config.localeString || 'default',
3391
3460
  customRangeErrors: config.customRangeErrors
3392
3461
  });
3393
3462