lisichatbot 1.5.3 → 1.5.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 +73 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
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);
@@ -2544,8 +2589,14 @@ function init(flowName, flowConfig, options = {}) {
2544
2589
  Object.assign(config.customRangeErrors, options.customRangeErrors);
2545
2590
  }
2546
2591
 
2592
+ // ✅ NEW: Support mode and data parameters
2593
+ const mode = options.mode || 'create'; // 'create' or 'edit'
2594
+ const editData = options.data || {};
2595
+
2547
2596
  console.log('✅ Flow initialized:', {
2548
2597
  flowName,
2598
+ mode,
2599
+ hasEditData: Object.keys(editData).length > 0,
2549
2600
  selectedBackground: config.selectedBackground,
2550
2601
  autoAdvanceDelay: config.autoAdvanceDelay,
2551
2602
  customRangeErrors: config.customRangeErrors
@@ -2554,7 +2605,18 @@ function init(flowName, flowConfig, options = {}) {
2554
2605
  flowData = flowConfig;
2555
2606
 
2556
2607
  chatState.step = 0;
2557
- chatState.data = flowConfig.initialData || {};
2608
+
2609
+ // ✅ NEW: Merge initialData with editData for edit mode
2610
+ if (mode === 'edit' && editData && Object.keys(editData).length > 0) {
2611
+ console.log('🔧 Edit mode enabled - pre-filling with data:', editData);
2612
+ chatState.data = {
2613
+ ...(flowConfig.initialData || {}),
2614
+ ...editData // Edit data takes precedence
2615
+ };
2616
+ } else {
2617
+ chatState.data = flowConfig.initialData || {};
2618
+ }
2619
+
2558
2620
  chatState.history = [];
2559
2621
  chatState.currentSelection = null;
2560
2622