lisichatbot 1.5.2 → 1.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +87 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -291,9 +291,18 @@ function renderMultiSelectDropdown(options, field) {
291
291
  console.log(' 🙈 Dropdown options wrapper hidden initially');
292
292
 
293
293
  // ✅ Get existing data for pre-filling (edit mode)
294
- const existingData = chatState.data[field] || [];
294
+ // NEW: Check if prefill is disabled for this step
295
+ const currentStep = flowData.flow[chatState.step];
296
+ const disablePrefill = currentStep?.disableInputValuePrefill === true;
297
+
298
+ const existingData = disablePrefill ? [] : (chatState.data[field] || []);
295
299
  const selectedValues = new Set(existingData);
296
- console.log(`📝 Pre-filling selections for ${field}:`, Array.from(selectedValues));
300
+
301
+ if (disablePrefill) {
302
+ console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
303
+ } else {
304
+ console.log(`📝 Pre-filling selections for ${field}:`, Array.from(selectedValues));
305
+ }
297
306
 
298
307
  const allOptions = [];
299
308
 
@@ -541,8 +550,17 @@ function renderOptions(options, field, isSingleSelect = true) {
541
550
  return;
542
551
  }
543
552
 
544
- const existingData = chatState.data[field];
545
- console.log(`📝 Pre-filling ${field}:`, existingData);
553
+ // NEW: Check if prefill is disabled for this step
554
+ const currentStep = flowData.flow[chatState.step];
555
+ const disablePrefill = currentStep?.disableInputValuePrefill === true;
556
+
557
+ const existingData = disablePrefill ? (isSingleSelect ? null : []) : chatState.data[field];
558
+
559
+ if (disablePrefill) {
560
+ console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
561
+ } else {
562
+ console.log(`📝 Pre-filling ${field}:`, existingData);
563
+ }
546
564
 
547
565
  const optionsWrapper = document.createElement('div');
548
566
  optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
@@ -666,8 +684,17 @@ function renderColorOptions(options, field) {
666
684
  return;
667
685
  }
668
686
 
669
- const existingData = chatState.data[field];
670
- console.log(`📝 Pre-filling ${field} (color):`, existingData);
687
+ // NEW: Check if prefill is disabled for this step
688
+ const currentStep = flowData.flow[chatState.step];
689
+ const disablePrefill = currentStep?.disableInputValuePrefill === true;
690
+
691
+ const existingData = disablePrefill ? [] : chatState.data[field];
692
+
693
+ if (disablePrefill) {
694
+ console.log(`⏭️ Pre-fill disabled for ${field} (color) - starting fresh`);
695
+ } else {
696
+ console.log(`📝 Pre-filling ${field} (color):`, existingData);
697
+ }
671
698
 
672
699
  const optionsWrapper = document.createElement('div');
673
700
  optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
@@ -788,8 +815,17 @@ function renderCustomSelectOptions(options, field, customConfig) {
788
815
  return;
789
816
  }
790
817
 
791
- const existingData = chatState.data[field];
792
- console.log(`📝 Pre-filling ${field} (custom):`, existingData);
818
+ // NEW: Check if prefill is disabled for this step
819
+ const currentStep = flowData.flow[chatState.step];
820
+ const disablePrefill = currentStep?.disableInputValuePrefill === true;
821
+
822
+ const existingData = disablePrefill ? null : chatState.data[field];
823
+
824
+ if (disablePrefill) {
825
+ console.log(`⏭️ Pre-fill disabled for ${field} (custom) - starting fresh`);
826
+ } else {
827
+ console.log(`📝 Pre-filling ${field} (custom):`, existingData);
828
+ }
793
829
 
794
830
  const optionsWrapper = document.createElement('div');
795
831
  optionsWrapper.setAttribute('data-chat-element', 'options-wrapper');
@@ -1401,8 +1437,17 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
1401
1437
  return;
1402
1438
  }
1403
1439
 
