@coras-io/embed 0.8.0 → 0.8.1

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,15 @@
1
1
  # @coras-io/embed
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3cc8fef: Line the seat selection summary bar up with the seat map column on wide screens instead of centring it in the viewport
8
+ - e48044e: Scroll smoothly to the basket after adding tickets on wider screens instead of jumping to the top of the page
9
+ - 06267c9: Show the selected city's hero image and breadcrumbs on the landing page when the city was chosen from the navbar search or opened from a link without its country
10
+ - ef34b68: Remove the drop shadow from the ticket selector on the details page so it reads as a field, not a button
11
+ - 24a5a4c: List grouped section options from the lowest price to the highest
12
+
3
13
  ## 0.8.0
4
14
 
5
15
  ### Minor Changes
@@ -21,6 +21,11 @@ export declare class CorasSeatedSelector extends LitElement {
21
21
  private violations;
22
22
  private reserved;
23
23
  private sheetExpanded;
24
+ private columnBounds;
25
+ private readonly columnObserver;
26
+ private measureColumn;
27
+ connectedCallback(): void;
28
+ disconnectedCallback(): void;
24
29
  private fallbackFired;
25
30
  private seatsTask;
26
31
  private chartDataCache;
@@ -13,6 +13,7 @@ import { apiGet } from "../../core/api/queries.js";
13
13
  import { clientContext } from "../../contexts/client.context.js";
14
14
  import { currencyContext, distributorIdContext, localeContext, } from "../../contexts/properties.context.js";
15
15
  import { map } from "lit/directives/map.js";
16
+ import { styleMap } from "lit/directives/style-map.js";
16
17
  import { fireInternalEvent } from "../../core/events.js";
17
18
  import { convertToLocaleCurrency } from "../../core/currency/index.js";
18
19
  import { buildChartData, buildSelectionSummary, buildTickets, } from "../seats-io/seats-io.transform.js";
@@ -53,6 +54,17 @@ let CorasSeatedSelector = class CorasSeatedSelector extends LitElement {
53
54
  // seat-count-and-total handle, expanded to the full breakdown on tap. Ignored
54
55
  // on wider screens, where the breakdown always shows.
55
56
  this.sheetExpanded = false;
57
+ // The summary bar is fixed to the viewport, so CSS alone cannot line it up
58
+ // with this element's column on wide pages. Its viewport offset and width are
59
+ // measured here and handed to the bar as custom properties.
60
+ this.columnBounds = null;
61
+ this.columnObserver = new ResizeObserver(() => this.measureColumn());
62
+ this.measureColumn = () => {
63
+ const { left, width } = this.getBoundingClientRect();
64
+ if (this.columnBounds?.left !== left || this.columnBounds.width !== width) {
65
+ this.columnBounds = { left, width };
66
+ }
67
+ };
56
68
  this.fallbackFired = false;
57
69
  this.seatsTask = new Task(this, {
58
70
  task: async ([client, attractionId, instanceId, locale, distributorID, currency,]) => {
@@ -139,6 +151,16 @@ let CorasSeatedSelector = class CorasSeatedSelector extends LitElement {
139
151
  };
140
152
  }
141
153
  static { this.styles = styles; }
154
+ connectedCallback() {
155
+ super.connectedCallback();
156
+ this.columnObserver.observe(this);
157
+ window.addEventListener("resize", this.measureColumn);
158
+ }
159
+ disconnectedCallback() {
160
+ super.disconnectedCallback();
161
+ this.columnObserver.disconnect();
162
+ window.removeEventListener("resize", this.measureColumn);
163
+ }
142
164
  get chartData() {
143
165
  const data = this.seatsTask.value;
144
166
  if (!data) {
@@ -222,8 +244,19 @@ let CorasSeatedSelector = class CorasSeatedSelector extends LitElement {
222
244
  }
223
245
  const { groups, fees, total } = buildSelectionSummary(this.selectedSeats, data.availableSeats, data.flatPriceBands, data.categories);
224
246
  const seatCount = this.selectedSeats.length;
247
+ const columnStyle = this.columnBounds
248
+ ? {
249
+ "--seated-drawer-left": `${this.columnBounds.left}px`,
250
+ "--seated-drawer-width": `${this.columnBounds.width}px`,
251
+ }
252
+ : {};
225
253
  return html `
226
- <div class="drawer" part="drawer" data-expanded=${this.sheetExpanded}>
254
+ <div
255
+ class="drawer"
256
+ part="drawer"
257
+ data-expanded=${this.sheetExpanded}
258
+ style=${styleMap(columnStyle)}
259
+ >
227
260
  <div class="drawer-inner">
228
261
  <button
229
262
  type="button"
@@ -369,6 +402,9 @@ __decorate([
369
402
  __decorate([
370
403
  state()
371
404
  ], CorasSeatedSelector.prototype, "sheetExpanded", void 0);
405
+ __decorate([
406
+ state()
407
+ ], CorasSeatedSelector.prototype, "columnBounds", void 0);
372
408
  CorasSeatedSelector = __decorate([
373
409
  localized()
374
410
  ], CorasSeatedSelector);
@@ -35,10 +35,8 @@ export default css `
35
35
  inset-inline: 0;
36
36
  bottom: 0;
37
37
  z-index: 20;
38
- display: flex;
39
- justify-content: center;
40
38
  box-sizing: border-box;
41
- padding: 24px clamp(16px, 4vw, 48px);
39
+ padding: 24px 0;
42
40
  background: var(--coras-color-background);
43
41
  border-top: 1px solid var(--coras-color-divider);
44
42
  box-shadow: var(--coras-shadow-top);
@@ -49,8 +47,9 @@ export default css `
49
47
  align-items: center;
50
48
  justify-content: space-between;
51
49
  gap: 24px;
52
- width: 100%;
53
- max-width: var(--coras-seated-max-width);
50
+ width: var(--seated-drawer-width, 100%);
51
+ margin-left: var(--seated-drawer-left, auto);
52
+ margin-right: auto;
54
53
  }
55
54
 
56
55
  .drawer-summary {
@@ -104,6 +103,8 @@ export default css `
104
103
  flex-direction: column;
105
104
  align-items: stretch;
106
105
  gap: 12px;
106
+ width: 100%;
107
+ margin: 0;
107
108
  }
108
109
 
109
110
  .sheet-handle {
@@ -35,7 +35,7 @@ export class CorasTourTicketTypeSelector extends LitElement {
35
35
  height="md"
36
36
  border-color="light"
37
37
  expanded
38
- ?shadow=${false}
38
+ .shadow=${false}
39
39
  ?error=${this.error}
40
40
  @click=${this.dropdownToggle}
41
41
  >
@@ -840,7 +840,7 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
840
840
  }
841
841
  else {
842
842
  this.openNavbarBasket();
843
- scrollToTop();
843
+ scrollToTop("smooth");
844
844
  }
845
845
  this.shouldRenderOptions = false;
846
846
  this.selectedPriceTypes = {};
@@ -1035,7 +1035,8 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
1035
1035
  @click="${async () => {
1036
1036
  await this.handleBasketModalToggle(this.selectedSectionId);
1037
1037
  this.isReservationPreviewModalOpened = false;
1038
- setTimeout(() => scrollToTop(), 0);
1038
+ const isMobile = window.matchMedia("(max-width: 800px)").matches;
1039
+ setTimeout(() => scrollToTop(isMobile ? "instant" : "smooth"), 0);
1039
1040
  }}"
1040
1041
  >
1041
1042
  ${msg("Add to basket")}
@@ -1292,7 +1293,7 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
1292
1293
  }
1293
1294
  else {
1294
1295
  this.openNavbarBasket();
1295
- scrollToTop();
1296
+ scrollToTop("smooth");
1296
1297
  }
1297
1298
  return true;
1298
1299
  }
@@ -1545,7 +1546,7 @@ let CorasDetailsPage = class CorasDetailsPage extends ErrorModalMixin(PointsMixi
1545
1546
  }
1546
1547
  else {
1547
1548
  this.openNavbarBasket();
1548
- scrollToTop();
1549
+ scrollToTop("smooth");
1549
1550
  }
1550
1551
  }
1551
1552
  get availabilityErrorCode() {
@@ -118,8 +118,8 @@ export declare const isBelowMinimumBookingSize: (totalTickets: number, minBookin
118
118
  */
119
119
  export declare const SECTION_GROUPING_THRESHOLD = 8;
120
120
  /**
121
- * Groups section options by their formatted ticket price, keeping the order in
122
- * which each price first appears.
121
+ * Groups section options by their formatted ticket price, ordered from the
122
+ * lowest price to the highest.
123
123
  */
124
124
  export declare const groupSectionsByPrice: ({ options, locale, currency, }: {
125
125
  options: components["schemas"]["AvailabilityItemModel"][];
@@ -96,27 +96,21 @@ export const calculateTotalPrice = (tickets) => {
96
96
  return sum + (ticket.full_price || 0);
97
97
  }, 0);
98
98
  };
99
- export const sumPricesAndFormat = ({ prices, locale, currency, }) => {
100
- if (!prices || prices.length === 0) {
101
- return convertToLocaleCurrency({
102
- value: 0,
103
- locale,
104
- currency,
105
- });
106
- }
99
+ const sumPrices = (prices, currency) => {
107
100
  let sum = 0;
108
- for (const priceItem of prices) {
101
+ for (const priceItem of prices ?? []) {
109
102
  if (priceItem.min_full_price &&
110
103
  typeof priceItem.min_full_price[currency] === "number") {
111
104
  sum += priceItem.min_full_price[currency];
112
105
  }
113
106
  }
114
- return convertToLocaleCurrency({
115
- value: sum,
116
- locale,
117
- currency,
118
- });
107
+ return sum;
119
108
  };
109
+ export const sumPricesAndFormat = ({ prices, locale, currency, }) => convertToLocaleCurrency({
110
+ value: sumPrices(prices, currency),
111
+ locale,
112
+ currency,
113
+ });
120
114
  export const isSingleDayAvailability = (salePeriods) => {
121
115
  if (!salePeriods || salePeriods.length === 0) {
122
116
  return false;
@@ -190,7 +184,11 @@ export const groupAvailabilityByTime = (items, locale) => {
190
184
  return groupItemsByTime(items, locale);
191
185
  };
192
186
  export const scrollToTop = (behavior = "instant") => {
193
- window.scrollTo({ top: 0, behavior });
187
+ const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
188
+ window.scrollTo({
189
+ top: 0,
190
+ behavior: prefersReducedMotion ? "instant" : behavior,
191
+ });
194
192
  };
195
193
  export const getAvailabilitySummary = (item, currency) => {
196
194
  const totalPrice = item.min_full_price[currency] ?? 0;
@@ -260,18 +258,23 @@ export const isBelowMinimumBookingSize = (totalTickets, minBookingSize) => total
260
258
  */
261
259
  export const SECTION_GROUPING_THRESHOLD = 8;
262
260
  /**
263
- * Groups section options by their formatted ticket price, keeping the order in
264
- * which each price first appears.
261
+ * Groups section options by their formatted ticket price, ordered from the
262
+ * lowest price to the highest.
265
263
  */
266
264
  export const groupSectionsByPrice = ({ options, locale, currency, }) => {
267
265
  const groups = new Map();
268
266
  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]);
267
+ const amount = sumPrices(option.prices, currency);
268
+ const price = convertToLocaleCurrency({ value: amount, locale, currency });
269
+ const group = groups.get(price) ?? { amount, sections: [] };
270
+ group.sections.push(option);
271
+ groups.set(price, group);
275
272
  }
276
- return Array.from(groups, ([price, sections]) => ({ price, sections }));
273
+ return Array.from(groups, ([price, { amount, sections }]) => ({
274
+ price,
275
+ amount,
276
+ sections,
277
+ }))
278
+ .sort((first, second) => first.amount - second.amount)
279
+ .map(({ price, sections }) => ({ price, sections }));
277
280
  };
@@ -119,6 +119,8 @@ export declare class CorasLandingPage extends CorasLandingPage_base {
119
119
  private renderShowMoreButton;
120
120
  private renderPoints;
121
121
  private renderAttractionCards;
122
+ private get resolvedCountry();
123
+ private renderLocationImage;
122
124
  private renderBreadcrumbs;
123
125
  private renderAttractionsSkeleton;
124
126
  private renderFiltersSkeleton;
@@ -223,7 +223,7 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(PointsMixi
223
223
  if (this.locationsData && (this.country || this.city)) {
224
224
  const matchingCountry = this.locationsData
225
225
  .flatMap((continent) => continent.countries ?? [])
226
- .find((country) => country?.slug === this.country);
226
+ .find((country) => country?.slug === this.resolvedCountry);
227
227
  const matchingCity = matchingCountry?.cities?.find((city) => city?.slug === this.city);
228
228
  const item = this.city && matchingCity
229
229
  ? { type: "city", value: this.city, name: matchingCity.name }
@@ -838,13 +838,34 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(PointsMixi
838
838
  </section>
839
839
  `;
840
840
  }
841
+ // The navbar search and a deep link give a city without its country; the
842
+ // locations response wraps the city in its country, so the slug comes from there.
843
+ get resolvedCountry() {
844
+ if (this.country || !this.city) {
845
+ return this.country;
846
+ }
847
+ return (this.locationsData
848
+ ?.flatMap((continent) => continent.countries ?? [])
849
+ .find((country) => country?.cities?.some((city) => city?.slug === this.city))?.slug ?? "");
850
+ }
851
+ renderLocationImage() {
852
+ if (this.city && !this.resolvedCountry) {
853
+ return nothing;
854
+ }
855
+ return html `
856
+ <coras-location-image
857
+ country=${this.resolvedCountry}
858
+ city=${this.city}
859
+ ></coras-location-image>
860
+ `;
861
+ }
841
862
  renderBreadcrumbs() {
842
863
  if (!this.city || !this.locationsData) {
843
864
  return nothing;
844
865
  }
845
866
  const matchingCountry = this.locationsData
846
867
  .flatMap((continent) => continent.countries ?? [])
847
- .find((country) => country?.slug === this.country);
868
+ .find((country) => country?.slug === this.resolvedCountry);
848
869
  if (!matchingCountry) {
849
870
  return nothing;
850
871
  }
@@ -855,7 +876,7 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(PointsMixi
855
876
  const handleCountryClick = () => {
856
877
  this.dispatchPageUpdate({
857
878
  page: "landing",
858
- country: this.country,
879
+ country: this.resolvedCountry,
859
880
  city: "",
860
881
  });
861
882
  };
@@ -917,11 +938,7 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(PointsMixi
917
938
  <coras-layout with-basket>
918
939
  <slot name="navbar" slot="navbar"></slot>
919
940
  <header class="hero-section">
920
- ${this.renderLocationSearchSelector()}
921
- <coras-location-image
922
- country=${this.country}
923
- city=${this.city}
924
- ></coras-location-image>
941
+ ${this.renderLocationSearchSelector()} ${this.renderLocationImage()}
925
942
  <div class="filters">
926
943
  ${this.renderDateSelector()} ${this.renderSortingSelectorDefault()}
927
944
  ${this.renderFiltersChip()}
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
- "version": "0.8.0",
23
+ "version": "0.8.1",
24
24
  "private": false,
25
25
  "homepage": "https://docs.coras.io",
26
26
  "bugs": {