@travelswitchhq/flight-search-react 1.2.3 → 1.2.5

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/index.cjs CHANGED
@@ -64,6 +64,41 @@ var buildEncryptedToken = (domainName) => {
64
64
  const encrypted = encryptor.encrypt(payload);
65
65
  return typeof encrypted === "string" ? encrypted : null;
66
66
  };
67
+ var MACHINE_ID_STORAGE_KEY = "MacId";
68
+ var generateUuid = () => {
69
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
70
+ return crypto.randomUUID();
71
+ }
72
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
73
+ const r = Math.random() * 16 | 0;
74
+ return (c === "x" ? r : r & 3 | 8).toString(16);
75
+ });
76
+ };
77
+ var getMachineId = () => {
78
+ try {
79
+ let machineId = localStorage.getItem(MACHINE_ID_STORAGE_KEY);
80
+ if (!machineId) {
81
+ machineId = generateUuid();
82
+ localStorage.setItem(MACHINE_ID_STORAGE_KEY, machineId);
83
+ }
84
+ return machineId;
85
+ } catch {
86
+ return generateUuid();
87
+ }
88
+ };
89
+ var generateTokenKey = (domainName) => {
90
+ const domain = normalizeDomainName(domainName);
91
+ const affiliateId = "";
92
+ const loggedInUserId = "";
93
+ const orgId = "";
94
+ return [domain, (/* @__PURE__ */ new Date()).getTime(), affiliateId, loggedInUserId, orgId, "", "", getMachineId()].join("~");
95
+ };
96
+ var buildEncryptedTokenKey = (domainName) => {
97
+ const encryptor = new import_jsencrypt.JSEncrypt();
98
+ encryptor.setPublicKey(RSA_PUBLIC_KEY);
99
+ const encrypted = encryptor.encrypt(generateTokenKey(domainName));
100
+ return typeof encrypted === "string" ? encrypted : "";
101
+ };
67
102
  var PRIMEICONS_LINK_ID = "tfsw-primeicons";
68
103
  var RSA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
69
104
  MIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgB0rRSHGZK/FtK15IRfQxtl
@@ -233,7 +268,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
233
268
  if (!searchKeyword.trim()) return [];
234
269
  const url = `${airportSearchApiBaseUrl.replace(/\/$/, "")}/Airport/GetList/${encodeURIComponent(langCode)}/${encodeURIComponent(searchKeyword.trim())}`;
235
270
  try {
236
- const res = await fetch(url);
271
+ const res = await fetch(url, { headers: { Token: buildEncryptedTokenKey(redirectionDomain ?? "") } });
237
272
  if (!res.ok) return [];
238
273
  const data = await res.json();
239
274
  if (Array.isArray(data)) return data;
@@ -243,7 +278,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
243
278
  } catch {
244
279
  return [];
245
280
  }
