@meetelise/chat 1.59.3 → 1.59.4
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/dist/src/WebComponent/pubnub-chat.d.ts +19 -0
- package/dist/src/hostPageModal.d.ts +12 -0
- package/package.json +1 -1
- package/public/dist/index.js +235 -180
- package/src/WebComponent/healthchat-styles.ts +15 -3
- package/src/WebComponent/leasing-chat-styles.ts +21 -3
- package/src/WebComponent/pubnub-chat-styles.ts +8 -0
- package/src/WebComponent/pubnub-chat.ts +163 -34
- package/src/WebComponent/utilities-styles.ts +15 -3
- package/src/chatKeyboard.test.ts +311 -0
- package/src/hostPageModal.ts +95 -0
|
@@ -82,14 +82,26 @@ export const healthChatStyles = css`
|
|
|
82
82
|
z-index: 100001;
|
|
83
83
|
}
|
|
84
84
|
#healthcare-inner-footer {
|
|
85
|
-
display:
|
|
85
|
+
display: grid;
|
|
86
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
87
|
+
grid-template-areas:
|
|
88
|
+
"label ."
|
|
89
|
+
"field send";
|
|
86
90
|
align-items: center;
|
|
87
|
-
justify-content: space-between;
|
|
88
91
|
box-sizing: border-box;
|
|
89
92
|
padding: 16px;
|
|
90
|
-
gap: 0px;
|
|
93
|
+
column-gap: 0px;
|
|
94
|
+
row-gap: 4px;
|
|
95
|
+
}
|
|
96
|
+
#healthcare-inner-footer .message-input-label {
|
|
97
|
+
grid-area: label;
|
|
98
|
+
color: black;
|
|
99
|
+
}
|
|
100
|
+
#healthcare-inner-footer > #healthcare-send-message-bttn {
|
|
101
|
+
grid-area: send;
|
|
91
102
|
}
|
|
92
103
|
#healthcare-inner-footer > #message-input {
|
|
104
|
+
grid-area: field;
|
|
93
105
|
width: 100%;
|
|
94
106
|
max-height: 100px;
|
|
95
107
|
overflowy: auto;
|
|
@@ -83,14 +83,28 @@ export const leasingChatStyles = css`
|
|
|
83
83
|
width: 100%;
|
|
84
84
|
background: black;
|
|
85
85
|
|
|
86
|
-
display:
|
|
86
|
+
display: grid;
|
|
87
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
88
|
+
grid-template-areas:
|
|
89
|
+
"label ."
|
|
90
|
+
"field send";
|
|
87
91
|
align-items: center;
|
|
88
|
-
|
|
92
|
+
column-gap: 16px;
|
|
93
|
+
row-gap: 4px;
|
|
89
94
|
box-sizing: border-box;
|
|
90
|
-
gap: 16px;
|
|
91
95
|
padding: 24px;
|
|
92
96
|
z-index: 100001;
|
|
93
97
|
}
|
|
98
|
+
#footer .message-input-label {
|
|
99
|
+
grid-area: label;
|
|
100
|
+
color: white;
|
|
101
|
+
}
|
|
102
|
+
#footer #message-input {
|
|
103
|
+
grid-area: field;
|
|
104
|
+
}
|
|
105
|
+
#footer #send-message-bttn {
|
|
106
|
+
grid-area: send;
|
|
107
|
+
}
|
|
94
108
|
#message-input {
|
|
95
109
|
width: 100%;
|
|
96
110
|
height: auto;
|
|
@@ -119,4 +133,8 @@ export const leasingChatStyles = css`
|
|
|
119
133
|
border: none;
|
|
120
134
|
cursor: pointer;
|
|
121
135
|
}
|
|
136
|
+
#send-message-bttn[aria-disabled="true"] {
|
|
137
|
+
cursor: default;
|
|
138
|
+
opacity: 0.45;
|
|
139
|
+
}
|
|
122
140
|
`;
|
|
@@ -202,6 +202,14 @@ export const pubnubChatStyles = css`
|
|
|
202
202
|
opacity: 0.5;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
.message-input-label {
|
|
206
|
+
font-size: 12px;
|
|
207
|
+
font-weight: 400;
|
|
208
|
+
line-height: 1.4;
|
|
209
|
+
letter-spacing: 0em;
|
|
210
|
+
text-align: left;
|
|
211
|
+
}
|
|
212
|
+
|
|
205
213
|
.sr-only {
|
|
206
214
|
position: absolute;
|
|
207
215
|
width: 1px;
|
|
@@ -40,6 +40,11 @@ import {
|
|
|
40
40
|
getConsentPreChatDisclaimer,
|
|
41
41
|
} from "../disclaimers";
|
|
42
42
|
import { BuildingWebchatView } from "../fetchBuildingWebchatView";
|
|
43
|
+
import {
|
|
44
|
+
hideHostSiblings,
|
|
45
|
+
restoreHostSiblings,
|
|
46
|
+
widgetLightHost,
|
|
47
|
+
} from "../hostPageModal";
|
|
43
48
|
|
|
44
49
|
@customElement("pubnub-chat")
|
|
45
50
|
export class PubnubChat extends LitElement {
|
|
@@ -136,6 +141,18 @@ export class PubnubChat extends LitElement {
|
|
|
136
141
|
|
|
137
142
|
private hasReplySnapshot = false;
|
|
138
143
|
|
|
144
|
+
/** True from Send until the reply paint settles, so focus can be repaired. */
|
|
145
|
+
private holdMessageFieldFocus = false;
|
|
146
|
+
|
|
147
|
+
/** True until initializePubnub and publish settle. Streaming is still false then. */
|
|
148
|
+
@state()
|
|
149
|
+
private sendInFlight = false;
|
|
150
|
+
|
|
151
|
+
private releaseFocusHoldQueued = false;
|
|
152
|
+
|
|
153
|
+
/** Widget element whose siblings were hidden for the phone dialog. */
|
|
154
|
+
private hostPageLock: Element | null = null;
|
|
155
|
+
|
|
139
156
|
@state()
|
|
140
157
|
privacyPolicyUrl = "http://bit.ly/me_privacy_policy";
|
|
141
158
|
|
|
@@ -163,6 +180,7 @@ export class PubnubChat extends LitElement {
|
|
|
163
180
|
|
|
164
181
|
disconnectedCallback(): void {
|
|
165
182
|
this._cleanupMobileListener?.();
|
|
183
|
+
this.releaseHostPage();
|
|
166
184
|
super.disconnectedCallback();
|
|
167
185
|
}
|
|
168
186
|
|
|
@@ -170,24 +188,44 @@ export class PubnubChat extends LitElement {
|
|
|
170
188
|
if (message.length === 0) {
|
|
171
189
|
return;
|
|
172
190
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
191
|
+
// isCurrentlyStreamingMessage stays false during channel creation and
|
|
192
|
+
// publish. Hold this gate for the whole call so Enter and Send cannot
|
|
193
|
+
// start a second sendMessage while initializePubnub is still running.
|
|
194
|
+
if (this.sendInFlight || this.myPubnub?.isCurrentlyStreamingMessage) {
|
|
195
|
+
if (this.holdMessageFieldFocus) this.focusMessageField();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.sendInFlight = true;
|
|
199
|
+
try {
|
|
200
|
+
this.shouldAutoScroll = true;
|
|
201
|
+
// Focus the field before the reply render. If Send is focused when it
|
|
202
|
+
// becomes unavailable, the browser moves focus to the document and
|
|
203
|
+
// iOS VoiceOver reads the host page behind the chat.
|
|
204
|
+
this.holdMessageFieldFocus = true;
|
|
205
|
+
this.focusMessageField();
|
|
206
|
+
this.messageInput.value = "";
|
|
207
|
+
this.autoResizeMessageInput();
|
|
208
|
+
|
|
209
|
+
// The first message triggers a channel creation which can take a few seconds,
|
|
210
|
+
// so we immediately add the message to the UI to avoid a delay.
|
|
211
|
+
if (this.messages.length === 0) {
|
|
212
|
+
this.messages = [
|
|
213
|
+
{
|
|
214
|
+
timestamp: 0,
|
|
215
|
+
message,
|
|
216
|
+
isLeadMessage: true,
|
|
217
|
+
chunks: [{ text: message, order: 0, isDone: true }],
|
|
218
|
+
type: SimpleMessageTypes.text,
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
await this.myPubnub?.sendMessage(message);
|
|
223
|
+
} finally {
|
|
224
|
+
this.sendInFlight = false;
|
|
225
|
+
this.focusMessageField();
|
|
226
|
+
await this.updateComplete;
|
|
227
|
+
this.restoreMessageFieldFocus();
|
|
189
228
|
}
|
|
190
|
-
await this.myPubnub?.sendMessage(message);
|
|
191
229
|
};
|
|
192
230
|
|
|
193
231
|
firstUpdated(): void {
|
|
@@ -282,14 +320,73 @@ export class PubnubChat extends LitElement {
|
|
|
282
320
|
|
|
283
321
|
async updated(): Promise<void> {
|
|
284
322
|
this.scrollToChatBottom();
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
323
|
+
// Do not focus a container here. An earlier call looked up
|
|
324
|
+
// "#healthchat-container" on document (the hash is not part of the id,
|
|
325
|
+
// and the node lives in this shadow root), so it never matched. Focusing
|
|
326
|
+
// the dialog on every reply render would pull the caret out of the field.
|
|
327
|
+
this.syncHostPage();
|
|
328
|
+
this.restoreMessageFieldFocus();
|
|
329
|
+
this.scheduleFocusHoldRelease();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Phone layout only. Desktop must leave the host page alone. */
|
|
333
|
+
private syncHostPage(): void {
|
|
334
|
+
if (!this._isMobile) {
|
|
335
|
+
this.releaseHostPage();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const host = widgetLightHost(this);
|
|
339
|
+
if (!host?.parentElement) return;
|
|
340
|
+
this.hostPageLock = host;
|
|
341
|
+
hideHostSiblings(host);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private releaseHostPage(): void {
|
|
345
|
+
if (!this.hostPageLock) return;
|
|
346
|
+
restoreHostSiblings(this.hostPageLock);
|
|
347
|
+
this.hostPageLock = null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* If Send or a dropped focus (document / body) is active during a send,
|
|
352
|
+
* put the caret back in the field. A control the user moved to inside
|
|
353
|
+
* the dialog, or a desktop page control they clicked, is left alone.
|
|
354
|
+
*/
|
|
355
|
+
private restoreMessageFieldFocus(): void {
|
|
356
|
+
if (!this.holdMessageFieldFocus) return;
|
|
357
|
+
const active = deepestActive();
|
|
358
|
+
if (active instanceof HTMLElement && active.id === "message-input") return;
|
|
359
|
+
const lost =
|
|
360
|
+
!active ||
|
|
361
|
+
active === document.body ||
|
|
362
|
+
active === document.documentElement;
|
|
363
|
+
const onSend =
|
|
364
|
+
active instanceof HTMLElement && active.id === "send-message-bttn";
|
|
365
|
+
if (lost || onSend) this.focusMessageField();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private scheduleFocusHoldRelease(): void {
|
|
369
|
+
if (!this.holdMessageFieldFocus || this.releaseFocusHoldQueued) return;
|
|
370
|
+
if (
|
|
371
|
+
this.sendInFlight ||
|
|
372
|
+
this.isLoadingMessages ||
|
|
373
|
+
this.myPubnub?.isCurrentlyStreamingMessage
|
|
374
|
+
) {
|
|
375
|
+
return;
|
|
292
376
|
}
|
|
377
|
+
this.releaseFocusHoldQueued = true;
|
|
378
|
+
requestAnimationFrame(() => {
|
|
379
|
+
this.releaseFocusHoldQueued = false;
|
|
380
|
+
if (
|
|
381
|
+
this.sendInFlight ||
|
|
382
|
+
this.isLoadingMessages ||
|
|
383
|
+
this.myPubnub?.isCurrentlyStreamingMessage
|
|
384
|
+
) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
this.restoreMessageFieldFocus();
|
|
388
|
+
this.holdMessageFieldFocus = false;
|
|
389
|
+
});
|
|
293
390
|
}
|
|
294
391
|
|
|
295
392
|
autoResizeMessageInput = (): void => {
|
|
@@ -301,6 +398,17 @@ export class PubnubChat extends LitElement {
|
|
|
301
398
|
return this.requiresConsent && !this.hasReceivedConsent;
|
|
302
399
|
};
|
|
303
400
|
|
|
401
|
+
/** Visible caption for the message field. Stays on screen while typing. */
|
|
402
|
+
private renderMessageFieldLabel(color?: string): TemplateResult {
|
|
403
|
+
const label = "Message";
|
|
404
|
+
return html`<label
|
|
405
|
+
class="message-input-label"
|
|
406
|
+
for="message-input"
|
|
407
|
+
style=${styleMap({ color })}
|
|
408
|
+
>${label}</label
|
|
409
|
+
>`;
|
|
410
|
+
}
|
|
411
|
+
|
|
304
412
|
/** Caret in the message field when the composer is on screen. */
|
|
305
413
|
focusMessageField(): boolean {
|
|
306
414
|
const root = this.shadowRoot;
|
|
@@ -308,7 +416,7 @@ export class PubnubChat extends LitElement {
|
|
|
308
416
|
if (!(input instanceof HTMLTextAreaElement) || !root) return false;
|
|
309
417
|
// Consent hides the footer with display:none. Focusing it would no-op.
|
|
310
418
|
if (input.getClientRects().length === 0) return false;
|
|
311
|
-
if (root.activeElement !== input) input.focus();
|
|
419
|
+
if (root.activeElement !== input) input.focus({ preventScroll: true });
|
|
312
420
|
return root.activeElement === input;
|
|
313
421
|
}
|
|
314
422
|
|
|
@@ -505,9 +613,9 @@ export class PubnubChat extends LitElement {
|
|
|
505
613
|
})}
|
|
506
614
|
>
|
|
507
615
|
<div id="utilities-inner-footer">
|
|
616
|
+
${this.renderMessageFieldLabel()}
|
|
508
617
|
<textarea
|
|
509
618
|
id="message-input"
|
|
510
|
-
aria-label="Message"
|
|
511
619
|
class=${classMap({
|
|
512
620
|
["webchat-font__desktop"]: !this._isMobile,
|
|
513
621
|
["webchat-font__mobile"]: this._isMobile,
|
|
@@ -682,9 +790,9 @@ export class PubnubChat extends LitElement {
|
|
|
682
790
|
})}
|
|
683
791
|
>
|
|
684
792
|
<div id="healthcare-inner-footer">
|
|
793
|
+
${this.renderMessageFieldLabel()}
|
|
685
794
|
<textarea
|
|
686
795
|
id="message-input"
|
|
687
|
-
aria-label="Message"
|
|
688
796
|
class=${classMap({
|
|
689
797
|
["webchat-font__desktop"]: !this._isMobile,
|
|
690
798
|
["webchat-font__mobile"]: this._isMobile,
|
|
@@ -900,9 +1008,16 @@ export class PubnubChat extends LitElement {
|
|
|
900
1008
|
: undefined,
|
|
901
1009
|
})}
|
|
902
1010
|
>
|
|
1011
|
+
${this.renderMessageFieldLabel(
|
|
1012
|
+
shouldUsePrimaryColorForChatFooter(
|
|
1013
|
+
this.building.orgId,
|
|
1014
|
+
this.building.id
|
|
1015
|
+
) && this.primaryColor !== defaultPrimaryColor
|
|
1016
|
+
? "black"
|
|
1017
|
+
: undefined
|
|
1018
|
+
)}
|
|
903
1019
|
<textarea
|
|
904
1020
|
id="message-input"
|
|
905
|
-
aria-label="Message"
|
|
906
1021
|
class=${classMap({
|
|
907
1022
|
["webchat-font__desktop"]: !this._isMobile,
|
|
908
1023
|
["webchat-font__mobile"]: this._isMobile,
|
|
@@ -918,13 +1033,16 @@ export class PubnubChat extends LitElement {
|
|
|
918
1033
|
})}
|
|
919
1034
|
placeholder="Ask a question..."
|
|
920
1035
|
@keydown=${(e: KeyboardEvent) => {
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
) {
|
|
1036
|
+
if (e.key !== "Enter") return;
|
|
1037
|
+
// Swallow the key while a send is in flight so it cannot insert
|
|
1038
|
+
// a newline or start another publish. Streaming already ignores Enter.
|
|
1039
|
+
if (this.sendInFlight) {
|
|
925
1040
|
e.preventDefault();
|
|
926
|
-
|
|
1041
|
+
return;
|
|
927
1042
|
}
|
|
1043
|
+
if (this.myPubnub?.isCurrentlyStreamingMessage) return;
|
|
1044
|
+
e.preventDefault();
|
|
1045
|
+
this.sendMessage(this.messageInput.value);
|
|
928
1046
|
}}
|
|
929
1047
|
@input=${() => this.autoResizeMessageInput()}
|
|
930
1048
|
rows="1"
|
|
@@ -934,7 +1052,10 @@ export class PubnubChat extends LitElement {
|
|
|
934
1052
|
tabindex="0"
|
|
935
1053
|
id="send-message-bttn"
|
|
936
1054
|
@click=${() => this.sendMessage(this.messageInput.value)}
|
|
937
|
-
|
|
1055
|
+
aria-disabled=${this.sendInFlight ||
|
|
1056
|
+
this.myPubnub?.isCurrentlyStreamingMessage
|
|
1057
|
+
? "true"
|
|
1058
|
+
: "false"}
|
|
938
1059
|
aria-label="Send message"
|
|
939
1060
|
>
|
|
940
1061
|
${shouldUsePrimaryColorForChatFooter(
|
|
@@ -986,6 +1107,14 @@ export function trapTabInside(
|
|
|
986
1107
|
}
|
|
987
1108
|
}
|
|
988
1109
|
|
|
1110
|
+
function deepestActive(): Element | null {
|
|
1111
|
+
let active: Element | null = document.activeElement;
|
|
1112
|
+
while (active?.shadowRoot?.activeElement) {
|
|
1113
|
+
active = active.shadowRoot.activeElement;
|
|
1114
|
+
}
|
|
1115
|
+
return active;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
989
1118
|
function activeElementInside(container: HTMLElement): HTMLElement | null {
|
|
990
1119
|
let active: Element | null = document.activeElement;
|
|
991
1120
|
while (active?.shadowRoot?.activeElement) {
|
|
@@ -72,14 +72,26 @@ export const utiltiesChatStyles = css`
|
|
|
72
72
|
z-index: 100001;
|
|
73
73
|
}
|
|
74
74
|
#utilities-inner-footer {
|
|
75
|
-
display:
|
|
75
|
+
display: grid;
|
|
76
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
77
|
+
grid-template-areas:
|
|
78
|
+
"label ."
|
|
79
|
+
"field send";
|
|
76
80
|
align-items: center;
|
|
77
|
-
justify-content: space-between;
|
|
78
81
|
box-sizing: border-box;
|
|
79
82
|
padding: 16px;
|
|
80
|
-
gap: 0px;
|
|
83
|
+
column-gap: 0px;
|
|
84
|
+
row-gap: 4px;
|
|
85
|
+
}
|
|
86
|
+
#utilities-inner-footer .message-input-label {
|
|
87
|
+
grid-area: label;
|
|
88
|
+
color: black;
|
|
89
|
+
}
|
|
90
|
+
#utilities-inner-footer > #utilities-send-message-bttn {
|
|
91
|
+
grid-area: send;
|
|
81
92
|
}
|
|
82
93
|
#utilities-inner-footer > #message-input {
|
|
94
|
+
grid-area: field;
|
|
83
95
|
width: 100%;
|
|
84
96
|
max-height: 100px;
|
|
85
97
|
overflowy: auto;
|