@nok-integration/storefront-react 0.20.6 → 0.20.8

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
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, useLayoutEffect, Fragment as Fragment$1 } from "react";
4
4
  var client = {};
5
5
  var catalog = {};
6
6
  var zod = {};
@@ -5189,8 +5189,8 @@ function resolveAssetUrl(src, base) {
5189
5189
  const MAX_AGE_MS = 5 * 6e4;
5190
5190
  const CAPACITY = 60;
5191
5191
  class ProductCache {
5192
- constructor(now2 = () => Date.now()) {
5193
- this.now = now2;
5192
+ constructor(now = () => Date.now()) {
5193
+ this.now = now;
5194
5194
  }
5195
5195
  now;
5196
5196
  entries = /* @__PURE__ */ new Map();
@@ -5702,7 +5702,17 @@ function useTopOffset(ref, property, enabled = true) {
5702
5702
  };
5703
5703
  }, [ref, property, enabled]);
5704
5704
  }
5705
- const HOLD_MS = 1e3;
5705
+ const HOLD_MS = 2500;
5706
+ function withoutRestoration() {
5707
+ const history = typeof window !== "undefined" ? window.history : void 0;
5708
+ if (!history || !("scrollRestoration" in history)) return () => {
5709
+ };
5710
+ const previous = history.scrollRestoration;
5711
+ history.scrollRestoration = "manual";
5712
+ return () => {
5713
+ history.scrollRestoration = previous;
5714
+ };
5715
+ }
5706
5716
  const RELEASES = ["touchstart", "wheel", "keydown", "pointerdown"];
5707
5717
  function anchorTop(shouldHold = () => true) {
5708
5718
  let released = false;
@@ -5730,14 +5740,7 @@ function anchorTop(shouldHold = () => true) {
5730
5740
  });
5731
5741
  return release;
5732
5742
  }