246
- }, [airportSearchApiBaseUrl, langCode]);
281
+ }, [airportSearchApiBaseUrl, langCode, redirectionDomain]);
247
282
  const getAirlineListBySearch = (0, import_react.useCallback)(async (searchKeyword) => {
248
283
  if (!searchKeyword.trim()) return [];
249
284
  const lang = (langCode ?? "en").toUpperCase();
@@ -446,6 +481,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
446
481
  (0, import_react.useEffect)(() => {
447
482
  const handleClickOutside = (event) => {
448
483
  const target = event.target;
484
+ if (target.closest("[data-tfsw-sheet]")) return;
449
485
  const isInsidePrimeDropdown = Boolean(
450
486
  target.closest(".p-dropdown-panel") || target.closest(".p-dropdown-items-wrapper") || target.closest(".p-dropdown-item") || target.closest('[data-pc-section="panel"]') || target.closest('[data-pc-name="dropdown"]')
451
487
  );
@@ -3004,6 +3040,7 @@ function FlightSearchFormStandard({
3004
3040
 
3005
3041
  // src/modern/Modern.tsx
3006
3042
  var import_react3 = require("react");
3043
+ var import_react_dom = require("react-dom");
3007
3044
  var import_calendar2 = require("primereact/calendar");
3008
3045
  var import_api2 = require("primereact/api");
3009
3046
 
@@ -3830,6 +3867,13 @@ var modernStyles = `
3830
3867
  font-size: 15px;
3831
3868
  }
3832
3869
 
3870
+ /* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
3871
+ variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
3872
+ .mdrn_root.mdrn_portal {
3873
+ --mdrn-z: 2147483000;
3874
+ display: contents;
3875
+ }
3876
+
3833
3877
  /* Dropdowns become full-screen sheets */
3834
3878
  .mdrn_dropdown,
3835
3879
  .mdrn_panel {
@@ -4062,6 +4106,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
4062
4106
  if (fontName) style["--mdrn-font"] = fontName;
4063
4107
  return style;
4064
4108
  }, [theme?.primary, theme?.primaryLight, fontName]);
4109
+ const [isMobile, setIsMobile] = (0, import_react3.useState)(false);
4110
+ (0, import_react3.useEffect)(() => {
4111
+ const query = window.matchMedia("(max-width: 1024px)");
4112
+ const sync = () => setIsMobile(query.matches);
4113
+ sync();
4114
+ query.addEventListener("change", sync);
4115
+ return () => query.removeEventListener("change", sync);
4116
+ }, []);
4117
+ const renderSheet = (sheet) => isMobile ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_root mdrn_portal", style: themeStyle, "data-tfsw-sheet": "", children: sheet }), document.body) : sheet;
4118
+ const [calendarHost, setCalendarHost] = (0, import_react3.useState)(null);
4119
+ const [openMobileCalendar, setOpenMobileCalendar] = (0, import_react3.useState)(null);
4120
+ const mobileCalendarProps = (key) => ({
4121
+ appendTo: calendarHost ?? "self",
4122
+ onShow: () => setOpenMobileCalendar(key),
4123
+ onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
4124
+ });
4125
+ (0, import_react3.useEffect)(() => setOpenMobileCalendar(null), [tripType, segments.length]);
4126
+ const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
4127
+ (0, import_react3.useEffect)(() => {
4128
+ if (!isSheetOpen) return;
4129
+ const { body } = document;
4130
+ const previousOverflow = body.style.overflow;
4131
+ body.style.overflow = "hidden";
4132
+ return () => {
4133
+ body.style.overflow = previousOverflow;
4134
+ };
4135
+ }, [isSheetOpen]);
4065
4136
  const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
4066
4137
  const first = segments[0];
4067
4138
  const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
@@ -4122,44 +4193,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
4122
4193
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
4123
4194
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
4124
4195
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ...inputProps, id: `${inputId}-mobile`, readOnly: true, className: "mdrn_input mdrn_mobile-only" }),
4125
- isOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_dropdown", children: [
4126
- renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4127
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4128
- "input",
4129
- {
4130
- type: "search",
4131
- autoFocus: true,
4132
- placeholder: `Search ${placeholder.toLowerCase()}`,
4133
- value: value === placeholder ? "" : value,
4134
- onChange: (e) => onSearch(e.target.value),
4135
- onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4136
- }
4137
- ) }),
4138
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4139
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4140
- const isActive = results.length > 0 && selectedIndex === i;
4141
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
4142
- "li",
4196
+ isOpen && renderSheet(
4197
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_dropdown", children: [
4198
+ renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4199
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4200
+ "input",
4143
4201
  {
4144
- role: "option",
4145
- "aria-selected": isActive,
4146
- className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4147
- onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4148
- children: [
4149
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4150
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-text", children: [
4151
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4152
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-place", children: [
4153
- airport.ct,
4154
- airport.cn ? `, ${airport.cn}` : ""
4202
+ type: "search",
4203
+ autoFocus: true,
4204
+ placeholder: `Search ${placeholder.toLowerCase()}`,
4205
+ value: value === placeholder ? "" : value,
4206
+ onChange: (e) => onSearch(e.target.value),
4207
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4208
+ }
4209
+ ) }),
4210
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4211
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4212
+ const isActive = results.length > 0 && selectedIndex === i;
4213
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
4214
+ "li",
4215
+ {
4216
+ role: "option",
4217
+ "aria-selected": isActive,
4218
+ className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4219
+ onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4220
+ children: [
4221
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4222
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-text", children: [
4223
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4224
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-place", children: [
4225
+ airport.ct,
4226
+ airport.cn ? `, ${airport.cn}` : ""
4227
+ ] })
4155
4228
  ] })
4156
- ] })
4157
- ]
4158
- },
4159
- airport.id ?? airport.ac ?? i
4160
- );
4161
- }) })
4162
- ] })
4229
+ ]
4230
+ },
4231
+ airport.id ?? airport.ac ?? i
4232
+ );
4233
+ }) })
4234
+ ] })
4235
+ )
4163
4236
  ] })
4164
4237
  ] });
4165
4238
  };
@@ -4203,7 +4276,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4203
4276
  {
4204
4277
  ref: mobileDateRangeCalendarRef,
4205
4278
  numberOfMonths: 10,
4206
- appendTo: "self",
4279
+ ...mobileCalendarProps("round-trip"),
4207
4280
  selectionMode: "range",
4208
4281
  readOnlyInput: true,
4209
4282
  value: first?.dateRange ?? null,
@@ -4249,7 +4322,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4249
4322
  {
4250
4323
  ref: oneWayMobileCalendarRef,
4251
4324
  numberOfMonths: 10,
4252
- appendTo: "self",
4325
+ ...mobileCalendarProps("one-way"),
4253
4326
  readOnlyInput: true,
4254
4327
  value: first?.departureDate ?? null,
4255
4328
  minDate: /* @__PURE__ */ new Date(),
@@ -4293,7 +4366,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4293
4366
  segmentMobileCalendarRefs.current[index] = el;
4294
4367
  },
4295
4368
  numberOfMonths: 10,
4296
- appendTo: "self",
4369
+ ...mobileCalendarProps(`segment-${index}`),
4297
4370
  readOnlyInput: true,
4298
4371
  value: segment.departureDate ?? null,
4299
4372
  minDate: getMinDateForSegment(index),
@@ -4320,49 +4393,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
4320
4393
  ]
4321
4394
  }
4322
4395
  ),
4323
- isRoomsGuestsMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4324
- renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4325
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-body", children: [
4326
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4327
- PASSENGER_ROWS.map((row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-row", children: [
4328
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-info", children: [
4329
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-label", children: row.label }),
4330
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-hint", children: row.hint })
4331
- ] }),
4332
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4333
- const isActive = (first?.[row.field] ?? 0) === count;
4334
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4335
- "button",
4396
+ isRoomsGuestsMenuOpen && renderSheet(
4397
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4398
+ renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4399
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-body", children: [
4400
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4401
+ PASSENGER_ROWS.map((row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-row", children: [
4402
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-info", children: [
4403
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-label", children: row.label }),
4404
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-hint", children: row.hint })
4405
+ ] }),
4406
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4407
+ const isActive = (first?.[row.field] ?? 0) === count;
4408
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4409
+ "button",
4410
+ {
4411
+ type: "button",
4412
+ className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4413
+ disabled: isPassengerOptionDisabled(row.field, count),
4414
+ onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4415
+ children: count
4416
+ },
4417
+ count
4418
+ );
4419
+ }) })
4420
+ ] }, row.field)),
4421
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4422
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "mdrn_chip", children: [
4423
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4424
+ "input",
4336
4425
  {
4337
- type: "button",
4338
- className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4339
- disabled: isPassengerOptionDisabled(row.field, count),
4340
- onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4341
- children: count
4342
- },
4343
- count
4344
- );
4345
- }) })
4346
- ] }, row.field)),
4347
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4348
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "mdrn_chip", children: [
4349
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4350
- "input",
4351
- {
4352
- type: "radio",
4353
- name: `${uid}-travel-class`,
4354
- checked: (first?.travelerClass ?? "Economy") === travelClass,
4355
- onChange: () => handleTravellerChange("travelerClass", travelClass)
4356
- }
4357
- ),
4358
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: travelClass })
4359
- ] }, travelClass)) })
4360
- ] }),
4361
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-foot", children: [
4362
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4363
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4426
+ type: "radio",
4427
+ name: `${uid}-travel-class`,
4428
+ checked: (first?.travelerClass ?? "Economy") === travelClass,
4429
+ onChange: () => handleTravellerChange("travelerClass", travelClass)
4430
+ }
4431
+ ),
4432
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: travelClass })
4433
+ ] }, travelClass)) })
4434
+ ] }),
4435
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-foot", children: [
4436
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4437
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4438
+ ] })
4364
4439
  ] })
4365
- ] })
4440
+ )
4366
4441
  ] });
4367
4442
  const searchButton = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "submit", className: "mdrn_search", children: "Search" });
4368
4443
  const renderMultiCity = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_mc", children: [
@@ -4443,7 +4518,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
4443
4518
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
4444
4519
  label
4445
4520
  ] }, key)) })
4446
- ] })
4521
+ ] }),
4522
+ isMobile && (0, import_react_dom.createPortal)(
4523
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_root mdrn_portal", style: themeStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_calendar", ref: setCalendarHost }) }),
4524
+ document.body
4525
+ )
4447
4526
  ] }) });
4448
4527
  }
4449
4528