lisichatbot 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +80 -37
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -222,19 +222,19 @@ function handleOptionClick(element, field, isSingleSelect) {
222
222
 
223
223
  allOptions.forEach(opt => {
224
224
  opt.classList.remove('cf-checked');
225
- opt.style.backgroundColor = 'transparent';
225
+ opt.style.setProperty('background-color', 'transparent', 'important');
226
226
 
227
227
  const otherTick = opt.querySelector('[data-chat-input-element="tick-icon"]');
228
228
  const otherInput = opt.querySelector('[data-chat-input-element="input"]');
229
229
 
230
- if (otherTick) otherTick.style.display = 'none';
230
+ if (otherTick) otherTick.style.setProperty('display', 'none', 'important');
231
231
  if (otherInput) otherInput.checked = false;
232
232
  });
233
233
 
234
234
  // Check this one
235
235
  element.classList.add('cf-checked');
236
- element.style.backgroundColor = config.selectedBackground;
237
- if (tickIcon) tickIcon.style.display = 'block';
236
+ element.style.setProperty('background-color', config.selectedBackground, 'important');
237
+ if (tickIcon) tickIcon.style.setProperty('display', 'block', 'important');
238
238
  if (input) input.checked = true;
239
239
 
240
240
  // Save value
@@ -245,10 +245,20 @@ function handleOptionClick(element, field, isSingleSelect) {
245
245
  // Multi-select
246
246
  const isChecked = !element.classList.contains('cf-checked');
247
247
 
248
+ console.log('Multi-select clicked:', {
249
+ field,
250
+ value,
251
+ isChecked,
252
+ selectedBackground: config.selectedBackground
253
+ });
254
+
248
255
  if (isChecked) {
249
256
  element.classList.add('cf-checked');
250
- element.style.backgroundColor = config.selectedBackground;
251
- if (tickIcon) tickIcon.style.display = 'block';
257
+ element.style.setProperty('background-color', config.selectedBackground, 'important');
258
+ if (tickIcon) {
259
+ tickIcon.style.setProperty('display', 'block', 'important');
260
+ console.log('Tick icon shown for:', optionName);
261
+ }
252
262
  if (input) input.checked = true;
253
263
 
254
264
  // Add to array
@@ -262,10 +272,12 @@ function handleOptionClick(element, field, isSingleSelect) {
262
272
  if (!exists) {
263
273
  chatState.data[field].push(value);
264
274
  }
275
+
276
+ console.log('Selected:', chatState.data[field]);
265
277
  } else {
266
278
  element.classList.remove('cf-checked');
267
- element.style.backgroundColor = 'transparent';
268
- if (tickIcon) tickIcon.style.display = 'none';
279
+ element.style.setProperty('background-color', 'transparent', 'important');
280
+ if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
269
281
  if (input) input.checked = false;
270
282
 
271
283
  // Remove from array
@@ -274,6 +286,8 @@ function handleOptionClick(element, field, isSingleSelect) {
274
286
  JSON.stringify(v) !== JSON.stringify(value)
275
287
  );
276
288
  }
289
+
290
+ console.log('Unselected:', chatState.data[field]);
277
291
  }
278
292
 
279
293
  // Get all selected names using custom attribute
@@ -299,16 +313,22 @@ function handleOptionClick(element, field, isSingleSelect) {
299
313
  // =============================================================================
300
314
 
301
315
  async function handleNext() {
302
- if (!chatState.currentSelection) return;
303
-
304
316
  const currentStep = flowData.flow[chatState.step];
317
+
318
+ // Check if input is required (default false)
319
+ const inputRequired = currentStep.inputRequired === true;
320
+
321
+ if (inputRequired && !chatState.currentSelection) {
322
+ console.log('Selection required but none made');
323
+ return;
324
+ }
305
325
 
306
326
  // Call onNext validation if exists
307
327
  if (currentStep.onNext) {
308
328
  try {
309
329
  disableNextButton();
310
330
  const canProceed = await currentStep.onNext(
311
- chatState.currentSelection.value,
331
+ chatState.currentSelection ? chatState.currentSelection.value : null,
312
332
  chatState.data
313
333
  );
314
334
 
@@ -324,16 +344,18 @@ async function handleNext() {
324
344
  }
325
345
  }
326
346
 
327
- // Add user message with edit capability
328
- addMessage(chatState.currentSelection.name, 'user', true, chatState.step);
347
+ // Add user message with edit capability (only if selection was made)
348
+ if (chatState.currentSelection) {
349
+ addMessage(chatState.currentSelection.name, 'user', true, chatState.step);
329
350
 
330
- // Save to history
331
- chatState.history.push({
332
- step: chatState.step,
333
- field: chatState.currentSelection.field,
334
- value: chatState.currentSelection.value,
335
- name: chatState.currentSelection.name
336
- });
351
+ // Save to history
352
+ chatState.history.push({
353
+ step: chatState.step,
354
+ field: chatState.currentSelection.field,
355
+ value: chatState.currentSelection.value,
356
+ name: chatState.currentSelection.name
357
+ });
358
+ }
337
359
 
338
360
  // Reset selection
339
361
  chatState.currentSelection = null;
@@ -372,10 +394,18 @@ async function showNextStep() {
372
394
  // Add message
373
395
  addMessage(nextStep.message);
374
396
 
397
+ // Check if input is required (default false)
398
+ const inputRequired = nextStep.inputRequired === true;
399
+
375
400
  // Add options if input exists
376
401
  if (nextStep.input) {
377
402
  const isSingleSelect = nextStep.inputType !== 'multi';
378
403
  renderOptions(nextStep.input.options, nextStep.input.field, isSingleSelect);
404
+
405
+ // Enable Next button if input not required (default behavior)
406
+ if (!inputRequired) {
407
+ enableNextButton();
408
+ }
379
409
  } else {
380
410
  // Auto-advance for steps without input
381
411
  setTimeout(() => {
@@ -390,8 +420,6 @@ async function showNextStep() {
390
420
  }
391
421
 
392
422
  function handleCompletion() {
393
- addMessage('Thank you! All done.');
394
-
395
423
  console.log('✅ Flow completed. Data:', chatState.data);
396
424
 
397
425
  // Hide Next button
@@ -434,6 +462,12 @@ function init(flowName, flowConfig) {
434
462
  if (flowConfig.config) {
435
463
  Object.assign(config, flowConfig.config);
436
464
  }
465
+
466
+ console.log('✅ Flow initialized:', {
467
+ flowName,
468
+ selectedBackground: config.selectedBackground,
469
+ autoAdvanceDelay: config.autoAdvanceDelay
470
+ });
437
471
 
438
472
  // Store flow data
439
473
  flowData = flowConfig;
@@ -561,17 +595,38 @@ function injectStyles() {
561
595
  const style = document.createElement('style');
562
596
  style.id = styleId;
563
597
  style.textContent = `
564
- /* Bot message spacing */
598
+ /* Bot message spacing and alignment */
565
599
  [data-chat-element="bot-message-wrapper"] {
566
600
  margin-bottom: 16px;
601
+ display: flex;
602
+ justify-content: flex-start;
603
+ width: 100%;
604
+ }
605
+
606
+ /* Bot message natural width from left */
607
+ [data-chat-element="bot-message-text"] {
608
+ max-width: 70%;
609
+ width: auto;
610
+ display: inline-block;
567
611
  }
568
612
 
569
- /* User message spacing */
613
+ /* User message spacing and alignment */
570
614
  [data-chat-element="user-message-wrapper"] {
571
615
  margin-bottom: 16px;
616
+ display: flex;
617
+ justify-content: flex-end;
618
+ width: 100%;
619
+ }
620
+
621
+ /* User message natural width from right */
622
+ [data-chat-element="user-message-text"] {
623
+ max-width: 70%;
624
+ width: auto;
625
+ display: inline-block;
626
+ text-align: left;
572
627
  }
573
628
 
574
- /* Options wrapper spacing */
629
+ /* Options wrapper spacing and gap */
575
630
  [data-chat-element="options-wrapper"] {
576
631
  margin-bottom: 20px;
577
632
  display: flex;
@@ -579,18 +634,6 @@ function injectStyles() {
579
634
  gap: 12px;
580
635
  }
581
636
 
582
- /* Ensure checked state shows background color */
583
- [data-chat-element="single-select-input"].cf-checked,
584
- [data-chat-element="multi-select-input"].cf-checked {
585
- background-color: var(--selected-bg, #667eea) !important;
586
- }
587
-
588
- /* Ensure tick icon shows when checked */
589
- [data-chat-element="single-select-input"].cf-checked [data-chat-input-element="tick-icon"],
590
- [data-chat-element="multi-select-input"].cf-checked [data-chat-input-element="tick-icon"] {
591
- display: block !important;
592
- }
593
-
594
637
  /* Messages container padding */
595
638
  [data-chat-element="messages-container"] {
596
639
  padding: 20px;