@meetelise/chat 1.59.2 → 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.
@@ -297,6 +297,10 @@ export class EmailUsWindow extends LitElement {
297
297
  brokerEmailError: string | null = null;
298
298
  @state()
299
299
  hasSubmittedForm = false;
300
+ /** The backend matched the submitter's own email to a broker the org already has: it made no lead and emailed
301
+ * them their submission link, so the confirmation mustn't promise that the leasing team will be in touch. */
302
+ @state()
303
+ isKnownBroker = false;
300
304
  @state()
301
305
  windowHeight = 525;
302
306
  @state()
@@ -499,7 +503,7 @@ export class EmailUsWindow extends LitElement {
499
503
  this.selectedLeadSource && this.selectedLeadSource.value
500
504
  ? this.selectedLeadSource.value
501
505
  : this.currentLeadSource;
502
- await createEmail(
506
+ const { knownBroker } = await createEmail(
503
507
  this.firstName,
504
508
  this.lastName,
505
509
  this.email,
@@ -536,6 +540,7 @@ export class EmailUsWindow extends LitElement {
536
540
  });
537
541
  this.leadSourceClient?.resetLeadSource();
538
542
  this.leadSourceMultitouchClient?.resetLeadSourceTouchpoints();
543
+ this.isKnownBroker = knownBroker;
539
544
  this.hasSubmittedForm = true;
540
545
  this.isSubmitting = false;
541
546
  // Remove the height of the button when it leaves the loading state
@@ -687,7 +692,9 @@ export class EmailUsWindow extends LitElement {
687
692
  </div>
688
693
  <div class="email-us__vertical-spacer"></div>
689
694
  <div class="email-us__submitted-info">
690
- ${this.isBrokerReferral
695
+ ${this.isKnownBroker
696
+ ? "It looks like you're a broker or locator. We've emailed you a link where you can submit your client."
697
+ : this.isBrokerReferral
691
698
  ? "Thank you for the referral. A member of our leasing team will contact your client."
692
699
  : "Thank you for your message. A member of our leasing team will contact you."}
693
700
  </div>
@@ -873,7 +880,7 @@ const createEmail = async (
873
880
  chatId?: string | null,
874
881
  leadSourcesWithTimestamps?: LeadSourceSubmittedListItem[],
875
882
  broker?: BrokerReferral | null
876
- ) => {
883
+ ): Promise<{ knownBroker: boolean }> => {
877
884
  const queryParams = new URLSearchParams(window.location.search);
878
885
  const requestBody = {
879
886
  email_address: email,
@@ -906,7 +913,7 @@ const createEmail = async (
906
913
  // A flag only: the broker's own details stay out of the data layer.
907
914
  ...(broker ? { isBrokerReferral: true } : {}),
908
915
  });
909
- await axios.post(
916
+ const response = await axios.post<{ known_broker?: boolean }>(
910
917
  "https://app.meetelise.com/platformApi/state/create/emailMe",
911
918
  requestBody,
912
919
  {
@@ -917,4 +924,5 @@ const createEmail = async (
917
924
  },
918
925
  }
919
926
  );
927
+ return { knownBroker: response.data?.known_broker === true };
920
928
  };
@@ -82,14 +82,26 @@ export const healthChatStyles = css`
82
82
  z-index: 100001;
83
83
  }
84
84
  #healthcare-inner-footer {
85
- display: flex;
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: flex;
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
- justify-content: space-between;
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
- this.shouldAutoScroll = true;
174
- this.messageInput.value = "";
175
- this.autoResizeMessageInput();
176
-
177
- // The first message triggers a channel creation which can take a few seconds,
178
- // so we immediately add the message to the UI to avoid a delay.
179
- if (this.messages.length === 0) {
180
- this.messages = [
181
- {
182
- timestamp: 0,
183
- message,
184
- isLeadMessage: true,
185
- chunks: [{ text: message, order: 0, isDone: true }],
186
- type: SimpleMessageTypes.text,
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
- try {
286
- const modal = document.getElementById("#healthchat-container");
287
- if (!modal) return;
288
- modal.focus();
289
- } catch (e) {
290
- // eslint-disable-next-line no-console
291
- console.error(e);
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
- e.key === "Enter" &&
923
- !this.myPubnub?.isCurrentlyStreamingMessage
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
- this.sendMessage(this.messageInput.value);
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
- ?disabled=${this.myPubnub?.isCurrentlyStreamingMessage}
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: flex;
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;
@@ -85,6 +85,53 @@ it("sends a broker referral with the client as the prospect and the broker field
85
85
  expect(JSON.stringify(event)).not.to.contain("bea@realty.example.com");
86
86
  });
87
87
 
88
+ const submittedText = async (emailUs: EmailUsWindow): Promise<string> => {
89
+ await emailUs.updateComplete;
90
+ return (
91
+ emailUs.shadowRoot
92
+ ?.querySelector(".email-us__submitted-info")
93
+ ?.textContent?.trim() ?? ""
94
+ );
95
+ };
96
+
97
+ it("tells a known broker writing in as the lead that they've been emailed their submission link", async () => {
98
+ const requests = captureRequests();
99
+ const emailUs = createForm({ brokerIntakeEnabled: true });
100
+ document.body.appendChild(emailUs);
101
+
102
+ const submission = emailUs.onClick();
103
+ requests[0].respond(
104
+ 200,
105
+ { "Content-Type": "application/json" },
106
+ JSON.stringify({ status: "ok", known_broker: true })
107
+ );
108
+ await submission;
109
+
110
+ expect(await submittedText(emailUs)).to.contain(
111
+ "We've emailed you a link where you can submit your client."
112
+ );
113
+ emailUs.remove();
114
+ });
115
+
116
+ it("tells any other lead the leasing team will be in touch", async () => {
117
+ const requests = captureRequests();
118
+ const emailUs = createForm({ brokerIntakeEnabled: true });
119
+ document.body.appendChild(emailUs);
120
+
121
+ const submission = emailUs.onClick();
122
+ requests[0].respond(
123
+ 200,
124
+ { "Content-Type": "application/json" },
125
+ JSON.stringify({ status: "ok" })
126
+ );
127
+ await submission;
128
+
129
+ expect(await submittedText(emailUs)).to.equal(
130
+ "Thank you for your message. A member of our leasing team will contact you."
131
+ );
132
+ emailUs.remove();
133
+ });
134
+
88
135
  it("sends the broker's phone on a referral email when they gave one", async () => {
89
136
  const requests = captureRequests();
90
137
  const emailUs = createForm({