@nok-integration/storefront-react 0.20.10 → 0.20.11

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.mjs CHANGED
@@ -6581,6 +6581,50 @@ function PriceBlock({ price: price2, compareAt: compareAt2, discountPct: discoun
6581
6581
  })]
6582
6582
  });
6583
6583
  }
6584
+ const STATE_KEY = "__daznShop";
6585
+ function current$1(name2) {
6586
+ if (typeof window === "undefined") return null;
6587
+ const state = window.history.state;
6588
+ const ours = state?.[STATE_KEY];
6589
+ if (!ours || ours.href !== window.location.href) return null;
6590
+ const value2 = ours[name2];
6591
+ return typeof value2 === "string" ? value2 : null;
6592
+ }
6593
+ function useInPlaceScreen(name2) {
6594
+ const [value2, setValue] = useState(() => current$1(name2));
6595
+ useEffect(() => {
6596
+ const onPop = () => setValue(current$1(name2));
6597
+ window.addEventListener("popstate", onPop);
6598
+ return () => window.removeEventListener("popstate", onPop);
6599
+ }, [name2]);
6600
+ const open = useCallback((next) => {
6601
+ const history = window.history;
6602
+ const state = history.state ?? {};
6603
+ const href = window.location.href;
6604
+ const ours = state[STATE_KEY]?.href === href ? state[STATE_KEY] : {};
6605
+ history.pushState({
6606
+ ...state,
6607
+ [STATE_KEY]: {
6608
+ ...ours,
6609
+ href,
6610
+ [name2]: next
6611
+ }
6612
+ }, "", href);
6613
+ setValue(next);
6614
+ }, [name2]);
6615
+ const close2 = useCallback(() => {
6616
+ if (current$1(name2) !== null) {
6617
+ window.history.back();
6618
+ return;
6619
+ }
6620
+ setValue(null);
6621
+ }, [name2]);
6622
+ return {
6623
+ value: value2,
6624
+ open,
6625
+ close: close2
6626
+ };
6627
+ }
6584
6628
  const timeline = "_timeline_1cum7_7";
6585
6629
  const row$8 = "_row_1cum7_15";
6586
6630
  const line$3 = "_line_1cum7_20";
@@ -7921,15 +7965,16 @@ function ChevronRight$1() {
7921
7965
  })
7922
7966
  });
7923
7967
  }
7968
+ const useBrowserLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
7924
7969
  function OrderTrackingView(props) {
7925
- const [flow, setFlow] = useState(null);
7926
- if (flow !== null) {
7970
+ const flow = useInPlaceScreen("returnFlow");
7971
+ if (flow.value !== null) {
7927
7972
  return jsx(ReturnFlowView, {
7928
7973
  orderRef: props.orderRef,
7929
- ...flow ? {
7930
- returnRef: flow
7974
+ ...flow.value ? {
7975
+ returnRef: flow.value
7931
7976
  } : {},
7932
- onDone: () => setFlow(null)
7977
+ onDone: flow.close
7933
7978
  });
7934
7979
  }
7935
7980
  return jsx(ShopSurface, {
@@ -7937,8 +7982,8 @@ function OrderTrackingView(props) {
7937
7982
  fill: true,
7938
7983
  children: jsx(OrderTrackingContent, {
7939
7984
  ...props,
7940
- onStartReturn: props.onStartReturn ?? (() => setFlow("")),
7941
- onOpenReturn: props.onOpenReturn ?? ((returnRef) => setFlow(returnRef))
7985
+ onStartReturn: props.onStartReturn ?? (() => flow.open("")),
7986
+ onOpenReturn: props.onOpenReturn ?? flow.open
7942
7987
  })
7943
7988
  });
7944
7989
  }
@@ -7969,6 +8014,11 @@ function OrderTrackingContent({ orderRef, locale: localeProp, onStartReturn, onO
7969
8014
  useEffect(() => {
7970
8015
  void load();
7971
8016
  }, [load]);
8017
+ const cancelled = order?.status === "cancelled";
8018
+ useBrowserLayoutEffect(() => {
8019
+ if (!cancelled) return;
8020
+ return anchorTop();
8021
+ }, [cancelled]);
7972
8022
  if (state === "loading") {
7973
8023
  return jsxs("div", {
7974
8024
  className: styles$y.page,
@@ -8446,11 +8496,11 @@ function Chevron() {
8446
8496
  });
8447
8497
  }
8448
8498
  function OrderListView(props) {
8449
- const [opened, setOpened] = useState(null);
8450
- if (opened !== null) {
8499
+ const opened = useInPlaceScreen("return");
8500
+ if (opened.value !== null) {
8451
8501
  return jsx(ReturnFlowView, {
8452
- returnRef: opened,
8453
- onDone: () => setOpened(null)
8502
+ returnRef: opened.value,
8503
+ onDone: opened.close
8454
8504
  });
8455
8505
  }
8456
8506
  return jsx(ShopSurface, {
@@ -8458,7 +8508,7 @@ function OrderListView(props) {
8458
8508
  fill: true,
8459
8509
  children: jsx(OrderListContent, {
8460
8510
  ...props,
8461
- onOpenReturn: props.onOpenReturn ?? setOpened
8511
+ onOpenReturn: props.onOpenReturn ?? opened.open
8462
8512
  })
8463
8513
  });
8464
8514
  }
@@ -6581,6 +6581,50 @@ function PriceBlock({ price: price2, compareAt: compareAt2, discountPct: discoun
6581
6581
  })]
6582
6582
  });
6583
6583
  }
6584
+ const STATE_KEY = "__daznShop";
6585
+ function current$1(name2) {
6586
+ if (typeof window === "undefined") return null;
6587
+ const state = window.history.state;
6588
+ const ours = state?.[STATE_KEY];
6589
+ if (!ours || ours.href !== window.location.href) return null;
6590
+ const value2 = ours[name2];
6591
+ return typeof value2 === "string" ? value2 : null;
6592
+ }
6593
+ function useInPlaceScreen(name2) {
6594
+ const [value2, setValue] = useState(() => current$1(name2));
6595
+ useEffect(() => {
6596
+ const onPop = () => setValue(current$1(name2));
6597
+ window.addEventListener("popstate", onPop);
6598
+ return () => window.removeEventListener("popstate", onPop);
6599
+ }, [name2]);
6600
+ const open = useCallback((next) => {
6601
+ const history = window.history;
6602
+ const state = history.state ?? {};
6603
+ const href = window.location.href;
6604
+ const ours = state[STATE_KEY]?.href === href ? state[STATE_KEY] : {};
6605
+ history.pushState({
6606
+ ...state,
6607
+ [STATE_KEY]: {
6608
+ ...ours,
6609
+ href,
6610
+ [name2]: next
6611
+ }
6612
+ }, "", href);
6613
+ setValue(next);
6614
+ }, [name2]);
6615
+ const close2 = useCallback(() => {
6616
+ if (current$1(name2) !== null) {
6617
+ window.history.back();
6618
+ return;
6619
+ }
6620
+ setValue(null);
6621
+ }, [name2]);
6622
+ return {
6623
+ value: value2,
6624
+ open,
6625
+ close: close2
6626
+ };
6627
+ }
6584
6628
  const timeline = "_timeline_1cum7_7";
6585
6629
  const row$8 = "_row_1cum7_15";
6586
6630
  const line$3 = "_line_1cum7_20";
@@ -7921,15 +7965,16 @@ function ChevronRight$1() {
7921
7965
  })
7922
7966
  });
7923
7967
  }
