lisichatbot 1.0.6 → 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 +84 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -143,6 +143,10 @@ function renderOptions(options, field, isSingleSelect = true) {
143
143
  // Make clone visible (remove display:none from template)
144
144
  clone.style.display = '';
145
145
 
146
+ // Reset to unchecked state
147
+ clone.classList.remove('cf-checked');
148
+ clone.style.backgroundColor = 'transparent';
149
+
146
150
  // Set data attributes on container
147
151
  clone.setAttribute('data-chat-element', inputTypeAttr);
148
152
  clone.setAttribute('data-field', field);
@@ -156,6 +160,7 @@ function renderOptions(options, field, isSingleSelect = true) {
156
160
  input.setAttribute('data-chat-element', inputTypeAttr);
157
161
  input.name = field;
158
162
  input.value = valueStr;
163
+ input.checked = false; // Ensure unchecked initially
159
164
  }
160
165
 
161
166
  // Find and ensure tick icon is hidden initially
@@ -217,19 +222,19 @@ function handleOptionClick(element, field, isSingleSelect) {
217
222
 
218
223
  allOptions.forEach(opt => {
219
224
  opt.classList.remove('cf-checked');
220
- opt.style.backgroundColor = 'transparent';
225
+ opt.style.setProperty('background-color', 'transparent', 'important');
221
226
 
222
227
  const otherTick = opt.querySelector('[data-chat-input-element="tick-icon"]');
223
228
  const otherInput = opt.querySelector('[data-chat-input-element="input"]');
224
229
 
225
- if (otherTick) otherTick.style.display = 'none';
230
+ if (otherTick) otherTick.style.setProperty('display', 'none', 'important');
226
231
  if (otherInput) otherInput.checked = false;
227
232
  });
228
233
 
229
234
  // Check this one
230
235
  element.classList.add('cf-checked');
231
- element.style.backgroundColor = config.selectedBackground;
232
- if (tickIcon) tickIcon.style.display = 'block';
236
+ element.style.setProperty('background-color', config.selectedBackground, 'important');
237
+ if (tickIcon) tickIcon.style.setProperty('display', 'block', 'important');
233
238
  if (input) input.checked = true;
234
239
 
235
240
  // Save value
@@ -240,10 +245,20 @@ function handleOptionClick(element, field, isSingleSelect) {
240
245
  // Multi-select
241
246
  const isChecked = !element.classList.contains('cf-checked');
242
247
 
248
+ console.log('Multi-select clicked:', {
249
+ field,
250
+ value,
251
+ isChecked,
252
+ selectedBackground: config.selectedBackground
253
+ });
254
+
243
255
  if (isChecked) {
244
256
  element.classList.add('cf-checked');
245
- element.style.backgroundColor = config.selectedBackground;
246
- 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
+ }
247
262
  if (input) input.checked = true;
248
263
 
249
264
  // Add to array
@@ -257,10 +272,12 @@ function handleOptionClick(element, field, isSingleSelect) {
257
272
  if (!exists) {
258
273
  chatState.data[field].push(value);
259
274
  }
275
+
276
+ console.log('Selected:', chatState.data[field]);
260
277
  } else {
261
278
  element.classList.remove('cf-checked');
262
- element.style.backgroundColor = 'transparent';
263
- if (tickIcon) tickIcon.style.display = 'none';
279
+ element.style.setProperty('background-color', 'transparent', 'important');
280
+ if (tickIcon) tickIcon.style.setProperty('display', 'none', 'important');
264
281
  if (input) input.checked = false;
265
282
 
266
283
  // Remove from array
@@ -269,6 +286,8 @@ function handleOptionClick(element, field, isSingleSelect) {
269
286
  JSON.stringify(v) !== JSON.stringify(value)
270
287
  );
271
288
  }
289
+
290
+ console.log('Unselected:', chatState.data[field]);
272
291
  }
273
292
 
274
293
  // Get all selected names using custom attribute
@@ -294,16 +313,22 @@ function handleOptionClick(element, field, isSingleSelect) {
294
313
  // =============================================================================
295
314
 
296
315
  async function handleNext() {
297
- if (!chatState.currentSelection) return;
298
-
299
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
+ }
300
325
 
301
326
  // Call onNext validation if exists
302
327
  if (currentStep.onNext) {
303
328
  try {
304
329
  disableNextButton();
305
330
  const canProceed = await currentStep.onNext(
306
- chatState.currentSelection.value,
331
+ chatState.currentSelection ? chatState.currentSelection.value : null,
307
332
  chatState.data
308
333
  );
309
334
 
@@ -319,16 +344,18 @@ async function handleNext() {
319
344
  }
320
345
  }
321
346
 
322
- // Add user message with edit capability
323
- 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);
324
350
 
325
- // Save to history
326
- chatState.history.push({
327
- step: chatState.step,
328
- field: chatState.currentSelection.field,
329
- value: chatState.currentSelection.value,
330
- name: chatState.currentSelection.name
331
- });
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
+ }
332
359
 
333
360
  // Reset selection
334
361
  chatState.currentSelection = null;
@@ -367,10 +394,18 @@ async function showNextStep() {
367
394
  // Add message
368
395
  addMessage(nextStep.message);
369
396
 
397
+ // Check if input is required (default false)
398
+ const inputRequired = nextStep.inputRequired === true;
399
+
370
400
  // Add options if input exists
371
401
  if (nextStep.input) {
372
402
  const isSingleSelect = nextStep.inputType !== 'multi';
373
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
+ }
374
409
  } else {
375
410
  // Auto-advance for steps without input
376
411
  setTimeout(() => {
@@ -429,6 +464,12 @@ function init(flowName, flowConfig) {
429
464
  if (flowConfig.config) {
430
465
  Object.assign(config, flowConfig.config);
431
466
  }
467
+
468
+ console.log('✅ Flow initialized:', {
469
+ flowName,
470
+ selectedBackground: config.selectedBackground,
471
+ autoAdvanceDelay: config.autoAdvanceDelay
472
+ });
432
473
 
433
474
  // Store flow data
434
475
  flowData = flowConfig;
@@ -556,17 +597,37 @@ function injectStyles() {
556
597
  const style = document.createElement('style');
557
598
  style.id = styleId;
558
599
  style.textContent = `
559
- /* Bot message spacing */
600
+ /* Bot message spacing and alignment */
560
601
  [data-chat-element="bot-message-wrapper"] {
561
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;
562
613
  }
563
614
 
564
- /* User message spacing */
615
+ /* User message spacing and alignment */
565
616
  [data-chat-element="user-message-wrapper"] {
566
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;
567
628
  }
568
629
 
569
- /* Options wrapper spacing */
630
+ /* Options wrapper spacing and gap */
570
631
  [data-chat-element="options-wrapper"] {
571
632
  margin-bottom: 20px;
572
633
  display: flex;