1404
- const existingValue = chatState.data[field];
1405
- console.log(`📝 Pre-filling ${field}:`, existingValue);
1440
+ // NEW: Check if prefill is disabled for this step
1441
+ const currentStep = flowData.flow[chatState.step];
1442
+ const disablePrefill = currentStep?.disableInputValuePrefill === true;
1443
+
1444
+ const existingValue = disablePrefill ? null : chatState.data[field];
1445
+
1446
+ if (disablePrefill) {
1447
+ console.log(`⏭️ Pre-fill disabled for ${field} - starting fresh`);
1448
+ } else {
1449
+ console.log(`📝 Pre-filling ${field}:`, existingValue);
1450
+ }
1406
1451
 
1407
1452
  const hasValidation = inputType === 'number' &&
1408
1453
  (inputConfig.min !== undefined || inputConfig.max !== undefined);
@@ -1880,6 +1925,36 @@ async function handleNext() {
1880
1925
  }
1881
1926
  }
1882
1927
 
1928
+ // ✅ NEW: Add user message BEFORE onNext executes (for autoAdvance flows)
1929
+ if (chatState.currentSelection) {
1930
+ const inputConfig = currentStep.input || {};
1931
+ const valueType = inputConfig.selectedInputValueType;
1932
+ const prefix = inputConfig.selectedInputPrefix || '';
1933
+ const suffix = inputConfig.selectedInputSuffix || '';
1934
+
1935
+ let displayName = chatState.currentSelection.name;
1936
+
1937
+ if (valueType === 'arrayRange' && Array.isArray(chatState.currentSelection.value)) {
1938
+ const [min, max] = chatState.currentSelection.value;
1939
+ const formattedMin = min.toLocaleString();
1940
+ const formattedMax = max.toLocaleString();
1941
+ displayName = `${formattedMin} - ${formattedMax}`;
1942
+ }
1943
+
1944
+ if (prefix) displayName = `${prefix} ${displayName}`;
1945
+ if (suffix) displayName = `${displayName} ${suffix}`;
1946
+
1947
+ console.log(`📝 Adding user message before onNext: "${displayName}"`);
1948
+ addMessage(displayName, 'user', false, chatState.step);
1949
+
1950
+ chatState.history.push({
1951
+ step: chatState.step,
1952
+ field: chatState.currentSelection.field,
1953
+ value: chatState.currentSelection.value,
1954
+ displayName: displayName
1955
+ });
1956
+ }
1957
+
1883
1958
  if (currentStep.onNext) {
1884
1959
  try {
1885
1960
  disableNextButton();
@@ -2019,34 +2094,8 @@ async function handleNext() {
2019
2094
  }
2020
2095
  }
2021
2096
 
2022
- if (chatState.currentSelection) {
2023
- const inputConfig = currentStep.input || {};
2024
- const valueType = inputConfig.selectedInputValueType;
2025
- const prefix = inputConfig.selectedInputPrefix || '';
2026
- const suffix = inputConfig.selectedInputSuffix || '';
2027
-
2028
- let displayName = chatState.currentSelection.name;
2029
-
2030
- if (valueType === 'arrayRange' && Array.isArray(chatState.currentSelection.value)) {
2031
- const [min, max] = chatState.currentSelection.value;
2032
- const formattedMin = min.toLocaleString();
2033
- const formattedMax = max.toLocaleString();
2034
- displayName = `${formattedMin} - ${formattedMax}`;
2035
- }
2036
-
2037
- if (prefix) displayName = `${prefix} ${displayName}`;
2038
- if (suffix) displayName = `${displayName} ${suffix}`;
2039
-
2040
- addMessage(displayName, 'user', false, chatState.step);
2041
-
2042
- chatState.history.push({
2043
- step: chatState.step,
2044
- field: chatState.currentSelection.field,
2045
- value: chatState.currentSelection.value,
2046
- name: displayName
2047
- });
2048
- }
2049
-
2097
+ // ✅ User message already added before onNext (line ~1883)
2098
+ // Clear current selection to prevent duplicate messages
2050
2099
  chatState.currentSelection = null;
2051
2100
  disableNextButton();
2052
2101