@@ -88,7 +88,6 @@ export class WebchatApp {
88
88
server,
89
89
} : WebchatArgs ) {
90
90
this . theme = theme
91
- // TODO: Review if is possible store persistentMenu, coverComponent, blockInputs, enableEmojiPicker, enableAttachments, enableUserInput, enableAnimations, etc as part of theme
92
91
this . persistentMenu = persistentMenu
93
92
this . coverComponent = coverComponent
94
93
this . blockInputs = blockInputs
@@ -371,17 +370,86 @@ export class WebchatApp {
371
370
return this . webchatRef . current ?. updateWebchatSettings ( settings )
372
371
}
373
372
374
- // eslint-disable-next-line complexity
373
+ createInitialTheme ( optionsAtRuntime : WebchatArgs = { } ) {
374
+ const theme = merge ( defaultTheme , this . theme , optionsAtRuntime . theme )
375
+
376
+ if ( theme . animations === undefined ) {
377
+ theme . animations = { }
378
+ }
379
+
380
+ theme . animations . enable =
381
+ theme . animations . enable ??
382
+ optionsAtRuntime . enableAnimations ??
383
+ this . enableAnimations
384
+
385
+ theme . coverComponent =
386
+ theme . coverComponent ??
387
+ optionsAtRuntime . coverComponent ??
388
+ this . coverComponent
389
+
390
+ theme . userInput = this . createInitialThemUserInput ( theme , optionsAtRuntime )
391
+
392
+ return theme
393
+ }
394
+
395
+ createInitialThemUserInput (
396
+ theme : WebchatTheme ,
397
+ optionsAtRuntime : WebchatArgs = { }
398
+ ) {
399
+ if ( theme . userInput === undefined ) {
400
+ theme . userInput = { }
401
+ }
402
+
403
+ console . log (
404
+ 'WebchatApp theme.userInput.enable' ,
405
+ theme . userInput . enable ,
406
+ optionsAtRuntime . enableUserInput ,
407
+ this . enableUserInput
408
+ )
409
+ theme . userInput . enable =
410
+ theme . userInput . enable ??
411
+ optionsAtRuntime . enableUserInput ??
412
+ this . enableUserInput
413
+
414
+ theme . userInput . persistentMenu =
415
+ theme . userInput . persistentMenu ??
416
+ optionsAtRuntime . persistentMenu ??
417
+ this . persistentMenu
418
+
419
+ theme . userInput . blockInputs =
420
+ theme . userInput . blockInputs ??
421
+ optionsAtRuntime . blockInputs ??
422
+ this . blockInputs
423
+
424
+ if ( theme . userInput . emojiPicker === undefined ) {
425
+ theme . userInput . emojiPicker = { }
426
+ }
427
+
428
+ theme . userInput . emojiPicker . enable =
429
+ theme . userInput . emojiPicker . enable ??
430
+ optionsAtRuntime . enableEmojiPicker ??
431
+ this . enableEmojiPicker
432
+
433
+ if ( theme . userInput . attachments === undefined ) {
434
+ theme . userInput . attachments = { }
435
+ }
436
+
437
+ theme . userInput . attachments . enable =
438
+ theme . userInput . attachments . enable ??
439
+ optionsAtRuntime . enableAttachments ??
440
+ this . enableAttachments
441
+
442
+ theme . userInput . blockInputs =
443
+ theme . userInput . blockInputs ??
444
+ optionsAtRuntime . blockInputs ??
445
+ this . blockInputs
446
+
447
+ return theme . userInput
448
+ }
449
+
375
450
getComponent ( host : HTMLDivElement , optionsAtRuntime : WebchatArgs = { } ) {
376
451
let {
377
- theme = defaultTheme ,
378
- persistentMenu,
379
- coverComponent,
380
- blockInputs,
381
- enableAttachments,
382
- enableUserInput,
383
- enableAnimations,
384
- enableEmojiPicker,
452
+ theme = { } ,
385
453
defaultDelay,
386
454
defaultTyping,
387
455
storage,
@@ -398,14 +466,7 @@ export class WebchatApp {
398
466
hostId,
399
467
...webchatOptions
400
468
} = optionsAtRuntime
401
- theme = merge ( this . theme , theme )
402
- persistentMenu = persistentMenu || this . persistentMenu
403
- coverComponent = coverComponent || this . coverComponent
404
- blockInputs = blockInputs || this . blockInputs
405
- enableEmojiPicker = enableEmojiPicker || this . enableEmojiPicker
406
- enableAttachments = enableAttachments || this . enableAttachments
407
- enableUserInput = enableUserInput || this . enableUserInput
408
- enableAnimations = enableAnimations || this . enableAnimations
469
+ theme = this . createInitialTheme ( optionsAtRuntime )
409
470
defaultDelay = defaultDelay || this . defaultDelay
410
471
defaultTyping = defaultTyping || this . defaultTyping
411
472
server = server || this . server
@@ -429,29 +490,22 @@ export class WebchatApp {
429
490
host = { this . host }
430
491
shadowDOM = { this . shadowDOM }
431
492
theme = { theme as WebchatTheme }
432
- persistentMenu = { persistentMenu }
433
- coverComponent = { coverComponent }
434
- blockInputs = { blockInputs }
435
- enableEmojiPicker = { enableEmojiPicker }
436
- enableAttachments = { enableAttachments }
437
- enableUserInput = { enableUserInput }
438
- enableAnimations = { enableAnimations }
439
493
storage = { this . storage }
440
494
storageKey = { this . storageKey }
441
495
defaultDelay = { defaultDelay }
442
496
defaultTyping = { defaultTyping }
443
497
onInit = { ( ...args : [ any ] ) => this . onInitWebchat ( ...args ) }
444
498
onOpen = { ( ...args : [ any ] ) => this . onOpenWebchat ( ...args ) }
445
499
onClose = { ( ...args : [ any ] ) => this . onCloseWebchat ( ...args ) }
446
- onUserInput = { ( ...args : [ any ] ) => this . onUserInput ( ...args ) } // TODO: Review this function, and his params
500
+ onUserInput = { ( ...args : [ any ] ) => this . onUserInput ( ...args ) }
447
501
onStateChange = { ( args : OnStateChangeArgs ) => {
448
502
this . onStateChange ( args )
449
503
} }
450
504
onTrackEvent = { (
451
505
request : ActionRequest ,
452
506
eventName : string ,
453
507
args ?: EventArgs
454
- ) => this . onTrackEventWebchat ( request , eventName , args ) } //TODO: Review if this implementation is correct
508
+ ) => this . onTrackEventWebchat ( request , eventName , args ) }
455
509
server = { server }
456
510
/>
457
511
)
0 commit comments