@coras-io/embed 0.7.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @coras-io/embed
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0fd91b9: Group event section options by price, with a section dropdown per price, when more than eight sections are available
8
+
9
+ ### Patch Changes
10
+
11
+ - 85df217: Remove the drop shadow from the date field on the details page so it reads as a field, not a button
12
+
13
+ ## 0.7.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 745ccef: Show the details page highlights in the landing page's card layout on smaller screens, with wide images instead of oversized squares
18
+ - 60c850d: Send the customer back to the event when they try again after a failed card payment, instead of re-submitting to a cancelled payment
19
+ - 681bb0c: Stop the seat map letting shoppers select seats that are sold or unavailable
20
+ - ef018d1: Keep the navbar basket count and currency selector in step with the basket; the count stayed at zero after the page mounted however many items were reserved
21
+
3
22
  ## 0.7.0
4
23
 
5
24
  ### Minor Changes
@@ -106,6 +106,9 @@ export class CorasSeatsIO extends LitElement {
106
106
  objectCategories,
107
107
  pricing,
108
108
  selectableObjects,
109
+ // Seats Coras has no availability for get no category, so no price, and
110
+ // seats.io keeps unpriced seats selectable despite selectableObjects.
111
+ objectWithoutPricingSelectable: false,
109
112
  selectedObjects: this.selectedObjects,
110
113
  ...(this.maxSelectedObjects
111
114
  ? { maxSelectedObjects: this.maxSelectedObjects }
@@ -1,10 +1,30 @@
1
- import { type CSSResultGroup, LitElement } from "lit";
1
+ import { type CSSResultGroup, LitElement, type PropertyValues } from "lit";
2
2
  import "../../button/button.js";
3
+ import "../../dropdown/dropdown.js";
3
4
  import "../../icon/icon.js";
5
+ import "../../select-list/select-list.js";
6
+ import "../../select-list/select-option/select-option.js";
7
+ export interface SportOptionSection {
8
+ id: string;
9
+ name: string;
10
+ }
4
11
  export declare class CorasSportOption extends LitElement {
5
12
  static styles: CSSResultGroup;
6
13
  assetsURL: string;
7
14
  section: string;
8
15
  price: string;
16
+ /**
17
+ * Sections sharing this price. With more than one, the section becomes a
18
+ * dropdown and `value` holds the chosen section id.
19
+ */
20
+ sections: SportOptionSection[];
21
+ value: string;
22
+ protected willUpdate(changed: PropertyValues<this>): void;
23
+ private dropdownOpen;
24
+ private toggleDropdown;
25
+ private closeDropdown;
26
+ private selectSection;
27
+ private stopPropagation;
28
+ private renderSection;
9
29
  render(): import("lit").TemplateResult<1>;
10
30
  }
@@ -4,11 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { LitElement, html } from "lit";
8
- import { property } from "lit/decorators.js";
7
+ import { LitElement, html, } from "lit";
8
+ import { property, state } from "lit/decorators.js";
9
+ import { map } from "lit/directives/map.js";
9
10
  import { localized, msg } from "@lit/localize";
10
11
  import "../../button/button.js";
12
+ import "../../dropdown/dropdown.js";
11
13
  import "../../icon/icon.js";
14
+ import "../../select-list/select-list.js";
15
+ import "../../select-list/select-option/select-option.js";
12
16
  import styles from "./sport-option.styles.js";
13
17
  let CorasSportOption = class CorasSportOption extends LitElement {
14
18
  constructor() {
@@ -16,16 +20,85 @@ let CorasSportOption = class CorasSportOption extends LitElement {
16
20
  this.assetsURL = "";
17
21
  this.section = "";
18
22
  this.price = "";
23
+ /**
24
+ * Sections sharing this price. With more than one, the section becomes a
25
+ * dropdown and `value` holds the chosen section id.
26
+ */
27
+ this.sections = [];
28
+ this.value = "";
29
+ this.dropdownOpen = false;
30
+ this.toggleDropdown = () => {
31
+ this.dropdownOpen = !this.dropdownOpen;
32
+ };
33
+ this.closeDropdown = (event) => {
34
+ event.stopPropagation();
35
+ this.dropdownOpen = false;
36
+ };
37
+ this.stopPropagation = (event) => {
38
+ event.stopPropagation();
39
+ };
19
40
  }
20
41
  static { this.styles = styles; }
42
+ willUpdate(changed) {
43
+ if (changed.has("sections") &&
44
+ !this.sections.some((section) => section.id === this.value)) {
45
+ this.value = this.sections[0]?.id ?? "";
46
+ }
47
+ }
48
+ selectSection(id) {
49
+ this.value = id;
50
+ this.dropdownOpen = false;
51
+ }
52
+ renderSection() {
53
+ if (this.sections.length > 1) {
54
+ const selected = this.sections.find(({ id }) => id === this.value);
55
+ return html `<div class="text" @click=${this.stopPropagation}>
56
+ <div class="label" id="section-label">${msg("Section")}</div>
57
+ <coras-dropdown
58
+ ?open=${this.dropdownOpen}
59
+ @dropdown-close-request=${this.closeDropdown}
60
+ auto-focus
61
+ >
62
+ <coras-button
63
+ slot="trigger"
64
+ variant="outlined"
65
+ radius="field"
66
+ height="md"
67
+ border-color="light"
68
+ expanded
69
+ .shadow=${false}
70
+ ?rotate-suffix=${this.dropdownOpen}
71
+ @click=${this.toggleDropdown}
72
+ >
73
+ <coras-icon
74
+ assets-url="${this.assetsURL}"
75
+ slot="suffix"
76
+ icon="keyboard-arrow-down"
77
+ ></coras-icon>
78
+ <span class="selected-section">${selected?.name}</span>
79
+ </coras-button>
80
+
81
+ <coras-select-list spacious aria-labelledby="section-label">
82
+ ${map(this.sections, ({ id, name }) => html `
83
+ <coras-select-option
84
+ key=${id}
85
+ ?selected=${id === this.value}
86
+ @click=${() => this.selectSection(id)}
87
+ >${name}</coras-select-option
88
+ >
89
+ `)}
90
+ </coras-select-list>
91
+ </coras-dropdown>
92
+ </div>`;
93
+ }
94
+ return html `<div class="text">
95
+ <div class="label">${msg("Section")}</div>
96
+ <div class="value">${this.sections[0]?.name ?? this.section}</div>
97
+ </div>`;
98
+ }
21
99
  render() {
22
100
  return html `<div class="sport-option">
23
- <div class="section">
24
- <div class="text">
25
- <div class="label">${msg("Section")}</div>
26
- <div class="value">${this.section}</div>
27
- </div>
28
- </div>
101
+ <div class="section">${this.renderSection()}</div>
29
102
  <div class="price">
30
103
  <div class="text">
31
104
  <div class="label">${msg("Price")}</div>
@@ -51,6 +124,15 @@ __decorate([
51
124
  __decorate([
52
125
  property({ type: String })
53
126
  ], CorasSportOption.prototype, "price", void 0);
127
+ __decorate([
128
+ property({ attribute: false })
129
+ ], CorasSportOption.prototype, "sections", void 0);
130
+ __decorate([
131
+ property({ type: String })
132
+ ], CorasSportOption.prototype, "value", void 0);
133
+ __decorate([
134
+ state()
135
+ ], CorasSportOption.prototype, "dropdownOpen", void 0);
54
136
  CorasSportOption = __decorate([
55
137
  localized()
56
138
  ], CorasSportOption);
@@ -103,6 +103,27 @@ export default css `
103
103
  }
104
104
  }
105
105
  }
106
+
107
+ .section {
108
+ min-width: 0;
109
+
110
+ .text {
111
+ flex: 1;
112
+ min-width: 0;
113
+ }
114
+ }
115
+
116
+ coras-dropdown {
117
+ display: block;
118
+ width: 100%;
119
+ }
120
+
121
+ .selected-section {
122
+ min-width: 0;
123
+ overflow: hidden;
124
+ text-overflow: ellipsis;
125
+ white-space: nowrap;
126
+ }
106
127
  }
107
128
 
108
129
  @container (max-width: 400px) {
@@ -11,7 +11,7 @@ import { supportedCurrencies } from "../core/currency/constants.js";
11
11
  import { registerSaudiRiyalFont } from "../core/currency/saudi-riyal-font.js";
12
12
  import { allLocales } from "../core/i18n/locale-codes.js";
13
13
  import { getTextDirection } from "../core/utils/locale.js";
14
- import { provide } from "@lit/context";
14
+ import { ContextRoot, provide } from "@lit/context";
15
15
  import { clientContext } from "../contexts/client.context.js";
16
16
  import { pageDispatchContext, } from "../contexts/events.context.js";
17
17
  import { fireEvent } from "../core/events.js";
@@ -36,6 +36,9 @@ export const BaseMixin = (superClass) => {
36
36
  // through markup, so the default stays silent until `mount` wires one.
37
37
  this.logger = NOOP_LOGGER;
38
38
  this._pageDispatch = this.dispatchPageUpdate.bind(this);
39
+ // Replays context requests that arrive before their provider renders
40
+ // inside this page's shadow DOM. See docs/ARCHITECTURE.md.
41
+ new ContextRoot().attach(this);
39
42
  }
40
43
  getPageProperties() {
41
44
  return {};
@@ -123,6 +123,7 @@ export declare class CorasDetailsPage extends CorasDetailsPage_base {
123
123
  private findSeatedPerformance;
124
124
  private renderSeatedSelector;
125
125
  private renderSectionOptions;
126
+ private renderSectionsByPrice;
126
127
  private handleSeatsConfirmed;
127
128
  private renderAvailabilityOptions;
128
129
  private openNavbarBasket;
@@ -56,7 +56,7 @@ import { BaseMixin } from "../../mixins/base.mixin.js";
56
56
  import { ErrorModalMixin } from "../../mixins/error-modal.mixin.js";
57
57
  import { currentPageContext } from "../../contexts/current-page.context.js";
58
58
  import { convertToLocaleCurrency } from "../../core/currency/index.js";
59
- import { calculateTotalPrice, formatDateWithTimezone, formatTicketDetails, getAvailabilityDays, getAvailabilityRequestKey, getAvailabilitySummary, getBookingSessionExpiry, getCurrentMonth, getMinBookingSize, getTicketsAmount, getTicketSelectorLabel, getTotalTicketsCount, groupAvailabilityByTime, isBelowMinimumBookingSize, isSingleDayAvailability, resolveAttractionLocation, scrollToTop, sumPricesAndFormat, } from "./details-page.utilts.js";
59
+ import { calculateTotalPrice, formatDateWithTimezone, formatTicketDetails, getAvailabilityDays, getAvailabilityRequestKey, getAvailabilitySummary, getBookingSessionExpiry, getCurrentMonth, getMinBookingSize, getTicketsAmount, getTicketSelectorLabel, getTotalTicketsCount, groupAvailabilityByTime, groupSectionsByPrice, isBelowMinimumBookingSize, isSingleDayAvailability, resolveAttractionLocation, scrollToTop, SECTION_GROUPING_THRESHOLD, sumPricesAndFormat, } from "./details-page.utilts.js";
60
60
  import { formatDateTimeForDisplay } from "../../core/utils/datetime.js";
61
61
  import { APIError } from "../../core/api/api-error.js";
62
62
  import { getBookingSession, storeBookingSession, } from "../../core/api/middlewares/booking-session/booking-session.utils.js";
@@ -640,6 +640,7 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
640
640
  height="md"
641
641
  border-color="light"
642
642
  expanded
643
+ .shadow=${false}
643
644
  @click=${this.toggleCalendarDropdown}
644
645
  ?error=${this.hasAvailabilityError}
645
646
  >
@@ -1489,24 +1490,46 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
1489
1490
  <coras-sport-options
1490
1491
  label="${msg(str `We have ${filteredOptions.length} available options`)}"
1491
1492
  >
1492
- ${map(filteredOptions, ({ name, selection_id, prices }) => html `
1493
- <coras-sport-option
1494
- assets-url="${this.assetsURL}"
1495
- section="${name || ""}"
1496
- price="${sumPricesAndFormat({
1497
- prices,
1493
+ ${filteredOptions.length > SECTION_GROUPING_THRESHOLD
1494
+ ? this.renderSectionsByPrice(filteredOptions)
1495
+ : map(filteredOptions, ({ name, selection_id, prices }) => html `
1496
+ <coras-sport-option
1497
+ assets-url="${this.assetsURL}"
1498
+ section="${name || ""}"
1499
+ price="${sumPricesAndFormat({
1500
+ prices,
1501
+ locale: this.locale,
1502
+ currency: this.currency,
1503
+ })}"
1504
+ @click=${() => {
1505
+ this.isReservationPreviewModalOpened = true;
1506
+ this.selectedSectionId = selection_id;
1507
+ }}
1508
+ ></coras-sport-option>
1509
+ `)}
1510
+ </coras-sport-options>
1511
+ </div>
1512
+ `;
1513
+ }
1514
+ renderSectionsByPrice(options) {
1515
+ return map(groupSectionsByPrice({
1516
+ options,
1498
1517
  locale: this.locale,
1499
1518
  currency: this.currency,
1500
- })}"
1501
- @click=${() => {
1519
+ }), ({ price, sections }) => html `
1520
+ <coras-sport-option
1521
+ assets-url="${this.assetsURL}"
1522
+ price="${price}"
1523
+ .sections=${sections.map(({ selection_id, name }) => ({
1524
+ id: selection_id,
1525
+ name: name || "",
1526
+ }))}
1527
+ @click=${(event) => {
1502
1528
  this.isReservationPreviewModalOpened = true;
1503
- this.selectedSectionId = selection_id;
1529
+ this.selectedSectionId = event.currentTarget.value;
1504
1530
  }}
1505
- ></coras-sport-option>
1506
- `)}
1507
- </coras-sport-options>
1508
- </div>
1509
- `;
1531
+ ></coras-sport-option>
1532
+ `);
1510
1533
  }
