@meetelise/chat 1.76.0 → 1.77.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/dist/src/WebComponent/SchedulerV2/itinerary-editor.d.ts +23 -2
- package/dist/src/WebComponent/SchedulerV2/scheduler-popover.d.ts +18 -1
- package/package.json +1 -1
- package/public/dist/index.js +451 -309
- package/src/WebComponent/SchedulerV2/itinerary-editor.ts +256 -68
- package/src/WebComponent/SchedulerV2/scheduler-popover.ts +100 -4
- package/src/tourSchedulerV2Booking.test.ts +110 -14
|
@@ -150,7 +150,10 @@ export class ItineraryEditor extends LitElement {
|
|
|
150
150
|
return this.planned && !this.loading;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
/** The stop whose "Change date & time" panel is open. */
|
|
153
154
|
@state() private editingTimeFor: number | null = null;
|
|
155
|
+
/** That panel's calendar is open. */
|
|
156
|
+
@state() private stopDateOpen = false;
|
|
154
157
|
/** The date field's calendar is open. */
|
|
155
158
|
@state() private dateOpen = false;
|
|
156
159
|
@state() private mobile = isMobile();
|
|
@@ -310,16 +313,157 @@ export class ItineraryEditor extends LitElement {
|
|
|
310
313
|
></date-picker>`;
|
|
311
314
|
}
|
|
312
315
|
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Closes a calendar when a day is picked, the day already chosen included,
|
|
318
|
+
* which the calendar reports without a date change, and focuses `trigger`.
|
|
319
|
+
* The calendar handles the click first, inside its own shadow root.
|
|
320
|
+
*/
|
|
321
|
+
private closeOnDay(close: () => void, trigger: string) {
|
|
322
|
+
return (e: MouseEvent): void => {
|
|
323
|
+
const day = e
|
|
324
|
+
.composedPath()
|
|
325
|
+
.find(
|
|
326
|
+
(n) =>
|
|
327
|
+
n instanceof HTMLButtonElement &&
|
|
328
|
+
n.matches("button.dayNumber:not(:disabled)")
|
|
329
|
+
);
|
|
330
|
+
if (!day) return;
|
|
331
|
+
close();
|
|
332
|
+
this.renderRoot.querySelector<HTMLElement>(trigger)?.focus();
|
|
333
|
+
};
|
|
320
334
|
}
|
|
321
335
|
|
|
322
|
-
|
|
336
|
+
/**
|
|
337
|
+
* The panel's date field: the stop's own day, which opens the calendar
|
|
338
|
+
* under it. Moving the stop to another day makes it a separate tour.
|
|
339
|
+
*/
|
|
340
|
+
private renderStopDateField(stop: PlanStop): TemplateResult {
|
|
341
|
+
const id = stop.building_id;
|
|
342
|
+
const date = isoDate(stop.start);
|
|
343
|
+
const label = formatLongDate(date);
|
|
344
|
+
return html`<p class="field-label" aria-hidden="true">Date</p>
|
|
345
|
+
<scheduler-popover
|
|
346
|
+
class="stop-date-popover"
|
|
347
|
+
?open=${this.stopDateOpen}
|
|
348
|
+
?inline=${this.mobile}
|
|
349
|
+
@popover-close=${() => (this.stopDateOpen = false)}
|
|
350
|
+
>
|
|
351
|
+
<button
|
|
352
|
+
id=${`stop-date-trigger-${id}`}
|
|
353
|
+
slot="trigger"
|
|
354
|
+
class="input picker-field"
|
|
355
|
+
aria-expanded=${String(this.stopDateOpen)}
|
|
356
|
+
aria-controls=${`stop-date-panel-${id}`}
|
|
357
|
+
aria-label=${`Date, ${label}`}
|
|
358
|
+
@click=${() => (this.stopDateOpen = !this.stopDateOpen)}
|
|
359
|
+
>
|
|
360
|
+
<span class="value">${label}</span>
|
|
361
|
+
${CalendarLineIcon(14)}
|
|
362
|
+
</button>
|
|
363
|
+
<div
|
|
364
|
+
id=${`stop-date-panel-${id}`}
|
|
365
|
+
class="stop-calendar-panel"
|
|
366
|
+
@click=${this.closeOnDay(
|
|
367
|
+
() => (this.stopDateOpen = false),
|
|
368
|
+
`#stop-date-trigger-${id}`
|
|
369
|
+
)}
|
|
370
|
+
>
|
|
371
|
+
${this.stopDateOpen
|
|
372
|
+
? this.renderDatePicker(stop.dates, date, (picked) =>
|
|
373
|
+
emit(this, "stop-date-change", { buildingId: id, date: picked })
|
|
374
|
+
)
|
|
375
|
+
: ""}
|
|
376
|
+
</div>
|
|
377
|
+
</scheduler-popover>`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Closes the stop's panel, and puts focus back on its button. */
|
|
381
|
+
private closeStopPanel(): void {
|
|
382
|
+
const id = this.editingTimeFor;
|
|
383
|
+
this.editingTimeFor = null;
|
|
384
|
+
this.stopDateOpen = false;
|
|
385
|
+
this.renderRoot
|
|
386
|
+
.querySelector<HTMLElement>(`.edit-time[data-building-id="${id}"]`)
|
|
387
|
+
?.focus();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* The design's "Change date & time" panel, under the stop's pencil (above
|
|
392
|
+
* it when there isn't room, in place on phones): the stop's date when it
|
|
393
|
+
* has another, then its times. Picking a time closes it.
|
|
394
|
+
*/
|
|
395
|
+
private renderStopPanel(
|
|
396
|
+
stop: PlanStop,
|
|
397
|
+
canChangeDate: boolean,
|
|
398
|
+
canChangeTime: boolean
|
|
399
|
+
): TemplateResult {
|
|
400
|
+
const id = stop.building_id;
|
|
401
|
+
const open = this.editingTimeFor === id;
|
|
402
|
+
const name = this.name(id);
|
|
403
|
+
return html`<scheduler-popover
|
|
404
|
+
class="stop-popover"
|
|
405
|
+
fit
|
|
406
|
+
?open=${open}
|
|
407
|
+
?inline=${this.mobile}
|
|
408
|
+
@popover-close=${() => {
|
|
409
|
+
// Another stop's pencil opens its own panel before this one hears it.
|
|
410
|
+
if (this.editingTimeFor !== id) return;
|
|
411
|
+
this.editingTimeFor = null;
|
|
412
|
+
this.stopDateOpen = false;
|
|
413
|
+
}}
|
|
414
|
+
>
|
|
415
|
+
<button
|
|
416
|
+
slot="trigger"
|
|
417
|
+
class="icon-button edit-time"
|
|
418
|
+
data-building-id=${id}
|
|
419
|
+
title=${canChangeDate ? "Change date & time" : "Change time"}
|
|
420
|
+
aria-expanded=${String(open)}
|
|
421
|
+
aria-controls=${`stop-panel-${id}`}
|
|
422
|
+
aria-label=${`Change the ${
|
|
423
|
+
canChangeDate ? "date or time" : "time"
|
|
424
|
+
} at ${name}`}
|
|
425
|
+
@click=${() => {
|
|
426
|
+
this.editingTimeFor = open ? null : id;
|
|
427
|
+
this.stopDateOpen = false;
|
|
428
|
+
}}
|
|
429
|
+
>
|
|
430
|
+
${PencilLineIcon(12)}
|
|
431
|
+
</button>
|
|
432
|
+
<div
|
|
433
|
+
id=${`stop-panel-${id}`}
|
|
434
|
+
class="stop-panel"
|
|
435
|
+
role="group"
|
|
436
|
+
aria-label=${`Date and time at ${name}`}
|
|
437
|
+
>
|
|
438
|
+
${open && canChangeDate ? this.renderStopDateField(stop) : ""}
|
|
439
|
+
${
|
|
440
|
+
// While /plan answers, these are the old plan's times, which may
|
|
441
|
+
// be on the stop's old day.
|
|
442
|
+
open && canChangeTime && !this.loading
|
|
443
|
+
? html`<p
|
|
444
|
+
id=${`stop-time-label-${id}`}
|
|
445
|
+
class="field-label time-label"
|
|
446
|
+
>
|
|
447
|
+
Time (${getTimezoneAbbreviation(stop.timezone)})
|
|
448
|
+
</p>
|
|
449
|
+
<div
|
|
450
|
+
class="stop-times"
|
|
451
|
+
role="group"
|
|
452
|
+
aria-labelledby=${`stop-time-label-${id}`}
|
|
453
|
+
>
|
|
454
|
+
${this.renderTimePicker(stop, () => this.closeStopPanel())}
|
|
455
|
+
</div>`
|
|
456
|
+
: ""
|
|
457
|
+
}
|
|
458
|
+
</div>
|
|
459
|
+
</scheduler-popover>`;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** A stop's times; `picked` runs once one is picked, the chosen one included. */
|
|
463
|
+
private renderTimePicker(
|
|
464
|
+
stop: PlanStop,
|
|
465
|
+
picked: () => void = () => undefined
|
|
466
|
+
): TemplateResult {
|
|
323
467
|
const times = [...new Set([stop.start, ...stop.alternatives])].sort();
|
|
324
468
|
return html`<time-picker
|
|
325
469
|
outlined
|
|
@@ -328,15 +472,16 @@ export class ItineraryEditor extends LitElement {
|
|
|
328
472
|
.options=${times.map(timeOption)}
|
|
329
473
|
.defaultSelectedTime=${timeOption(stop.start)}
|
|
330
474
|
@change=${(e: Event) => {
|
|
331
|
-
const
|
|
332
|
-
if (!
|
|
475
|
+
const time = (e.target as TimePicker).selectedTime;
|
|
476
|
+
if (!time) {
|
|
333
477
|
// A second click unselects, but every stop needs a time: hand the
|
|
334
478
|
// picker this stop's time again, which it selects when none is.
|
|
335
479
|
(e.target as TimePicker).defaultSelectedTime = timeOption(stop.start);
|
|
480
|
+
picked();
|
|
336
481
|
return;
|
|
337
482
|
}
|
|
338
|
-
const start = `${
|
|
339
|
-
|
|
483
|
+
const start = `${time.dateWithTimeZoneOffset.datetime}${time.dateWithTimeZoneOffset.offset}`;
|
|
484
|
+
picked();
|
|
340
485
|
if (start !== stop.start) {
|
|
341
486
|
emit(this, "stop-time-change", {
|
|
342
487
|
buildingId: stop.building_id,
|
|
@@ -365,19 +510,6 @@ export class ItineraryEditor extends LitElement {
|
|
|
365
510
|
*/
|
|
366
511
|
private renderDateField(): TemplateResult {
|
|
367
512
|
const label = this.date ? formatLongDate(this.date) : "Select a date";
|
|
368
|
-
// The calendar handles the click first, inside its own shadow root.
|
|
369
|
-
const closeOnDay = (e: MouseEvent) => {
|
|
370
|
-
const day = e
|
|
371
|
-
.composedPath()
|
|
372
|
-
.find(
|
|
373
|
-
(n) =>
|
|
374
|
-
n instanceof HTMLButtonElement &&
|
|
375
|
-
n.matches("button.dayNumber:not(:disabled)")
|
|
376
|
-
);
|
|
377
|
-
if (!day) return;
|
|
378
|
-
this.dateOpen = false;
|
|
379
|
-
this.renderRoot.querySelector<HTMLElement>("#date-trigger")?.focus();
|
|
380
|
-
};
|
|
381
513
|
return html`<h2 id="date-heading" class="section-heading">Date</h2>
|
|
382
514
|
<scheduler-popover
|
|
383
515
|
class="date-popover"
|
|
@@ -399,7 +531,14 @@ export class ItineraryEditor extends LitElement {
|
|
|
399
531
|
>
|
|
400
532
|
${CalendarLineIcon(14)}
|
|
401
533
|
</button>
|
|
402
|
-
<div
|
|
534
|
+
<div
|
|
535
|
+
id="date-panel"
|
|
536
|
+
class="calendar-panel"
|
|
537
|
+
@click=${this.closeOnDay(
|
|
538
|
+
() => (this.dateOpen = false),
|
|
539
|
+
"#date-trigger"
|
|
540
|
+
)}
|
|
541
|
+
>
|
|
403
542
|
${this.renderDatePicker()}
|
|
404
543
|
</div>
|
|
405
544
|
</scheduler-popover>
|
|
@@ -423,7 +562,6 @@ export class ItineraryEditor extends LitElement {
|
|
|
423
562
|
const community = this.communities.get(stop.building_id);
|
|
424
563
|
const ids = this.newStopIds();
|
|
425
564
|
const newIndex = ids.indexOf(stop.building_id);
|
|
426
|
-
const editing = this.editingTimeFor === stop.building_id;
|
|
427
565
|
const canReorder = !stop.fixed && ids.length > 1;
|
|
428
566
|
// With no other day or time to pick, they're plain text rather than a picker.
|
|
429
567
|
const canChangeTime =
|
|
@@ -499,35 +637,16 @@ export class ItineraryEditor extends LitElement {
|
|
|
499
637
|
${community?.name ?? ""}
|
|
500
638
|
</p>
|
|
501
639
|
<p class="subtitle">${formatAddress(community?.address ?? null)}</p>
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
} at ${community?.name ?? ""}`}
|
|
513
|
-
@click=${() =>
|
|
514
|
-
(this.editingTimeFor = editing ? null : stop.building_id)}
|
|
515
|
-
>
|
|
516
|
-
${time} ${PencilLineIcon(12)}
|
|
517
|
-
</button>`}
|
|
518
|
-
${editing && canChangeDate ? this.renderStopDatePicker(stop) : ""}
|
|
519
|
-
${
|
|
520
|
-
// While /plan answers, these are the old plan's times, which may
|
|
521
|
-
// be on the stop's old day.
|
|
522
|
-
editing && canChangeTime && !this.loading
|
|
523
|
-
? html`<div class="stop-times">
|
|
524
|
-
${this.renderTimePicker(stop)}
|
|
525
|
-
<p class="subtitle">
|
|
526
|
-
Times in ${getTimezoneAbbreviation(stop.timezone)}
|
|
527
|
-
</p>
|
|
528
|
-
</div>`
|
|
529
|
-
: ""
|
|
530
|
-
}
|
|
640
|
+
<div class="stop-time">
|
|
641
|
+
<span
|
|
642
|
+
>${time}${stop.fixed
|
|
643
|
+
? html`<span class="sr-only">, booked</span>`
|
|
644
|
+
: ""}</span
|
|
645
|
+
>
|
|
646
|
+
${canChangeTime || canChangeDate
|
|
647
|
+
? this.renderStopPanel(stop, canChangeDate, canChangeTime)
|
|
648
|
+
: ""}
|
|
649
|
+
</div>
|
|
531
650
|
</div>
|
|
532
651
|
${stop.fixed
|
|
533
652
|
? html`<span class="booked-mark">${CheckCircleLineIcon(18, 1)}</span>`
|
|
@@ -722,27 +841,96 @@ export class ItineraryEditor extends LitElement {
|
|
|
722
841
|
opacity: 0.85;
|
|
723
842
|
}
|
|
724
843
|
|
|
844
|
+
/* A stop's time, then its pencil; on phones its panel opens under both. */
|
|
845
|
+
.stop-card .stop-time {
|
|
846
|
+
display: flex;
|
|
847
|
+
flex-wrap: wrap;
|
|
848
|
+
gap: 4px;
|
|
849
|
+
}
|
|
850
|
+
|
|
725
851
|
.edit-time {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
color: inherit;
|
|
729
|
-
cursor: pointer;
|
|
730
|
-
font: inherit;
|
|
731
|
-
font-size: 12px;
|
|
852
|
+
color: var(--tsv2-placeholder);
|
|
853
|
+
height: 16px;
|
|
732
854
|
padding: 0;
|
|
855
|
+
position: relative;
|
|
856
|
+
width: 16px;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/* A 32px target around the 16px pencil. */
|
|
860
|
+
.edit-time::after {
|
|
861
|
+
content: "";
|
|
862
|
+
inset: -8px;
|
|
863
|
+
position: absolute;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
.edit-time:hover {
|
|
867
|
+
color: var(--tsv2-text);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/* The design's 360px panel: 16px in, 6px from the pencil. */
|
|
871
|
+
.stop-popover {
|
|
872
|
+
--scheduler-popover-gap: 6px;
|
|
873
|
+
--scheduler-popover-padding: 16px;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/* As tall as the pencil, so the panel's 6px are from the pencil itself. */
|
|
877
|
+
.stop-popover:not([inline]) {
|
|
878
|
+
display: flex;
|
|
733
879
|
}
|
|
734
880
|
|
|
735
|
-
.
|
|
736
|
-
|
|
881
|
+
.stop-panel {
|
|
882
|
+
width: 326px;
|
|
737
883
|
}
|
|
738
884
|
|
|
739
|
-
.stop-
|
|
885
|
+
.stop-panel > .time-label:not(:first-child) {
|
|
886
|
+
margin-top: 16px;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/* Four rows of times, scrolling into the panel's bottom padding. */
|
|
740
890
|
.stop-times {
|
|
741
|
-
margin-
|
|
891
|
+
margin-bottom: -16px;
|
|
892
|
+
max-height: 160px;
|
|
893
|
+
overflow-y: auto;
|
|
894
|
+
padding-bottom: 16px;
|
|
895
|
+
scrollbar-width: none;
|
|
742
896
|
}
|
|
743
897
|
|
|
744
|
-
.stop-times
|
|
745
|
-
|
|
898
|
+
.stop-times::-webkit-scrollbar {
|
|
899
|
+
display: none;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/* The panel's calendar floats 16px under its date field, as wide. */
|
|
903
|
+
.stop-date-popover {
|
|
904
|
+
display: block;
|
|
905
|
+
--scheduler-popover-gap: 16px;
|
|
906
|
+
--scheduler-popover-padding: 12px;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
.stop-date-popover .picker-field[aria-expanded="true"] {
|
|
910
|
+
border-color: var(--tsv2-accent);
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
.stop-calendar-panel {
|
|
914
|
+
width: 300px;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
.stop-popover[inline] .stop-panel {
|
|
918
|
+
margin-top: 8px;
|
|
919
|
+
width: 100%;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
.stop-popover[inline] .stop-times {
|
|
923
|
+
margin-bottom: 0;
|
|
924
|
+
max-height: none;
|
|
925
|
+
padding-bottom: 0;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
.stop-date-popover[inline] .stop-calendar-panel {
|
|
929
|
+
border: 1px solid var(--tsv2-line);
|
|
930
|
+
border-radius: 8px;
|
|
931
|
+
margin-top: 8px;
|
|
932
|
+
padding: 12px;
|
|
933
|
+
width: auto;
|
|
746
934
|
}
|
|
747
935
|
|
|
748
936
|
.booked-mark {
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
import { css, html, LitElement, TemplateResult } from "lit";
|
|
2
|
-
import { customElement, property } from "lit/decorators.js";
|
|
1
|
+
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|
2
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
3
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
4
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
5
|
+
|
|
6
|
+
/** The nearest box that clips `el`, across shadow roots: its scroller, or the window. */
|
|
7
|
+
const clippingBox = (
|
|
8
|
+
el: Element
|
|
9
|
+
): { top: number; right: number; bottom: number; left: number } => {
|
|
10
|
+
const up = (n: Element): Element | null =>
|
|
11
|
+
n.assignedSlot ??
|
|
12
|
+
n.parentElement ??
|
|
13
|
+
((n.getRootNode() as ShadowRoot).host || null);
|
|
14
|
+
for (let n = up(el); n; n = up(n)) {
|
|
15
|
+
const { overflowX, overflowY } = getComputedStyle(n);
|
|
16
|
+
if (overflowX !== "visible" || overflowY !== "visible") {
|
|
17
|
+
return n.getBoundingClientRect();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { top: 0, right: innerWidth, bottom: innerHeight, left: 0 };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** The room the design leaves between a fitted panel and its scroller's edge. */
|
|
24
|
+
const EDGE = 8;
|
|
3
25
|
|
|
4
26
|
/**
|
|
5
27
|
* A trigger and the small panel it opens, for the v2 scheduler's secondary
|
|
@@ -10,6 +32,10 @@ import { customElement, property } from "lit/decorators.js";
|
|
|
10
32
|
* `inline` (phones) it opens in place instead, after its siblings in the
|
|
11
33
|
* parent's flex row, as the filter row always did there.
|
|
12
34
|
*
|
|
35
|
+
* With `fit`, the panel stays inside the scroller it opens in, as the
|
|
36
|
+
* design's per-stop panel does: above the trigger when there isn't room
|
|
37
|
+
* under it, and moved left when it would run past the right edge.
|
|
38
|
+
*
|
|
13
39
|
* The parent owns `open`; the element asks for a close with `popover-close`.
|
|
14
40
|
* Slot the trigger as `slot="trigger"` and the panel's content in the default
|
|
15
41
|
* slot, so the trigger's `aria-controls` can name an id in the parent's tree.
|
|
@@ -22,6 +48,49 @@ export class SchedulerPopover extends LitElement {
|
|
|
22
48
|
@property({ type: Boolean, reflect: true })
|
|
23
49
|
inline = false;
|
|
24
50
|
|
|
51
|
+
/** Keep the panel inside its scroller (see above). Off, it always opens below. */
|
|
52
|
+
@property({ type: Boolean })
|
|
53
|
+
fit = false;
|
|
54
|
+
|
|
55
|
+
/** With `fit`, where the open panel sits; null until it has been measured. */
|
|
56
|
+
@state() private placement: { above: boolean; shift: number } | null = null;
|
|
57
|
+
|
|
58
|
+
/** It opens, or a phone turns into a wider screen with it open. */
|
|
59
|
+
private opening(changed: PropertyValues<this>): boolean {
|
|
60
|
+
return this.open && (changed.has("open") || changed.has("inline"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected willUpdate(changed: PropertyValues<this>): void {
|
|
64
|
+
if (this.opening(changed)) this.placement = null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected updated(changed: PropertyValues<this>): void {
|
|
68
|
+
if (this.opening(changed) && this.fit && !this.inline) {
|
|
69
|
+
// After the panel's own elements have rendered, before it is shown.
|
|
70
|
+
requestAnimationFrame(() => this.place());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Opens the panel above its trigger only when it fits there and not below:
|
|
76
|
+
* what runs past the scroller's foot can be scrolled to, but not its top.
|
|
77
|
+
*/
|
|
78
|
+
private place(): void {
|
|
79
|
+
const panel = this.renderRoot.querySelector<HTMLElement>(".panel");
|
|
80
|
+
if (!this.open || !panel) return;
|
|
81
|
+
const box = clippingBox(this);
|
|
82
|
+
const trigger = this.getBoundingClientRect();
|
|
83
|
+
const below = panel.getBoundingClientRect();
|
|
84
|
+
const gap = below.top - trigger.bottom;
|
|
85
|
+
const roomBelow = box.bottom - trigger.bottom;
|
|
86
|
+
const roomAbove = trigger.top - box.top;
|
|
87
|
+
const needed = gap + below.height;
|
|
88
|
+
const above = roomBelow < needed && roomAbove >= needed;
|
|
89
|
+
const overflow = below.right - (box.right - EDGE);
|
|
90
|
+
const shift = Math.max(0, Math.min(overflow, below.left - box.left - EDGE));
|
|
91
|
+
this.placement = { above, shift };
|
|
92
|
+
}
|
|
93
|
+
|
|
25
94
|
connectedCallback(): void {
|
|
26
95
|
super.connectedCallback();
|
|
27
96
|
document.addEventListener("click", this.onDocumentClick);
|
|
@@ -69,8 +138,24 @@ export class SchedulerPopover extends LitElement {
|
|
|
69
138
|
};
|
|
70
139
|
|
|
71
140
|
render(): TemplateResult {
|
|
141
|
+
const fitted = this.fit && !this.inline;
|
|
72
142
|
return html`<slot name="trigger"></slot>
|
|
73
|
-
<div
|
|
143
|
+
<div
|
|
144
|
+
class=${classMap({
|
|
145
|
+
panel: true,
|
|
146
|
+
measuring: fitted && !this.placement,
|
|
147
|
+
above: fitted && !!this.placement?.above,
|
|
148
|
+
})}
|
|
149
|
+
style=${styleMap({
|
|
150
|
+
left:
|
|
151
|
+
fitted && this.placement?.shift
|
|
152
|
+
? `${-this.placement.shift}px`
|
|
153
|
+
: undefined,
|
|
154
|
+
})}
|
|
155
|
+
?hidden=${!this.open}
|
|
156
|
+
>
|
|
157
|
+
<slot></slot>
|
|
158
|
+
</div>`;
|
|
74
159
|
}
|
|
75
160
|
|
|
76
161
|
static styles = css`
|
|
@@ -91,7 +176,7 @@ export class SchedulerPopover extends LitElement {
|
|
|
91
176
|
box-shadow: 0 2px 16px 0 rgba(0, 0, 0, 0.13);
|
|
92
177
|
box-sizing: border-box;
|
|
93
178
|
left: 0;
|
|
94
|
-
margin-top: 8px;
|
|
179
|
+
margin-top: var(--scheduler-popover-gap, 8px);
|
|
95
180
|
padding: var(--scheduler-popover-padding, 11px);
|
|
96
181
|
position: absolute;
|
|
97
182
|
top: 100%;
|
|
@@ -99,6 +184,17 @@ export class SchedulerPopover extends LitElement {
|
|
|
99
184
|
z-index: 20;
|
|
100
185
|
}
|
|
101
186
|
|
|
187
|
+
/* With fit: laid out, unseen, for a frame while it is measured. */
|
|
188
|
+
.panel.measuring {
|
|
189
|
+
visibility: hidden;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.panel.above {
|
|
193
|
+
bottom: 100%;
|
|
194
|
+
margin: 0 0 var(--scheduler-popover-gap, 8px);
|
|
195
|
+
top: auto;
|
|
196
|
+
}
|
|
197
|
+
|
|
102
198
|
:host([inline]) .panel {
|
|
103
199
|
background: none;
|
|
104
200
|
border: none;
|
|
@@ -371,6 +371,27 @@ const bookAndAddLinden = async (scheduler: TourSchedulerV2) => {
|
|
|
371
371
|
);
|
|
372
372
|
};
|
|
373
373
|
|
|
374
|
+
/** "Add another stop", then Cedar & Main from the nearby communities. */
|
|
375
|
+
const addCedar = async (
|
|
376
|
+
scheduler: TourSchedulerV2,
|
|
377
|
+
editor: ItineraryEditor
|
|
378
|
+
) => {
|
|
379
|
+
editor.shadowRoot?.querySelector<HTMLButtonElement>(".add-stop")?.click();
|
|
380
|
+
const picker = await waitFor(() =>
|
|
381
|
+
inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
|
|
382
|
+
);
|
|
383
|
+
await picker.updateComplete;
|
|
384
|
+
const cedar = await waitFor(() =>
|
|
385
|
+
Array.from(
|
|
386
|
+
picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
|
|
387
|
+
"button.floorplan-image-card"
|
|
388
|
+
) ?? []
|
|
389
|
+
).find((card) => card.textContent?.includes("Cedar & Main"))
|
|
390
|
+
);
|
|
391
|
+
cedar.click();
|
|
392
|
+
await waitFor(() => editor.stops.some((stop) => stop.building_id === CEDAR));
|
|
393
|
+
};
|
|
394
|
+
|
|
374
395
|
afterEach(() => {
|
|
375
396
|
restore();
|
|
376
397
|
document.querySelectorAll("tour-scheduler-v2").forEach((el) => el.remove());
|
|
@@ -477,6 +498,12 @@ it("moves an added stop to its own day, keeping the booked tour's day, adds the
|
|
|
477
498
|
"Change the date or time at The Linden"
|
|
478
499
|
);
|
|
479
500
|
edit.click();
|
|
501
|
+
const dateField = await waitFor(() =>
|
|
502
|
+
editor.shadowRoot?.querySelector<HTMLButtonElement>(
|
|
503
|
+
`#stop-date-trigger-${LINDEN}`
|
|
504
|
+
)
|
|
505
|
+
);
|
|
506
|
+
dateField.click();
|
|
480
507
|
const picker = await waitFor(() =>
|
|
481
508
|
editor.shadowRoot?.querySelector<HTMLElement & { selectedDate?: Date }>(
|
|
482
509
|
"date-picker"
|
|
@@ -529,6 +556,88 @@ it("moves an added stop to its own day, keeping the booked tour's day, adds the
|
|
|
529
556
|
]);
|
|
530
557
|
});
|
|
531
558
|
|
|
559
|
+
it("opens a stop's date and time panel from its pencil, closes it on Escape or a picked time, and returns focus to the pencil", async () => {
|
|
560
|
+
const { plans } = fakeBackend();
|
|
561
|
+
const scheduler = mount();
|
|
562
|
+
await bookAndAddLinden(scheduler);
|
|
563
|
+
const editor = await waitFor(() =>
|
|
564
|
+
inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
|
|
565
|
+
);
|
|
566
|
+
const inEditor = <T extends Element>(selector: string) =>
|
|
567
|
+
editor.shadowRoot?.querySelector<T>(selector) ?? null;
|
|
568
|
+
const pencil = await waitFor(() =>
|
|
569
|
+
inEditor<HTMLButtonElement>(`.edit-time[data-building-id="${LINDEN}"]`)
|
|
570
|
+
);
|
|
571
|
+
const popover = pencil.closest<HTMLElement & { open: boolean }>(
|
|
572
|
+
"scheduler-popover"
|
|
573
|
+
);
|
|
574
|
+
// The booked stop has no pencil.
|
|
575
|
+
expect(editor.shadowRoot?.querySelectorAll(".edit-time").length).to.equal(1);
|
|
576
|
+
|
|
577
|
+
pencil.click();
|
|
578
|
+
await editor.updateComplete;
|
|
579
|
+
expect(popover?.open).to.equal(true);
|
|
580
|
+
expect(pencil.getAttribute("aria-expanded")).to.equal("true");
|
|
581
|
+
const panel = inEditor(`#${pencil.getAttribute("aria-controls")}`);
|
|
582
|
+
expect(panel?.getAttribute("aria-label")).to.equal(
|
|
583
|
+
"Date and time at The Linden"
|
|
584
|
+
);
|
|
585
|
+
// Another time than the stop's, once the picker has marked the stop's.
|
|
586
|
+
const laterTime = () =>
|
|
587
|
+
waitFor(() => {
|
|
588
|
+
const options = panel
|
|
589
|
+
?.querySelector("time-picker")
|
|
590
|
+
?.shadowRoot?.querySelectorAll<HTMLButtonElement>(".option");
|
|
591
|
+
return (
|
|
592
|
+
options &&
|
|
593
|
+
Array.from(options).some((o) => o.classList.contains("selected")) &&
|
|
594
|
+
Array.from(options).find((o) => !o.classList.contains("selected"))
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
const later = await laterTime();
|
|
598
|
+
|
|
599
|
+
later.dispatchEvent(
|
|
600
|
+
new KeyboardEvent("keydown", {
|
|
601
|
+
key: "Escape",
|
|
602
|
+
bubbles: true,
|
|
603
|
+
composed: true,
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
await editor.updateComplete;
|
|
607
|
+
expect(popover?.open).to.equal(false);
|
|
608
|
+
expect(editor.shadowRoot?.activeElement).to.equal(pencil);
|
|
609
|
+
|
|
610
|
+
pencil.click();
|
|
611
|
+
await editor.updateComplete;
|
|
612
|
+
const planned = plans.length;
|
|
613
|
+
(await laterTime()).click();
|
|
614
|
+
await editor.updateComplete;
|
|
615
|
+
expect(popover?.open).to.equal(false);
|
|
616
|
+
expect(editor.shadowRoot?.activeElement).to.equal(pencil);
|
|
617
|
+
await waitFor(() => plans.length > planned);
|
|
618
|
+
// The first new stop's time leads the plan.
|
|
619
|
+
expect(plans[plans.length - 1].start_time).to.equal("10:45");
|
|
620
|
+
|
|
621
|
+
// With a panel open, another stop's pencil opens that stop's panel instead.
|
|
622
|
+
await waitFor(() => editor.canAddStop);
|
|
623
|
+
await addCedar(scheduler, editor);
|
|
624
|
+
const cedarPencil = await waitFor(
|
|
625
|
+
() =>
|
|
626
|
+
!editor.loading &&
|
|
627
|
+
inEditor<HTMLButtonElement>(`.edit-time[data-building-id="${CEDAR}"]`)
|
|
628
|
+
);
|
|
629
|
+
pencil.click();
|
|
630
|
+
await editor.updateComplete;
|
|
631
|
+
expect(popover?.open).to.equal(true);
|
|
632
|
+
cedarPencil.click();
|
|
633
|
+
await editor.updateComplete;
|
|
634
|
+
expect(popover?.open).to.equal(false);
|
|
635
|
+
expect(
|
|
636
|
+
cedarPencil.closest<HTMLElement & { open: boolean }>("scheduler-popover")
|
|
637
|
+
?.open
|
|
638
|
+
).to.equal(true);
|
|
639
|
+
});
|
|
640
|
+
|
|
532
641
|
it("picks one community at a time: a pick replaces the community and opens its schedule", async () => {
|
|
533
642
|
fakeBackend();
|
|
534
643
|
const scheduler = mount();
|
|
@@ -986,20 +1095,7 @@ it("adds stops one at a time after a booking, offering each next stop after the
|
|
|
986
1095
|
const editor = await waitFor(() =>
|
|
987
1096
|
inScheduler<ItineraryEditor>(scheduler, "itinerary-editor")
|
|
988
1097
|
);
|
|
989
|
-
editor
|
|
990
|
-
const picker = await waitFor(() =>
|
|
991
|
-
inScheduler<CommunityPicker>(scheduler, ".add-stop-picker community-picker")
|
|
992
|
-
);
|
|
993
|
-
await picker.updateComplete;
|
|
994
|
-
const cedar = await waitFor(() =>
|
|
995
|
-
Array.from(
|
|
996
|
-
picker.shadowRoot?.querySelectorAll<HTMLButtonElement>(
|
|
997
|
-
"button.floorplan-image-card"
|
|
998
|
-
) ?? []
|
|
999
|
-
).find((card) => card.textContent?.includes("Cedar & Main"))
|
|
1000
|
-
);
|
|
1001
|
-
cedar.click();
|
|
1002
|
-
await waitFor(() => editor.stops.some((stop) => stop.building_id === CEDAR));
|
|
1098
|
+
await addCedar(scheduler, editor);
|
|
1003
1099
|
expect(inScheduler(scheduler, ".add-stop-picker")).to.equal(null);
|
|
1004
1100
|
|
|
1005
1101
|
// Its communities were asked for after The Linden, without either community.
|