5733
- const TRAVERSAL_WINDOW_MS = 1e3;
5734
- const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
5735
- let lastTraversal = -Infinity;
5736
- if (typeof window !== "undefined") {
5737
- window.addEventListener("popstate", () => {
5738
- lastTraversal = now();
5739
- });
5740
- }
5743
+ const useMountEffect$1 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5741
5744
  function documentTop(el) {
5742
5745
  let top2 = 0;
5743
5746
  for (let node = el; node; node = node.offsetParent) {
@@ -5749,11 +5752,15 @@ function beginsOnTheFirstViewport(el) {
5749
5752
  return documentTop(el) < window.innerHeight;
5750
5753
  }
5751
5754
  function useScreenAnchor(ref, enabled = true) {
5752
- useEffect(() => {
5755
+ useMountEffect$1(() => {
5753
5756
  const el = ref.current;
5754
5757
  if (!el || !enabled) return;
5755
- if (now() - lastTraversal < TRAVERSAL_WINDOW_MS) return;
5756
- return anchorTop(() => beginsOnTheFirstViewport(el));
5758
+ const restore = withoutRestoration();
5759
+ const release = anchorTop(() => beginsOnTheFirstViewport(el));
5760
+ return () => {
5761
+ release();
5762
+ restore();
5763
+ };
5757
5764
  }, [ref, enabled]);
5758
5765
  }
5759
5766
  const ShopSurface = forwardRef(function ShopSurface2({ tone, fill: fill2 = false, children, className, ...rest }, ref) {
@@ -10358,14 +10365,14 @@ function formatRemaining(ms) {
10358
10365
  return `${hh}:${mm}:${ss}`;
10359
10366
  }
10360
10367
  function PromoBanner({ promo: promo2 }) {
10361
- const [now2, setNow] = useState(null);
10368
+ const [now, setNow] = useState(null);
10362
10369
  useEffect(() => {
10363
10370
  if (!promo2.ends_at) return;
10364
10371
  setNow(Date.now());
10365
10372
  const id = setInterval(() => setNow(Date.now()), 1e3);
10366
10373
  return () => clearInterval(id);
10367
10374
  }, [promo2.ends_at]);
10368
- const remaining = promo2.ends_at && now2 !== null ? new Date(promo2.ends_at).getTime() - now2 : null;
10375
+ const remaining = promo2.ends_at && now !== null ? new Date(promo2.ends_at).getTime() - now : null;
10369
10376
  const showTimer = remaining !== null && remaining > 0;
10370
10377
  return jsxs("div", {
10371
10378
  className: styles$b.banner,
@@ -11274,8 +11281,9 @@ const styles$2 = {
11274
11281
  cta,
11275
11282
  mosaic
11276
11283
  };
11284
+ const useMountEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11277
11285
  function useDocumentSnap(ref, enabled = true) {
11278
- useEffect(() => {
11286
+ useMountEffect(() => {
11279
11287
  const el = ref.current;
11280
11288
  if (!el || !enabled || typeof document === "undefined") return;
11281
11289
  const root2 = document.documentElement;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, useLayoutEffect, Fragment as Fragment$1 } from "react";
4
4
  var client = {};
5
5
  var catalog = {};
6
6
  var zod = {};
@@ -5189,8 +5189,8 @@ function resolveAssetUrl(src, base) {
5189
5189
  const MAX_AGE_MS = 5 * 6e4;
5190
5190
  const CAPACITY = 60;
5191
5191
  class ProductCache {
5192
- constructor(now2 = () => Date.now()) {
5193
- this.now = now2;
5192
+ constructor(now = () => Date.now()) {
5193
+ this.now = now;
5194
5194
  }
5195
5195
  now;
5196
5196
  entries = /* @__PURE__ */ new Map();
@@ -5702,7 +5702,17 @@ function useTopOffset(ref, property, enabled = true) {
5702
5702
  };
5703
5703
  }, [ref, property, enabled]);
5704
5704
  }
5705
- const HOLD_MS = 1e3;
5705
+ const HOLD_MS = 2500;
5706
+ function withoutRestoration() {
5707
+ const history = typeof window !== "undefined" ? window.history : void 0;
5708
+ if (!history || !("scrollRestoration" in history)) return () => {
5709
+ };
5710
+ const previous = history.scrollRestoration;
5711
+ history.scrollRestoration = "manual";
5712
+ return () => {
5713
+ history.scrollRestoration = previous;
5714
+ };
5715
+ }
5706
5716
  const RELEASES = ["touchstart", "wheel", "keydown", "pointerdown"];
5707
5717
  function anchorTop(shouldHold = () => true) {
5708
5718
  let released = false;
@@ -5730,14 +5740,7 @@ function anchorTop(shouldHold = () => true) {
5730
5740
  });
5731
5741
  return release;
5732
5742
  }
5733
- const TRAVERSAL_WINDOW_MS = 1e3;
5734
- const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
5735
- let lastTraversal = -Infinity;
5736
- if (typeof window !== "undefined") {
5737
- window.addEventListener("popstate", () => {
5738
- lastTraversal = now();
5739
- });
5740
- }
5743
+ const useMountEffect$1 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5741
5744
  function documentTop(el) {
5742
5745
  let top2 = 0;
5743
5746
  for (let node = el; node; node = node.offsetParent) {
@@ -5749,11 +5752,15 @@ function beginsOnTheFirstViewport(el) {
5749
5752
  return documentTop(el) < window.innerHeight;
5750
5753
  }
5751
5754
  function useScreenAnchor(ref, enabled = true) {
5752
- useEffect(() => {
5755
+ useMountEffect$1(() => {
5753
5756
  const el = ref.current;
5754
5757
  if (!el || !enabled) return;
5755
- if (now() - lastTraversal < TRAVERSAL_WINDOW_MS) return;
5756
- return anchorTop(() => beginsOnTheFirstViewport(el));
5758
+ const restore = withoutRestoration();
5759
+ const release = anchorTop(() => beginsOnTheFirstViewport(el));
5760
+ return () => {
5761
+ release();
5762
+ restore();
5763
+ };
5757
5764
  }, [ref, enabled]);
5758
5765
  }
5759
5766
  const ShopSurface = forwardRef(function ShopSurface2({ tone, fill: fill2 = false, children, className, ...rest }, ref) {
@@ -10358,14 +10365,14 @@ function formatRemaining(ms) {
10358
10365
  return `${hh}:${mm}:${ss}`;
10359
10366
  }
10360
10367
  function PromoBanner({ promo: promo2 }) {
10361
- const [now2, setNow] = useState(null);
10368
+ const [now, setNow] = useState(null);
10362
10369
  useEffect(() => {
10363
10370
  if (!promo2.ends_at) return;
10364
10371
  setNow(Date.now());
10365
10372
  const id = setInterval(() => setNow(Date.now()), 1e3);
10366
10373
  return () => clearInterval(id);
10367
10374
  }, [promo2.ends_at]);
10368
- const remaining = promo2.ends_at && now2 !== null ? new Date(promo2.ends_at).getTime() - now2 : null;
10375
+ const remaining = promo2.ends_at && now !== null ? new Date(promo2.ends_at).getTime() - now : null;
10369
10376
  const showTimer = remaining !== null && remaining > 0;
10370
10377
  return jsxs("div", {
10371
10378
  className: styles$b.banner,
@@ -11274,8 +11281,9 @@ const styles$2 = {
11274
11281
  cta,
11275
11282
  mosaic
11276
11283
  };
11284
+ const useMountEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11277
11285
  function useDocumentSnap(ref, enabled = true) {
11278
- useEffect(() => {
11286
+ useMountEffect(() => {
11279
11287
  const el = ref.current;
11280
11288
  if (!el || !enabled || typeof document === "undefined") return;
11281
11289
  const root2 = document.documentElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.20.6",
3
+ "version": "0.20.8",
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",