1511
1534
  // The navbar is a light-DOM child the SDK slots into the page (sdk/chrome.ts)
1512
1535
  // and picks the modal or dropdown for its own layout.
@@ -29,7 +29,7 @@ export default css `
29
29
  gap: 2.5rem;
30
30
  width: 100%;
31
31
 
32
- @container --coras-layout (max-width: 800px) {
32
+ @container coras-layout (max-width: 800px) {
33
33
  grid-template-columns: 1fr;
34
34
  }
35
35
  }
@@ -133,7 +133,7 @@ export default css `
133
133
 
134
134
  coras-layout {
135
135
  container-type: inline-size;
136
- container-name: --coras-layout;
136
+ container-name: coras-layout;
137
137
 
138
138
  coras-breadcrumbs {
139
139
  display: block;
@@ -257,7 +257,7 @@ export default css `
257
257
  }
258
258
  }
259
259
 
260
- @container --coras-layout (max-width: 800px) {
260
+ @container coras-layout (max-width: 800px) {
261
261
  .attraction-header {
262
262
  grid-template-columns: 1fr;
263
263
  }
@@ -553,7 +553,7 @@ export default css `
553
553
  }
554
554
  }
555
555
 
556
- @container --coras-layout (max-width: 800px) {
556
+ @container coras-layout (max-width: 800px) {
557
557
  coras-layout {
558
558
  .attraction-header {
559
559
  height: auto;
@@ -113,3 +113,19 @@ export declare const getMinBookingSize: (apiResponse: components["schemas"]["Att
113
113
  * ticket and the minimum, not the visitor clearing the selector.
114
114
  */
115
115
  export declare const isBelowMinimumBookingSize: (totalTickets: number, minBookingSize: number) => boolean;
116
+ /**
117
+ * Above this many sections the options list groups them by price band.
118
+ */
119
+ export declare const SECTION_GROUPING_THRESHOLD = 8;
120
+ /**
121
+ * Groups section options by their formatted ticket price, keeping the order in
122
+ * which each price first appears.
123
+ */
124
+ export declare const groupSectionsByPrice: ({ options, locale, currency, }: {
125
+ options: components["schemas"]["AvailabilityItemModel"][];
126
+ locale: SupportedLocales;
127
+ currency: SupportedCurrencies;
128
+ }) => {
129
+ price: string;
130
+ sections: components["schemas"]["AvailabilityItemModel"][];
131
+ }[];
@@ -255,3 +255,23 @@ export const getMinBookingSize = (apiResponse) => {
255
255
  * ticket and the minimum, not the visitor clearing the selector.
256
256
  */
257
257
  export const isBelowMinimumBookingSize = (totalTickets, minBookingSize) => totalTickets > 0 && totalTickets < minBookingSize;
258
+ /**
259
+ * Above this many sections the options list groups them by price band.
260
+ */
261
+ export const SECTION_GROUPING_THRESHOLD = 8;
262
+ /**
263
+ * Groups section options by their formatted ticket price, keeping the order in
264
+ * which each price first appears.
265
+ */
266
+ export const groupSectionsByPrice = ({ options, locale, currency, }) => {
267
+ const groups = new Map();
268
+ for (const option of options) {
269
+ const price = sumPricesAndFormat({
270
+ prices: option.prices,
271
+ locale,
272
+ currency,
273
+ });
274
+ groups.set(price, [...(groups.get(price) ?? []), option]);
275
+ }
276
+ return Array.from(groups, ([price, sections]) => ({ price, sections }));
277
+ };
@@ -28,7 +28,7 @@ export default css `
28
28
  }
29
29
  }
30
30
 
31
- @container (max-width: 800px) {
31
+ @container (max-width: 1000px) {
32
32
  :host .cards {
33
33
  grid-template-columns: repeat(2, 1fr);
34
34
  }
@@ -214,6 +214,10 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
214
214
  * Handles API errors by mapping them to form fields
215
215
  */
216
216
  private handleApiErrors;
217
+ /**
218
+ * The failed transaction consumed both the booking session and the
219
+ * PaymentIntent, so a retry has to start a new booking from the event.
220
+ */
217
221
  private handleTryAgain;
218
222
  /**
219
223
  * Dispatches the coras:payment-status event with a failed status.
@@ -32,6 +32,7 @@ import styles from "./payment-page.styles.js";
32
32
  import "../../components/bottom-drawer/bottom-drawer.js";
33
33
  import "../../components/expiration-timer/expiration-timer.js";
34
34
  import { Task, TaskStatus } from "@lit/task";
35
+ import { formatISO, parseISO } from "date-fns";
35
36
  import { FIELDS } from "./payment-page.fields.js";
36
37
  import "./partials/stripe/stripe.js";
37
38
  import "./partials/country-field/country-field.js";
@@ -1277,6 +1278,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1277
1278
  this.redirectToConfirmation(true);
1278
1279
  }
1279
1280
  else if (isFinalStatus(status)) {
1281
+ // The API cancels the PaymentIntent with the transaction, so it cannot be confirmed again
1282
+ this.pendingClientSecret = null;
1280
1283
  this.logger.error("Transaction failed with status:", status);
1281
1284
  this.flowController.transition("failed");
1282
1285
  this.redirectToConfirmation(false);
@@ -1316,13 +1319,23 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1316
1319
  }
1317
1320
  void this.updateComplete.then(() => this.scrollToFirstError());
1318
1321
  }
1322
+ /**
1323
+ * The failed transaction consumed both the booking session and the
1324
+ * PaymentIntent, so a retry has to start a new booking from the event.
1325
+ */
1319
1326
  handleTryAgain() {
1320
- // Reset submit state so the user can re-submit
1321
- this.flowController.retry();
1322
- this.paymentFailed = false;
1323
- this.formController.formErrors = {};
1324
- this.stripeController.clearAllErrors();
1325
- this.requestUpdate();
1327
+ const [reservation] = this.reservationsTask.value?.reservations ?? [];
1328
+ if (!reservation) {
1329
+ this.dispatchPageUpdate({ page: "landing" });
1330
+ return;
1331
+ }
1332
+ this.dispatchPageUpdate({
1333
+ page: "details",
1334
+ id: reservation.attraction_id,
1335
+ date: formatISO(parseISO(reservation.start_datetime), {
1336
+ representation: "date",
1337
+ }),
1338
+ });
1326
1339
  }
1327
1340
  /**
1328
1341
  * Dispatches the coras:payment-status event with a failed status.
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
- "version": "0.7.0",
23
+ "version": "0.8.0",
24
24
  "private": false,
25
25
  "homepage": "https://docs.coras.io",
26
26
  "bugs": {