lisichatbot 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +79 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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(() => {
@@ -434,6 +464,12 @@ function init(flowName, flowConfig) {
434
464
  if (flowConfig.config) {
435
465
  Object.assign(config, flowConfig.config);
436
466
  }
467
+
468
+ console.log('✅ Flow initialized:', {
469
+ flowName,
470
+ selectedBackground: config.selectedBackground,
471
+ autoAdvanceDelay: config.autoAdvanceDelay
472
+ });
437
473
 
438
474
  // Store flow data
439
475
  flowData = flowConfig;
@@ -561,17 +597,37 @@ function injectStyles() {
561
597
  const style = document.createElement('style');
562
598
  style.id = styleId;
563
599
  style.textContent = `
564
- /* Bot message spacing */
600
+ /* Bot message spacing and alignment */
565
601
  [data-chat-element="bot-message-wrapper"] {
566
602
  margin-bottom: 16px;
603
+ display: flex;
604
+ justify-content: flex-start;
605
+ width: 100%;
606
+ }
607
+
608
+ /* Bot message natural width from left */
609
+ [data-chat-element="bot-message-text"] {
610
+ max-width: 70%;
611
+ width: auto;
612
+ display: inline-block;
567
613
  }
568
614
 
569
- /* User message spacing */
615
+ /* User message spacing and alignment */
570
616
  [data-chat-element="user-message-wrapper"] {
571
617
  margin-bottom: 16px;
618
+ display: flex;
619
+ justify-content: flex-end;
620
+ width: 100%;
621
+ }
622
+
623
+ /* User message natural width from right */
624
+ [data-chat-element="user-message-text"] {
625
+ max-width: 70%;
626
+ width: auto;
627
+ display: inline-block;
572
628
  }
573
629
 
574
- /* Options wrapper spacing */
630
+ /* Options wrapper spacing and gap */
575
631
  [data-chat-element="options-wrapper"] {
576
632
  margin-bottom: 20px;
577
633
  display: flex;
@@ -579,18 +635,6 @@ function injectStyles() {
579
635
  gap: 12px;
580
636
  }
581
637
 
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
638
  /* Messages container padding */
595
639
  [data-chat-element="messages-container"] {
596
640
  padding: 20px;