lisichatbot 1.8.8 → 1.9.0
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 +59 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,13 +18,15 @@ let chatState = {
|
|
|
18
18
|
currentSelection: null,
|
|
19
19
|
returnToStep: null,
|
|
20
20
|
completed: false,
|
|
21
|
-
editPath: [] // ✅ NEW: Array of step names/numbers to edit in sequence
|
|
21
|
+
editPath: [], // ✅ NEW: Array of step names/numbers to edit in sequence
|
|
22
|
+
chatMode: 'create' // ✅ NEW: Track if in 'create' or 'edit' mode
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
let elements = {
|
|
25
26
|
container: null,
|
|
26
27
|
messages: null,
|
|
27
28
|
nextBtn: null,
|
|
29
|
+
cancelBtn: null, // ✅ NEW: Cancel button element
|
|
28
30
|
originalNextBtnText: null
|
|
29
31
|
};
|
|
30
32
|
|
|
@@ -32,6 +34,7 @@ let config = {
|
|
|
32
34
|
selectedBackground: '#667eea',
|
|
33
35
|
autoAdvanceDelay: 2000,
|
|
34
36
|
enableAnimations: true,
|
|
37
|
+
showCancelButton: false, // ✅ NEW: Control cancel button visibility
|
|
35
38
|
customRangeErrors: {
|
|
36
39
|
minRequired: 'Minimum value is required',
|
|
37
40
|
maxRequired: 'Maximum value is required',
|
|
@@ -2122,6 +2125,17 @@ async function handleNext() {
|
|
|
2122
2125
|
try {
|
|
2123
2126
|
disableNextButton();
|
|
2124
2127
|
|
|
2128
|
+
// ✅ NEW: Show loader and hide text when button is disabled
|
|
2129
|
+
const nextBtnText = elements.nextBtn.querySelector('[data-chat-element="next-button-text"]');
|
|
2130
|
+
const nextBtnLoader = elements.nextBtn.querySelector('[data-chat-element="next-button-loader"]');
|
|
2131
|
+
|
|
2132
|
+
if (nextBtnText) {
|
|
2133
|
+
nextBtnText.style.display = 'none';
|
|
2134
|
+
}
|
|
2135
|
+
if (nextBtnLoader) {
|
|
2136
|
+
nextBtnLoader.style.display = 'block';
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2125
2139
|
// ✅ NEW: Create showMessage helper function
|
|
2126
2140
|
const showMessage = (message) => {
|
|
2127
2141
|
console.log('💬 showMessage called:', message);
|
|
@@ -2136,6 +2150,14 @@ async function handleNext() {
|
|
|
2136
2150
|
showMessage // ✅ NEW: Third parameter
|
|
2137
2151
|
);
|
|
2138
2152
|
|
|
2153
|
+
// ✅ NEW: Hide loader and show text after onNext completes
|
|
2154
|
+
if (nextBtnText) {
|
|
2155
|
+
nextBtnText.style.display = '';
|
|
2156
|
+
}
|
|
2157
|
+
if (nextBtnLoader) {
|
|
2158
|
+
nextBtnLoader.style.display = 'none';
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2139
2161
|
// ✅ Still support showMessage in return object for backwards compatibility
|
|
2140
2162
|
if (result && typeof result === 'object' && result.showMessage) {
|
|
2141
2163
|
console.log('💬 onNext displaying message from return:', result.showMessage);
|
|
@@ -2386,6 +2408,18 @@ async function handleNext() {
|
|
|
2386
2408
|
} catch (error) {
|
|
2387
2409
|
console.error('Validation error:', error);
|
|
2388
2410
|
alert('An error occurred. Please try again.');
|
|
2411
|
+
|
|
2412
|
+
// ✅ NEW: Hide loader and show text on error
|
|
2413
|
+
const nextBtnText = elements.nextBtn.querySelector('[data-chat-element="next-button-text"]');
|
|
2414
|
+
const nextBtnLoader = elements.nextBtn.querySelector('[data-chat-element="next-button-loader"]');
|
|
2415
|
+
|
|
2416
|
+
if (nextBtnText) {
|
|
2417
|
+
nextBtnText.style.display = '';
|
|
2418
|
+
}
|
|
2419
|
+
if (nextBtnLoader) {
|
|
2420
|
+
nextBtnLoader.style.display = 'none';
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2389
2423
|
enableNextButton();
|
|
2390
2424
|
return;
|
|
2391
2425
|
}
|
|
@@ -3260,12 +3294,14 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3260
3294
|
hasEditData: Object.keys(editData).length > 0,
|
|
3261
3295
|
selectedBackground: config.selectedBackground,
|
|
3262
3296
|
autoAdvanceDelay: config.autoAdvanceDelay,
|
|
3297
|
+
showCancelButton: config.showCancelButton,
|
|
3263
3298
|
customRangeErrors: config.customRangeErrors
|
|
3264
3299
|
});
|
|
3265
3300
|
|
|
3266
3301
|
flowData = flowConfig;
|
|
3267
3302
|
|
|
3268
3303
|
chatState.step = 0;
|
|
3304
|
+
chatState.chatMode = mode; // ✅ NEW: Store mode in chatState as chatMode
|
|
3269
3305
|
|
|
3270
3306
|
// ✅ NEW: Merge initialData with editData for edit mode
|
|
3271
3307
|
if (mode === 'edit' && editData && Object.keys(editData).length > 0) {
|
|
@@ -3283,6 +3319,7 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3283
3319
|
|
|
3284
3320
|
elements.messages = elements.container.querySelector('[data-chat-element="messages-container"]');
|
|
3285
3321
|
elements.nextBtn = elements.container.querySelector('[data-chat-element="next-button"]');
|
|
3322
|
+
elements.cancelBtn = elements.container.querySelector('[data-chat-element="cancel-button"]');
|
|
3286
3323
|
|
|
3287
3324
|
if (!elements.messages) {
|
|
3288
3325
|
console.error('messages-container not found. Please add <div data-chat-element="messages-container"></div>');
|
|
@@ -3294,6 +3331,24 @@ function init(flowName, flowConfig, options = {}) {
|
|
|
3294
3331
|
return null;
|
|
3295
3332
|
}
|
|
3296
3333
|
|
|
3334
|
+
// ✅ NEW: Show/hide cancel button based on config (no styling, only visibility)
|
|
3335
|
+
if (elements.cancelBtn) {
|
|
3336
|
+
if (config.showCancelButton === true) {
|
|
3337
|
+
elements.cancelBtn.style.display = '';
|
|
3338
|
+
console.log('✅ Cancel button shown (showCancelButton: true)');
|
|
3339
|
+
} else {
|
|
3340
|
+
elements.cancelBtn.style.display = 'none';
|
|
3341
|
+
console.log('🚫 Cancel button hidden (showCancelButton: false)');
|
|
3342
|
+
}
|
|
3343
|
+
} else {
|
|
3344
|
+
if (config.showCancelButton === true) {
|
|
3345
|
+
console.warn('⚠️ showCancelButton is true but cancel button element not found');
|
|
3346
|
+
console.warn(' Please add <button data-chat-element="cancel-button">Cancel</button> to your HTML');
|
|
3347
|
+
} else {
|
|
3348
|
+
console.log('ℹ️ Cancel button not found (optional, showCancelButton: false)');
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3297
3352
|
const nextBtnTextElement = elements.nextBtn.querySelector('[data-chat-element="next-button-text"]');
|
|
3298
3353
|
if (nextBtnTextElement) {
|
|
3299
3354
|
elements.originalNextBtnText = nextBtnTextElement.textContent || nextBtnTextElement.innerText || 'Next';
|
|
@@ -3354,7 +3409,8 @@ function getState() {
|
|
|
3354
3409
|
return {
|
|
3355
3410
|
step: chatState.step,
|
|
3356
3411
|
data: { ...chatState.data },
|
|
3357
|
-
history: [...chatState.history]
|
|
3412
|
+
history: [...chatState.history],
|
|
3413
|
+
chatMode: chatState.chatMode // ✅ Include chatMode in state
|
|
3358
3414
|
};
|
|
3359
3415
|
}
|
|
3360
3416
|
|
|
@@ -3363,6 +3419,7 @@ function reset() {
|
|
|
3363
3419
|
chatState.data = flowData.initialData || {};
|
|
3364
3420
|
chatState.history = [];
|
|
3365
3421
|
chatState.currentSelection = null;
|
|
3422
|
+
chatState.chatMode = 'create'; // ✅ Reset to create mode
|
|
3366
3423
|
|
|
3367
3424
|
// ✅ Move back any injected elements before clearing
|
|
3368
3425
|
if (elements.messages) {
|