lisichatbot 2.1.4 β 2.1.6
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.
- package/package.json +1 -1
- package/src/index.js +339 -375
package/src/index.js
CHANGED
|
@@ -63,7 +63,7 @@ function scrollToBottom() {
|
|
|
63
63
|
// β
Scroll to bottom + extra padding to ensure everything is visible
|
|
64
64
|
elements.messages.scrollTop = elements.messages.scrollHeight + 200;
|
|
65
65
|
|
|
66
|
-
console.log(` π Forced scroll to: ${elements.messages.scrollHeight + 200}px (height: ${elements.messages.scrollHeight}px)`);
|
|
66
|
+
// console.log(` π Forced scroll to: ${elements.messages.scrollHeight + 200}px (height: ${elements.messages.scrollHeight}px)`);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
function enableNextButton() {
|
|
@@ -71,7 +71,7 @@ function enableNextButton() {
|
|
|
71
71
|
elements.nextBtn.disabled = false;
|
|
72
72
|
elements.nextBtn.style.setProperty('opacity', '1', 'important');
|
|
73
73
|
elements.nextBtn.style.setProperty('cursor', 'pointer', 'important');
|
|
74
|
-
console.log(' β
Next button ENABLED (opacity: 1, cursor: pointer)');
|
|
74
|
+
// console.log(' β
Next button ENABLED (opacity: 1, cursor: pointer)');
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -80,7 +80,7 @@ function disableNextButton() {
|
|
|
80
80
|
elements.nextBtn.disabled = true;
|
|
81
81
|
elements.nextBtn.style.setProperty('opacity', '0.5', 'important');
|
|
82
82
|
elements.nextBtn.style.setProperty('cursor', 'not-allowed', 'important');
|
|
83
|
-
console.log(' π Next button DISABLED (opacity: 0.5, cursor: not-allowed)');
|
|
83
|
+
// console.log(' π Next button DISABLED (opacity: 0.5, cursor: not-allowed)');
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -129,14 +129,14 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
if (type === 'bot') {
|
|
132
|
-
console.log(`\nπ Processing bot message - Step ${stepNumber || 'N/A'}, hasInput: ${hasInput}`);
|
|
132
|
+
// console.log(`\nπ Processing bot message - Step ${stepNumber || 'N/A'}, hasInput: ${hasInput}`);
|
|
133
133
|
|
|
134
134
|
const editIcon = clone.querySelector('[data-chat-element="bot-edit-icon"]');
|
|
135
135
|
if (editIcon) {
|
|
136
|
-
console.log(' β Edit icon element found');
|
|
136
|
+
// console.log(' β Edit icon element found');
|
|
137
137
|
|
|
138
138
|
editIcon.style.setProperty('display', 'none', 'important');
|
|
139
|
-
console.log(' β Edit icon hidden (display: none !important)');
|
|
139
|
+
// console.log(' β Edit icon hidden (display: none !important)');
|
|
140
140
|
|
|
141
141
|
const isLatest = clone.hasAttribute('data-chat-latest');
|
|
142
142
|
|
|
@@ -145,21 +145,21 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
|
|
|
145
145
|
editIcon.onclick = (e) => {
|
|
146
146
|
e.stopPropagation();
|
|
147
147
|
e.preventDefault();
|
|
148
|
-
console.log(`\nπ±οΈ EDIT ICON CLICKED - Step ${stepNumber}`);
|
|
149
|
-
console.log(` Current step: ${chatState.step}`);
|
|
150
|
-
console.log(` Calling editStep(${stepNumber})...`);
|
|
148
|
+
// console.log(`\nπ±οΈ EDIT ICON CLICKED - Step ${stepNumber}`);
|
|
149
|
+
// console.log(` Current step: ${chatState.step}`);
|
|
150
|
+
// console.log(` Calling editStep(${stepNumber})...`);
|
|
151
151
|
editStep(stepNumber);
|
|
152
152
|
};
|
|
153
153
|
editIcon.style.setProperty('display', 'flex', 'important');
|
|
154
154
|
editIcon.style.setProperty('margin-left', '8px', 'important');
|
|
155
155
|
editIcon.style.setProperty('cursor', 'pointer', 'important');
|
|
156
|
-
console.log(` βοΈ Edit icon SHOWN (step ${stepNumber} is latest previous step with input)`);
|
|
156
|
+
// console.log(` βοΈ Edit icon SHOWN (step ${stepNumber} is latest previous step with input)`);
|
|
157
157
|
} else if (hasInput && stepNumber === chatState.step) {
|
|
158
|
-
console.log(` βΈοΈ Edit icon HIDDEN (step ${stepNumber} is CURRENT step)`);
|
|
158
|
+
// console.log(` βΈοΈ Edit icon HIDDEN (step ${stepNumber} is CURRENT step)`);
|
|
159
159
|
} else if (!isLatest && hasInput && stepNumber < chatState.step) {
|
|
160
|
-
console.log(` π Edit icon HIDDEN (step ${stepNumber} is OLD instance)`);
|
|
160
|
+
// console.log(` π Edit icon HIDDEN (step ${stepNumber} is OLD instance)`);
|
|
161
161
|
} else {
|
|
162
|
-
console.log(` βͺ Edit icon HIDDEN (step ${stepNumber || 'N/A'} has no input)`);
|
|
162
|
+
// console.log(` βͺ Edit icon HIDDEN (step ${stepNumber || 'N/A'} has no input)`);
|
|
163
163
|
}
|
|
164
164
|
} else {
|
|
165
165
|
console.warn(' β οΈ Edit icon element not found in bot-message-wrapper!');
|
|
@@ -184,7 +184,7 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
|
|
|
184
184
|
setTimeout(() => {
|
|
185
185
|
const computedMargin = window.getComputedStyle(editIconAfterAppend).marginLeft;
|
|
186
186
|
const computedDisplay = window.getComputedStyle(editIconAfterAppend).display;
|
|
187
|
-
console.log(` π Edit icon - Display: ${computedDisplay}, Margin: ${computedMargin}`);
|
|
187
|
+
// console.log(` π Edit icon - Display: ${computedDisplay}, Margin: ${computedMargin}`);
|
|
188
188
|
}, 100);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -200,7 +200,7 @@ function addMessage(content, type = 'bot', hasInput = false, stepNumber = null)
|
|
|
200
200
|
function updateEditIcons() {
|
|
201
201
|
const allBotMessages = elements.messages.querySelectorAll('[data-chat-element="bot-message-wrapper"]');
|
|
202
202
|
|
|
203
|
-
console.log(`\nπ Updating edit icons - Current step: ${chatState.step}, Completed: ${chatState.completed}`);
|
|
203
|
+
// console.log(`\nπ Updating edit icons - Current step: ${chatState.step}, Completed: ${chatState.completed}`);
|
|
204
204
|
|
|
205
205
|
allBotMessages.forEach(wrapper => {
|
|
206
206
|
const stepNumber = parseInt(wrapper.getAttribute('data-chat-step'));
|
|
@@ -214,14 +214,14 @@ function updateEditIcons() {
|
|
|
214
214
|
// β
NEW: Check if edit is disabled for this step
|
|
215
215
|
if (stepData && stepData.disableEdit === true) {
|
|
216
216
|
editIcon.style.setProperty('display', 'none', 'important');
|
|
217
|
-
console.log(` π« Step ${stepNumber}: Icon HIDDEN (edit disabled)`);
|
|
217
|
+
// console.log(` π« Step ${stepNumber}: Icon HIDDEN (edit disabled)`);
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
// β
FIX: In edit mode, keep edit icons visible even after completion
|
|
222
222
|
if (chatState.completed && chatState.chatMode !== 'edit') {
|
|
223
223
|
editIcon.style.setProperty('display', 'none', 'important');
|
|
224
|
-
console.log(` π Step ${stepNumber}: Icon HIDDEN (flow completed in create mode)`);
|
|
224
|
+
// console.log(` π Step ${stepNumber}: Icon HIDDEN (flow completed in create mode)`);
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -241,14 +241,14 @@ function updateEditIcons() {
|
|
|
241
241
|
editIcon.onclick = (e) => {
|
|
242
242
|
e.stopPropagation();
|
|
243
243
|
e.preventDefault();
|
|
244
|
-
console.log(`\nπ±οΈ EDIT ICON CLICKED (from updateEditIcons) - Step ${stepNumber}`);
|
|
245
|
-
console.log(` Current step: ${chatState.step}`);
|
|
244
|
+
// console.log(`\nπ±οΈ EDIT ICON CLICKED (from updateEditIcons) - Step ${stepNumber}`);
|
|
245
|
+
// console.log(` Current step: ${chatState.step}`);
|
|
246
246
|
|
|
247
247
|
// β
In editSteps mode, go back to that step within the editSteps flow
|
|
248
248
|
if (chatState.editSteps && chatState.editSteps.length > 0) {
|
|
249
249
|
const editStepIdx = chatState.editSteps.indexOf(stepNumber);
|
|
250
250
|
if (editStepIdx !== -1) {
|
|
251
|
-
console.log(` π€οΈ editSteps: jumping back to editSteps[${editStepIdx}] (step ${stepNumber})`);
|
|
251
|
+
// console.log(` π€οΈ editSteps: jumping back to editSteps[${editStepIdx}] (step ${stepNumber})`);
|
|
252
252
|
chatState.editStepsIndex = editStepIdx;
|
|
253
253
|
chatState.step = stepNumber;
|
|
254
254
|
chatState.currentSelection = null;
|
|
@@ -271,10 +271,10 @@ function updateEditIcons() {
|
|
|
271
271
|
|
|
272
272
|
// β
Check if this step has an editSteps path (normal mode)
|
|
273
273
|
if (stepData.editSteps && Array.isArray(stepData.editSteps) && stepData.editSteps.length > 0) {
|
|
274
|
-
console.log(` π€οΈ Step has editSteps path:`, stepData.editSteps);
|
|
274
|
+
// console.log(` π€οΈ Step has editSteps path:`, stepData.editSteps);
|
|
275
275
|
startEditPath(stepData.editSteps);
|
|
276
276
|
} else {
|
|
277
|
-
console.log(` Calling editStep(${stepNumber})...`);
|
|
277
|
+
// console.log(` Calling editStep(${stepNumber})...`);
|
|
278
278
|
editStep(stepNumber);
|
|
279
279
|
}
|
|
280
280
|
};
|
|
@@ -282,15 +282,15 @@ function updateEditIcons() {
|
|
|
282
282
|
editIcon.style.setProperty('display', 'flex', 'important');
|
|
283
283
|
editIcon.style.setProperty('cursor', 'pointer', 'important');
|
|
284
284
|
editIcon.style.setProperty('margin-left', '8px', 'important');
|
|
285
|
-
console.log(` βοΈ Step ${stepNumber}: Icon SHOWN (latest previous step)`);
|
|
285
|
+
// console.log(` βοΈ Step ${stepNumber}: Icon SHOWN (latest previous step)`);
|
|
286
286
|
} else {
|
|
287
287
|
editIcon.style.setProperty('display', 'none', 'important');
|
|
288
288
|
if (!isLatest && hasInput && stepNumber < chatState.step) {
|
|
289
|
-
console.log(` π Step ${stepNumber}: Icon HIDDEN (old instance)`);
|
|
289
|
+
// console.log(` π Step ${stepNumber}: Icon HIDDEN (old instance)`);
|
|
290
290
|
} else if (stepNumber === chatState.step) {
|
|
291
|
-
console.log(` βΈοΈ Step ${stepNumber}: Icon HIDDEN (current step)`);
|
|
291
|
+
// console.log(` βΈοΈ Step ${stepNumber}: Icon HIDDEN (current step)`);
|
|
292
292
|
} else if (!hasInput) {
|
|
293
|
-
console.log(` βͺ Step ${stepNumber}: Icon HIDDEN (no input)`);
|
|
293
|
+
// console.log(` βͺ Step ${stepNumber}: Icon HIDDEN (no input)`);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
}
|
|
@@ -304,8 +304,8 @@ function updateEditIcons() {
|
|
|
304
304
|
function renderMultiSelectDropdown(options, field) {
|
|
305
305
|
if (!elements.messages) return;
|
|
306
306
|
|
|
307
|
-
console.log(`\nπ¨ renderMultiSelectDropdown for field: ${field}`);
|
|
308
|
-
console.log(`Options:`, options);
|
|
307
|
+
// console.log(`\nπ¨ renderMultiSelectDropdown for field: ${field}`);
|
|
308
|
+
// console.log(`Options:`, options);
|
|
309
309
|
|
|
310
310
|
const template = document.querySelector('[data-chat-element="multi-select-dropdown"]');
|
|
311
311
|
if (!template) {
|
|
@@ -348,7 +348,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
348
348
|
|
|
349
349
|
// β
NEW: Hide dropdown options wrapper initially
|
|
350
350
|
optionsWrapper.style.display = 'none';
|
|
351
|
-
console.log(' π Dropdown options wrapper hidden initially');
|
|
351
|
+
// console.log(' π Dropdown options wrapper hidden initially');
|
|
352
352
|
|
|
353
353
|
// β
Get existing data for pre-filling (edit mode)
|
|
354
354
|
// β
NEW: Check if prefill is disabled for this step
|
|
@@ -364,20 +364,20 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
364
364
|
if (dropdownInput) {
|
|
365
365
|
if (existingData.length > 0) {
|
|
366
366
|
dropdownInput.style.display = 'none';
|
|
367
|
-
console.log(` π Dropdown input hidden initially (${existingData.length} pre-filled selection${existingData.length === 1 ? '' : 's'})`);
|
|
367
|
+
// console.log(` π Dropdown input hidden initially (${existingData.length} pre-filled selection${existingData.length === 1 ? '' : 's'})`);
|
|
368
368
|
} else {
|
|
369
369
|
dropdownInput.style.display = '';
|
|
370
|
-
console.log(` ποΈ Dropdown input visible initially (no pre-filled selections)`);
|
|
370
|
+
// console.log(` ποΈ Dropdown input visible initially (no pre-filled selections)`);
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
if (disablePrefill) {
|
|
375
|
-
console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
375
|
+
// console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
376
376
|
} else {
|
|
377
377
|
if (hasOverride) {
|
|
378
|
-
console.log(` π Pre-fill override active for ${field}:`, Array.from(selectedValues));
|
|
378
|
+
// console.log(` π Pre-fill override active for ${field}:`, Array.from(selectedValues));
|
|
379
379
|
} else {
|
|
380
|
-
console.log(`π Pre-filling selections for ${field}:`, Array.from(selectedValues));
|
|
380
|
+
// console.log(`π Pre-filling selections for ${field}:`, Array.from(selectedValues));
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
@@ -403,7 +403,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
403
403
|
// β
FIX: Use display: block instead of empty string
|
|
404
404
|
tickIcon.style.display = 'block';
|
|
405
405
|
}
|
|
406
|
-
console.log(` β
Pre-selected: ${option.name}`);
|
|
406
|
+
// console.log(` β
Pre-selected: ${option.name}`);
|
|
407
407
|
} else {
|
|
408
408
|
if (tickIcon) {
|
|
409
409
|
tickIcon.style.display = 'none';
|
|
@@ -425,10 +425,10 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
425
425
|
|
|
426
426
|
if (isVisible) {
|
|
427
427
|
optionsWrapper.style.display = 'none';
|
|
428
|
-
console.log(' π Dropdown closed');
|
|
428
|
+
// console.log(' π Dropdown closed');
|
|
429
429
|
} else {
|
|
430
430
|
optionsWrapper.style.display = '';
|
|
431
|
-
console.log(' ποΈ Dropdown opened');
|
|
431
|
+
// console.log(' ποΈ Dropdown opened');
|
|
432
432
|
|
|
433
433
|
setTimeout(() => {
|
|
434
434
|
searchBar.focus();
|
|
@@ -445,7 +445,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
445
445
|
if (!clone.contains(e.target)) {
|
|
446
446
|
if (optionsWrapper.style.display !== 'none') {
|
|
447
447
|
optionsWrapper.style.display = 'none';
|
|
448
|
-
console.log(' π Dropdown closed (clicked outside)');
|
|
448
|
+
// console.log(' π Dropdown closed (clicked outside)');
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
};
|
|
@@ -455,7 +455,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
455
455
|
|
|
456
456
|
searchBar.oninput = (e) => {
|
|
457
457
|
const searchTerm = e.target.value.toLowerCase();
|
|
458
|
-
console.log(`π Searching for: "${searchTerm}"`);
|
|
458
|
+
// console.log(`π Searching for: "${searchTerm}"`);
|
|
459
459
|
|
|
460
460
|
allOptions.forEach(({ element, option }) => {
|
|
461
461
|
const matchesName = option.name.toLowerCase().includes(searchTerm);
|
|
@@ -474,7 +474,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
474
474
|
const currentSelections = chatState.data[field] || [];
|
|
475
475
|
const isCurrentlySelected = currentSelections.includes(option.value);
|
|
476
476
|
|
|
477
|
-
console.log(`π― Toggle option: ${option.name}`, { isCurrentlySelected });
|
|
477
|
+
// console.log(`π― Toggle option: ${option.name}`, { isCurrentlySelected });
|
|
478
478
|
|
|
479
479
|
if (isCurrentlySelected) {
|
|
480
480
|
chatState.data[field] = currentSelections.filter(v => v !== option.value);
|
|
@@ -483,7 +483,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
483
483
|
// β
FIX: Explicitly set to 'none'
|
|
484
484
|
tickIcon.style.display = 'none';
|
|
485
485
|
}
|
|
486
|
-
console.log(` β Deselected: ${option.name}`);
|
|
486
|
+
// console.log(` β Deselected: ${option.name}`);
|
|
487
487
|
} else {
|
|
488
488
|
chatState.data[field] = [...currentSelections, option.value];
|
|
489
489
|
optionEl.style.backgroundColor = config.selectedBackground;
|
|
@@ -491,7 +491,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
491
491
|
// β
FIX: Explicitly set to 'block'
|
|
492
492
|
tickIcon.style.display = 'block';
|
|
493
493
|
}
|
|
494
|
-
console.log(` β
Selected: ${option.name}`);
|
|
494
|
+
// console.log(` β
Selected: ${option.name}`);
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
chatState.currentSelection = {
|
|
@@ -503,7 +503,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
503
503
|
}).join(', ')
|
|
504
504
|
};
|
|
505
505
|
|
|
506
|
-
console.log(` π Current selections:`, chatState.data[field]);
|
|
506
|
+
// console.log(` π Current selections:`, chatState.data[field]);
|
|
507
507
|
|
|
508
508
|
renderTags(field, options, tagsContainer, tagTemplateClone, optionsContainer);
|
|
509
509
|
|
|
@@ -531,7 +531,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
531
531
|
});
|
|
532
532
|
|
|
533
533
|
const selections = chatState.data[field] || [];
|
|
534
|
-
console.log(`π·οΈ Rendering ${selections.length} tags`);
|
|
534
|
+
// console.log(`π·οΈ Rendering ${selections.length} tags`);
|
|
535
535
|
|
|
536
536
|
selections.forEach(value => {
|
|
537
537
|
const option = options.find(o => o.value === value);
|
|
@@ -550,11 +550,11 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
550
550
|
|
|
551
551
|
if (crossIcon) {
|
|
552
552
|
crossIcon.style.display = 'block';
|
|
553
|
-
console.log(` β
Cross icon visible for: ${option.name}`);
|
|
553
|
+
// console.log(` β
Cross icon visible for: ${option.name}`);
|
|
554
554
|
|
|
555
555
|
crossIcon.onclick = (e) => {
|
|
556
556
|
e.stopPropagation();
|
|
557
|
-
console.log(`ποΈ Removing tag: ${option.name}`);
|
|
557
|
+
// console.log(`ποΈ Removing tag: ${option.name}`);
|
|
558
558
|
|
|
559
559
|
chatState.data[field] = chatState.data[field].filter(v => v !== value);
|
|
560
560
|
|
|
@@ -579,7 +579,7 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
579
579
|
}).join(', ')
|
|
580
580
|
};
|
|
581
581
|
|
|
582
|
-
console.log(` π Remaining selections:`, chatState.data[field]);
|
|
582
|
+
// console.log(` π Remaining selections:`, chatState.data[field]);
|
|
583
583
|
|
|
584
584
|
if (chatState.data[field].length === 0) {
|
|
585
585
|
// β
FIX: Check if input is required before disabling
|
|
@@ -605,10 +605,10 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
605
605
|
if (dropdownInput) {
|
|
606
606
|
if (selections.length > 0) {
|
|
607
607
|
dropdownInput.style.display = 'none';
|
|
608
|
-
console.log(` π Dropdown input hidden (${selections.length} tag${selections.length === 1 ? '' : 's'} displayed)`);
|
|
608
|
+
// console.log(` π Dropdown input hidden (${selections.length} tag${selections.length === 1 ? '' : 's'} displayed)`);
|
|
609
609
|
} else {
|
|
610
610
|
dropdownInput.style.display = '';
|
|
611
|
-
console.log(` ποΈ Dropdown input visible (no tags)`);
|
|
611
|
+
// console.log(` ποΈ Dropdown input visible (no tags)`);
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
}
|
|
@@ -627,14 +627,14 @@ function renderMultiSelectDropdown(options, field) {
|
|
|
627
627
|
}).join(', ')
|
|
628
628
|
};
|
|
629
629
|
|
|
630
|
-
console.log(` β
Pre-filled ${selectedValues.size} selections, Next button enabled`);
|
|
631
|
-
console.log(` π Set currentSelection.name: "${chatState.currentSelection.name}"`);
|
|
630
|
+
// console.log(` β
Pre-filled ${selectedValues.size} selections, Next button enabled`);
|
|
631
|
+
// console.log(` π Set currentSelection.name: "${chatState.currentSelection.name}"`);
|
|
632
632
|
}
|
|
633
633
|
|
|
634
634
|
elements.messages.appendChild(clone);
|
|
635
635
|
scrollToBottom();
|
|
636
636
|
|
|
637
|
-
console.log(`β
Multi-select dropdown rendered for ${field}`);
|
|
637
|
+
// console.log(`β
Multi-select dropdown rendered for ${field}`);
|
|
638
638
|
}
|
|
639
639
|
|
|
640
640
|
// =============================================================================
|
|
@@ -662,12 +662,12 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
662
662
|
const existingData = disablePrefill ? (isSingleSelect ? null : []) : chatState.data[field];
|
|
663
663
|
|
|
664
664
|
if (disablePrefill) {
|
|
665
|
-
console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
665
|
+
// console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
666
666
|
} else {
|
|
667
667
|
if (hasOverride || isEditing) {
|
|
668
|
-
console.log(` π Pre-fill override active for ${field}:`, existingData);
|
|
668
|
+
// console.log(` π Pre-fill override active for ${field}:`, existingData);
|
|
669
669
|
} else {
|
|
670
|
-
console.log(`π Pre-filling ${field}:`, existingData);
|
|
670
|
+
// console.log(`π Pre-filling ${field}:`, existingData);
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
|
|
@@ -702,7 +702,7 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
702
702
|
if (shouldBeChecked) {
|
|
703
703
|
clone.classList.add('cf-checked');
|
|
704
704
|
clone.style.backgroundColor = config.selectedBackground;
|
|
705
|
-
console.log(` β
Pre-selected: ${optionName}`);
|
|
705
|
+
// console.log(` β
Pre-selected: ${optionName}`);
|
|
706
706
|
hasPreselectedOptions = true; // β
Mark that we have pre-selections
|
|
707
707
|
} else {
|
|
708
708
|
clone.classList.remove('cf-checked');
|
|
@@ -775,7 +775,7 @@ function renderOptions(options, field, isSingleSelect = true) {
|
|
|
775
775
|
}
|
|
776
776
|
|
|
777
777
|
enableNextButton();
|
|
778
|
-
console.log(` β
Pre-selected options found - Next button enabled`);
|
|
778
|
+
// console.log(` β
Pre-selected options found - Next button enabled`);
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
781
|
|
|
@@ -803,12 +803,12 @@ function renderColorOptions(options, field) {
|
|
|
803
803
|
const existingData = disablePrefill ? [] : chatState.data[field];
|
|
804
804
|
|
|
805
805
|
if (disablePrefill) {
|
|
806
|
-
console.log(`βοΈ Pre-fill disabled for ${field} (color) - starting fresh`);
|
|
806
|
+
// console.log(`βοΈ Pre-fill disabled for ${field} (color) - starting fresh`);
|
|
807
807
|
} else {
|
|
808
808
|
if (hasOverride || isEditing) {
|
|
809
|
-
console.log(` π Pre-fill override active for ${field} (color):`, existingData);
|
|
809
|
+
// console.log(` π Pre-fill override active for ${field} (color):`, existingData);
|
|
810
810
|
} else {
|
|
811
|
-
console.log(`π Pre-filling ${field} (color):`, existingData);
|
|
811
|
+
// console.log(`π Pre-filling ${field} (color):`, existingData);
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
814
|
|
|
@@ -838,7 +838,7 @@ function renderColorOptions(options, field) {
|
|
|
838
838
|
if (shouldBeChecked) {
|
|
839
839
|
clone.classList.add('cf-checked');
|
|
840
840
|
clone.style.backgroundColor = config.selectedBackground;
|
|
841
|
-
console.log(` β
Pre-selected color: ${optionName}`);
|
|
841
|
+
// console.log(` β
Pre-selected color: ${optionName}`);
|
|
842
842
|
hasPreselectedOptions = true; // β
Mark that we have pre-selections
|
|
843
843
|
} else {
|
|
844
844
|
clone.classList.remove('cf-checked');
|
|
@@ -913,7 +913,7 @@ function renderColorOptions(options, field) {
|
|
|
913
913
|
};
|
|
914
914
|
|
|
915
915
|
enableNextButton();
|
|
916
|
-
console.log(` β
Pre-selected color options found - Next button enabled`);
|
|
916
|
+
// console.log(` β
Pre-selected color options found - Next button enabled`);
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
919
|
|
|
@@ -938,24 +938,24 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
938
938
|
const isEditing = (chatState.returnToStep !== null && chatState.returnToStep !== undefined) || (chatState.editSteps && chatState.editSteps.length > 0);
|
|
939
939
|
const disablePrefill = currentStep?.disableInputValuePrefill === true && !hasOverride && !isEditing;
|
|
940
940
|
|
|
941
|
-
console.log(`\nπ === PREFILL DEBUG for field: ${field} ===`);
|
|
942
|
-
console.log(` disableInputValuePrefill:`, currentStep?.disableInputValuePrefill);
|
|
943
|
-
console.log(` prefillOverrideFields:`, chatState.prefillOverrideFields);
|
|
944
|
-
console.log(` hasOverride:`, hasOverride);
|
|
945
|
-
console.log(` isEditing:`, isEditing);
|
|
946
|
-
console.log(` disablePrefill:`, disablePrefill);
|
|
947
|
-
console.log(` chatState.data[${field}]:`, chatState.data[field]);
|
|
941
|
+
// console.log(`\nπ === PREFILL DEBUG for field: ${field} ===`);
|
|
942
|
+
// console.log(` disableInputValuePrefill:`, currentStep?.disableInputValuePrefill);
|
|
943
|
+
// console.log(` prefillOverrideFields:`, chatState.prefillOverrideFields);
|
|
944
|
+
// console.log(` hasOverride:`, hasOverride);
|
|
945
|
+
// console.log(` isEditing:`, isEditing);
|
|
946
|
+
// console.log(` disablePrefill:`, disablePrefill);
|
|
947
|
+
// console.log(` chatState.data[${field}]:`, chatState.data[field]);
|
|
948
948
|
|
|
949
949
|
const existingData = disablePrefill ? null : chatState.data[field];
|
|
950
|
-
console.log(` β
existingData:`, existingData);
|
|
950
|
+
// console.log(` β
existingData:`, existingData);
|
|
951
951
|
|
|
952
952
|
if (disablePrefill) {
|
|
953
|
-
console.log(`βοΈ Pre-fill disabled for ${field} (custom) - starting fresh`);
|
|
953
|
+
// console.log(`βοΈ Pre-fill disabled for ${field} (custom) - starting fresh`);
|
|
954
954
|
} else {
|
|
955
955
|
if (hasOverride) {
|
|
956
|
-
console.log(` π Pre-fill override active for ${field} (custom):`, existingData);
|
|
956
|
+
// console.log(` π Pre-fill override active for ${field} (custom):`, existingData);
|
|
957
957
|
} else {
|
|
958
|
-
console.log(`π Pre-filling ${field} (custom):`, existingData);
|
|
958
|
+
// console.log(`π Pre-filling ${field} (custom):`, existingData);
|
|
959
959
|
}
|
|
960
960
|
}
|
|
961
961
|
|
|
@@ -963,7 +963,7 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
963
963
|
const existingWrapper = elements.messages.querySelector(`[data-chat-element="options-wrapper"][data-field="${field}"]`);
|
|
964
964
|
if (existingWrapper) {
|
|
965
965
|
existingWrapper.remove();
|
|
966
|
-
console.log(` ποΈ Removed existing options-wrapper for field: ${field}`);
|
|
966
|
+
// console.log(` ποΈ Removed existing options-wrapper for field: ${field}`);
|
|
967
967
|
}
|
|
968
968
|
|
|
969
969
|
const optionsWrapper = document.createElement('div');
|
|
@@ -991,12 +991,12 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
991
991
|
const shouldBeChecked = existingData !== undefined &&
|
|
992
992
|
JSON.stringify(existingData) === JSON.stringify(optionValue);
|
|
993
993
|
|
|
994
|
-
console.log(` π Option "${optionName}": existingData=${JSON.stringify(existingData)} vs optionValue=${JSON.stringify(optionValue)} β shouldBeChecked=${shouldBeChecked}`);
|
|
994
|
+
// console.log(` π Option "${optionName}": existingData=${JSON.stringify(existingData)} vs optionValue=${JSON.stringify(optionValue)} β shouldBeChecked=${shouldBeChecked}`);
|
|
995
995
|
|
|
996
996
|
if (shouldBeChecked) {
|
|
997
997
|
clone.classList.add('cf-checked');
|
|
998
998
|
clone.style.setProperty('background-color', config.selectedBackground, 'important'); // β
Use !important
|
|
999
|
-
console.log(` β
Pre-selected: ${optionName}`);
|
|
999
|
+
// console.log(` β
Pre-selected: ${optionName}`);
|
|
1000
1000
|
hasPreselectedOption = true; // β
Mark that we have a pre-selection
|
|
1001
1001
|
hasMatchingNormalOption = true; // β
A normal option matched
|
|
1002
1002
|
} else {
|
|
@@ -1044,7 +1044,7 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
1044
1044
|
if (isCustomSelected) {
|
|
1045
1045
|
customClone.classList.add('cf-checked');
|
|
1046
1046
|
customClone.style.setProperty('background-color', config.selectedBackground, 'important'); // β
Use !important
|
|
1047
|
-
console.log(` β
Pre-selected: Custom Range [${existingData[0]}, ${existingData[1]}]`);
|
|
1047
|
+
// console.log(` β
Pre-selected: Custom Range [${existingData[0]}, ${existingData[1]}]`);
|
|
1048
1048
|
hasPreselectedOption = true; // β
Mark that custom is pre-selected
|
|
1049
1049
|
} else {
|
|
1050
1050
|
customClone.classList.remove('cf-checked');
|
|
@@ -1122,7 +1122,7 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
1122
1122
|
const validation = validateMinMax(field, customConfig);
|
|
1123
1123
|
if (validation.valid) {
|
|
1124
1124
|
enableNextButton();
|
|
1125
|
-
console.log(` β
Pre-selected custom range is valid - Next button enabled`);
|
|
1125
|
+
// console.log(` β
Pre-selected custom range is valid - Next button enabled`);
|
|
1126
1126
|
}
|
|
1127
1127
|
} else {
|
|
1128
1128
|
// Regular option selected
|
|
@@ -1152,11 +1152,11 @@ function renderCustomSelectOptions(options, field, customConfig) {
|
|
|
1152
1152
|
};
|
|
1153
1153
|
|
|
1154
1154
|
enableNextButton();
|
|
1155
|
-
console.log(` β
Pre-selected option found - Next button enabled`);
|
|
1156
|
-
console.log(` Field: "${field}"`);
|
|
1157
|
-
console.log(` Value:`, existingData);
|
|
1158
|
-
console.log(` Display name: "${displayName}"`);
|
|
1159
|
-
console.log(` π Set chatState.currentSelection:`, chatState.currentSelection);
|
|
1155
|
+
// console.log(` β
Pre-selected option found - Next button enabled`);
|
|
1156
|
+
// console.log(` Field: "${field}"`);
|
|
1157
|
+
// console.log(` Value:`, existingData);
|
|
1158
|
+
// console.log(` Display name: "${displayName}"`);
|
|
1159
|
+
// console.log(` π Set chatState.currentSelection:`, chatState.currentSelection);
|
|
1160
1160
|
}
|
|
1161
1161
|
}
|
|
1162
1162
|
}
|
|
@@ -1176,7 +1176,7 @@ function renderMinMaxInputs(field, customConfig, existingData, hasMatchingNormal
|
|
|
1176
1176
|
|
|
1177
1177
|
const existingRangeWrapper = elements.messages.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
|
|
1178
1178
|
if (existingRangeWrapper) {
|
|
1179
|
-
console.log(' ποΈ Removing existing rangeWrapper for re-render');
|
|
1179
|
+
// console.log(' ποΈ Removing existing rangeWrapper for re-render');
|
|
1180
1180
|
existingRangeWrapper.remove();
|
|
1181
1181
|
}
|
|
1182
1182
|
|
|
@@ -1217,7 +1217,7 @@ function renderMinMaxInputs(field, customConfig, existingData, hasMatchingNormal
|
|
|
1217
1217
|
const numValue = Number(existingData[0]);
|
|
1218
1218
|
minInput.value = numValue.toLocaleString();
|
|
1219
1219
|
minInput.setAttribute('data-raw-value', existingData[0]);
|
|
1220
|
-
console.log(` β
Pre-filled min: ${existingData[0]} (display: ${numValue.toLocaleString()})`);
|
|
1220
|
+
// console.log(` β
Pre-filled min: ${existingData[0]} (display: ${numValue.toLocaleString()})`);
|
|
1221
1221
|
}
|
|
1222
1222
|
}
|
|
1223
1223
|
|
|
@@ -1241,7 +1241,7 @@ function renderMinMaxInputs(field, customConfig, existingData, hasMatchingNormal
|
|
|
1241
1241
|
const numValue = Number(existingData[1]);
|
|
1242
1242
|
maxInput.value = numValue.toLocaleString();
|
|
1243
1243
|
maxInput.setAttribute('data-raw-value', existingData[1]);
|
|
1244
|
-
console.log(` β
Pre-filled max: ${existingData[1]} (display: ${numValue.toLocaleString()})`);
|
|
1244
|
+
// console.log(` β
Pre-filled max: ${existingData[1]} (display: ${numValue.toLocaleString()})`);
|
|
1245
1245
|
}
|
|
1246
1246
|
}
|
|
1247
1247
|
|
|
@@ -1299,7 +1299,7 @@ function renderMinMaxInputs(field, customConfig, existingData, hasMatchingNormal
|
|
|
1299
1299
|
if (showMinMax) {
|
|
1300
1300
|
updateVisualFeedback();
|
|
1301
1301
|
validateMinMax(field, customConfig);
|
|
1302
|
-
console.log(' β
Applied visual feedback for pre-filled values');
|
|
1302
|
+
// console.log(' β
Applied visual feedback for pre-filled values');
|
|
1303
1303
|
}
|
|
1304
1304
|
|
|
1305
1305
|
minInput.onchange = () => {
|
|
@@ -1385,7 +1385,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1385
1385
|
const valueStr = element.getAttribute('data-value');
|
|
1386
1386
|
const optionName = element.getAttribute('data-name');
|
|
1387
1387
|
|
|
1388
|
-
console.log(`Custom-select clicked:`, { field, name: optionName, isCustom });
|
|
1388
|
+
// console.log(`Custom-select clicked:`, { field, name: optionName, isCustom });
|
|
1389
1389
|
|
|
1390
1390
|
// β
FIX: Check if this option is already selected - allow deselection
|
|
1391
1391
|
const isAlreadySelected = element.classList.contains('cf-checked');
|
|
@@ -1394,7 +1394,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1394
1394
|
|
|
1395
1395
|
if (isAlreadySelected) {
|
|
1396
1396
|
// β
Deselect the currently selected option
|
|
1397
|
-
console.log(` π Deselecting "${optionName}"`);
|
|
1397
|
+
// console.log(` π Deselecting "${optionName}"`);
|
|
1398
1398
|
|
|
1399
1399
|
element.classList.remove('cf-checked');
|
|
1400
1400
|
element.style.setProperty('background-color', 'transparent', 'important');
|
|
@@ -1413,7 +1413,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1413
1413
|
delete chatState.data[field];
|
|
1414
1414
|
chatState.currentSelection = null;
|
|
1415
1415
|
|
|
1416
|
-
console.log(` β Deselected "${optionName}" - No selection`);
|
|
1416
|
+
// console.log(` β Deselected "${optionName}" - No selection`);
|
|
1417
1417
|
|
|
1418
1418
|
// β
Check if input is required - disable button if nothing selected
|
|
1419
1419
|
const currentStep = flowData.flow[chatState.step];
|
|
@@ -1421,17 +1421,17 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1421
1421
|
|
|
1422
1422
|
if (inputRequired) {
|
|
1423
1423
|
disableNextButton();
|
|
1424
|
-
console.log(' π Input required - Next button disabled');
|
|
1424
|
+
// console.log(' π Input required - Next button disabled');
|
|
1425
1425
|
} else {
|
|
1426
1426
|
enableNextButton();
|
|
1427
|
-
console.log(' π Input not required - Next button still enabled');
|
|
1427
|
+
// console.log(' π Input not required - Next button still enabled');
|
|
1428
1428
|
}
|
|
1429
1429
|
|
|
1430
1430
|
return; // Exit early
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
// β
Select this option (deselect others first)
|
|
1434
|
-
console.log(` β
Selecting "${optionName}"`);
|
|
1434
|
+
// console.log(` β
Selecting "${optionName}"`);
|
|
1435
1435
|
|
|
1436
1436
|
allOptions.forEach(opt => {
|
|
1437
1437
|
opt.classList.remove('cf-checked');
|
|
@@ -1452,7 +1452,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1452
1452
|
rangeWrapper.style.display = 'flex';
|
|
1453
1453
|
|
|
1454
1454
|
// β
Aggressive scrolling to show range inputs
|
|
1455
|
-
console.log(' π Custom selected - scrolling to show range inputs');
|
|
1455
|
+
// console.log(' π Custom selected - scrolling to show range inputs');
|
|
1456
1456
|
|
|
1457
1457
|
// Immediate scroll
|
|
1458
1458
|
scrollToBottom();
|
|
@@ -1476,7 +1476,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1476
1476
|
}
|
|
1477
1477
|
|
|
1478
1478
|
chatState.currentSelection = null;
|
|
1479
|
-
console.log(' βΉοΈ Custom selected - waiting for min/max input');
|
|
1479
|
+
// console.log(' βΉοΈ Custom selected - waiting for min/max input');
|
|
1480
1480
|
} else {
|
|
1481
1481
|
const rangeWrapper = document.querySelector(`[data-chat-element="range-wrapper"][data-field="${field}"]`);
|
|
1482
1482
|
if (rangeWrapper) {
|
|
@@ -1488,12 +1488,12 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1488
1488
|
if (minInput) {
|
|
1489
1489
|
minInput.value = '';
|
|
1490
1490
|
minInput.removeAttribute('data-raw-value');
|
|
1491
|
-
console.log(' π§Ή Cleared min input');
|
|
1491
|
+
// console.log(' π§Ή Cleared min input');
|
|
1492
1492
|
}
|
|
1493
1493
|
if (maxInput) {
|
|
1494
1494
|
maxInput.value = '';
|
|
1495
1495
|
maxInput.removeAttribute('data-raw-value');
|
|
1496
|
-
console.log(' π§Ή Cleared max input');
|
|
1496
|
+
// console.log(' π§Ή Cleared max input');
|
|
1497
1497
|
}
|
|
1498
1498
|
|
|
1499
1499
|
const minContainer = rangeWrapper.querySelector('[data-chat-element="single-select-custom-min"]');
|
|
@@ -1514,7 +1514,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1514
1514
|
const errorDiv = rangeWrapper.querySelector('[data-chat-element="range-error"]');
|
|
1515
1515
|
if (errorDiv) errorDiv.style.display = 'none';
|
|
1516
1516
|
|
|
1517
|
-
console.log(' π§Ή Min/max inputs cleared and hidden');
|
|
1517
|
+
// console.log(' π§Ή Min/max inputs cleared and hidden');
|
|
1518
1518
|
}
|
|
1519
1519
|
|
|
1520
1520
|
let value;
|
|
@@ -1526,21 +1526,21 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1526
1526
|
|
|
1527
1527
|
chatState.data[field] = value;
|
|
1528
1528
|
chatState.currentSelection = { field, value, name: optionName };
|
|
1529
|
-
console.log(' β
Regular option selected:', value);
|
|
1529
|
+
// console.log(' β
Regular option selected:', value);
|
|
1530
1530
|
enableNextButton();
|
|
1531
1531
|
|
|
1532
1532
|
// β
NEW: Check if auto-advance is enabled for regular options (not custom)
|
|
1533
1533
|
const currentStep = flowData.flow[chatState.step];
|
|
1534
1534
|
if (currentStep.autoAdvance === true) {
|
|
1535
|
-
console.log(' β‘ Auto-advance enabled - proceeding to next step');
|
|
1535
|
+
// console.log(' β‘ Auto-advance enabled - proceeding to next step');
|
|
1536
1536
|
|
|
1537
1537
|
// Add a small delay for visual feedback
|
|
1538
1538
|
const delay = currentStep.autoAdvanceDelay || 500;
|
|
1539
|
-
console.log(` β±οΈ Waiting ${delay}ms before advancing`);
|
|
1539
|
+
// console.log(` β±οΈ Waiting ${delay}ms before advancing`);
|
|
1540
1540
|
|
|
1541
1541
|
setTimeout(() => {
|
|
1542
1542
|
if (elements.nextBtn && !elements.nextBtn.disabled) {
|
|
1543
|
-
console.log(' βΆοΈ Auto-advancing to next step');
|
|
1543
|
+
// console.log(' βΆοΈ Auto-advancing to next step');
|
|
1544
1544
|
handleNext();
|
|
1545
1545
|
}
|
|
1546
1546
|
}, delay);
|
|
@@ -1549,7 +1549,7 @@ function handleCustomSelectClick(element, field, customConfig) {
|
|
|
1549
1549
|
}
|
|
1550
1550
|
|
|
1551
1551
|
function validateMinMax(field, customConfig, showErrors = false) {
|
|
1552
|
-
console.log(`\nπ === VALIDATING MIN/MAX for field: ${field} (showErrors: ${showErrors}) ===`);
|
|
1552
|
+
// console.log(`\nπ === VALIDATING MIN/MAX for field: ${field} (showErrors: ${showErrors}) ===`);
|
|
1553
1553
|
|
|
1554
1554
|
const errors = config.customRangeErrors;
|
|
1555
1555
|
|
|
@@ -1558,7 +1558,7 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1558
1558
|
const errorDiv = document.querySelector(`[data-chat-element="range-error"][data-field="${field}"]`);
|
|
1559
1559
|
|
|
1560
1560
|
if (!minInput || !maxInput) {
|
|
1561
|
-
console.log('β Min or Max input not found');
|
|
1561
|
+
// console.log('β Min or Max input not found');
|
|
1562
1562
|
return { valid: false, error: null };
|
|
1563
1563
|
}
|
|
1564
1564
|
|
|
@@ -1573,13 +1573,9 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1573
1573
|
const minConstraint = customConfig.min !== undefined ? customConfig.min : 0;
|
|
1574
1574
|
const maxConstraint = customConfig.max !== undefined ? customConfig.max : 100;
|
|
1575
1575
|
|
|
1576
|
-
console.log(`π Input values:
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
console.log(`π Constraints:
|
|
1581
|
-
Min constraint: >= ${minConstraint}
|
|
1582
|
-
Max constraint: <= ${maxConstraint}`);
|
|
1576
|
+
// console.log(`π Input values: Min raw value: "${minRawValue}" (filled: ${minFilled}, parsed: ${minValue}) Max raw value: "${maxRawValue}" (filled: ${maxFilled}, parsed: ${maxValue})`);
|
|
1577
|
+
|
|
1578
|
+
// console.log(`π Constraints: Min constraint: >= ${minConstraint} Max constraint: <= ${maxConstraint}`);
|
|
1583
1579
|
|
|
1584
1580
|
const showErrorDiv = (message) => {
|
|
1585
1581
|
if (showErrors && errorDiv) { // β
Only show error if showErrors is true
|
|
@@ -1588,7 +1584,7 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1588
1584
|
}
|
|
1589
1585
|
delete chatState.data[field];
|
|
1590
1586
|
chatState.currentSelection = null;
|
|
1591
|
-
console.log(`ποΈ Data cleared for field: ${field}`);
|
|
1587
|
+
// console.log(`ποΈ Data cleared for field: ${field}`);
|
|
1592
1588
|
};
|
|
1593
1589
|
|
|
1594
1590
|
const hideErrorDiv = () => {
|
|
@@ -1600,7 +1596,7 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1600
1596
|
if (minFilled && !maxFilled) {
|
|
1601
1597
|
const error = errors.maxRequired;
|
|
1602
1598
|
showErrorDiv(error);
|
|
1603
|
-
console.log(`β FAIL: Only min filled`);
|
|
1599
|
+
// console.log(`β FAIL: Only min filled`);
|
|
1604
1600
|
disableNextButton();
|
|
1605
1601
|
return { valid: false, error };
|
|
1606
1602
|
}
|
|
@@ -1608,7 +1604,7 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1608
1604
|
if (!minFilled && maxFilled) {
|
|
1609
1605
|
const error = errors.minRequired;
|
|
1610
1606
|
showErrorDiv(error);
|
|
1611
|
-
console.log(`β FAIL: Only max filled`);
|
|
1607
|
+
// console.log(`β FAIL: Only max filled`);
|
|
1612
1608
|
disableNextButton();
|
|
1613
1609
|
return { valid: false, error };
|
|
1614
1610
|
}
|
|
@@ -1617,7 +1613,7 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1617
1613
|
hideErrorDiv();
|
|
1618
1614
|
delete chatState.data[field];
|
|
1619
1615
|
chatState.currentSelection = null;
|
|
1620
|
-
console.log(`βΉοΈ Both empty - waiting for input`);
|
|
1616
|
+
// console.log(`βΉοΈ Both empty - waiting for input`);
|
|
1621
1617
|
disableNextButton();
|
|
1622
1618
|
return { valid: false, error: null };
|
|
1623
1619
|
}
|
|
@@ -1625,40 +1621,40 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1625
1621
|
if (isNaN(minValue) || isNaN(maxValue)) {
|
|
1626
1622
|
const error = errors.bothRequired;
|
|
1627
1623
|
showErrorDiv(error);
|
|
1628
|
-
console.log(`β FAIL: Invalid numbers (min: ${minValue}, max: ${maxValue})`);
|
|
1624
|
+
// console.log(`β FAIL: Invalid numbers (min: ${minValue}, max: ${maxValue})`);
|
|
1629
1625
|
disableNextButton();
|
|
1630
1626
|
return { valid: false, error };
|
|
1631
1627
|
}
|
|
1632
1628
|
|
|
1633
|
-
console.log(`π Checking: ${minValue} < ${minConstraint}?`);
|
|
1629
|
+
// console.log(`π Checking: ${minValue} < ${minConstraint}?`);
|
|
1634
1630
|
if (minValue < minConstraint) {
|
|
1635
1631
|
const error = errors.minBelowConstraint.replace('{min}', minConstraint);
|
|
1636
1632
|
showErrorDiv(error);
|
|
1637
|
-
console.log(`β FAIL: Min (${minValue}) < constraint (${minConstraint})`);
|
|
1633
|
+
// console.log(`β FAIL: Min (${minValue}) < constraint (${minConstraint})`);
|
|
1638
1634
|
disableNextButton();
|
|
1639
1635
|
return { valid: false, error };
|
|
1640
1636
|
}
|
|
1641
|
-
console.log(`β
PASS: Min (${minValue}) >= constraint (${minConstraint})`);
|
|
1637
|
+
// console.log(`β
PASS: Min (${minValue}) >= constraint (${minConstraint})`);
|
|
1642
1638
|
|
|
1643
|
-
console.log(`π Checking: ${maxValue} > ${maxConstraint}?`);
|
|
1639
|
+
// console.log(`π Checking: ${maxValue} > ${maxConstraint}?`);
|
|
1644
1640
|
if (maxValue > maxConstraint) {
|
|
1645
1641
|
const error = errors.maxAboveConstraint.replace('{max}', maxConstraint);
|
|
1646
1642
|
showErrorDiv(error);
|
|
1647
|
-
console.log(`β FAIL: Max (${maxValue}) > constraint (${maxConstraint})`);
|
|
1643
|
+
// console.log(`β FAIL: Max (${maxValue}) > constraint (${maxConstraint})`);
|
|
1648
1644
|
disableNextButton();
|
|
1649
1645
|
return { valid: false, error };
|
|
1650
1646
|
}
|
|
1651
|
-
console.log(`β
PASS: Max (${maxValue}) <= constraint (${maxConstraint})`);
|
|
1647
|
+
// console.log(`β
PASS: Max (${maxValue}) <= constraint (${maxConstraint})`);
|
|
1652
1648
|
|
|
1653
|
-
console.log(`π Checking: ${minValue} >= ${maxValue}?`);
|
|
1649
|
+
// console.log(`π Checking: ${minValue} >= ${maxValue}?`);
|
|
1654
1650
|
if (minValue >= maxValue) {
|
|
1655
1651
|
const error = errors.minGreaterThanMax;
|
|
1656
1652
|
showErrorDiv(error);
|
|
1657
|
-
console.log(`β FAIL: Min (${minValue}) >= Max (${maxValue})`);
|
|
1653
|
+
// console.log(`β FAIL: Min (${minValue}) >= Max (${maxValue})`);
|
|
1658
1654
|
disableNextButton();
|
|
1659
1655
|
return { valid: false, error };
|
|
1660
1656
|
}
|
|
1661
|
-
console.log(`β
PASS: Min (${minValue}) < Max (${maxValue})`);
|
|
1657
|
+
// console.log(`β
PASS: Min (${minValue}) < Max (${maxValue})`);
|
|
1662
1658
|
|
|
1663
1659
|
hideErrorDiv();
|
|
1664
1660
|
|
|
@@ -1698,10 +1694,10 @@ function validateMinMax(field, customConfig, showErrors = false) {
|
|
|
1698
1694
|
name: displayName
|
|
1699
1695
|
};
|
|
1700
1696
|
|
|
1701
|
-
console.log(`β
β
β
ALL VALIDATION PASSED!`);
|
|
1702
|
-
console.log(`πΎ Data saved: chatState.data.${field} = [${minValue}, ${maxValue}]`);
|
|
1703
|
-
console.log(`πΎ Display name: "${displayName}"`);
|
|
1704
|
-
console.log(`π’ Next button: ENABLED\n`);
|
|
1697
|
+
// console.log(`β
β
β
ALL VALIDATION PASSED!`);
|
|
1698
|
+
// console.log(`πΎ Data saved: chatState.data.${field} = [${minValue}, ${maxValue}]`);
|
|
1699
|
+
// console.log(`πΎ Display name: "${displayName}"`);
|
|
1700
|
+
// console.log(`π’ Next button: ENABLED\n`);
|
|
1705
1701
|
|
|
1706
1702
|
enableNextButton();
|
|
1707
1703
|
return { valid: true, error: null };
|
|
@@ -1732,12 +1728,12 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1732
1728
|
const existingValue = disablePrefill ? null : chatState.data[field];
|
|
1733
1729
|
|
|
1734
1730
|
if (disablePrefill) {
|
|
1735
|
-
console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
1731
|
+
// console.log(`βοΈ Pre-fill disabled for ${field} - starting fresh`);
|
|
1736
1732
|
} else {
|
|
1737
1733
|
if (hasOverride) {
|
|
1738
|
-
console.log(` π Pre-fill override active for ${field}:`, existingValue);
|
|
1734
|
+
// console.log(` π Pre-fill override active for ${field}:`, existingValue);
|
|
1739
1735
|
} else {
|
|
1740
|
-
console.log(`π Pre-filling ${field}:`, existingValue);
|
|
1736
|
+
// console.log(`π Pre-filling ${field}:`, existingValue);
|
|
1741
1737
|
}
|
|
1742
1738
|
}
|
|
1743
1739
|
|
|
@@ -1745,10 +1741,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1745
1741
|
(inputConfig.min !== undefined || inputConfig.max !== undefined);
|
|
1746
1742
|
|
|
1747
1743
|
if (hasValidation) {
|
|
1748
|
-
console.log(` π Validation enabled for ${field}:`, {
|
|
1749
|
-
min: inputConfig.min,
|
|
1750
|
-
max: inputConfig.max
|
|
1751
|
-
});
|
|
1744
|
+
// console.log(` π Validation enabled for ${field}:`, { min: inputConfig.min, max: inputConfig.max });
|
|
1752
1745
|
}
|
|
1753
1746
|
|
|
1754
1747
|
const clone = existingInput.cloneNode(true);
|
|
@@ -1774,7 +1767,7 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1774
1767
|
|
|
1775
1768
|
if (hasValue) {
|
|
1776
1769
|
inputElement.value = existingValue;
|
|
1777
|
-
console.log(` β
Pre-filled with: "${existingValue}"`);
|
|
1770
|
+
// console.log(` β
Pre-filled with: "${existingValue}"`);
|
|
1778
1771
|
|
|
1779
1772
|
// Set currentSelection for pre-filled value
|
|
1780
1773
|
chatState.currentSelection = {
|
|
@@ -1794,15 +1787,15 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1794
1787
|
|
|
1795
1788
|
if (isValid) {
|
|
1796
1789
|
enableNextButton();
|
|
1797
|
-
console.log(` β
Pre-filled number is valid - Next button enabled`);
|
|
1790
|
+
// console.log(` β
Pre-filled number is valid - Next button enabled`);
|
|
1798
1791
|
} else {
|
|
1799
1792
|
disableNextButton();
|
|
1800
|
-
console.log(` β Pre-filled number is invalid - Next button disabled`);
|
|
1793
|
+
// console.log(` β Pre-filled number is invalid - Next button disabled`);
|
|
1801
1794
|
}
|
|
1802
1795
|
} else {
|
|
1803
1796
|
// β
FIX: Enable button for pre-filled text input
|
|
1804
1797
|
enableNextButton();
|
|
1805
|
-
console.log(` β
Pre-filled text - Next button enabled`);
|
|
1798
|
+
// console.log(` β
Pre-filled text - Next button enabled`);
|
|
1806
1799
|
}
|
|
1807
1800
|
} else {
|
|
1808
1801
|
// β
No pre-filled value - set initial button state
|
|
@@ -1813,10 +1806,10 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1813
1806
|
|
|
1814
1807
|
if (inputRequired || hasValidation) {
|
|
1815
1808
|
disableNextButton();
|
|
1816
|
-
console.log(` π Empty input (required or has validation) - Next button disabled`);
|
|
1809
|
+
// console.log(` π Empty input (required or has validation) - Next button disabled`);
|
|
1817
1810
|
} else {
|
|
1818
1811
|
enableNextButton();
|
|
1819
|
-
console.log(` π Empty input (optional, no validation) - Next button enabled`);
|
|
1812
|
+
// console.log(` π Empty input (optional, no validation) - Next button enabled`);
|
|
1820
1813
|
}
|
|
1821
1814
|
}
|
|
1822
1815
|
|
|
@@ -1859,10 +1852,10 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1859
1852
|
|
|
1860
1853
|
if (isValid) {
|
|
1861
1854
|
enableNextButton();
|
|
1862
|
-
console.log(` β
Number input valid: ${value} - Next button enabled`);
|
|
1855
|
+
// console.log(` β
Number input valid: ${value} - Next button enabled`);
|
|
1863
1856
|
} else {
|
|
1864
1857
|
disableNextButton();
|
|
1865
|
-
console.log(` β Number input invalid: ${errorMessage} - Next button disabled`);
|
|
1858
|
+
// console.log(` β Number input invalid: ${errorMessage} - Next button disabled`);
|
|
1866
1859
|
}
|
|
1867
1860
|
} else {
|
|
1868
1861
|
// β
FIX: Handle number inputs without validation
|
|
@@ -1875,21 +1868,21 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1875
1868
|
|
|
1876
1869
|
if (inputRequired) {
|
|
1877
1870
|
disableNextButton();
|
|
1878
|
-
console.log(` π Number input empty/NaN and required - Next button disabled`);
|
|
1871
|
+
// console.log(` π Number input empty/NaN and required - Next button disabled`);
|
|
1879
1872
|
} else {
|
|
1880
1873
|
enableNextButton();
|
|
1881
|
-
console.log(` π Number input empty/NaN but not required - Next button enabled`);
|
|
1874
|
+
// console.log(` π Number input empty/NaN but not required - Next button enabled`);
|
|
1882
1875
|
}
|
|
1883
1876
|
} else {
|
|
1884
1877
|
// Has valid number value
|
|
1885
1878
|
enableNextButton();
|
|
1886
|
-
console.log(` β
Number input has value: ${value} - Next button enabled`);
|
|
1879
|
+
// console.log(` β
Number input has value: ${value} - Next button enabled`);
|
|
1887
1880
|
}
|
|
1888
1881
|
} else {
|
|
1889
1882
|
// Text input logic
|
|
1890
1883
|
if (rawValue && rawValue.trim() !== '') {
|
|
1891
1884
|
enableNextButton();
|
|
1892
|
-
console.log(` β
Text input has value - Next button enabled`);
|
|
1885
|
+
// console.log(` β
Text input has value - Next button enabled`);
|
|
1893
1886
|
} else {
|
|
1894
1887
|
// β
Check if input is required
|
|
1895
1888
|
const currentStep = flowData.flow[chatState.step];
|
|
@@ -1897,10 +1890,10 @@ function renderTextInput(field, inputType = 'text', inputConfig = {}) {
|
|
|
1897
1890
|
|
|
1898
1891
|
if (inputRequired) {
|
|
1899
1892
|
disableNextButton();
|
|
1900
|
-
console.log(` π Text input empty and required - Next button disabled`);
|
|
1893
|
+
// console.log(` π Text input empty and required - Next button disabled`);
|
|
1901
1894
|
} else {
|
|
1902
1895
|
enableNextButton();
|
|
1903
|
-
console.log(` π Text input empty but not required - Next button enabled`);
|
|
1896
|
+
// console.log(` π Text input empty but not required - Next button enabled`);
|
|
1904
1897
|
}
|
|
1905
1898
|
}
|
|
1906
1899
|
}
|
|
@@ -1924,7 +1917,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
1924
1917
|
const now = Date.now();
|
|
1925
1918
|
const lastClick = element.getAttribute('data-last-click');
|
|
1926
1919
|
if (lastClick && (now - parseInt(lastClick)) < 300) {
|
|
1927
|
-
console.log('Ignored double-click');
|
|
1920
|
+
// console.log('Ignored double-click');
|
|
1928
1921
|
return;
|
|
1929
1922
|
}
|
|
1930
1923
|
element.setAttribute('data-last-click', now.toString());
|
|
@@ -1938,11 +1931,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
1938
1931
|
const inputType = element.getAttribute('data-chat-element');
|
|
1939
1932
|
|
|
1940
1933
|
const mode = isSingleSelect ? 'Single-select' : 'Multi-select';
|
|
1941
|
-
console.log(`${mode} clicked:`, {
|
|
1942
|
-
field,
|
|
1943
|
-
value: valueStr,
|
|
1944
|
-
name: optionName
|
|
1945
|
-
});
|
|
1934
|
+
// console.log(`${mode} clicked:`, { field, value: valueStr, name: optionName });
|
|
1946
1935
|
|
|
1947
1936
|
let value;
|
|
1948
1937
|
try {
|
|
@@ -1960,7 +1949,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
1960
1949
|
|
|
1961
1950
|
if (isAlreadySelected) {
|
|
1962
1951
|
// β
Deselect the currently selected option
|
|
1963
|
-
console.log(` π Deselecting "${optionName}"`);
|
|
1952
|
+
// console.log(` π Deselecting "${optionName}"`);
|
|
1964
1953
|
|
|
1965
1954
|
element.classList.remove('cf-checked');
|
|
1966
1955
|
element.style.setProperty('background-color', 'transparent', 'important');
|
|
@@ -1971,7 +1960,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
1971
1960
|
delete chatState.data[field];
|
|
1972
1961
|
chatState.currentSelection = null;
|
|
1973
1962
|
|
|
1974
|
-
console.log(` β Deselected "${optionName}" - No selection`);
|
|
1963
|
+
// console.log(` β Deselected "${optionName}" - No selection`);
|
|
1975
1964
|
|
|
1976
1965
|
// β
Check if input is required - disable button if nothing selected
|
|
1977
1966
|
const currentStep = flowData.flow[chatState.step];
|
|
@@ -1979,14 +1968,14 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
1979
1968
|
|
|
1980
1969
|
if (inputRequired) {
|
|
1981
1970
|
disableNextButton();
|
|
1982
|
-
console.log(' π Input required - Next button disabled');
|
|
1971
|
+
// console.log(' π Input required - Next button disabled');
|
|
1983
1972
|
} else {
|
|
1984
1973
|
enableNextButton();
|
|
1985
|
-
console.log(' π Input not required - Next button still enabled');
|
|
1974
|
+
// console.log(' π Input not required - Next button still enabled');
|
|
1986
1975
|
}
|
|
1987
1976
|
} else {
|
|
1988
1977
|
// β
Select this option (deselect others first)
|
|
1989
|
-
console.log(` β
Selecting "${optionName}"`);
|
|
1978
|
+
// console.log(` β
Selecting "${optionName}"`);
|
|
1990
1979
|
|
|
1991
1980
|
allOptions.forEach(opt => {
|
|
1992
1981
|
opt.classList.remove('cf-checked');
|
|
@@ -2012,15 +2001,15 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
2012
2001
|
// β
NEW: Check if auto-advance is enabled
|
|
2013
2002
|
const currentStep = flowData.flow[chatState.step];
|
|
2014
2003
|
if (currentStep.autoAdvance === true) {
|
|
2015
|
-
console.log(' β‘ Auto-advance enabled - proceeding to next step');
|
|
2004
|
+
// console.log(' β‘ Auto-advance enabled - proceeding to next step');
|
|
2016
2005
|
|
|
2017
2006
|
// Add a small delay for visual feedback
|
|
2018
2007
|
const delay = currentStep.autoAdvanceDelay || 500;
|
|
2019
|
-
console.log(` β±οΈ Waiting ${delay}ms before advancing`);
|
|
2008
|
+
// console.log(` β±οΈ Waiting ${delay}ms before advancing`);
|
|
2020
2009
|
|
|
2021
2010
|
setTimeout(() => {
|
|
2022
2011
|
if (elements.nextBtn && !elements.nextBtn.disabled) {
|
|
2023
|
-
console.log(' βΆοΈ Auto-advancing to next step');
|
|
2012
|
+
// console.log(' βΆοΈ Auto-advancing to next step');
|
|
2024
2013
|
handleNext();
|
|
2025
2014
|
}
|
|
2026
2015
|
}, delay);
|
|
@@ -2030,11 +2019,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
2030
2019
|
} else {
|
|
2031
2020
|
const isChecked = !element.classList.contains('cf-checked');
|
|
2032
2021
|
|
|
2033
|
-
console.log(`Multi-select "${optionName}":`, {
|
|
2034
|
-
isChecked,
|
|
2035
|
-
currentData: chatState.data[field],
|
|
2036
|
-
valueToToggle: value
|
|
2037
|
-
});
|
|
2022
|
+
// console.log(`Multi-select "${optionName}":`, { isChecked, currentData: chatState.data[field], valueToToggle: value });
|
|
2038
2023
|
|
|
2039
2024
|
if (isChecked) {
|
|
2040
2025
|
element.classList.add('cf-checked');
|
|
@@ -2055,36 +2040,29 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
2055
2040
|
chatState.data[field].push(value);
|
|
2056
2041
|
}
|
|
2057
2042
|
|
|
2058
|
-
console.log(`β
Added "${optionName}"`);
|
|
2059
|
-
console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
2043
|
+
// console.log(`β
Added "${optionName}"`);
|
|
2044
|
+
// console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
2060
2045
|
} else {
|
|
2061
2046
|
element.classList.remove('cf-checked');
|
|
2062
2047
|
element.style.setProperty('background-color', 'transparent', 'important');
|
|
2063
2048
|
if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
|
|
2064
2049
|
if (input) input.checked = false;
|
|
2065
2050
|
|
|
2066
|
-
console.log(` BEFORE filter - chatState.data.${field}:`, chatState.data[field]);
|
|
2051
|
+
// console.log(` BEFORE filter - chatState.data.${field}:`, chatState.data[field]);
|
|
2067
2052
|
|
|
2068
2053
|
if (Array.isArray(chatState.data[field])) {
|
|
2069
2054
|
const beforeLength = chatState.data[field].length;
|
|
2070
2055
|
chatState.data[field] = chatState.data[field].filter(v => {
|
|
2071
2056
|
const match = JSON.stringify(v) === JSON.stringify(value);
|
|
2072
|
-
console.log(` Comparing:`, {
|
|
2073
|
-
arrayValue: v,
|
|
2074
|
-
clickedValue: value,
|
|
2075
|
-
stringifiedArray: JSON.stringify(v),
|
|
2076
|
-
stringifiedClick: JSON.stringify(value),
|
|
2077
|
-
match: match,
|
|
2078
|
-
keep: !match
|
|
2079
|
-
});
|
|
2057
|
+
// console.log(` Comparing:`, { arrayValue: v, clickedValue: value, match: match, keep: !match });
|
|
2080
2058
|
return !match;
|
|
2081
2059
|
});
|
|
2082
2060
|
const afterLength = chatState.data[field].length;
|
|
2083
|
-
console.log(` AFTER filter - removed ${beforeLength - afterLength} items`);
|
|
2061
|
+
// console.log(` AFTER filter - removed ${beforeLength - afterLength} items`);
|
|
2084
2062
|
}
|
|
2085
2063
|
|
|
2086
|
-
console.log(`β Removed "${optionName}"`);
|
|
2087
|
-
console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
2064
|
+
// console.log(`β Removed "${optionName}"`);
|
|
2065
|
+
// console.log(` chatState.data.${field}:`, chatState.data[field]);
|
|
2088
2066
|
}
|
|
2089
2067
|
|
|
2090
2068
|
// β
FIX: Build currentSelection from actual data array, not DOM elements
|
|
@@ -2092,7 +2070,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
2092
2070
|
if (!chatState.data[field] || chatState.data[field].length === 0) {
|
|
2093
2071
|
// No selections
|
|
2094
2072
|
chatState.currentSelection = null;
|
|
2095
|
-
console.log(`π No selections - currentSelection set to null`);
|
|
2073
|
+
// console.log(`π No selections - currentSelection set to null`);
|
|
2096
2074
|
} else {
|
|
2097
2075
|
// Build name from actual data array by finding matching options
|
|
2098
2076
|
const selectedNames = chatState.data[field].map(val => {
|
|
@@ -2110,11 +2088,7 @@ function handleOptionClick(element, field, isSingleSelect, options) {
|
|
|
2110
2088
|
name: selectedNames || 'None selected'
|
|
2111
2089
|
};
|
|
2112
2090
|
|
|
2113
|
-
console.log(`π Final state after toggle:`, {
|
|
2114
|
-
field,
|
|
2115
|
-
dataValue: chatState.data[field],
|
|
2116
|
-
currentSelectionName: chatState.currentSelection.name
|
|
2117
|
-
});
|
|
2091
|
+
// console.log(`π Final state after toggle:`, { field, dataValue: chatState.data[field], currentSelectionName: chatState.currentSelection.name });
|
|
2118
2092
|
}
|
|
2119
2093
|
}
|
|
2120
2094
|
|
|
@@ -2131,7 +2105,7 @@ async function handleNext() {
|
|
|
2131
2105
|
const inputRequired = currentStep.inputRequired === true;
|
|
2132
2106
|
|
|
2133
2107
|
if (inputRequired && !chatState.currentSelection) {
|
|
2134
|
-
console.log('Selection required but none made');
|
|
2108
|
+
// console.log('Selection required but none made');
|
|
2135
2109
|
return;
|
|
2136
2110
|
}
|
|
2137
2111
|
|
|
@@ -2146,13 +2120,13 @@ async function handleNext() {
|
|
|
2146
2120
|
// Check for empty or invalid values
|
|
2147
2121
|
if (inputType === 'text') {
|
|
2148
2122
|
if (value === undefined || value === null || value === '' || (typeof value === 'string' && value.trim() === '')) {
|
|
2149
|
-
console.log('β Text input required but empty - cannot proceed');
|
|
2123
|
+
// console.log('β Text input required but empty - cannot proceed');
|
|
2150
2124
|
disableNextButton();
|
|
2151
2125
|
return;
|
|
2152
2126
|
}
|
|
2153
2127
|
} else if (inputType === 'number') {
|
|
2154
2128
|
if (value === undefined || value === null || value === '' || isNaN(value)) {
|
|
2155
|
-
console.log('β Number input required but empty/NaN - cannot proceed');
|
|
2129
|
+
// console.log('β Number input required but empty/NaN - cannot proceed');
|
|
2156
2130
|
disableNextButton();
|
|
2157
2131
|
return;
|
|
2158
2132
|
}
|
|
@@ -2163,19 +2137,19 @@ async function handleNext() {
|
|
|
2163
2137
|
const max = inputConfig.max;
|
|
2164
2138
|
|
|
2165
2139
|
if (min !== undefined && value < min) {
|
|
2166
|
-
console.log(`β Number input below minimum (${value} < ${min}) - cannot proceed`);
|
|
2140
|
+
// console.log(`β Number input below minimum (${value} < ${min}) - cannot proceed`);
|
|
2167
2141
|
disableNextButton();
|
|
2168
2142
|
return;
|
|
2169
2143
|
}
|
|
2170
2144
|
|
|
2171
2145
|
if (max !== undefined && value > max) {
|
|
2172
|
-
console.log(`β Number input above maximum (${value} > ${max}) - cannot proceed`);
|
|
2146
|
+
// console.log(`β Number input above maximum (${value} > ${max}) - cannot proceed`);
|
|
2173
2147
|
disableNextButton();
|
|
2174
2148
|
return;
|
|
2175
2149
|
}
|
|
2176
2150
|
}
|
|
2177
2151
|
|
|
2178
|
-
console.log(`β
${inputType} input validation passed:`, value);
|
|
2152
|
+
// console.log(`β
${inputType} input validation passed:`, value);
|
|
2179
2153
|
}
|
|
2180
2154
|
}
|
|
2181
2155
|
|
|
@@ -2183,9 +2157,9 @@ async function handleNext() {
|
|
|
2183
2157
|
const field = currentStep.input.field;
|
|
2184
2158
|
const customConfig = currentStep.input.custom;
|
|
2185
2159
|
|
|
2186
|
-
console.log(`\nπ― === HANDLE NEXT: Checking single-select-custom validation ===`);
|
|
2187
|
-
console.log(`Field: ${field}`);
|
|
2188
|
-
console.log(`Custom config:`, customConfig);
|
|
2160
|
+
// console.log(`\nπ― === HANDLE NEXT: Checking single-select-custom validation ===`);
|
|
2161
|
+
// console.log(`Field: ${field}`);
|
|
2162
|
+
// console.log(`Custom config:`, customConfig);
|
|
2189
2163
|
|
|
2190
2164
|
const customOptionElement = document.querySelector(
|
|
2191
2165
|
`[data-field="${field}"][data-is-custom="true"][data-chat-element="single-select-input"]`
|
|
@@ -2194,31 +2168,31 @@ async function handleNext() {
|
|
|
2194
2168
|
|
|
2195
2169
|
const selectedValue = chatState.data[field];
|
|
2196
2170
|
|
|
2197
|
-
console.log(`Selected value:`, selectedValue);
|
|
2198
|
-
console.log(`Is custom option selected? ${isCustomOptionSelected}`);
|
|
2171
|
+
// console.log(`Selected value:`, selectedValue);
|
|
2172
|
+
// console.log(`Is custom option selected? ${isCustomOptionSelected}`);
|
|
2199
2173
|
|
|
2200
2174
|
if (isCustomOptionSelected && customConfig) {
|
|
2201
|
-
console.log(`π Running final validation before proceeding...`);
|
|
2175
|
+
// console.log(`π Running final validation before proceeding...`);
|
|
2202
2176
|
|
|
2203
2177
|
const validation = validateMinMax(field, customConfig, true); // β
Show errors on Next click
|
|
2204
2178
|
|
|
2205
|
-
console.log(`Validation result:`, validation);
|
|
2179
|
+
// console.log(`Validation result:`, validation);
|
|
2206
2180
|
|
|
2207
2181
|
if (!validation.valid) {
|
|
2208
2182
|
if (validation.error) {
|
|
2209
|
-
console.log(' β οΈ Validation failed in handleNext - error shown in error div');
|
|
2183
|
+
// console.log(' β οΈ Validation failed in handleNext - error shown in error div');
|
|
2210
2184
|
// β
Error is already shown in the error div by validateMinMax
|
|
2211
2185
|
// Don't hide options or add bot message - just stop progression
|
|
2212
2186
|
} else {
|
|
2213
|
-
console.log(' β οΈ Validation incomplete, waiting for user input');
|
|
2187
|
+
// console.log(' β οΈ Validation incomplete, waiting for user input');
|
|
2214
2188
|
}
|
|
2215
2189
|
|
|
2216
2190
|
return;
|
|
2217
2191
|
}
|
|
2218
2192
|
|
|
2219
|
-
console.log('β
Validation passed, proceeding to next step');
|
|
2193
|
+
// console.log('β
Validation passed, proceeding to next step');
|
|
2220
2194
|
} else if (customConfig && chatState.currentSelection && chatState.currentSelection.value === customConfig.value) {
|
|
2221
|
-
console.log(' β οΈ Custom option selected but no valid range entered');
|
|
2195
|
+
// console.log(' β οΈ Custom option selected but no valid range entered');
|
|
2222
2196
|
return;
|
|
2223
2197
|
}
|
|
2224
2198
|
}
|
|
@@ -2255,7 +2229,7 @@ async function handleNext() {
|
|
|
2255
2229
|
if (prefix) displayName = `${prefix} ${displayName}`;
|
|
2256
2230
|
if (suffix) displayName = `${displayName} ${suffix}`;
|
|
2257
2231
|
|
|
2258
|
-
console.log(`π Adding user message before onNext: "${displayName}"`);
|
|
2232
|
+
// console.log(`π Adding user message before onNext: "${displayName}"`);
|
|
2259
2233
|
addMessage(displayName, 'user', false, chatState.step);
|
|
2260
2234
|
|
|
2261
2235
|
chatState.history.push({
|
|
@@ -2283,7 +2257,7 @@ async function handleNext() {
|
|
|
2283
2257
|
|
|
2284
2258
|
// β
NEW: Create showMessage helper function
|
|
2285
2259
|
const showMessage = (message) => {
|
|
2286
|
-
console.log('π¬ showMessage called:', message);
|
|
2260
|
+
// console.log('π¬ showMessage called:', message);
|
|
2287
2261
|
addMessage(message, 'bot', false, null);
|
|
2288
2262
|
scrollToBottom();
|
|
2289
2263
|
};
|
|
@@ -2305,14 +2279,14 @@ async function handleNext() {
|
|
|
2305
2279
|
|
|
2306
2280
|
// β
Still support showMessage in return object for backwards compatibility
|
|
2307
2281
|
if (result && typeof result === 'object' && result.showMessage) {
|
|
2308
|
-
console.log('π¬ onNext displaying message from return:', result.showMessage);
|
|
2282
|
+
// console.log('π¬ onNext displaying message from return:', result.showMessage);
|
|
2309
2283
|
addMessage(result.showMessage, 'bot', false, null);
|
|
2310
2284
|
scrollToBottom();
|
|
2311
2285
|
}
|
|
2312
2286
|
|
|
2313
2287
|
// β
NEW: Check if onNext wants to update steps by field name
|
|
2314
2288
|
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
2315
|
-
console.log('π― onNext returned data to update steps by field name:', result.updateStepByField);
|
|
2289
|
+
// console.log('π― onNext returned data to update steps by field name:', result.updateStepByField);
|
|
2316
2290
|
|
|
2317
2291
|
// Iterate through all field updates
|
|
2318
2292
|
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
@@ -2325,22 +2299,22 @@ async function handleNext() {
|
|
|
2325
2299
|
|
|
2326
2300
|
if (targetStepIndex !== -1) {
|
|
2327
2301
|
const targetStep = flowData.flow[targetStepIndex];
|
|
2328
|
-
console.log(` β
Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2302
|
+
// console.log(` β
Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2329
2303
|
|
|
2330
2304
|
// Update the step's input properties
|
|
2331
2305
|
if (updates.options !== undefined) {
|
|
2332
2306
|
targetStep.input.options = updates.options;
|
|
2333
|
-
console.log(` β Updated options (${updates.options.length} items)`);
|
|
2307
|
+
// console.log(` β Updated options (${updates.options.length} items)`);
|
|
2334
2308
|
}
|
|
2335
2309
|
|
|
2336
2310
|
if (updates.min !== undefined) {
|
|
2337
2311
|
targetStep.input.min = updates.min;
|
|
2338
|
-
console.log(` β Updated min: ${updates.min}`);
|
|
2312
|
+
// console.log(` β Updated min: ${updates.min}`);
|
|
2339
2313
|
}
|
|
2340
2314
|
|
|
2341
2315
|
if (updates.max !== undefined) {
|
|
2342
2316
|
targetStep.input.max = updates.max;
|
|
2343
|
-
console.log(` β Updated max: ${updates.max}`);
|
|
2317
|
+
// console.log(` β Updated max: ${updates.max}`);
|
|
2344
2318
|
}
|
|
2345
2319
|
|
|
2346
2320
|
if (updates.selectedInputValueType !== undefined) {
|
|
@@ -2366,36 +2340,36 @@ async function handleNext() {
|
|
|
2366
2340
|
|
|
2367
2341
|
// β
Support updating chatState.data from onNext (same as onStart)
|
|
2368
2342
|
if (result && typeof result === 'object' && result.data && typeof result.data === 'object') {
|
|
2369
|
-
console.log(` π onNext returned data to update chatState.data:`, result.data);
|
|
2343
|
+
// console.log(` π onNext returned data to update chatState.data:`, result.data);
|
|
2370
2344
|
Object.keys(result.data).forEach(key => {
|
|
2371
2345
|
chatState.data[key] = result.data[key];
|
|
2372
|
-
console.log(` β chatState.data.${key} = ${JSON.stringify(result.data[key])}`);
|
|
2346
|
+
// console.log(` β chatState.data.${key} = ${JSON.stringify(result.data[key])}`);
|
|
2373
2347
|
});
|
|
2374
2348
|
}
|
|
2375
2349
|
|
|
2376
2350
|
// β
NEW: Check if onNext wants to jump to step by name
|
|
2377
2351
|
if (result && typeof result === 'object' && result.goToStepName) {
|
|
2378
|
-
console.log(`π― onNext requested jump to step name: "${result.goToStepName}"`);
|
|
2352
|
+
// console.log(`π― onNext requested jump to step name: "${result.goToStepName}"`);
|
|
2379
2353
|
|
|
2380
2354
|
const stepName = result.goToStepName;
|
|
2381
2355
|
const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
|
|
2382
2356
|
|
|
2383
2357
|
if (targetStepIndex !== -1) {
|
|
2384
|
-
console.log(` β
Found step "${stepName}" at index ${targetStepIndex}`);
|
|
2358
|
+
// console.log(` β
Found step "${stepName}" at index ${targetStepIndex}`);
|
|
2385
2359
|
|
|
2386
2360
|
// β
NEW: Handle prefillData to override disableInputValuePrefill
|
|
2387
2361
|
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2388
|
-
console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
2362
|
+
// console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
2389
2363
|
|
|
2390
2364
|
// Merge prefillData into chatState.data
|
|
2391
2365
|
Object.keys(result.prefillData).forEach(key => {
|
|
2392
2366
|
chatState.data[key] = result.prefillData[key];
|
|
2393
|
-
console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
2367
|
+
// console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
2394
2368
|
});
|
|
2395
2369
|
|
|
2396
2370
|
// β
Store which fields should override disableInputValuePrefill
|
|
2397
2371
|
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2398
|
-
console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
2372
|
+
// console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
2399
2373
|
}
|
|
2400
2374
|
|
|
2401
2375
|
chatState.step = targetStepIndex;
|
|
@@ -2426,24 +2400,24 @@ async function handleNext() {
|
|
|
2426
2400
|
|
|
2427
2401
|
// β
NEW: Check if onNext wants to jump to a specific step
|
|
2428
2402
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
2429
|
-
console.log(`π― onNext requested jump to step ${result.goToStep}`);
|
|
2403
|
+
// console.log(`π― onNext requested jump to step ${result.goToStep}`);
|
|
2430
2404
|
|
|
2431
2405
|
const targetStep = result.goToStep;
|
|
2432
2406
|
|
|
2433
2407
|
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
2434
2408
|
// β
NEW: Handle prefillData to override disableInputValuePrefill
|
|
2435
2409
|
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
2436
|
-
console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
2410
|
+
// console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
2437
2411
|
|
|
2438
2412
|
// Merge prefillData into chatState.data
|
|
2439
2413
|
Object.keys(result.prefillData).forEach(key => {
|
|
2440
2414
|
chatState.data[key] = result.prefillData[key];
|
|
2441
|
-
console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
2415
|
+
// console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
2442
2416
|
});
|
|
2443
2417
|
|
|
2444
2418
|
// β
Store which fields should override disableInputValuePrefill
|
|
2445
2419
|
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
2446
|
-
console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
2420
|
+
// console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
2447
2421
|
}
|
|
2448
2422
|
|
|
2449
2423
|
chatState.step = targetStep;
|
|
@@ -2462,7 +2436,7 @@ async function handleNext() {
|
|
|
2462
2436
|
|
|
2463
2437
|
// β
NEW: Check if onNext returned data to update next step
|
|
2464
2438
|
if (result && typeof result === 'object' && result.updateNextStep) {
|
|
2465
|
-
console.log('π onNext returned data to update next step:', result);
|
|
2439
|
+
// console.log('π onNext returned data to update next step:', result);
|
|
2466
2440
|
|
|
2467
2441
|
const nextStepIndex = chatState.step + 1;
|
|
2468
2442
|
if (nextStepIndex < flowData.flow.length) {
|
|
@@ -2475,18 +2449,18 @@ async function handleNext() {
|
|
|
2475
2449
|
|
|
2476
2450
|
// Check if result has a property matching the input field name
|
|
2477
2451
|
if (result[inputFieldName]) {
|
|
2478
|
-
console.log(` β
Updating input properties for field "${inputFieldName}":`, result[inputFieldName]);
|
|
2452
|
+
// console.log(` β
Updating input properties for field "${inputFieldName}":`, result[inputFieldName]);
|
|
2479
2453
|
|
|
2480
2454
|
// Update nested properties
|
|
2481
2455
|
if (result[inputFieldName].options !== undefined) {
|
|
2482
2456
|
nextStep.input.options = result[inputFieldName].options;
|
|
2483
|
-
console.log(` β input.options updated with ${result[inputFieldName].options.length} items`);
|
|
2457
|
+
// console.log(` β input.options updated with ${result[inputFieldName].options.length} items`);
|
|
2484
2458
|
}
|
|
2485
2459
|
|
|
2486
2460
|
// Can also update other input properties
|
|
2487
2461
|
if (result[inputFieldName].field !== undefined) {
|
|
2488
2462
|
nextStep.input.field = result[inputFieldName].field;
|
|
2489
|
-
console.log(` β input.field updated to: ${result[inputFieldName].field}`);
|
|
2463
|
+
// console.log(` β input.field updated to: ${result[inputFieldName].field}`);
|
|
2490
2464
|
}
|
|
2491
2465
|
|
|
2492
2466
|
if (result[inputFieldName].selectedInputValueType !== undefined) {
|
|
@@ -2518,34 +2492,34 @@ async function handleNext() {
|
|
|
2518
2492
|
// β
LEGACY: Direct properties (backwards compatible)
|
|
2519
2493
|
// Update options if provided
|
|
2520
2494
|
if (result.options && nextStep.input) {
|
|
2521
|
-
console.log(` β
Updating step ${nextStepIndex} input.options (direct):`, result.options);
|
|
2495
|
+
// console.log(` β
Updating step ${nextStepIndex} input.options (direct):`, result.options);
|
|
2522
2496
|
nextStep.input.options = result.options;
|
|
2523
2497
|
}
|
|
2524
2498
|
|
|
2525
2499
|
// β
Update field name if provided
|
|
2526
2500
|
if (result.field && nextStep.input) {
|
|
2527
|
-
console.log(` β
Updating step ${nextStepIndex} field name: ${result.field}`);
|
|
2501
|
+
// console.log(` β
Updating step ${nextStepIndex} field name: ${result.field}`);
|
|
2528
2502
|
nextStep.input.field = result.field;
|
|
2529
2503
|
}
|
|
2530
2504
|
|
|
2531
2505
|
// Update any other step properties if provided
|
|
2532
2506
|
if (result.message) {
|
|
2533
|
-
console.log(` β
Updating step ${nextStepIndex} message:`, result.message);
|
|
2507
|
+
// console.log(` β
Updating step ${nextStepIndex} message:`, result.message);
|
|
2534
2508
|
nextStep.message = result.message;
|
|
2535
2509
|
}
|
|
2536
2510
|
|
|
2537
2511
|
if (result.inputType) {
|
|
2538
|
-
console.log(` β
Updating step ${nextStepIndex} inputType:`, result.inputType);
|
|
2512
|
+
// console.log(` β
Updating step ${nextStepIndex} inputType:`, result.inputType);
|
|
2539
2513
|
nextStep.inputType = result.inputType;
|
|
2540
2514
|
}
|
|
2541
2515
|
|
|
2542
2516
|
if (result.shouldDisplay !== undefined) {
|
|
2543
|
-
console.log(` β
Updating step ${nextStepIndex} shouldDisplay`);
|
|
2517
|
+
// console.log(` β
Updating step ${nextStepIndex} shouldDisplay`);
|
|
2544
2518
|
nextStep.shouldDisplay = result.shouldDisplay;
|
|
2545
2519
|
}
|
|
2546
2520
|
|
|
2547
2521
|
if (result.dependsOn !== undefined) {
|
|
2548
|
-
console.log(` β
Updating step ${nextStepIndex} dependsOn:`, result.dependsOn);
|
|
2522
|
+
// console.log(` β
Updating step ${nextStepIndex} dependsOn:`, result.dependsOn);
|
|
2549
2523
|
nextStep.dependsOn = result.dependsOn;
|
|
2550
2524
|
}
|
|
2551
2525
|
}
|
|
@@ -2593,7 +2567,7 @@ async function handleNext() {
|
|
|
2593
2567
|
// More steps to edit
|
|
2594
2568
|
chatState.editStepsIndex = nextEditIndex;
|
|
2595
2569
|
const nextStepIndex = chatState.editSteps[nextEditIndex];
|
|
2596
|
-
console.log(`\nπ€οΈ Edit-steps: moving to step ${nextEditIndex + 1}/${chatState.editSteps.length} (flow index ${nextStepIndex})`);
|
|
2570
|
+
// console.log(`\nπ€οΈ Edit-steps: moving to step ${nextEditIndex + 1}/${chatState.editSteps.length} (flow index ${nextStepIndex})`);
|
|
2597
2571
|
|
|
2598
2572
|
chatState.step = nextStepIndex;
|
|
2599
2573
|
|
|
@@ -2614,7 +2588,7 @@ async function handleNext() {
|
|
|
2614
2588
|
return;
|
|
2615
2589
|
} else {
|
|
2616
2590
|
// All edit steps done - call onEditComplete
|
|
2617
|
-
console.log(`\nβ
Edit-steps complete! All ${chatState.editSteps.length} steps finished.`);
|
|
2591
|
+
// console.log(`\nβ
Edit-steps complete! All ${chatState.editSteps.length} steps finished.`);
|
|
2618
2592
|
|
|
2619
2593
|
const dataCopy = { ...chatState.data };
|
|
2620
2594
|
const historyCopy = [...chatState.history];
|
|
@@ -2629,7 +2603,7 @@ async function handleNext() {
|
|
|
2629
2603
|
|
|
2630
2604
|
// Call onEditComplete callback (await if async)
|
|
2631
2605
|
if (callback) {
|
|
2632
|
-
console.log('π Calling onEditComplete with data:', dataCopy);
|
|
2606
|
+
// console.log('π Calling onEditComplete with data:', dataCopy);
|
|
2633
2607
|
try {
|
|
2634
2608
|
await callback(dataCopy);
|
|
2635
2609
|
} catch (error) {
|
|
@@ -2680,7 +2654,7 @@ async function handleNext() {
|
|
|
2680
2654
|
|
|
2681
2655
|
if (chatState.returnToStep !== null) {
|
|
2682
2656
|
const targetStep = chatState.returnToStep;
|
|
2683
|
-
console.log(`\nπ Returning to saved step ${targetStep} (edited step complete)`);
|
|
2657
|
+
// console.log(`\nπ Returning to saved step ${targetStep} (edited step complete)`);
|
|
2684
2658
|
|
|
2685
2659
|
// β
Check if we should continue to next step or jump back
|
|
2686
2660
|
const nextStep = chatState.step + 1;
|
|
@@ -2690,7 +2664,7 @@ async function handleNext() {
|
|
|
2690
2664
|
const currentStepIndex = chatState.step;
|
|
2691
2665
|
const editedStepField = flowData.flow[currentStepIndex]?.input?.field;
|
|
2692
2666
|
|
|
2693
|
-
console.log(` π Checking if step ${nextStep} should be shown (between ${currentStepIndex} and ${targetStep})`);
|
|
2667
|
+
// console.log(` π Checking if step ${nextStep} should be shown (between ${currentStepIndex} and ${targetStep})`);
|
|
2694
2668
|
|
|
2695
2669
|
// Check if the next step depends on the edited field
|
|
2696
2670
|
const nextStepConfig = flowData.flow[nextStep];
|
|
@@ -2698,7 +2672,7 @@ async function handleNext() {
|
|
|
2698
2672
|
const dependencies = Array.isArray(nextStepConfig.dependsOn) ? nextStepConfig.dependsOn : [nextStepConfig.dependsOn];
|
|
2699
2673
|
|
|
2700
2674
|
if (dependencies.includes(editedStepField)) {
|
|
2701
|
-
console.log(` π Step ${nextStep} depends on ${editedStepField} - checking shouldDisplay`);
|
|
2675
|
+
// console.log(` π Step ${nextStep} depends on ${editedStepField} - checking shouldDisplay`);
|
|
2702
2676
|
|
|
2703
2677
|
// Check shouldDisplay
|
|
2704
2678
|
let shouldShow = true; // Default to true if no shouldDisplay
|
|
@@ -2709,7 +2683,7 @@ async function handleNext() {
|
|
|
2709
2683
|
shouldShow = await nextStepConfig.shouldDisplay(
|
|
2710
2684
|
{ ...chatState.data, chatMode: chatState.chatMode } // β
Include chatMode
|
|
2711
2685
|
);
|
|
2712
|
-
console.log(` π Step ${nextStep} shouldDisplay: ${shouldShow}`);
|
|
2686
|
+
// console.log(` π Step ${nextStep} shouldDisplay: ${shouldShow}`);
|
|
2713
2687
|
} catch (error) {
|
|
2714
2688
|
console.error(`Error in shouldDisplay for step ${nextStep}:`, error);
|
|
2715
2689
|
shouldShow = false;
|
|
@@ -2721,7 +2695,7 @@ async function handleNext() {
|
|
|
2721
2695
|
|
|
2722
2696
|
if (shouldShow) {
|
|
2723
2697
|
// Show this dependent step, keep returnToStep for later
|
|
2724
|
-
console.log(` β
Step ${nextStep} should be shown - continuing to it (returnToStep=${targetStep} preserved)`);
|
|
2698
|
+
// console.log(` β
Step ${nextStep} should be shown - continuing to it (returnToStep=${targetStep} preserved)`);
|
|
2725
2699
|
chatState.step = nextStep;
|
|
2726
2700
|
|
|
2727
2701
|
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
@@ -2733,14 +2707,14 @@ async function handleNext() {
|
|
|
2733
2707
|
await showNextStep();
|
|
2734
2708
|
return;
|
|
2735
2709
|
} else {
|
|
2736
|
-
console.log(` βοΈ Step ${nextStep} shouldDisplay returned false - will check next step`);
|
|
2710
|
+
// console.log(` βοΈ Step ${nextStep} shouldDisplay returned false - will check next step`);
|
|
2737
2711
|
}
|
|
2738
2712
|
}
|
|
2739
2713
|
}
|
|
2740
2714
|
|
|
2741
2715
|
// Next step doesn't depend on edited field or shouldn't be shown
|
|
2742
2716
|
// Continue to next step normally (it will check shouldDisplay in showNextStep)
|
|
2743
|
-
console.log(` β‘οΈ Continuing to next step ${nextStep} (normal flow)`);
|
|
2717
|
+
// console.log(` β‘οΈ Continuing to next step ${nextStep} (normal flow)`);
|
|
2744
2718
|
chatState.step = nextStep;
|
|
2745
2719
|
|
|
2746
2720
|
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
@@ -2753,13 +2727,13 @@ async function handleNext() {
|
|
|
2753
2727
|
return;
|
|
2754
2728
|
} else {
|
|
2755
2729
|
// Reached or passed target
|
|
2756
|
-
console.log(` βοΈ Reached target step`);
|
|
2730
|
+
// console.log(` βοΈ Reached target step`);
|
|
2757
2731
|
|
|
2758
2732
|
// β
NEW: Check if there are more steps in the edit path
|
|
2759
2733
|
if (chatState.editPath && chatState.editPath.length > 0) {
|
|
2760
2734
|
const nextEditStep = chatState.editPath.shift();
|
|
2761
|
-
console.log(` π€οΈ Edit path continues - going to step ${nextEditStep}`);
|
|
2762
|
-
console.log(` π€οΈ Remaining edit path:`, chatState.editPath);
|
|
2735
|
+
// console.log(` π€οΈ Edit path continues - going to step ${nextEditStep}`);
|
|
2736
|
+
// console.log(` π€οΈ Remaining edit path:`, chatState.editPath);
|
|
2763
2737
|
|
|
2764
2738
|
// Keep returnToStep for when edit path completes
|
|
2765
2739
|
chatState.step = nextEditStep;
|
|
@@ -2774,7 +2748,7 @@ async function handleNext() {
|
|
|
2774
2748
|
return;
|
|
2775
2749
|
} else {
|
|
2776
2750
|
// No more edit path, return to saved step
|
|
2777
|
-
console.log(` β
Edit complete - returning to step ${targetStep}`);
|
|
2751
|
+
// console.log(` β
Edit complete - returning to step ${targetStep}`);
|
|
2778
2752
|
chatState.returnToStep = null;
|
|
2779
2753
|
chatState.editPath = []; // Clear any remaining path
|
|
2780
2754
|
chatState.step = targetStep;
|
|
@@ -2803,7 +2777,7 @@ async function handleNext() {
|
|
|
2803
2777
|
allRangeWrappers.forEach(wrapper => {
|
|
2804
2778
|
wrapper.style.display = 'none';
|
|
2805
2779
|
});
|
|
2806
|
-
console.log(' π Hidden all range-wrappers');
|
|
2780
|
+
// console.log(' π Hidden all range-wrappers');
|
|
2807
2781
|
|
|
2808
2782
|
updateEditIcons();
|
|
2809
2783
|
|
|
@@ -2826,7 +2800,7 @@ function findNextAccessibleStep(currentStep) {
|
|
|
2826
2800
|
const stepConfig = flowData.flow[nextStep];
|
|
2827
2801
|
|
|
2828
2802
|
if (stepConfig.accessibleViaJumpOnly === true) {
|
|
2829
|
-
console.log(` βοΈ Skipping step ${nextStep} (accessibleViaJumpOnly)`);
|
|
2803
|
+
// console.log(` βοΈ Skipping step ${nextStep} (accessibleViaJumpOnly)`);
|
|
2830
2804
|
nextStep++;
|
|
2831
2805
|
} else {
|
|
2832
2806
|
return nextStep;
|
|
@@ -2850,7 +2824,7 @@ async function showNextStep() {
|
|
|
2850
2824
|
if (elements.messages) {
|
|
2851
2825
|
const injectedElements = elements.messages.querySelectorAll('[data-chat-injected="true"]');
|
|
2852
2826
|
if (injectedElements.length > 0) {
|
|
2853
|
-
console.log(` π§Ή Restoring ${injectedElements.length} previously injected element(s) to original location`);
|
|
2827
|
+
// console.log(` π§Ή Restoring ${injectedElements.length} previously injected element(s) to original location`);
|
|
2854
2828
|
injectedElements.forEach(el => {
|
|
2855
2829
|
// Remove the injected marker
|
|
2856
2830
|
el.removeAttribute('data-chat-injected');
|
|
@@ -2866,11 +2840,11 @@ async function showNextStep() {
|
|
|
2866
2840
|
} else {
|
|
2867
2841
|
el._originalParent.appendChild(el);
|
|
2868
2842
|
}
|
|
2869
|
-
console.log(' β©οΈ Moved element back to original parent (hidden)');
|
|
2843
|
+
// console.log(' β©οΈ Moved element back to original parent (hidden)');
|
|
2870
2844
|
} else {
|
|
2871
2845
|
// Fallback: just remove if no original parent stored
|
|
2872
2846
|
el.remove();
|
|
2873
|
-
console.log(` β οΈ No original parent - removed element`);
|
|
2847
|
+
// console.log(` β οΈ No original parent - removed element`);
|
|
2874
2848
|
}
|
|
2875
2849
|
});
|
|
2876
2850
|
}
|
|
@@ -2880,7 +2854,7 @@ async function showNextStep() {
|
|
|
2880
2854
|
// β
Skip shouldDisplay check entirely if this step is explicitly in editSteps
|
|
2881
2855
|
const isInEditSteps = chatState.editSteps && chatState.editSteps.includes(chatState.step);
|
|
2882
2856
|
if (isInEditSteps) {
|
|
2883
|
-
console.log(` π Step ${chatState.step} is in editSteps - overriding shouldDisplay, always showing`);
|
|
2857
|
+
// console.log(` π Step ${chatState.step} is in editSteps - overriding shouldDisplay, always showing`);
|
|
2884
2858
|
}
|
|
2885
2859
|
if (nextStep.shouldDisplay && !isInEditSteps) {
|
|
2886
2860
|
let shouldShow = false;
|
|
@@ -2891,7 +2865,7 @@ async function showNextStep() {
|
|
|
2891
2865
|
shouldShow = await nextStep.shouldDisplay(
|
|
2892
2866
|
{ ...chatState.data, chatMode: chatState.chatMode } // β
Include chatMode
|
|
2893
2867
|
);
|
|
2894
|
-
console.log(` π shouldDisplay function returned: ${shouldShow}`);
|
|
2868
|
+
// console.log(` π shouldDisplay function returned: ${shouldShow}`);
|
|
2895
2869
|
} catch (error) {
|
|
2896
2870
|
console.error('Error in shouldDisplay function:', error);
|
|
2897
2871
|
shouldShow = false;
|
|
@@ -2899,11 +2873,11 @@ async function showNextStep() {
|
|
|
2899
2873
|
} else if (typeof nextStep.shouldDisplay === 'boolean') {
|
|
2900
2874
|
// Simple boolean
|
|
2901
2875
|
shouldShow = nextStep.shouldDisplay;
|
|
2902
|
-
console.log(` π shouldDisplay boolean: ${shouldShow}`);
|
|
2876
|
+
// console.log(` π shouldDisplay boolean: ${shouldShow}`);
|
|
2903
2877
|
}
|
|
2904
2878
|
|
|
2905
2879
|
if (!shouldShow) {
|
|
2906
|
-
console.log(` βοΈ Skipping step ${chatState.step} (shouldDisplay returned false)`);
|
|
2880
|
+
// console.log(` βοΈ Skipping step ${chatState.step} (shouldDisplay returned false)`);
|
|
2907
2881
|
|
|
2908
2882
|
// β
In editSteps mode, skip to the next step in the editSteps list
|
|
2909
2883
|
if (chatState.editSteps && chatState.editSteps.length > 0) {
|
|
@@ -2911,12 +2885,12 @@ async function showNextStep() {
|
|
|
2911
2885
|
if (nextEditIndex < chatState.editSteps.length) {
|
|
2912
2886
|
chatState.editStepsIndex = nextEditIndex;
|
|
2913
2887
|
chatState.step = chatState.editSteps[nextEditIndex];
|
|
2914
|
-
console.log(` π€οΈ editSteps: skipping to next edit step ${chatState.step}`);
|
|
2888
|
+
// console.log(` π€οΈ editSteps: skipping to next edit step ${chatState.step}`);
|
|
2915
2889
|
await showNextStep();
|
|
2916
2890
|
return;
|
|
2917
2891
|
} else {
|
|
2918
2892
|
// All remaining edit steps should be skipped - trigger edit completion
|
|
2919
|
-
console.log(` π€οΈ editSteps: no more steps - completing`);
|
|
2893
|
+
// console.log(` π€οΈ editSteps: no more steps - completing`);
|
|
2920
2894
|
handleCompletion();
|
|
2921
2895
|
return;
|
|
2922
2896
|
}
|
|
@@ -2934,14 +2908,14 @@ async function showNextStep() {
|
|
|
2934
2908
|
return;
|
|
2935
2909
|
}
|
|
2936
2910
|
|
|
2937
|
-
console.log(` β
Displaying step ${chatState.step} (shouldDisplay returned true)`);
|
|
2911
|
+
// console.log(` β
Displaying step ${chatState.step} (shouldDisplay returned true)`);
|
|
2938
2912
|
}
|
|
2939
2913
|
|
|
2940
2914
|
if (nextStep.onStart) {
|
|
2941
2915
|
try {
|
|
2942
2916
|
// β
NEW: Create showMessage helper function
|
|
2943
2917
|
const showMessage = (message) => {
|
|
2944
|
-
console.log('π¬ showMessage called:', message);
|
|
2918
|
+
// console.log('π¬ showMessage called:', message);
|
|
2945
2919
|
addMessage(message, 'bot', false, null);
|
|
2946
2920
|
scrollToBottom();
|
|
2947
2921
|
};
|
|
@@ -2954,14 +2928,14 @@ async function showNextStep() {
|
|
|
2954
2928
|
|
|
2955
2929
|
// β
Still support showMessage in return object for backwards compatibility
|
|
2956
2930
|
if (result && typeof result === 'object' && result.showMessage) {
|
|
2957
|
-
console.log('π¬ onStart displaying message from return:', result.showMessage);
|
|
2931
|
+
// console.log('π¬ onStart displaying message from return:', result.showMessage);
|
|
2958
2932
|
addMessage(result.showMessage, 'bot', false, null);
|
|
2959
2933
|
scrollToBottom();
|
|
2960
2934
|
}
|
|
2961
2935
|
|
|
2962
2936
|
// β
NEW: Check if onStart wants to update steps by field name
|
|
2963
2937
|
if (result && typeof result === 'object' && result.updateStepByField) {
|
|
2964
|
-
console.log('π― onStart returned data to update steps by field name:', result.updateStepByField);
|
|
2938
|
+
// console.log('π― onStart returned data to update steps by field name:', result.updateStepByField);
|
|
2965
2939
|
|
|
2966
2940
|
// Iterate through all field updates
|
|
2967
2941
|
Object.keys(result.updateStepByField).forEach(fieldName => {
|
|
@@ -2974,22 +2948,22 @@ async function showNextStep() {
|
|
|
2974
2948
|
|
|
2975
2949
|
if (targetStepIndex !== -1) {
|
|
2976
2950
|
const targetStep = flowData.flow[targetStepIndex];
|
|
2977
|
-
console.log(` β
Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2951
|
+
// console.log(` β
Found step ${targetStepIndex} with field "${fieldName}"`);
|
|
2978
2952
|
|
|
2979
2953
|
// Update the step's input properties
|
|
2980
2954
|
if (updates.options !== undefined) {
|
|
2981
2955
|
targetStep.input.options = updates.options;
|
|
2982
|
-
console.log(` β Updated options (${updates.options.length} items)`);
|
|
2956
|
+
// console.log(` β Updated options (${updates.options.length} items)`);
|
|
2983
2957
|
}
|
|
2984
2958
|
|
|
2985
2959
|
if (updates.min !== undefined) {
|
|
2986
2960
|
targetStep.input.min = updates.min;
|
|
2987
|
-
console.log(` β Updated min: ${updates.min}`);
|
|
2961
|
+
// console.log(` β Updated min: ${updates.min}`);
|
|
2988
2962
|
}
|
|
2989
2963
|
|
|
2990
2964
|
if (updates.max !== undefined) {
|
|
2991
2965
|
targetStep.input.max = updates.max;
|
|
2992
|
-
console.log(` β Updated max: ${updates.max}`);
|
|
2966
|
+
// console.log(` β Updated max: ${updates.max}`);
|
|
2993
2967
|
}
|
|
2994
2968
|
|
|
2995
2969
|
if (updates.selectedInputValueType !== undefined) {
|
|
@@ -3015,7 +2989,7 @@ async function showNextStep() {
|
|
|
3015
2989
|
|
|
3016
2990
|
// β
NEW: Check if onStart returned data to update current step
|
|
3017
2991
|
if (result && typeof result === 'object' && result.updateCurrentStep) {
|
|
3018
|
-
console.log('π onStart returned data to update current step:', result);
|
|
2992
|
+
// console.log('π onStart returned data to update current step:', result);
|
|
3019
2993
|
|
|
3020
2994
|
const currentStepIndex = chatState.step;
|
|
3021
2995
|
const currentStep = flowData.flow[currentStepIndex];
|
|
@@ -3026,12 +3000,12 @@ async function showNextStep() {
|
|
|
3026
3000
|
|
|
3027
3001
|
// Check if result has a property matching the input field name
|
|
3028
3002
|
if (result[inputFieldName]) {
|
|
3029
|
-
console.log(` β
Updating current step input.${inputFieldName}:`, result[inputFieldName]);
|
|
3003
|
+
// console.log(` β
Updating current step input.${inputFieldName}:`, result[inputFieldName]);
|
|
3030
3004
|
|
|
3031
3005
|
// Update nested properties
|
|
3032
3006
|
if (result[inputFieldName].options !== undefined) {
|
|
3033
3007
|
currentStep.input.options = result[inputFieldName].options;
|
|
3034
|
-
console.log(` β input.options updated with ${result[inputFieldName].options.length} items`);
|
|
3008
|
+
// console.log(` β input.options updated with ${result[inputFieldName].options.length} items`);
|
|
3035
3009
|
}
|
|
3036
3010
|
|
|
3037
3011
|
if (result[inputFieldName].field !== undefined) {
|
|
@@ -3066,80 +3040,80 @@ async function showNextStep() {
|
|
|
3066
3040
|
|
|
3067
3041
|
// β
Direct properties (backwards compatible)
|
|
3068
3042
|
if (result.options && currentStep.input) {
|
|
3069
|
-
console.log(` β
Updating current step input.options (direct):`, result.options);
|
|
3043
|
+
// console.log(` β
Updating current step input.options (direct):`, result.options);
|
|
3070
3044
|
currentStep.input.options = result.options;
|
|
3071
3045
|
}
|
|
3072
3046
|
|
|
3073
3047
|
if (result.field && currentStep.input) {
|
|
3074
|
-
console.log(` β
Updating current step field name: ${result.field}`);
|
|
3048
|
+
// console.log(` β
Updating current step field name: ${result.field}`);
|
|
3075
3049
|
currentStep.input.field = result.field;
|
|
3076
3050
|
}
|
|
3077
3051
|
|
|
3078
3052
|
// Update step-level properties
|
|
3079
3053
|
if (result.message) {
|
|
3080
|
-
console.log(` β
Updating current step message:`, result.message);
|
|
3054
|
+
// console.log(` β
Updating current step message:`, result.message);
|
|
3081
3055
|
currentStep.message = result.message;
|
|
3082
3056
|
}
|
|
3083
3057
|
|
|
3084
3058
|
if (result.inputType) {
|
|
3085
|
-
console.log(` β
Updating current step inputType:`, result.inputType);
|
|
3059
|
+
// console.log(` β
Updating current step inputType:`, result.inputType);
|
|
3086
3060
|
currentStep.inputType = result.inputType;
|
|
3087
3061
|
}
|
|
3088
3062
|
|
|
3089
3063
|
if (result.shouldDisplay !== undefined) {
|
|
3090
|
-
console.log(` β
Updating current step shouldDisplay`);
|
|
3064
|
+
// console.log(` β
Updating current step shouldDisplay`);
|
|
3091
3065
|
currentStep.shouldDisplay = result.shouldDisplay;
|
|
3092
3066
|
}
|
|
3093
3067
|
|
|
3094
3068
|
if (result.dependsOn !== undefined) {
|
|
3095
|
-
console.log(` β
Updating current step dependsOn:`, result.dependsOn);
|
|
3069
|
+
// console.log(` β
Updating current step dependsOn:`, result.dependsOn);
|
|
3096
3070
|
currentStep.dependsOn = result.dependsOn;
|
|
3097
3071
|
}
|
|
3098
3072
|
|
|
3099
3073
|
if (result.autoAdvance !== undefined) {
|
|
3100
|
-
console.log(` β
Updating current step autoAdvance:`, result.autoAdvance);
|
|
3074
|
+
// console.log(` β
Updating current step autoAdvance:`, result.autoAdvance);
|
|
3101
3075
|
currentStep.autoAdvance = result.autoAdvance;
|
|
3102
3076
|
}
|
|
3103
3077
|
|
|
3104
3078
|
if (result.autoAdvanceDelay !== undefined) {
|
|
3105
|
-
console.log(` β
Updating current step autoAdvanceDelay:`, result.autoAdvanceDelay);
|
|
3079
|
+
// console.log(` β
Updating current step autoAdvanceDelay:`, result.autoAdvanceDelay);
|
|
3106
3080
|
currentStep.autoAdvanceDelay = result.autoAdvanceDelay;
|
|
3107
3081
|
}
|
|
3108
3082
|
}
|
|
3109
3083
|
|
|
3110
3084
|
// β
NEW: Support updating chatState.data from onStart (moved outside updateCurrentStep block)
|
|
3111
3085
|
if (result && typeof result === 'object' && result.data && typeof result.data === 'object') {
|
|
3112
|
-
console.log(` π onStart returned data to update chatState.data:`, result.data);
|
|
3086
|
+
// console.log(` π onStart returned data to update chatState.data:`, result.data);
|
|
3113
3087
|
// Merge returned data into chatState.data
|
|
3114
3088
|
Object.keys(result.data).forEach(key => {
|
|
3115
3089
|
chatState.data[key] = result.data[key];
|
|
3116
|
-
console.log(` β chatState.data.${key} = ${JSON.stringify(result.data[key])}`);
|
|
3090
|
+
// console.log(` β chatState.data.${key} = ${JSON.stringify(result.data[key])}`);
|
|
3117
3091
|
});
|
|
3118
3092
|
}
|
|
3119
3093
|
|
|
3120
3094
|
// β
NEW: Check if onStart wants to jump to step by name
|
|
3121
3095
|
if (result && typeof result === 'object' && result.goToStepName) {
|
|
3122
|
-
console.log(`π― onStart requested jump to step name: "${result.goToStepName}"`);
|
|
3096
|
+
// console.log(`π― onStart requested jump to step name: "${result.goToStepName}"`);
|
|
3123
3097
|
|
|
3124
3098
|
const stepName = result.goToStepName;
|
|
3125
3099
|
const targetStepIndex = flowData.flow.findIndex(step => step.name === stepName);
|
|
3126
3100
|
|
|
3127
3101
|
if (targetStepIndex !== -1) {
|
|
3128
|
-
console.log(` β
Found step "${stepName}" at index ${targetStepIndex}`);
|
|
3102
|
+
// console.log(` β
Found step "${stepName}" at index ${targetStepIndex}`);
|
|
3129
3103
|
|
|
3130
3104
|
// β
NEW: Handle prefillData to override disableInputValuePrefill
|
|
3131
3105
|
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
3132
|
-
console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
3106
|
+
// console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
3133
3107
|
|
|
3134
3108
|
// Merge prefillData into chatState.data
|
|
3135
3109
|
Object.keys(result.prefillData).forEach(key => {
|
|
3136
3110
|
chatState.data[key] = result.prefillData[key];
|
|
3137
|
-
console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
3111
|
+
// console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
3138
3112
|
});
|
|
3139
3113
|
|
|
3140
3114
|
// β
Store which fields should override disableInputValuePrefill
|
|
3141
3115
|
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
3142
|
-
console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
3116
|
+
// console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
3143
3117
|
}
|
|
3144
3118
|
|
|
3145
3119
|
// β
Check if we're jumping from the very first step (needs extra time to initialize)
|
|
@@ -3161,24 +3135,24 @@ async function showNextStep() {
|
|
|
3161
3135
|
|
|
3162
3136
|
// β
NEW: Check if onStart wants to jump to a specific step
|
|
3163
3137
|
if (result && typeof result === 'object' && typeof result.goToStep === 'number') {
|
|
3164
|
-
console.log(`π― onStart requested jump to step ${result.goToStep}`);
|
|
3138
|
+
// console.log(`π― onStart requested jump to step ${result.goToStep}`);
|
|
3165
3139
|
|
|
3166
3140
|
const targetStep = result.goToStep;
|
|
3167
3141
|
|
|
3168
3142
|
if (targetStep >= 0 && targetStep < flowData.flow.length) {
|
|
3169
3143
|
// β
NEW: Handle prefillData to override disableInputValuePrefill
|
|
3170
3144
|
if (result.prefillData && typeof result.prefillData === 'object') {
|
|
3171
|
-
console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
3145
|
+
// console.log(` π Pre-filling data for jump:`, result.prefillData);
|
|
3172
3146
|
|
|
3173
3147
|
// Merge prefillData into chatState.data
|
|
3174
3148
|
Object.keys(result.prefillData).forEach(key => {
|
|
3175
3149
|
chatState.data[key] = result.prefillData[key];
|
|
3176
|
-
console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
3150
|
+
// console.log(` β Set ${key}:`, result.prefillData[key]);
|
|
3177
3151
|
});
|
|
3178
3152
|
|
|
3179
3153
|
// β
Store which fields should override disableInputValuePrefill
|
|
3180
3154
|
chatState.prefillOverrideFields = Object.keys(result.prefillData);
|
|
3181
|
-
console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
3155
|
+
// console.log(` π Override active for fields:`, chatState.prefillOverrideFields);
|
|
3182
3156
|
}
|
|
3183
3157
|
|
|
3184
3158
|
// β
Check if we're jumping from the very first step (needs extra time to initialize)
|
|
@@ -3200,7 +3174,7 @@ async function showNextStep() {
|
|
|
3200
3174
|
|
|
3201
3175
|
// β
NEW: Check if onStart wants to block this step and skip to next
|
|
3202
3176
|
if (result && typeof result === 'object' && result.blockStep === true) {
|
|
3203
|
-
console.log('βοΈ Step blocked by onStart - skipping to next step');
|
|
3177
|
+
// console.log('βοΈ Step blocked by onStart - skipping to next step');
|
|
3204
3178
|
// β
NEW: Find next accessible step
|
|
3205
3179
|
chatState.step = findNextAccessibleStep(chatState.step);
|
|
3206
3180
|
|
|
@@ -3219,7 +3193,7 @@ async function showNextStep() {
|
|
|
3219
3193
|
(typeof result === 'object' && result.canStart !== false);
|
|
3220
3194
|
|
|
3221
3195
|
if (!canStart) {
|
|
3222
|
-
console.log('β Step blocked by onStart - flow stopped');
|
|
3196
|
+
// console.log('β Step blocked by onStart - flow stopped');
|
|
3223
3197
|
return;
|
|
3224
3198
|
}
|
|
3225
3199
|
} catch (error) {
|
|
@@ -3249,7 +3223,7 @@ async function showNextStep() {
|
|
|
3249
3223
|
messageToDisplay = nextStep.message(
|
|
3250
3224
|
{ ...chatState.data, chatMode: chatState.chatMode } // β
Include chatMode
|
|
3251
3225
|
);
|
|
3252
|
-
console.log(` π¬ Dynamic message (function): "${messageToDisplay}"`);
|
|
3226
|
+
// console.log(` π¬ Dynamic message (function): "${messageToDisplay}"`);
|
|
3253
3227
|
} catch (error) {
|
|
3254
3228
|
console.error('Error in message function:', error);
|
|
3255
3229
|
messageToDisplay = 'Error loading message';
|
|
@@ -3260,7 +3234,7 @@ async function showNextStep() {
|
|
|
3260
3234
|
// Create function from template string
|
|
3261
3235
|
const templateFunc = new Function('data', `return \`${nextStep.message}\`;`);
|
|
3262
3236
|
messageToDisplay = templateFunc(chatState.data);
|
|
3263
|
-
console.log(` π¬ Dynamic message (template): "${messageToDisplay}"`);
|
|
3237
|
+
// console.log(` π¬ Dynamic message (template): "${messageToDisplay}"`);
|
|
3264
3238
|
} catch (error) {
|
|
3265
3239
|
console.error('Error parsing template message:', error);
|
|
3266
3240
|
messageToDisplay = nextStep.message; // Fallback to original
|
|
@@ -3271,7 +3245,7 @@ async function showNextStep() {
|
|
|
3271
3245
|
|
|
3272
3246
|
// β
NEW: Add custom elements if specified
|
|
3273
3247
|
if (nextStep.addElements && Array.isArray(nextStep.addElements)) {
|
|
3274
|
-
console.log(` π¨ Adding ${nextStep.addElements.length} custom element(s) to chat`);
|
|
3248
|
+
// console.log(` π¨ Adding ${nextStep.addElements.length} custom element(s) to chat`);
|
|
3275
3249
|
|
|
3276
3250
|
nextStep.addElements.forEach((selector, index) => {
|
|
3277
3251
|
try {
|
|
@@ -3281,13 +3255,13 @@ async function showNextStep() {
|
|
|
3281
3255
|
// If not found in normal location, check if it's still in chat from previous init
|
|
3282
3256
|
if (!element) {
|
|
3283
3257
|
element = elements.messages.querySelector(selector);
|
|
3284
|
-
console.log(` - messages.querySelector(): ${element ? 'FOUND β
' : 'not found'}`);
|
|
3258
|
+
// console.log(` - messages.querySelector(): ${element ? 'FOUND β
' : 'not found'}`);
|
|
3285
3259
|
}
|
|
3286
3260
|
|
|
3287
3261
|
// If still not found, search entire document
|
|
3288
3262
|
if (!element) {
|
|
3289
3263
|
element = document.body.querySelector(selector);
|
|
3290
|
-
console.log(` - body.querySelector(): ${element ? 'FOUND β
' : 'not found'}`);
|
|
3264
|
+
// console.log(` - body.querySelector(): ${element ? 'FOUND β
' : 'not found'}`);
|
|
3291
3265
|
}
|
|
3292
3266
|
|
|
3293
3267
|
if (element) {
|
|
@@ -3296,9 +3270,9 @@ async function showNextStep() {
|
|
|
3296
3270
|
if (!element._originalParent) {
|
|
3297
3271
|
element._originalParent = element.parentElement;
|
|
3298
3272
|
element._originalNextSibling = element.nextSibling;
|
|
3299
|
-
console.log(' πΎ Stored original parent for:', selector);
|
|
3273
|
+
// console.log(' πΎ Stored original parent for:', selector);
|
|
3300
3274
|
} else {
|
|
3301
|
-
console.log(' β»οΈ Using existing parent reference for:', selector);
|
|
3275
|
+
// console.log(' β»οΈ Using existing parent reference for:', selector);
|
|
3302
3276
|
}
|
|
3303
3277
|
|
|
3304
3278
|
// Make it visible (in case it was hidden)
|
|
@@ -3310,7 +3284,7 @@ async function showNextStep() {
|
|
|
3310
3284
|
// Move to messages container (preserves event listeners!)
|
|
3311
3285
|
elements.messages.appendChild(element);
|
|
3312
3286
|
|
|
3313
|
-
console.log(` β
Added element ${index + 1}: ${selector}`);
|
|
3287
|
+
// console.log(` β
Added element ${index + 1}: ${selector}`);
|
|
3314
3288
|
} else {
|
|
3315
3289
|
console.warn(` β οΈ Element not found: ${selector}`);
|
|
3316
3290
|
}
|
|
@@ -3341,10 +3315,10 @@ async function showNextStep() {
|
|
|
3341
3315
|
|
|
3342
3316
|
if (inputRequired && !hasPreFill) {
|
|
3343
3317
|
disableNextButton();
|
|
3344
|
-
console.log(' π Multi-select-color required with no pre-fill - Next button disabled');
|
|
3318
|
+
// console.log(' π Multi-select-color required with no pre-fill - Next button disabled');
|
|
3345
3319
|
} else if (!inputRequired && !hasPreFill) {
|
|
3346
3320
|
enableNextButton();
|
|
3347
|
-
console.log(' π Multi-select-color not required - Next button enabled');
|
|
3321
|
+
// console.log(' π Multi-select-color not required - Next button enabled');
|
|
3348
3322
|
}
|
|
3349
3323
|
// If hasPreFill, renderColorOptions already handled it
|
|
3350
3324
|
} else if (inputType === 'single-select-custom') {
|
|
@@ -3385,10 +3359,10 @@ async function showNextStep() {
|
|
|
3385
3359
|
|
|
3386
3360
|
if (inputRequired && !hasPreFill) {
|
|
3387
3361
|
disableNextButton();
|
|
3388
|
-
console.log(' π Single-select-custom required with no pre-fill - Next button disabled');
|
|
3362
|
+
// console.log(' π Single-select-custom required with no pre-fill - Next button disabled');
|
|
3389
3363
|
} else if (!inputRequired && !hasPreFill) {
|
|
3390
3364
|
enableNextButton();
|
|
3391
|
-
console.log(' π Single-select-custom not required - Next button enabled');
|
|
3365
|
+
// console.log(' π Single-select-custom not required - Next button enabled');
|
|
3392
3366
|
}
|
|
3393
3367
|
// If hasPreFill, renderCustomSelectOptions already handled it
|
|
3394
3368
|
} else if (inputType === 'multi-select-dropdown') {
|
|
@@ -3398,10 +3372,10 @@ async function showNextStep() {
|
|
|
3398
3372
|
// β
FIX: Enable Next button initially if NOT required
|
|
3399
3373
|
if (inputRequired) {
|
|
3400
3374
|
disableNextButton();
|
|
3401
|
-
console.log(' π Next button disabled initially (input required)');
|
|
3375
|
+
// console.log(' π Next button disabled initially (input required)');
|
|
3402
3376
|
} else {
|
|
3403
3377
|
enableNextButton();
|
|
3404
|
-
console.log(' π Next button enabled (input NOT required)');
|
|
3378
|
+
// console.log(' π Next button enabled (input NOT required)');
|
|
3405
3379
|
}
|
|
3406
3380
|
} else {
|
|
3407
3381
|
const isSingleSelect = inputType === 'single-select';
|
|
@@ -3419,10 +3393,10 @@ async function showNextStep() {
|
|
|
3419
3393
|
|
|
3420
3394
|
if (inputRequired && !hasPreFill) {
|
|
3421
3395
|
disableNextButton();
|
|
3422
|
-
console.log(` π ${inputType} required with no pre-fill - Next button disabled`);
|
|
3396
|
+
// console.log(` π ${inputType} required with no pre-fill - Next button disabled`);
|
|
3423
3397
|
} else if (!inputRequired && !hasPreFill) {
|
|
3424
3398
|
enableNextButton();
|
|
3425
|
-
console.log(` π ${inputType} not required - Next button enabled`);
|
|
3399
|
+
// console.log(` π ${inputType} not required - Next button enabled`);
|
|
3426
3400
|
}
|
|
3427
3401
|
// If hasPreFill, renderOptions already handled it
|
|
3428
3402
|
}
|
|
@@ -3432,7 +3406,7 @@ async function showNextStep() {
|
|
|
3432
3406
|
|
|
3433
3407
|
if (shouldAutoAdvance) {
|
|
3434
3408
|
const delay = nextStep.autoAdvanceDelay !== undefined ? nextStep.autoAdvanceDelay : config.autoAdvanceDelay;
|
|
3435
|
-
console.log(` β±οΈ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
|
|
3409
|
+
// console.log(` β±οΈ Auto-advance delay: ${delay}ms ${nextStep.autoAdvanceDelay !== undefined ? '(step-level)' : '(global)'}`);
|
|
3436
3410
|
|
|
3437
3411
|
setTimeout(() => {
|
|
3438
3412
|
// β
NEW: Add user message if there's a currentSelection (pre-filled value)
|
|
@@ -3467,7 +3441,7 @@ async function showNextStep() {
|
|
|
3467
3441
|
if (prefix) displayName = `${prefix} ${displayName}`;
|
|
3468
3442
|
if (suffix) displayName = `${displayName} ${suffix}`;
|
|
3469
3443
|
|
|
3470
|
-
console.log(`π Adding user message for auto-advance: "${displayName}"`);
|
|
3444
|
+
// console.log(`π Adding user message for auto-advance: "${displayName}"`);
|
|
3471
3445
|
addMessage(displayName, 'user', false, chatState.step);
|
|
3472
3446
|
|
|
3473
3447
|
chatState.history.push({
|
|
@@ -3491,7 +3465,7 @@ async function showNextStep() {
|
|
|
3491
3465
|
} else {
|
|
3492
3466
|
// β
No input and no auto-advance - just enable Next button
|
|
3493
3467
|
enableNextButton();
|
|
3494
|
-
console.log(' π No input field - Next button enabled for manual progression');
|
|
3468
|
+
// console.log(' π No input field - Next button enabled for manual progression');
|
|
3495
3469
|
}
|
|
3496
3470
|
}
|
|
3497
3471
|
|
|
@@ -3499,10 +3473,10 @@ async function showNextStep() {
|
|
|
3499
3473
|
if (elements.nextBtn) {
|
|
3500
3474
|
if (showNextButton) {
|
|
3501
3475
|
elements.nextBtn.style.display = '';
|
|
3502
|
-
console.log(' ποΈ Next button shown (nextButtonDisplay: true or undefined)');
|
|
3476
|
+
// console.log(' ποΈ Next button shown (nextButtonDisplay: true or undefined)');
|
|
3503
3477
|
} else {
|
|
3504
3478
|
elements.nextBtn.style.display = 'none';
|
|
3505
|
-
console.log(' π Next button hidden (nextButtonDisplay: false)');
|
|
3479
|
+
// console.log(' π Next button hidden (nextButtonDisplay: false)');
|
|
3506
3480
|
}
|
|
3507
3481
|
}
|
|
3508
3482
|
|
|
@@ -3520,19 +3494,19 @@ async function showNextStep() {
|
|
|
3520
3494
|
|
|
3521
3495
|
if (isLastEditStep) {
|
|
3522
3496
|
buttonText = chatState.editFinalButtonText;
|
|
3523
|
-
console.log(` π Next button text: "${buttonText}" (editFinalButtonText - last edit step)`);
|
|
3497
|
+
// console.log(` π Next button text: "${buttonText}" (editFinalButtonText - last edit step)`);
|
|
3524
3498
|
} else if (nextStep.nextButtonText) {
|
|
3525
3499
|
// Step-level override takes highest priority
|
|
3526
3500
|
buttonText = nextStep.nextButtonText;
|
|
3527
|
-
console.log(` π Next button text: "${buttonText}" (step-level)`);
|
|
3501
|
+
// console.log(` π Next button text: "${buttonText}" (step-level)`);
|
|
3528
3502
|
} else if (config.nextButtonText) {
|
|
3529
3503
|
// Global config nextButtonText
|
|
3530
3504
|
buttonText = config.nextButtonText;
|
|
3531
|
-
console.log(` π Next button text: "${buttonText}" (global config)`);
|
|
3505
|
+
// console.log(` π Next button text: "${buttonText}" (global config)`);
|
|
3532
3506
|
} else {
|
|
3533
3507
|
// Fall back to original
|
|
3534
3508
|
buttonText = elements.originalNextBtnText;
|
|
3535
|
-
console.log(` π Next button text: "${buttonText}" (original)`);
|
|
3509
|
+
// console.log(` π Next button text: "${buttonText}" (original)`);
|
|
3536
3510
|
}
|
|
3537
3511
|
|
|
3538
3512
|
nextBtnTextElement.textContent = buttonText;
|
|
@@ -3548,11 +3522,11 @@ async function showNextStep() {
|
|
|
3548
3522
|
const currentField = nextStep.input?.field;
|
|
3549
3523
|
if (currentField && chatState.prefillOverrideFields.includes(currentField)) {
|
|
3550
3524
|
chatState.prefillOverrideFields = chatState.prefillOverrideFields.filter(f => f !== currentField);
|
|
3551
|
-
console.log(` π Removed ${currentField} from override list. Remaining:`, chatState.prefillOverrideFields);
|
|
3525
|
+
// console.log(` π Removed ${currentField} from override list. Remaining:`, chatState.prefillOverrideFields);
|
|
3552
3526
|
|
|
3553
3527
|
// Clear the list entirely if empty
|
|
3554
3528
|
if (chatState.prefillOverrideFields.length === 0) {
|
|
3555
|
-
console.log(` π All override fields processed - clearing list`);
|
|
3529
|
+
// console.log(` π All override fields processed - clearing list`);
|
|
3556
3530
|
delete chatState.prefillOverrideFields;
|
|
3557
3531
|
}
|
|
3558
3532
|
}
|
|
@@ -3574,30 +3548,30 @@ async function showNextStep() {
|
|
|
3574
3548
|
}
|
|
3575
3549
|
|
|
3576
3550
|
function handleCompletion() {
|
|
3577
|
-
console.log('β
Flow completed. Data:', chatState.data);
|
|
3551
|
+
// console.log('β
Flow completed. Data:', chatState.data);
|
|
3578
3552
|
|
|
3579
3553
|
chatState.completed = true;
|
|
3580
|
-
console.log(' π Flow marked as completed');
|
|
3554
|
+
// console.log(' π Flow marked as completed');
|
|
3581
3555
|
|
|
3582
3556
|
// β
Hide all range wrappers (single-select-custom inputs)
|
|
3583
3557
|
const allRangeWrappers = document.querySelectorAll('[data-chat-element="range-wrapper"]');
|
|
3584
3558
|
allRangeWrappers.forEach(wrapper => {
|
|
3585
3559
|
wrapper.style.display = 'none';
|
|
3586
3560
|
});
|
|
3587
|
-
console.log(' π Hidden all range-wrappers on completion');
|
|
3561
|
+
// console.log(' π Hidden all range-wrappers on completion');
|
|
3588
3562
|
|
|
3589
3563
|
// β
Hide all text and number inputs
|
|
3590
3564
|
const allTextInputs = document.querySelectorAll('[data-chat-element="text-input"]');
|
|
3591
3565
|
allTextInputs.forEach(input => {
|
|
3592
3566
|
input.style.display = 'none';
|
|
3593
3567
|
});
|
|
3594
|
-
console.log(' π Hidden all text-inputs on completion');
|
|
3568
|
+
// console.log(' π Hidden all text-inputs on completion');
|
|
3595
3569
|
|
|
3596
3570
|
const allNumberInputs = document.querySelectorAll('[data-chat-element="number-input"]');
|
|
3597
3571
|
allNumberInputs.forEach(input => {
|
|
3598
3572
|
input.style.display = 'none';
|
|
3599
3573
|
});
|
|
3600
|
-
console.log(' π Hidden all number-inputs on completion');
|
|
3574
|
+
// console.log(' π Hidden all number-inputs on completion');
|
|
3601
3575
|
|
|
3602
3576
|
updateEditIcons();
|
|
3603
3577
|
|
|
@@ -3638,12 +3612,12 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3638
3612
|
}
|
|
3639
3613
|
|
|
3640
3614
|
if (flowConfig.customRangeErrors) {
|
|
3641
|
-
console.log('β
Using custom range errors from flow object');
|
|
3615
|
+
// console.log('β
Using custom range errors from flow object');
|
|
3642
3616
|
Object.assign(config.customRangeErrors, flowConfig.customRangeErrors);
|
|
3643
3617
|
}
|
|
3644
3618
|
|
|
3645
3619
|
if (options.customRangeErrors) {
|
|
3646
|
-
console.log('β
Using custom range errors from options parameter');
|
|
3620
|
+
// console.log('β
Using custom range errors from options parameter');
|
|
3647
3621
|
Object.assign(config.customRangeErrors, options.customRangeErrors);
|
|
3648
3622
|
}
|
|
3649
3623
|
|
|
@@ -3651,17 +3625,7 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3651
3625
|
const mode = options.mode || 'create'; // 'create' or 'edit'
|
|
3652
3626
|
const editData = options.data || {};
|
|
3653
3627
|
|
|
3654
|
-
console.log('β
Flow initialized:', {
|
|
3655
|
-
flowName,
|
|
3656
|
-
mode,
|
|
3657
|
-
hasEditData: Object.keys(editData).length > 0,
|
|
3658
|
-
selectedBackground: config.selectedBackground,
|
|
3659
|
-
autoAdvanceDelay: config.autoAdvanceDelay,
|
|
3660
|
-
showCancelButton: config.showCancelButton,
|
|
3661
|
-
nextButtonText: config.nextButtonText || 'not set',
|
|
3662
|
-
localeString: config.localeString || 'default',
|
|
3663
|
-
customRangeErrors: config.customRangeErrors
|
|
3664
|
-
});
|
|
3628
|
+
// console.log('β
Flow initialized:', { flowName, mode, hasEditData: Object.keys(editData).length > 0, selectedBackground: config.selectedBackground, autoAdvanceDelay: config.autoAdvanceDelay, showCancelButton: config.showCancelButton, nextButtonText: config.nextButtonText || 'not set', localeString: config.localeString || 'default', customRangeErrors: config.customRangeErrors });
|
|
3665
3629
|
|
|
3666
3630
|
flowData = flowConfig;
|
|
3667
3631
|
|
|
@@ -3674,13 +3638,13 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3674
3638
|
|
|
3675
3639
|
// β
NEW: Merge initialData with editData for edit mode
|
|
3676
3640
|
if (mode === 'edit' && editData && Object.keys(editData).length > 0) {
|
|
3677
|
-
console.log('π§ Edit mode enabled - pre-filling with data:', editData);
|
|
3641
|
+
// console.log('π§ Edit mode enabled - pre-filling with data:', editData);
|
|
3678
3642
|
chatState.data = {
|
|
3679
3643
|
...(flowConfig.initialData || {}),
|
|
3680
3644
|
...editData // Edit data takes precedence
|
|
3681
3645
|
};
|
|
3682
3646
|
} else {
|
|
3683
|
-
chatState.data = flowConfig.initialData || {};
|
|
3647
|
+
chatState.data = { ...(flowConfig.initialData || {}) };
|
|
3684
3648
|
}
|
|
3685
3649
|
|
|
3686
3650
|
chatState.history = [];
|
|
@@ -3694,7 +3658,7 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3694
3658
|
const index = flowConfig.flow.findIndex(s => s.name === stepName);
|
|
3695
3659
|
if (index !== -1) {
|
|
3696
3660
|
resolvedSteps.push(index);
|
|
3697
|
-
console.log(` π editSteps: "${stepName}" β step index ${index}`);
|
|
3661
|
+
// console.log(` π editSteps: "${stepName}" β step index ${index}`);
|
|
3698
3662
|
} else {
|
|
3699
3663
|
console.warn(` β οΈ editSteps: step name "${stepName}" not found in flow`);
|
|
3700
3664
|
}
|
|
@@ -3706,9 +3670,9 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3706
3670
|
chatState.onEditComplete = typeof options.onEditComplete === 'function' ? options.onEditComplete : null;
|
|
3707
3671
|
chatState.editFinalButtonText = options.editFinalButtonText || null;
|
|
3708
3672
|
chatState.step = resolvedSteps[0]; // Start at the first edit step
|
|
3709
|
-
console.log(`π€οΈ Edit-steps mode: ${resolvedSteps.length} steps to edit`, resolvedSteps);
|
|
3710
|
-
console.log(` onEditComplete: ${chatState.onEditComplete ? 'provided' : 'not provided'}`);
|
|
3711
|
-
console.log(` editFinalButtonText: ${chatState.editFinalButtonText || 'not set'}`);
|
|
3673
|
+
// console.log(`π€οΈ Edit-steps mode: ${resolvedSteps.length} steps to edit`, resolvedSteps);
|
|
3674
|
+
// console.log(` onEditComplete: ${chatState.onEditComplete ? 'provided' : 'not provided'}`);
|
|
3675
|
+
// console.log(` editFinalButtonText: ${chatState.editFinalButtonText || 'not set'}`);
|
|
3712
3676
|
} else {
|
|
3713
3677
|
console.warn('β οΈ editSteps provided but no valid step names found - using normal flow');
|
|
3714
3678
|
chatState.editSteps = null;
|
|
@@ -3741,24 +3705,24 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3741
3705
|
if (elements.cancelBtn) {
|
|
3742
3706
|
if (config.showCancelButton === true) {
|
|
3743
3707
|
elements.cancelBtn.style.display = '';
|
|
3744
|
-
console.log('β
Cancel button shown (showCancelButton: true)');
|
|
3708
|
+
// console.log('β
Cancel button shown (showCancelButton: true)');
|
|
3745
3709
|
} else {
|
|
3746
3710
|
elements.cancelBtn.style.display = 'none';
|
|
3747
|
-
console.log('π« Cancel button hidden (showCancelButton: false)');
|
|
3711
|
+
// console.log('π« Cancel button hidden (showCancelButton: false)');
|
|
3748
3712
|
}
|
|
3749
3713
|
} else {
|
|
3750
3714
|
if (config.showCancelButton === true) {
|
|
3751
3715
|
console.warn('β οΈ showCancelButton is true but cancel button element not found');
|
|
3752
3716
|
console.warn(' Please add <button data-chat-element="cancel-button">Cancel</button> to your HTML');
|
|
3753
3717
|
} else {
|
|
3754
|
-
console.log('βΉοΈ Cancel button not found (optional, showCancelButton: false)');
|
|
3718
|
+
// console.log('βΉοΈ Cancel button not found (optional, showCancelButton: false)');
|
|
3755
3719
|
}
|
|
3756
3720
|
}
|
|
3757
3721
|
|
|
3758
3722
|
const nextBtnTextElement = elements.nextBtn.querySelector('[data-chat-element="next-button-text"]');
|
|
3759
3723
|
if (nextBtnTextElement) {
|
|
3760
3724
|
elements.originalNextBtnText = nextBtnTextElement.textContent || nextBtnTextElement.innerText || 'Next';
|
|
3761
|
-
console.log(`πΎ Stored original button text: "${elements.originalNextBtnText}" (from next-button-text element)`);
|
|
3725
|
+
// console.log(`πΎ Stored original button text: "${elements.originalNextBtnText}" (from next-button-text element)`);
|
|
3762
3726
|
} else {
|
|
3763
3727
|
console.warn('β οΈ Element with data-chat-element="next-button-text" not found inside next-button');
|
|
3764
3728
|
console.warn(' Button text customization will not work. Please add <span data-chat-element="next-button-text">Next</span> inside your button');
|
|
@@ -3769,7 +3733,7 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3769
3733
|
// This prevents elements from being permanently deleted on re-initialization
|
|
3770
3734
|
const existingInjected = elements.messages.querySelectorAll('[data-chat-injected="true"]');
|
|
3771
3735
|
if (existingInjected.length > 0) {
|
|
3772
|
-
console.log(` β©οΈ Moving back ${existingInjected.length} injected element(s) before clearing (re-init)`);
|
|
3736
|
+
// console.log(` β©οΈ Moving back ${existingInjected.length} injected element(s) before clearing (re-init)`);
|
|
3773
3737
|
existingInjected.forEach(el => {
|
|
3774
3738
|
el.style.display = 'none';
|
|
3775
3739
|
el.removeAttribute('data-chat-injected');
|
|
@@ -3800,7 +3764,7 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3800
3764
|
|
|
3801
3765
|
showNextStep();
|
|
3802
3766
|
|
|
3803
|
-
console.log(`β
Flow "${flowName}" initialized`);
|
|
3767
|
+
// console.log(`β
Flow "${flowName}" initialized`);
|
|
3804
3768
|
|
|
3805
3769
|
return {
|
|
3806
3770
|
getState,
|
|
@@ -3822,7 +3786,7 @@ function getState() {
|
|
|
3822
3786
|
|
|
3823
3787
|
function reset() {
|
|
3824
3788
|
chatState.step = 0;
|
|
3825
|
-
chatState.data = flowData.initialData || {};
|
|
3789
|
+
chatState.data = { ...(flowData.initialData || {}) };
|
|
3826
3790
|
chatState.history = [];
|
|
3827
3791
|
chatState.currentSelection = null;
|
|
3828
3792
|
chatState.chatMode = 'create'; // β
Reset to create mode
|
|
@@ -3845,7 +3809,7 @@ function reset() {
|
|
|
3845
3809
|
} else {
|
|
3846
3810
|
el._originalParent.appendChild(el);
|
|
3847
3811
|
}
|
|
3848
|
-
console.log(' β©οΈ Moved element back during reset');
|
|
3812
|
+
// console.log(' β©οΈ Moved element back during reset');
|
|
3849
3813
|
}
|
|
3850
3814
|
});
|
|
3851
3815
|
|
|
@@ -3861,15 +3825,15 @@ function reset() {
|
|
|
3861
3825
|
}
|
|
3862
3826
|
|
|
3863
3827
|
function goToStep(stepNumber) {
|
|
3864
|
-
console.log(`\nπ― goToStep() called with stepNumber: ${stepNumber}`);
|
|
3865
|
-
console.log(` Current step before: ${chatState.step}`);
|
|
3828
|
+
// console.log(`\nπ― goToStep() called with stepNumber: ${stepNumber}`);
|
|
3829
|
+
// console.log(` Current step before: ${chatState.step}`);
|
|
3866
3830
|
|
|
3867
3831
|
if (stepNumber < 0 || stepNumber >= flowData.flow.length) {
|
|
3868
3832
|
console.error('Invalid step number:', stepNumber);
|
|
3869
3833
|
return;
|
|
3870
3834
|
}
|
|
3871
3835
|
|
|
3872
|
-
console.log(` Setting chatState.step to ${stepNumber}`);
|
|
3836
|
+
// console.log(` Setting chatState.step to ${stepNumber}`);
|
|
3873
3837
|
chatState.step = stepNumber;
|
|
3874
3838
|
chatState.currentSelection = null;
|
|
3875
3839
|
|
|
@@ -3877,19 +3841,19 @@ function goToStep(stepNumber) {
|
|
|
3877
3841
|
const targetStep = flowData.flow[stepNumber];
|
|
3878
3842
|
if (targetStep?.input?.field && chatState.data[targetStep.input.field] !== undefined) {
|
|
3879
3843
|
chatState.prefillOverrideFields = [targetStep.input.field];
|
|
3880
|
-
console.log(` π Set prefill override for field: ${targetStep.input.field}`);
|
|
3844
|
+
// console.log(` π Set prefill override for field: ${targetStep.input.field}`);
|
|
3881
3845
|
}
|
|
3882
3846
|
|
|
3883
|
-
console.log(` Keeping messages visible (not clearing)...`);
|
|
3847
|
+
// console.log(` Keeping messages visible (not clearing)...`);
|
|
3884
3848
|
|
|
3885
|
-
console.log(` Disabling next button and calling showNextStep()...`);
|
|
3849
|
+
// console.log(` Disabling next button and calling showNextStep()...`);
|
|
3886
3850
|
disableNextButton();
|
|
3887
3851
|
showNextStep();
|
|
3888
3852
|
}
|
|
3889
3853
|
|
|
3890
3854
|
// β
NEW: Start editing through a path of steps
|
|
3891
3855
|
function startEditPath(stepNamesOrNumbers) {
|
|
3892
|
-
console.log(`\nπ€οΈ startEditPath() called with:`, stepNamesOrNumbers);
|
|
3856
|
+
// console.log(`\nπ€οΈ startEditPath() called with:`, stepNamesOrNumbers);
|
|
3893
3857
|
|
|
3894
3858
|
if (!Array.isArray(stepNamesOrNumbers) || stepNamesOrNumbers.length === 0) {
|
|
3895
3859
|
console.error('editPath must be a non-empty array');
|
|
@@ -3917,26 +3881,26 @@ function startEditPath(stepNamesOrNumbers) {
|
|
|
3917
3881
|
return;
|
|
3918
3882
|
}
|
|
3919
3883
|
|
|
3920
|
-
console.log(` β
Resolved to step numbers:`, stepNumbers);
|
|
3884
|
+
// console.log(` β
Resolved to step numbers:`, stepNumbers);
|
|
3921
3885
|
|
|
3922
3886
|
// Save current step as return point
|
|
3923
3887
|
chatState.returnToStep = chatState.step;
|
|
3924
|
-
console.log(` πΎ Saved return step: ${chatState.returnToStep}`);
|
|
3888
|
+
// console.log(` πΎ Saved return step: ${chatState.returnToStep}`);
|
|
3925
3889
|
|
|
3926
3890
|
// Save the edit path (remaining steps to edit)
|
|
3927
3891
|
chatState.editPath = [...stepNumbers];
|
|
3928
|
-
console.log(` π€οΈ Edit path set:`, chatState.editPath);
|
|
3892
|
+
// console.log(` π€οΈ Edit path set:`, chatState.editPath);
|
|
3929
3893
|
|
|
3930
3894
|
// Start editing the first step in the path
|
|
3931
3895
|
const firstStep = chatState.editPath.shift();
|
|
3932
|
-
console.log(` π― Starting with step ${firstStep}`);
|
|
3896
|
+
// console.log(` π― Starting with step ${firstStep}`);
|
|
3933
3897
|
|
|
3934
3898
|
editStep(firstStep);
|
|
3935
3899
|
}
|
|
3936
3900
|
|
|
3937
3901
|
function editStep(stepNumber) {
|
|
3938
|
-
console.log(`\nπ editStep() called with stepNumber: ${stepNumber}`);
|
|
3939
|
-
console.log(` Current step before edit: ${chatState.step}`);
|
|
3902
|
+
// console.log(`\nπ editStep() called with stepNumber: ${stepNumber}`);
|
|
3903
|
+
// console.log(` Current step before edit: ${chatState.step}`);
|
|
3940
3904
|
|
|
3941
3905
|
if (stepNumber < 0 || stepNumber >= flowData.flow.length) {
|
|
3942
3906
|
console.error('Invalid step number:', stepNumber);
|
|
@@ -3944,19 +3908,19 @@ function editStep(stepNumber) {
|
|
|
3944
3908
|
}
|
|
3945
3909
|
|
|
3946
3910
|
chatState.returnToStep = chatState.step;
|
|
3947
|
-
console.log(` πΎ Saved return step: ${chatState.returnToStep}`);
|
|
3911
|
+
// console.log(` πΎ Saved return step: ${chatState.returnToStep}`);
|
|
3948
3912
|
|
|
3949
3913
|
if (chatState.completed) {
|
|
3950
3914
|
chatState.completed = false;
|
|
3951
|
-
console.log(` π Flow unmarked as completed (editing)`);
|
|
3915
|
+
// console.log(` π Flow unmarked as completed (editing)`);
|
|
3952
3916
|
}
|
|
3953
3917
|
|
|
3954
|
-
console.log(` Clearing history from step ${stepNumber} forward...`);
|
|
3918
|
+
// console.log(` Clearing history from step ${stepNumber} forward...`);
|
|
3955
3919
|
chatState.history = chatState.history.filter(h => h.step < stepNumber);
|
|
3956
3920
|
|
|
3957
3921
|
// β
Find dependent steps (but don't clear anything)
|
|
3958
3922
|
const editedStepField = flowData.flow[stepNumber]?.input?.field;
|
|
3959
|
-
console.log(` π Checking for steps dependent on: ${editedStepField}`);
|
|
3923
|
+
// console.log(` π Checking for steps dependent on: ${editedStepField}`);
|
|
3960
3924
|
|
|
3961
3925
|
if (editedStepField) {
|
|
3962
3926
|
// Find all steps that depend on the edited step
|
|
@@ -3968,21 +3932,21 @@ function editStep(stepNumber) {
|
|
|
3968
3932
|
|
|
3969
3933
|
if (dependencies.includes(editedStepField)) {
|
|
3970
3934
|
dependentSteps.push(index);
|
|
3971
|
-
console.log(` π Found dependent step ${index} (depends on ${editedStepField})`);
|
|
3935
|
+
// console.log(` π Found dependent step ${index} (depends on ${editedStepField})`);
|
|
3972
3936
|
}
|
|
3973
3937
|
}
|
|
3974
3938
|
});
|
|
3975
3939
|
|
|
3976
3940
|
if (dependentSteps.length > 0) {
|
|
3977
|
-
console.log(` β
${dependentSteps.length} dependent steps will be re-shown after editing`);
|
|
3978
|
-
console.log(` β
All data, messages, and history kept intact`);
|
|
3941
|
+
// console.log(` β
${dependentSteps.length} dependent steps will be re-shown after editing`);
|
|
3942
|
+
// console.log(` β
All data, messages, and history kept intact`);
|
|
3979
3943
|
}
|
|
3980
3944
|
}
|
|
3981
3945
|
|
|
3982
|
-
console.log(` β
Keeping ALL data, messages, and history intact for editing`);
|
|
3983
|
-
console.log(` Current data:`, chatState.data);
|
|
3946
|
+
// console.log(` β
Keeping ALL data, messages, and history intact for editing`);
|
|
3947
|
+
// console.log(` Current data:`, chatState.data);
|
|
3984
3948
|
|
|
3985
|
-
console.log(` Calling goToStep(${stepNumber})...`);
|
|
3949
|
+
// console.log(` Calling goToStep(${stepNumber})...`);
|
|
3986
3950
|
goToStep(stepNumber);
|
|
3987
3951
|
}
|
|
3988
3952
|
|
|
@@ -4066,7 +4030,7 @@ function displayMessage(message) {
|
|
|
4066
4030
|
|
|
4067
4031
|
addMessage(message, 'bot', false, null);
|
|
4068
4032
|
scrollToBottom();
|
|
4069
|
-
console.log('π¬ Message displayed:', message);
|
|
4033
|
+
// console.log('π¬ Message displayed:', message);
|
|
4070
4034
|
}
|
|
4071
4035
|
|
|
4072
4036
|
module.exports = {
|