ublo-lib 1.50.11 → 1.50.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cart-transfer.d.ts","sourceRoot":"","sources":["../../../src/common/components/cart-transfer.tsx"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,UAAU,YAAY,QAgCnC"}
1
+ {"version":3,"file":"cart-transfer.d.ts","sourceRoot":"","sources":["../../../src/common/components/cart-transfer.tsx"],"names":[],"mappings":"AAaA,MAAM,CAAC,OAAO,UAAU,YAAY,QAYnC"}
@@ -1,45 +1,71 @@
1
1
  import * as React from "react";
2
2
  import getConfig from "next/config";
3
- const STORAGE_KEY = "cartId";
3
+ const PARAM = "msemSession";
4
+ const KEYS = ["cartId", "cartIds", "resort", "stay", "paxplan"];
5
+ const { domains = {} } = getConfig().publicRuntimeConfig;
6
+ const hosts = Object.values(domains).filter(Boolean);
7
+ if (typeof window !== "undefined" && hosts.length > 1)
8
+ receiveSession();
4
9
  export default function CartTransfer() {
5
10
  React.useEffect(() => {
6
- const { domains } = getConfig()?.publicRuntimeConfig ?? {};
7
- const hosts = Object.values(domains ?? {}).filter(Boolean);
8
11
  if (hosts.length < 2)
9
12
  return;
10
- receiveCartId();
11
- const addCartId = (e) => {
12
- const a = e.target?.closest?.("a[href]");
13
- if (!a || a.host === location.host || !hosts.includes(a.host))
14
- return;
15
- try {
16
- const storedCartId = window.sessionStorage.getItem(STORAGE_KEY);
17
- if (!storedCartId)
18
- return;
19
- const url = new URL(a.href);
20
- url.searchParams.set(STORAGE_KEY, String(JSON.parse(storedCartId)));
21
- a.href = url.toString();
22
- }
23
- catch (e) { }
24
- };
25
- document.addEventListener("click", addCartId, true);
26
- document.addEventListener("auxclick", addCartId, true);
13
+ document.addEventListener("click", onLinkClick, true);
14
+ document.addEventListener("auxclick", onLinkClick, true);
27
15
  return () => {
28
- document.removeEventListener("click", addCartId, true);
29
- document.removeEventListener("auxclick", addCartId, true);
16
+ document.removeEventListener("click", onLinkClick, true);
17
+ document.removeEventListener("auxclick", onLinkClick, true);
30
18
  };
31
19
  }, []);
32
20
  return null;
33
21
  }
34
- function receiveCartId() {
22
+ function onLinkClick(e) {
23
+ const link = e.target.closest("a[href]");
24
+ if (e.defaultPrevented || !link || !isOtherLangLink(link))
25
+ return;
26
+ if (!sessionStorage.getItem("cartId"))
27
+ return;
28
+ const url = new URL(link.href);
29
+ url.searchParams.set(PARAM, JSON.stringify(readSession()));
30
+ if (isPlainClick(e, link)) {
31
+ e.preventDefault();
32
+ location.assign(url);
33
+ }
34
+ else {
35
+ link.href = url.toString();
36
+ }
37
+ }
38
+ function readSession() {
39
+ const session = {};
40
+ for (const key of KEYS) {
41
+ const value = sessionStorage.getItem(key);
42
+ if (value)
43
+ session[key] = JSON.parse(value);
44
+ }
45
+ return session;
46
+ }
47
+ function receiveSession() {
35
48
  try {
36
- const url = new URL(window.location.href);
37
- const cartId = url.searchParams.get(STORAGE_KEY);
38
- if (!cartId)
49
+ const url = new URL(location.href);
50
+ const param = url.searchParams.get(PARAM);
51
+ if (!param)
39
52
  return;
40
- window.sessionStorage.setItem(STORAGE_KEY, JSON.stringify(cartId));
41
- url.searchParams.delete(STORAGE_KEY);
42
- window.history.replaceState(window.history.state, "", url);
53
+ const session = JSON.parse(param);
54
+ for (const key of KEYS) {
55
+ if (key in session) {
56
+ sessionStorage.setItem(key, JSON.stringify(session[key]));
57
+ }
58
+ }
59
+ url.searchParams.delete(PARAM);
60
+ history.replaceState(history.state, "", url);
43
61
  }
44
- catch (e) { }
62
+ catch { }
63
+ }
64
+ function isOtherLangLink(link) {
65
+ return link.host !== location.host && hosts.includes(link.host);
66
+ }
67
+ function isPlainClick(e, link) {
68
+ const modified = e.metaKey || e.ctrlKey || e.shiftKey || e.altKey;
69
+ const sameTab = !link.target || link.target === "_self";
70
+ return e.type === "click" && e.button === 0 && !modified && sameTab;
45
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.50.11",
3
+ "version": "1.50.12",
4
4
  "peerDependencies": {
5
5
  "classnames": "^2.5.1",
6
6
  "dt-design-system": "^3.12.0",