7968
+ const useBrowserLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
7924
7969
  function OrderTrackingView(props) {
7925
- const [flow, setFlow] = useState(null);
7926
- if (flow !== null) {
7970
+ const flow = useInPlaceScreen("returnFlow");
7971
+ if (flow.value !== null) {
7927
7972
  return jsx(ReturnFlowView, {
7928
7973
  orderRef: props.orderRef,
7929
- ...flow ? {
7930
- returnRef: flow
7974
+ ...flow.value ? {
7975
+ returnRef: flow.value
7931
7976
  } : {},
7932
- onDone: () => setFlow(null)
7977
+ onDone: flow.close
7933
7978
  });
7934
7979
  }
7935
7980
  return jsx(ShopSurface, {
@@ -7937,8 +7982,8 @@ function OrderTrackingView(props) {
7937
7982
  fill: true,
7938
7983
  children: jsx(OrderTrackingContent, {
7939
7984
  ...props,
7940
- onStartReturn: props.onStartReturn ?? (() => setFlow("")),
7941
- onOpenReturn: props.onOpenReturn ?? ((returnRef) => setFlow(returnRef))
7985
+ onStartReturn: props.onStartReturn ?? (() => flow.open("")),
7986
+ onOpenReturn: props.onOpenReturn ?? flow.open
7942
7987
  })
7943
7988
  });
7944
7989
  }
@@ -7969,6 +8014,11 @@ function OrderTrackingContent({ orderRef, locale: localeProp, onStartReturn, onO
7969
8014
  useEffect(() => {
7970
8015
  void load();
7971
8016
  }, [load]);
8017
+ const cancelled = order?.status === "cancelled";
8018
+ useBrowserLayoutEffect(() => {
8019
+ if (!cancelled) return;
8020
+ return anchorTop();
8021
+ }, [cancelled]);
7972
8022
  if (state === "loading") {
7973
8023
  return jsxs("div", {
7974
8024
  className: styles$y.page,
@@ -8446,11 +8496,11 @@ function Chevron() {
8446
8496
  });
8447
8497
  }
8448
8498
  function OrderListView(props) {
8449
- const [opened, setOpened] = useState(null);
8450
- if (opened !== null) {
8499
+ const opened = useInPlaceScreen("return");
8500
+ if (opened.value !== null) {
8451
8501
  return jsx(ReturnFlowView, {
8452
- returnRef: opened,
8453
- onDone: () => setOpened(null)
8502
+ returnRef: opened.value,
8503
+ onDone: opened.close
8454
8504
  });
8455
8505
  }
8456
8506
  return jsx(ShopSurface, {
@@ -8458,7 +8508,7 @@ function OrderListView(props) {
8458
8508
  fill: true,
8459
8509
  children: jsx(OrderListContent, {
8460
8510
  ...props,
8461
- onOpenReturn: props.onOpenReturn ?? setOpened
8511
+ onOpenReturn: props.onOpenReturn ?? opened.open
8462
8512
  })
8463
8513
  });
8464
8514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.20.10",
3
+ "version": "0.20.11",
4
4
  "description": "Mountable React storefront components: catalogue, product detail and cart, mounted directly into a host DOM tree. No iframe.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",