lisichatbot 1.1.1 → 1.1.2

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 +85 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisichatbot",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -202,6 +202,69 @@ function renderOptions(options, field, isSingleSelect = true) {
202
202
  });
203
203
  }
204
204
 
205
+ // =============================================================================
206
+ // TEXT/NUMBER INPUT RENDERING
207
+ // =============================================================================
208
+
209
+ function renderTextInput(field, inputType = 'text') {
210
+ if (!elements.messages) return;
211
+
212
+ // Determine input type attribute value
213
+ const inputTypeAttr = inputType === 'number' ? 'number-input' : 'text-input';
214
+
215
+ // Find existing input element in HTML by data-chat-element
216
+ const inputSelector = `[data-chat-element="${inputTypeAttr}"]`;
217
+ const existingInput = document.querySelector(inputSelector);
218
+
219
+ if (!existingInput) {
220
+ console.error(`Element with ${inputSelector} not found in HTML. Please add it to your HTML.`);
221
+ return;
222
+ }
223
+
224
+ // Clone existing input element
225
+ const clone = existingInput.cloneNode(true);
226
+
227
+ // Make clone visible
228
+ clone.style.display = '';
229
+
230
+ // Set data attributes
231
+ clone.setAttribute('data-field', field);
232
+
233
+ // Find the actual input element
234
+ const inputElement = clone.querySelector('[data-chat-input-element="input"]');
235
+ if (inputElement) {
236
+ inputElement.setAttribute('data-field', field);
237
+ inputElement.name = field;
238
+ inputElement.value = '';
239
+ inputElement.type = inputType === 'number' ? 'number' : 'text';
240
+
241
+ // Add input event to enable Next button when user types
242
+ inputElement.oninput = (e) => {
243
+ const value = inputType === 'number' ? parseFloat(e.target.value) : e.target.value;
244
+
245
+ // Save value
246
+ chatState.data[field] = value;
247
+ chatState.currentSelection = { field, value, name: value };
248
+
249
+ // Enable Next button if there's a value
250
+ if (value !== '' && value !== null && !isNaN(value)) {
251
+ enableNextButton();
252
+ } else {
253
+ disableNextButton();
254
+ }
255
+ };
256
+ }
257
+
258
+ // Append to messages
259
+ elements.messages.appendChild(clone);
260
+ scrollToBottom();
261
+
262
+ // Focus the input
263
+ if (inputElement) {
264
+ setTimeout(() => inputElement.focus(), 100);
265
+ }
266
+ }
267
+
205
268
  // =============================================================================
206
269
  // OPTION CLICK HANDLER USING CUSTOM ATTRIBUTES
207
270
  // =============================================================================
@@ -225,7 +288,8 @@ function handleOptionClick(element, field, isSingleSelect) {
225
288
  const optionName = element.getAttribute('data-name');
226
289
  const inputType = element.getAttribute('data-chat-element');
227
290
 
228
- console.log(`${isSingleSelect ? 'Single-select' : 'Multi-select'} mode:`, {
291
+ const mode = isSingleSelect ? 'Single-select' : 'Multi-select';
292
+ console.log(`${mode} clicked:`, {
229
293
  field,
230
294
  value: valueStr,
231
295
  name: optionName
@@ -415,12 +479,27 @@ async function showNextStep() {
415
479
 
416
480
  // Add options if input exists
417
481
  if (nextStep.input) {
418
- const isSingleSelect = nextStep.inputType !== 'multi';
419
- renderOptions(nextStep.input.options, nextStep.input.field, isSingleSelect);
482
+ const inputType = nextStep.inputType || 'single-select'; // Default to single-select
420
483
 
421
- // Enable Next button if input not required (default behavior)
422
- if (!inputRequired) {
423
- enableNextButton();
484
+ if (inputType === 'text' || inputType === 'number') {
485
+ // Render text or number input
486
+ renderTextInput(nextStep.input.field, inputType);
487
+
488
+ // Disable Next button initially (enabled when user types)
489
+ if (inputRequired) {
490
+ disableNextButton();
491
+ } else {
492
+ enableNextButton();
493
+ }
494
+ } else {
495
+ // Render options (single-select or multi-select)
496
+ const isSingleSelect = inputType === 'single-select';
497
+ renderOptions(nextStep.input.options, nextStep.input.field, isSingleSelect);
498
+
499
+ // Enable Next button if input not required (default behavior)
500
+ if (!inputRequired) {
501
+ enableNextButton();
502
+ }
424
503
  }
425
504
  } else {
426
505
  // Auto-advance for steps without input