@shopify/shop-minis-react 0.1.5 → 0.1.7
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/_virtual/index10.js +2 -2
- package/dist/_virtual/index5.js +2 -3
- package/dist/_virtual/index5.js.map +1 -1
- package/dist/_virtual/index6.js +3 -2
- package/dist/_virtual/index6.js.map +1 -1
- package/dist/_virtual/index7.js +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/components/atoms/list.js +106 -41
- package/dist/components/atoms/list.js.map +1 -1
- package/dist/components/commerce/add-to-cart.js +82 -0
- package/dist/components/commerce/add-to-cart.js.map +1 -0
- package/dist/components/{atoms → commerce}/favorite-button.js +1 -1
- package/dist/components/commerce/favorite-button.js.map +1 -0
- package/dist/components/commerce/product-card.js +10 -10
- package/dist/components/commerce/product-card.js.map +1 -1
- package/dist/components/commerce/product-link.js +6 -6
- package/dist/components/commerce/product-link.js.map +1 -1
- package/dist/index.js +276 -274
- package/dist/index.js.map +1 -1
- package/dist/internal/components/refresh-indicator.js +83 -0
- package/dist/internal/components/refresh-indicator.js.map +1 -0
- package/dist/internal/usePullToRefresh.js +149 -0
- package/dist/internal/usePullToRefresh.js.map +1 -0
- package/dist/internal/utils/virtuoso-dom.js +20 -0
- package/dist/internal/utils/virtuoso-dom.js.map +1 -0
- package/dist/mocks.js +1 -0
- package/dist/mocks.js.map +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/@radix-ui_react-use-is-hydrated@0.1.0_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/@videojs_xhr@2.7.0/node_modules/@videojs/xhr/lib/index.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/@xmldom_xmldom@0.8.10/node_modules/@xmldom/xmldom/lib/index.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PopChild.js +55 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PopChild.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PresenceChild.js +35 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PresenceChild.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/index.js +46 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/index.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/utils.js +13 -0
- package/dist/shop-minis-react/node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/utils.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/mpd-parser@1.3.1/node_modules/mpd-parser/dist/mpd-parser.es.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.1.0/node_modules/use-sync-external-store/shim/index.js +1 -1
- package/package.json +2 -2
- package/src/components/atoms/list.tsx +97 -12
- package/src/components/commerce/add-to-cart.test.tsx +73 -0
- package/src/components/commerce/add-to-cart.tsx +132 -0
- package/src/components/{atoms → commerce}/favorite-button.tsx +1 -1
- package/src/components/commerce/product-card.tsx +2 -1
- package/src/components/commerce/product-link.test.tsx +1 -0
- package/src/components/commerce/product-link.tsx +2 -1
- package/src/components/index.ts +2 -1
- package/src/internal/components/refresh-indicator.tsx +103 -0
- package/src/internal/usePullToRefresh.ts +286 -0
- package/src/internal/utils/virtuoso-dom.ts +26 -0
- package/src/mocks.ts +1 -0
- package/src/stories/AddToCart.stories.tsx +186 -0
- package/src/stories/FavoriteButton.stories.tsx +2 -2
- package/src/stories/PullToRefreshList.stories.tsx +122 -0
- package/src/styles/animations.css +54 -0
- package/src/test-utils.tsx +1 -0
- package/dist/components/atoms/favorite-button.js.map +0 -1
- /package/src/components/{atoms → commerce}/favorite-button.test.tsx +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as x, useState as y, useEffect as h } from "react";
|
|
3
|
+
import { cn as o } from "../../lib/utils.js";
|
|
4
|
+
const b = x(({ pullDistance: l, threshold: i, isRefreshing: t, canRefresh: n, className: m }, c) => {
|
|
5
|
+
const [a, s] = y(!1), e = Math.min(l / i, 1), p = 0.54 + e * (1 - 0.54), u = t ? 1 : 0.5 + e * 0.5, d = t ? 1 : Math.min(e * 1.5, 1), f = t ? 0 : e * 3;
|
|
6
|
+
return h(() => {
|
|
7
|
+
if (t && !a) {
|
|
8
|
+
s(!0);
|
|
9
|
+
const w = setTimeout(() => s(!1), 360);
|
|
10
|
+
return () => clearTimeout(w);
|
|
11
|
+
}
|
|
12
|
+
}, [t, a]), /* @__PURE__ */ r(
|
|
13
|
+
"div",
|
|
14
|
+
{
|
|
15
|
+
ref: c,
|
|
16
|
+
className: o(
|
|
17
|
+
"flex items-center justify-center w-full h-full",
|
|
18
|
+
"transition-all duration-200 ease-out",
|
|
19
|
+
m
|
|
20
|
+
),
|
|
21
|
+
style: {
|
|
22
|
+
transform: `translateY(${f}px)`
|
|
23
|
+
},
|
|
24
|
+
children: /* @__PURE__ */ r(
|
|
25
|
+
"div",
|
|
26
|
+
{
|
|
27
|
+
className: o(
|
|
28
|
+
"flex flex-col items-center space-y-2 rounded-full px-4 py-2 backdrop-blur-sm transition-all duration-200",
|
|
29
|
+
n || t ? "bg-primary/20 border-2 border-primary/40" : "bg-background/90"
|
|
30
|
+
),
|
|
31
|
+
style: {
|
|
32
|
+
opacity: d,
|
|
33
|
+
transform: `scale(${u})`
|
|
34
|
+
},
|
|
35
|
+
children: /* @__PURE__ */ r(
|
|
36
|
+
"div",
|
|
37
|
+
{
|
|
38
|
+
className: o(
|
|
39
|
+
"h-8 w-8 transition-all duration-200",
|
|
40
|
+
a && "animate-bump"
|
|
41
|
+
),
|
|
42
|
+
children: /* @__PURE__ */ r(
|
|
43
|
+
"svg",
|
|
44
|
+
{
|
|
45
|
+
viewBox: "0 0 52 58",
|
|
46
|
+
fill: "none",
|
|
47
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
48
|
+
className: o(
|
|
49
|
+
"h-full w-full transition-colors duration-200",
|
|
50
|
+
n || t ? "text-primary" : "text-muted-foreground"
|
|
51
|
+
),
|
|
52
|
+
children: /* @__PURE__ */ r(
|
|
53
|
+
"path",
|
|
54
|
+
{
|
|
55
|
+
className: o(
|
|
56
|
+
"shop-spinner-path",
|
|
57
|
+
!t && "shop-spinner-progress",
|
|
58
|
+
t && "animate-shop-spin"
|
|
59
|
+
),
|
|
60
|
+
d: "M3 13C5 11.75 10.4968 6.92307 21.5 6.4999C34.5 5.99993 42 13 45 23C48.3 34 42.9211 48.1335 30.5 51C17.5 54 6.6 46 6 37C5.46667 29 10.5 25 14 23",
|
|
61
|
+
stroke: "currentColor",
|
|
62
|
+
strokeWidth: "8",
|
|
63
|
+
strokeLinecap: "square",
|
|
64
|
+
strokeLinejoin: "miter",
|
|
65
|
+
style: {
|
|
66
|
+
"--spinner-progress": t ? "1" : p
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
b.displayName = "RefreshIndicator";
|
|
80
|
+
export {
|
|
81
|
+
b as RefreshIndicator
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=refresh-indicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-indicator.js","sources":["../../../src/internal/components/refresh-indicator.tsx"],"sourcesContent":["import {forwardRef, useEffect, useState} from 'react'\n\nimport {cn} from '../../lib/utils'\n\nexport interface PullToRefreshIndicatorProps {\n pullDistance: number\n threshold: number\n isRefreshing: boolean\n canRefresh: boolean\n className?: string\n}\n\nexport const RefreshIndicator = forwardRef<\n HTMLDivElement,\n PullToRefreshIndicatorProps\n>(({pullDistance, threshold, isRefreshing, canRefresh, className}, ref) => {\n const [showBumpAnimation, setShowBumpAnimation] = useState(false)\n\n const progress = Math.min(pullDistance / threshold, 1)\n\n const spinnerProgress = 0.54 + progress * (1 - 0.54)\n\n const scale = isRefreshing ? 1 : 0.5 + progress * 0.5\n\n const opacity = isRefreshing ? 1 : Math.min(progress * 1.5, 1)\n\n const translateY = isRefreshing ? 0 : progress * 3\n\n useEffect(() => {\n if (isRefreshing && !showBumpAnimation) {\n setShowBumpAnimation(true)\n const timer = setTimeout(() => setShowBumpAnimation(false), 360)\n return () => clearTimeout(timer)\n }\n return undefined\n }, [isRefreshing, showBumpAnimation])\n\n return (\n <div\n ref={ref}\n className={cn(\n 'flex items-center justify-center w-full h-full',\n 'transition-all duration-200 ease-out',\n className\n )}\n style={{\n transform: `translateY(${translateY}px)`,\n }}\n >\n <div\n className={cn(\n 'flex flex-col items-center space-y-2 rounded-full px-4 py-2 backdrop-blur-sm transition-all duration-200',\n canRefresh || isRefreshing\n ? 'bg-primary/20 border-2 border-primary/40'\n : 'bg-background/90'\n )}\n style={{\n opacity,\n transform: `scale(${scale})`,\n }}\n >\n <div\n className={cn(\n 'h-8 w-8 transition-all duration-200',\n showBumpAnimation && 'animate-bump'\n )}\n >\n <svg\n viewBox=\"0 0 52 58\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n className={cn(\n 'h-full w-full transition-colors duration-200',\n canRefresh || isRefreshing\n ? 'text-primary'\n : 'text-muted-foreground'\n )}\n >\n <path\n className={cn(\n 'shop-spinner-path',\n !isRefreshing && 'shop-spinner-progress',\n isRefreshing && 'animate-shop-spin'\n )}\n d=\"M3 13C5 11.75 10.4968 6.92307 21.5 6.4999C34.5 5.99993 42 13 45 23C48.3 34 42.9211 48.1335 30.5 51C17.5 54 6.6 46 6 37C5.46667 29 10.5 25 14 23\"\n stroke=\"currentColor\"\n strokeWidth=\"8\"\n strokeLinecap=\"square\"\n strokeLinejoin=\"miter\"\n style={\n {\n '--spinner-progress': isRefreshing ? '1' : spinnerProgress,\n } as React.CSSProperties\n }\n />\n </svg>\n </div>\n </div>\n </div>\n )\n})\n\nRefreshIndicator.displayName = 'RefreshIndicator'\n"],"names":["RefreshIndicator","forwardRef","pullDistance","threshold","isRefreshing","canRefresh","className","ref","showBumpAnimation","setShowBumpAnimation","useState","progress","spinnerProgress","scale","opacity","translateY","useEffect","timer","jsx","cn"],"mappings":";;;AAYa,MAAAA,IAAmBC,EAG9B,CAAC,EAAC,cAAAC,GAAc,WAAAC,GAAW,cAAAC,GAAc,YAAAC,GAAY,WAAAC,EAAS,GAAGC,MAAQ;AACzE,QAAM,CAACC,GAAmBC,CAAoB,IAAIC,EAAS,EAAK,GAE1DC,IAAW,KAAK,IAAIT,IAAeC,GAAW,CAAC,GAE/CS,IAAkB,OAAOD,KAAY,IAAI,OAEzCE,IAAQT,IAAe,IAAI,MAAMO,IAAW,KAE5CG,IAAUV,IAAe,IAAI,KAAK,IAAIO,IAAW,KAAK,CAAC,GAEvDI,IAAaX,IAAe,IAAIO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C;AAAA,kBAAA;AAAA,gBAEJ;AAAA,cAAA;AAAA,YACF;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ,CAAC;AAEDZ,EAAiB,cAAc;"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useState as M, useRef as P, useCallback as o, useEffect as O } from "react";
|
|
2
|
+
const _ = 200, H = 400;
|
|
3
|
+
function U({
|
|
4
|
+
onRefresh: g,
|
|
5
|
+
threshold: R = _,
|
|
6
|
+
indicatorThreshold: p = 0,
|
|
7
|
+
enabled: E = !1
|
|
8
|
+
}) {
|
|
9
|
+
const [Y, u] = M({
|
|
10
|
+
isPulling: !1,
|
|
11
|
+
pullDistance: 0,
|
|
12
|
+
canRefresh: !1
|
|
13
|
+
}), i = P(0), F = P(0), f = P(null), e = P(null), a = P(!1), A = o(
|
|
14
|
+
(n) => {
|
|
15
|
+
!E || !f.current || a.current || (e.current && (cancelAnimationFrame(e.current), e.current = null), u((t) => {
|
|
16
|
+
const r = f.current;
|
|
17
|
+
if (!r) return t;
|
|
18
|
+
if (r.scrollTop <= 0) {
|
|
19
|
+
const h = n.touches[0];
|
|
20
|
+
i.current = h.clientY;
|
|
21
|
+
} else
|
|
22
|
+
return i.current = 0, {
|
|
23
|
+
...t,
|
|
24
|
+
isPulling: !1,
|
|
25
|
+
pullDistance: 0,
|
|
26
|
+
canRefresh: !1
|
|
27
|
+
};
|
|
28
|
+
return t;
|
|
29
|
+
}));
|
|
30
|
+
},
|
|
31
|
+
[E]
|
|
32
|
+
), S = o(
|
|
33
|
+
(n, t) => {
|
|
34
|
+
!E || !f.current || i.current === 0 || u((r) => {
|
|
35
|
+
if (a.current)
|
|
36
|
+
return r;
|
|
37
|
+
const c = f.current;
|
|
38
|
+
if (!c) return r;
|
|
39
|
+
const h = c.scrollTop <= 0;
|
|
40
|
+
F.current = n;
|
|
41
|
+
const s = F.current - i.current;
|
|
42
|
+
if (h && s > 0) {
|
|
43
|
+
const l = s, m = l >= p;
|
|
44
|
+
if (m && t && t(), m || r.isPulling) {
|
|
45
|
+
const D = l > R ? R + (l - R) * 0.5 : l;
|
|
46
|
+
return {
|
|
47
|
+
...r,
|
|
48
|
+
isPulling: m,
|
|
49
|
+
pullDistance: D,
|
|
50
|
+
canRefresh: l >= R
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return r;
|
|
54
|
+
} else if (r.isPulling)
|
|
55
|
+
return {
|
|
56
|
+
...r,
|
|
57
|
+
isPulling: !1,
|
|
58
|
+
pullDistance: 0,
|
|
59
|
+
canRefresh: !1
|
|
60
|
+
};
|
|
61
|
+
return r;
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
[R, p, E]
|
|
65
|
+
), L = o(
|
|
66
|
+
(n) => {
|
|
67
|
+
if (a.current) return;
|
|
68
|
+
const t = n.touches[0];
|
|
69
|
+
t && i.current !== 0 && S(t.clientY, () => n.preventDefault());
|
|
70
|
+
},
|
|
71
|
+
[S]
|
|
72
|
+
), v = o(() => {
|
|
73
|
+
a.current = !1;
|
|
74
|
+
}, []), w = o((n) => {
|
|
75
|
+
e.current && (cancelAnimationFrame(e.current), e.current = null);
|
|
76
|
+
let t = n;
|
|
77
|
+
if (t === void 0 && u((s) => (t = s.pullDistance, s)), !t || t <= 0) {
|
|
78
|
+
u((s) => ({
|
|
79
|
+
...s,
|
|
80
|
+
pullDistance: 0,
|
|
81
|
+
canRefresh: !1,
|
|
82
|
+
isPulling: !1
|
|
83
|
+
}));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const r = H, c = Date.now(), h = () => {
|
|
87
|
+
const s = Date.now() - c, T = Math.min(s / r, 1), l = 1 - (1 - T) ** 3, m = t * (1 - l);
|
|
88
|
+
u((D) => ({
|
|
89
|
+
...D,
|
|
90
|
+
pullDistance: m,
|
|
91
|
+
canRefresh: T < 1 ? D.canRefresh : !1
|
|
92
|
+
})), T < 1 ? e.current = requestAnimationFrame(h) : (e.current = null, u((D) => ({
|
|
93
|
+
...D,
|
|
94
|
+
pullDistance: 0,
|
|
95
|
+
canRefresh: !1,
|
|
96
|
+
isPulling: !1
|
|
97
|
+
})));
|
|
98
|
+
};
|
|
99
|
+
e.current = requestAnimationFrame(h);
|
|
100
|
+
}, []), d = o(async () => {
|
|
101
|
+
if (a.current) {
|
|
102
|
+
i.current = 0;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
i.current = 0, e.current && (cancelAnimationFrame(e.current), e.current = null);
|
|
106
|
+
let n = !1, t = 0;
|
|
107
|
+
const r = a.current;
|
|
108
|
+
if (u((c) => (n = c.canRefresh && !r, t = c.pullDistance, {
|
|
109
|
+
...c,
|
|
110
|
+
isPulling: !1
|
|
111
|
+
})), t <= 0) {
|
|
112
|
+
u((c) => ({
|
|
113
|
+
...c,
|
|
114
|
+
pullDistance: 0,
|
|
115
|
+
canRefresh: !1
|
|
116
|
+
}));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (n && g) {
|
|
120
|
+
a.current = !0;
|
|
121
|
+
try {
|
|
122
|
+
await g();
|
|
123
|
+
} catch (c) {
|
|
124
|
+
console.error("Pull to refresh failed:", c);
|
|
125
|
+
}
|
|
126
|
+
v();
|
|
127
|
+
}
|
|
128
|
+
w(t);
|
|
129
|
+
}, [g, w, v]), I = o(
|
|
130
|
+
(n) => {
|
|
131
|
+
if (n)
|
|
132
|
+
return f.current = n, n.addEventListener("touchstart", A, { passive: !1 }), n.addEventListener("touchmove", L, { passive: !1 }), n.addEventListener("touchend", d), n.addEventListener("touchcancel", d), () => {
|
|
133
|
+
n.removeEventListener("touchstart", A), n.removeEventListener("touchmove", L), n.removeEventListener("touchend", d), n.removeEventListener("touchcancel", d);
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
[A, L, d]
|
|
137
|
+
);
|
|
138
|
+
return O(() => () => {
|
|
139
|
+
e.current && (cancelAnimationFrame(e.current), e.current = null);
|
|
140
|
+
}, []), {
|
|
141
|
+
state: Y,
|
|
142
|
+
bindToElement: I,
|
|
143
|
+
containerRef: f
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
U as usePullToRefresh
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=usePullToRefresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePullToRefresh.js","sources":["../../src/internal/usePullToRefresh.ts"],"sourcesContent":["import {useCallback, useEffect, useRef, useState} from 'react'\n\nconst DEFAULT_REFRESH_PULL_THRESHOLD = 200\nconst ANIMATION_DURATION = 400\n\nexport interface UsePullToRefreshOptions {\n onRefresh?: () => Promise<void>\n threshold?: number\n indicatorThreshold?: number\n enabled?: boolean\n}\n\nexport interface PullToRefreshState {\n isPulling: boolean\n pullDistance: number\n canRefresh: boolean\n}\n\nexport function usePullToRefresh({\n onRefresh,\n threshold = DEFAULT_REFRESH_PULL_THRESHOLD,\n indicatorThreshold = 0,\n enabled = false,\n}: UsePullToRefreshOptions) {\n const [state, setState] = useState<PullToRefreshState>({\n isPulling: false,\n pullDistance: 0,\n canRefresh: false,\n })\n\n const startY = useRef(0)\n const currentY = useRef(0)\n const containerRef = useRef<HTMLElement | null>(null)\n const animationRef = useRef<number | null>(null)\n const isRefreshingRef = useRef(false)\n\n const handleTouchStart = useCallback(\n (event: TouchEvent) => {\n if (!enabled || !containerRef.current || isRefreshingRef.current) return\n\n if (animationRef.current) {\n cancelAnimationFrame(animationRef.current)\n animationRef.current = null\n }\n\n setState(prev => {\n const container = containerRef.current\n if (!container) return prev\n\n const isAtTop = container.scrollTop <= 0\n\n if (isAtTop) {\n const touch = event.touches[0]\n startY.current = touch.clientY\n } else {\n startY.current = 0\n return {\n ...prev,\n isPulling: false,\n pullDistance: 0,\n canRefresh: false,\n }\n }\n\n return prev\n })\n },\n [enabled]\n )\n\n const handleMove = useCallback(\n (clientY: number, preventDefault?: () => void) => {\n if (!enabled || !containerRef.current || startY.current === 0) {\n return\n }\n\n setState(prev => {\n if (isRefreshingRef.current) {\n return prev\n }\n\n const container = containerRef.current\n if (!container) return prev\n\n const isAtTop = container.scrollTop <= 0\n currentY.current = clientY\n const deltaY = currentY.current - startY.current\n const isValidPull = isAtTop && deltaY > 0\n\n if (isValidPull) {\n const pullDistance = deltaY\n const shouldShowIndicator = pullDistance >= indicatorThreshold\n\n if (shouldShowIndicator && preventDefault) {\n preventDefault()\n }\n\n if (shouldShowIndicator || prev.isPulling) {\n const elasticDistance =\n pullDistance > threshold\n ? threshold + (pullDistance - threshold) * 0.5\n : pullDistance\n\n return {\n ...prev,\n isPulling: shouldShowIndicator,\n pullDistance: elasticDistance,\n canRefresh: pullDistance >= threshold,\n }\n }\n\n return prev\n } else if (prev.isPulling) {\n return {\n ...prev,\n isPulling: false,\n pullDistance: 0,\n canRefresh: false,\n }\n }\n\n return prev\n })\n },\n [threshold, indicatorThreshold, enabled]\n )\n\n const handleTouchMove = useCallback(\n (event: TouchEvent) => {\n if (isRefreshingRef.current) return\n\n const touch = event.touches[0]\n if (!touch) return\n\n if (startY.current !== 0) {\n handleMove(touch.clientY, () => event.preventDefault())\n }\n },\n [handleMove]\n )\n\n const resetRefreshingState = useCallback(() => {\n isRefreshingRef.current = false\n }, [])\n\n const animatePullDistanceToZero = useCallback((fromDistance?: number) => {\n if (animationRef.current) {\n cancelAnimationFrame(animationRef.current)\n animationRef.current = null\n }\n\n let startDistance = fromDistance\n if (startDistance === undefined) {\n setState(prev => {\n startDistance = prev.pullDistance\n return prev\n })\n }\n\n if (!startDistance || startDistance <= 0) {\n setState(prev => ({\n ...prev,\n pullDistance: 0,\n canRefresh: false,\n isPulling: false,\n }))\n return\n }\n\n const duration = ANIMATION_DURATION\n const startTime = Date.now()\n\n const animate = () => {\n const elapsed = Date.now() - startTime\n const progress = Math.min(elapsed / duration, 1)\n\n const easeOut = 1 - (1 - progress) ** 3\n const currentDistance = startDistance! * (1 - easeOut)\n\n setState(prev => ({\n ...prev,\n pullDistance: currentDistance,\n canRefresh: progress < 1 ? prev.canRefresh : false,\n }))\n\n if (progress < 1) {\n animationRef.current = requestAnimationFrame(animate)\n } else {\n animationRef.current = null\n setState(prev => ({\n ...prev,\n pullDistance: 0,\n canRefresh: false,\n isPulling: false,\n }))\n }\n }\n\n animationRef.current = requestAnimationFrame(animate)\n }, [])\n\n const handleEnd = useCallback(async () => {\n if (isRefreshingRef.current) {\n startY.current = 0\n return\n }\n\n startY.current = 0\n\n if (animationRef.current) {\n cancelAnimationFrame(animationRef.current)\n animationRef.current = null\n }\n\n let shouldRefresh = false\n let currentPullDistance = 0\n const wasRefreshing = isRefreshingRef.current\n\n setState(prev => {\n shouldRefresh = prev.canRefresh && !wasRefreshing\n currentPullDistance = prev.pullDistance\n\n return {\n ...prev,\n isPulling: false,\n }\n })\n\n if (currentPullDistance <= 0) {\n setState(prev => ({\n ...prev,\n pullDistance: 0,\n canRefresh: false,\n }))\n return\n }\n\n if (shouldRefresh && onRefresh) {\n isRefreshingRef.current = true\n try {\n await onRefresh()\n } catch (error) {\n console.error('Pull to refresh failed:', error)\n }\n resetRefreshingState()\n }\n\n animatePullDistanceToZero(currentPullDistance)\n }, [onRefresh, animatePullDistanceToZero, resetRefreshingState])\n\n const bindToElement = useCallback(\n (element: HTMLElement | null) => {\n if (!element) return\n\n containerRef.current = element\n\n element.addEventListener('touchstart', handleTouchStart, {passive: false})\n element.addEventListener('touchmove', handleTouchMove, {passive: false})\n element.addEventListener('touchend', handleEnd)\n element.addEventListener('touchcancel', handleEnd)\n\n return () => {\n element.removeEventListener('touchstart', handleTouchStart)\n element.removeEventListener('touchmove', handleTouchMove)\n element.removeEventListener('touchend', handleEnd)\n element.removeEventListener('touchcancel', handleEnd)\n }\n },\n [handleTouchStart, handleTouchMove, handleEnd]\n )\n\n useEffect(() => {\n return () => {\n if (animationRef.current) {\n cancelAnimationFrame(animationRef.current)\n animationRef.current = null\n }\n }\n }, [])\n\n return {\n state,\n bindToElement,\n containerRef,\n }\n}\n"],"names":["DEFAULT_REFRESH_PULL_THRESHOLD","ANIMATION_DURATION","usePullToRefresh","onRefresh","threshold","indicatorThreshold","enabled","state","setState","useState","startY","useRef","currentY","containerRef","animationRef","isRefreshingRef","handleTouchStart","useCallback","event","prev","container","touch","handleMove","clientY","preventDefault","isAtTop","deltaY","pullDistance","shouldShowIndicator","elasticDistance","handleTouchMove","resetRefreshingState","animatePullDistanceToZero","fromDistance","startDistance","duration","startTime","animate","elapsed","progress","easeOut","currentDistance","handleEnd","shouldRefresh","currentPullDistance","wasRefreshing","error","bindToElement","element","useEffect"],"mappings":";AAEA,MAAMA,IAAiC,KACjCC,IAAqB;AAepB,SAASC,EAAiB;AAAA,EAC/B,WAAAC;AAAA,EACA,WAAAC,IAAYJ;AAAA,EACZ,oBAAAK,IAAqB;AAAA,EACrB,SAAAC,IAAU;AACZ,GAA4B;AAC1B,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAA6B;AAAA,IACrD,WAAW;AAAA,IACX,cAAc;AAAA,IACd,YAAY;AAAA,EAAA,CACb,GAEKC,IAASC,EAAO,CAAC,GACjBC,IAAWD,EAAO,CAAC,GACnBE,IAAeF,EAA2B,IAAI,GAC9CG,IAAeH,EAAsB,IAAI,GACzCI,IAAkBJ,EAAO,EAAK,GAE9BK,IAAmBC;AAAA,IACvB,CAACC,MAAsB;AACrB,MAAI,CAACZ,KAAW,CAACO,EAAa,WAAWE,EAAgB,YAErDD,EAAa,YACf,qBAAqBA,EAAa,OAAO,GACzCA,EAAa,UAAU,OAGzBN,EAAS,CAAQW,MAAA;AACf,cAAMC,IAAYP,EAAa;AAC3B,YAAA,CAACO,EAAkB,QAAAD;AAIvB,YAFgBC,EAAU,aAAa,GAE1B;AACL,gBAAAC,IAAQH,EAAM,QAAQ,CAAC;AAC7B,UAAAR,EAAO,UAAUW,EAAM;AAAA,QAAA;AAEvB,iBAAAX,EAAO,UAAU,GACV;AAAA,YACL,GAAGS;AAAA,YACH,WAAW;AAAA,YACX,cAA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AU;AAAA,EAE3B,GACC,EAAE,GAEE;AAAA,IACL,OAAAP;AAAA,IACA,eAAAwC;AAAA,IACA,cAAAlC;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const c = (o) => {
|
|
2
|
+
const t = "[data-virtuoso-scroller]";
|
|
3
|
+
let l = null;
|
|
4
|
+
if (l = o.querySelector(t), l) return l;
|
|
5
|
+
if (!l) {
|
|
6
|
+
const s = Array.from(o.querySelectorAll("div"));
|
|
7
|
+
for (const e of s) {
|
|
8
|
+
const r = window.getComputedStyle(e);
|
|
9
|
+
if (r.overflowY === "auto" || r.overflowY === "scroll") {
|
|
10
|
+
l = e;
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return l || o;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
c as findVirtuosoScrollableElement
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=virtuoso-dom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtuoso-dom.js","sources":["../../../src/internal/utils/virtuoso-dom.ts"],"sourcesContent":["// For finding the scrollable element within a container for pull-to-refresh functionality.\n\nexport const findVirtuosoScrollableElement = (\n container: HTMLElement\n): HTMLElement => {\n const selector = '[data-virtuoso-scroller]'\n\n let scrollableElement: HTMLElement | null = null\n\n scrollableElement = container.querySelector(selector) as HTMLElement\n\n if (scrollableElement) return scrollableElement\n\n if (!scrollableElement) {\n const allDivs = Array.from(container.querySelectorAll('div'))\n for (const div of allDivs) {\n const style = window.getComputedStyle(div)\n if (style.overflowY === 'auto' || style.overflowY === 'scroll') {\n scrollableElement = div as HTMLElement\n break\n }\n }\n }\n\n return scrollableElement || container\n}\n"],"names":["findVirtuosoScrollableElement","container","selector","scrollableElement","allDivs","div","style"],"mappings":"AAEa,MAAAA,IAAgC,CAC3CC,MACgB;AAChB,QAAMC,IAAW;AAEjB,MAAIC,IAAwC;AAI5C,MAFoBA,IAAAF,EAAU,cAAcC,CAAQ,GAEhDC,EAA0B,QAAAA;AAE9B,MAAI,CAACA,GAAmB;AACtB,UAAMC,IAAU,MAAM,KAAKH,EAAU,iBAAiB,KAAK,CAAC;AAC5D,eAAWI,KAAOD,GAAS;AACnB,YAAAE,IAAQ,OAAO,iBAAiBD,CAAG;AACzC,UAAIC,EAAM,cAAc,UAAUA,EAAM,cAAc,UAAU;AAC1C,QAAAH,IAAAE;AACpB;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAGF,SAAOF,KAAqBF;AAC9B;"}
|
package/dist/mocks.js
CHANGED
package/dist/mocks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks.js","sources":["../src/mocks.ts"],"sourcesContent":["import {\n Product,\n Gender,\n UserState,\n MinisContentStatus,\n} from '@shopify/shop-minis-platform'\nimport {ShopActions} from '@shopify/shop-minis-platform/actions'\n\n// Helper functions for common data structures\nexport const createProduct = (\n id: string,\n title: string,\n price = '99.99',\n compareAtPrice?: string\n): Product => ({\n id,\n title,\n price: {amount: price, currencyCode: 'USD'},\n ...(compareAtPrice && {\n compareAtPrice: {amount: compareAtPrice, currencyCode: 'USD'},\n }),\n reviewAnalytics: {averageRating: 4.5, reviewCount: 10},\n shop: createShop('shop1', 'Mock Shop'),\n defaultVariantId: `variant-${id}`,\n isFavorited: false,\n featuredImage: {\n url: `https://cdn.shopify.com/static/sample-images/teapot.jpg`,\n altText: title,\n },\n})\n\nexport const createShop = (\n id: string,\n name: string,\n options?: {\n themeType?: 'coverImage' | 'brandColor' | 'logoColor' | 'none'\n withBrandSettings?: boolean\n primaryColor?: string\n logoDominantColor?: string\n logoAverageColor?: string\n coverDominantColor?: string\n wordmarkUrl?: string\n coverImageUrl?: string\n featuredImagesLimit?: number\n }\n) => {\n // Determine theme configuration\n const themeType = options?.themeType || 'none'\n const shouldHaveBrandSettings =\n options?.withBrandSettings || themeType !== 'none'\n\n // Generate featured images\n const featuredImagesCount = options?.featuredImagesLimit || 3\n const featuredImages = Array.from({length: featuredImagesCount}, (_, i) => ({\n url: `https://picsum.photos/400/400?random=${id}-${i}`,\n sensitive: false,\n altText: `${name} featured image ${i + 1}`,\n }))\n\n // Configure colors based on theme type\n const getThemeColors = () => {\n switch (themeType) {\n case 'coverImage':\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor || '#FF6B35',\n }\n case 'brandColor':\n return {\n primary: options?.primaryColor || '#27AE60',\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n case 'logoColor':\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor || '#E74C3C',\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n default:\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n }\n }\n\n // Configure header theme\n const createHeaderTheme = () => {\n if (themeType === 'coverImage' || options?.coverImageUrl) {\n return {\n id: `header-theme-${id}`,\n coverImage: {\n url:\n options?.coverImageUrl ||\n 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800&h=400&fit=crop',\n altText: `${name} cover image`,\n sensitive: false,\n thumbhash: 'k9oGHQRnh493V4dIeHeXh4h3iIeI',\n },\n wordmark:\n options?.wordmarkUrl || themeType === 'coverImage'\n ? {\n url:\n options?.wordmarkUrl ||\n 'https://merrypeople.com/cdn/shop/files/Transparent_Background_1.png?v=1696465429&width=1024',\n altText: `${name} wordmark`,\n sensitive: false,\n }\n : undefined,\n }\n }\n\n if (options?.wordmarkUrl) {\n return {\n id: `header-theme-${id}`,\n wordmark: {\n url: options.wordmarkUrl,\n altText: `${name} wordmark`,\n sensitive: false,\n },\n }\n }\n\n return undefined\n }\n\n return {\n id,\n name,\n primaryDomain: {\n url: `https://${name.toLowerCase().replace(/\\s+/g, '-')}.com`,\n },\n reviewAnalytics: {averageRating: 4.3, reviewCount: 50},\n visualTheme: {\n id: `visual-theme-${id}`,\n featuredImages,\n logoImage: {\n url: `https://picsum.photos/100/100?random=${id}`,\n sensitive: false,\n },\n brandSettings: shouldHaveBrandSettings\n ? {\n id: `brand-settings-${id}`,\n colors: {\n id: `colors-${id}`,\n ...getThemeColors(),\n },\n headerTheme: createHeaderTheme(),\n }\n : undefined,\n },\n }\n}\n\nconst createPagination = (hasNext = false) => ({\n hasNextPage: hasNext,\n endCursor: hasNext ? 'cursor123' : null,\n})\n\nconst createProductList = (id: string, name: string, products: any[] = []) => ({\n id,\n publicId: `public-${id}`,\n name,\n products,\n})\n\n// Helper type to extract the data type from a ShopAction\ntype ShopActionDataType<T> = T extends (\n ...args: any[]\n) => Promise<{ok: true; data: infer R} | {ok: false; error: any}>\n ? R\n : never\n\nfunction makeMockMethod<K extends keyof ShopActions>(\n key: K,\n result: ShopActionDataType<ShopActions[K]>\n): ShopActions[K] {\n return ((params: Parameters<ShopActions[K]>[0]) => {\n console.log(`[Mock Action] ${String(key)}`, params)\n return Promise.resolve({ok: true as const, data: result})\n }) as ShopActions[K]\n}\n\nexport function makeMockActions(): ShopActions {\n const results: {\n [K in keyof ShopActions]: ShopActionDataType<ShopActions[K]>\n } = {\n translateContentUp: undefined,\n translateContentDown: undefined,\n followShop: true,\n unfollowShop: false,\n favorite: undefined,\n unfavorite: undefined,\n getShopAppInformation: {\n appVersion: '1.0.0',\n buildNumber: '12345',\n buildId: 'dev-build-123',\n },\n productRecommendationImpression: undefined,\n productRecommendationClick: undefined,\n hideEntryPoint: undefined,\n closeMini: undefined,\n getAccountInformation: {\n status: 'available',\n value: 'user@example.com',\n },\n getCurrentUser: {\n data: {\n displayName: 'John Doe',\n avatarImage: {url: 'https://example.com/avatar.jpg'},\n },\n },\n createOrderAttribution: undefined,\n addToCart: undefined,\n buyProduct: undefined,\n buyProducts: undefined,\n showErrorScreen: undefined,\n showErrorToast: undefined,\n getDeeplinkPaths: {\n matchers: ['/products', '/collections', '/cart'],\n },\n navigateToDeeplink: undefined,\n navigateToShop: undefined,\n navigateToProduct: undefined,\n navigateToOrder: undefined,\n navigateToCheckout: undefined,\n createImageUploadLink: {\n targets: [\n {\n url: 'https://example.com/upload',\n resourceUrl: 'https://example.com/resource',\n parameters: [{name: 'key', value: 'upload-123'}],\n },\n ],\n },\n completeImageUpload: {\n files: [\n {\n id: 'file-123',\n fileStatus: 'READY',\n image: {url: 'https://example.com/image.jpg'},\n },\n ],\n },\n getPersistedItem: 'stored-value',\n setPersistedItem: undefined,\n removePersistedItem: undefined,\n getAllPersistedKeys: ['key1', 'key2', 'key3'],\n clearPersistedItems: undefined,\n getInternalPersistedItem: 'internal-value',\n setInternalPersistedItem: undefined,\n removeInternalPersistedItem: undefined,\n getAllInternalPersistedKeys: ['internal-key1', 'internal-key2'],\n clearInternalPersistedItems: undefined,\n getSecret: 'secret-value',\n setSecret: undefined,\n removeSecret: undefined,\n reportInteraction: undefined,\n reportImpression: undefined,\n reportContentImpression: undefined,\n getProductLists: {\n data: [\n createProductList('list-1', 'Wishlist'),\n createProductList('list-2', 'Favorites'),\n ],\n pageInfo: createPagination(),\n },\n getProductList: {\n data: createProductList('list-1', 'Wishlist', [\n createProduct('prod-1', 'Sample Product'),\n ]),\n pageInfo: createPagination(),\n },\n addProductList: createProductList('list-3', 'New List'),\n removeProductList: undefined,\n renameProductList: createProductList('list-1', 'Updated Wishlist'),\n addProductListItem: undefined,\n removeProductListItem: undefined,\n getRecommendedProducts: {\n data: [\n createProduct('rec-1', 'Recommended Product 1', '79.99'),\n createProduct('rec-2', 'Recommended Product 2', '129.99'),\n createProduct('rec-3', 'Recommended Product 3', '129.99'),\n createProduct('rec-4', 'Recommended Product 4', '29.99'),\n createProduct('rec-5', 'Recommended Product 5', '39.99'),\n createProduct('rec-6', 'Recommended Product 6', '49.99'),\n createProduct('rec-7', 'Recommended Product 7', '59.99'),\n createProduct('rec-8', 'Recommended Product 8', '69.99'),\n createProduct('rec-9', 'Recommended Product 9', '129.99'),\n ],\n pageInfo: createPagination(),\n },\n getRecommendedShops: {\n data: [\n createShop('shop-1', 'Amazing Store'),\n createShop('shop-2', 'Best Deals Shop'),\n ],\n pageInfo: createPagination(),\n },\n searchProductsByShop: {\n data: [\n createProduct('search-1', 'Search Result 1', '59.99'),\n createProduct('search-2', 'Search Result 2', '89.99'),\n ],\n pageInfo: createPagination(),\n },\n getOrders: {\n data: [\n {\n id: 'order-1',\n name: '#1001',\n lineItems: [\n {\n productTitle: 'Sample Product',\n variantTitle: 'Medium',\n quantity: 2,\n product: null,\n },\n ],\n shop: createShop('shop-1', 'Sample Shop'),\n },\n ],\n pageInfo: createPagination(),\n },\n getBuyerAttributes: {\n data: {\n genderAffinity: 'NEUTRAL' as Gender,\n categoryAffinities: [\n {id: 'cat1', name: 'Electronics'},\n {id: 'cat2', name: 'Clothing'},\n ],\n },\n },\n showFeedbackSheet: undefined,\n getPopularProducts: {\n data: [\n createProduct('pop-1', 'The Hero Snowboard', '702.95'),\n createProduct('pop-2', 'Snow Jacket', '605.95', '702.00'),\n createProduct('pop-3', 'Winter Gloves', '89.95'),\n createProduct('pop-4', 'Summer Gloves', '89.95'),\n createProduct('pop-5', 'Spring Gloves', '89.95'),\n createProduct('pop-6', 'Playstation 5', '499.95'),\n createProduct('pop-7', 'Xbox Series X', '499.95'),\n createProduct('pop-8', 'Nintendo Switch', '299.95'),\n createProduct('pop-9', 'Playstation 4', '299.95'),\n createProduct('pop-10', 'Nintendo 3DS', '89.95'),\n ],\n pageInfo: createPagination(),\n },\n share: {\n message: 'Shared!',\n success: true,\n },\n shareSingle: {\n message: 'Shared!',\n success: true,\n },\n getCuratedProducts: {\n data: [\n createProduct('cur-1', 'Curated Product 1', '79.99'),\n createProduct('cur-2', 'Curated Product 2', '129.99'),\n ],\n pageInfo: createPagination(),\n },\n getSavedProducts: {\n data: [createProduct('saved-1', 'Saved Product 1', '49.99')],\n pageInfo: createPagination(),\n },\n getRecentProducts: {\n data: [createProduct('recent-1', 'Recent Product 1', '59.99')],\n pageInfo: createPagination(),\n },\n getProductSearch: {\n data: [createProduct('search-3', 'Search Product 3', '39.99')],\n pageInfo: createPagination(),\n },\n getProducts: {data: [createProduct('prod-2', 'Product 2', '19.99')]},\n getProduct: {data: createProduct('prod-1', 'Sample Product')},\n getProductVariants: {\n data: [\n {\n id: 'variant-1',\n isFavorited: false,\n image: {url: 'https://example.com/variant-1.jpg'},\n price: {amount: '19.99', currencyCode: 'USD'},\n compareAtPrice: {amount: '29.99', currencyCode: 'USD'},\n },\n ],\n pageInfo: createPagination(),\n },\n getProductMedia: {\n data: [\n {\n id: 'media-1',\n image: {url: 'https://example.com/media-1.jpg'},\n mediaContentType: 'IMAGE',\n alt: 'Sample product image',\n },\n ],\n pageInfo: createPagination(),\n },\n getShop: {data: createShop('shop-1', 'Sample Shop')},\n getRecentShops: {\n data: [createShop('recent-shop-1', 'Recent Shop 1')],\n pageInfo: createPagination(),\n },\n getFollowedShops: {\n data: [createShop('followed-shop-1', 'Followed Shop 1')],\n pageInfo: createPagination(),\n },\n previewProductInAr: undefined,\n createContent: {\n data: {\n publicId: 'content-123',\n externalId: null,\n image: {\n id: 'img-123',\n url: 'https://cdn.shopify.com/s/files/1/0633/6574/2742/files/Namnlosdesign-47.png?v=1740438079',\n width: 800,\n height: 600,\n },\n title: 'Mock Content',\n description: 'This is a mock content item',\n visibility: ['DISCOVERABLE'],\n shareableUrl: 'https://example.com/content/123',\n products: null,\n },\n },\n getContent: {\n data: [\n {\n publicId: 'content-123',\n image: {\n id: 'img-123',\n url: 'https://cdn.shopify.com/s/files/1/0633/6574/2742/files/Namnlosdesign-47.png?v=1740438079',\n width: 800,\n height: 600,\n },\n title: 'Mock Content',\n visibility: ['DISCOVERABLE'],\n status: MinisContentStatus.READY,\n },\n ],\n },\n generateUserToken: {\n data: {\n token: 'user-token-123',\n expiresAt: '2025-01-01',\n userState: UserState.VERIFIED,\n },\n },\n navigateToCart: undefined,\n requestPermission: {\n granted: true,\n },\n } as const\n\n const mock: Partial<ShopActions> = {}\n for (const key in results) {\n if (Object.prototype.hasOwnProperty.call(results, key)) {\n // @ts-expect-error: dynamic assignment is safe due to exhaustive mapping\n mock[key] = makeMockMethod(\n key as keyof ShopActions,\n results[key as keyof typeof results]\n )\n }\n }\n return mock as ShopActions\n}\n\n// Detect if running on a mobile device\nconst isMobile = (): boolean => {\n const userAgent = navigator.userAgent.toLowerCase()\n const isIOS = /iphone|ipad|ipod/.test(userAgent)\n const isAndroid = /android/.test(userAgent)\n\n return isIOS || isAndroid\n}\n\nexport const injectMocks = ({force}: {force?: boolean} = {}) => {\n // Only inject mocks if we aren't on a mobile device or we force it\n if (isMobile() && !force) {\n return\n }\n\n if (!window.minisSDK) {\n window.minisSDK = makeMockActions()\n window.minisParams = {\n handle: 'mock-handle',\n initialUrl: '/mock-initial-url',\n platform: 'web',\n }\n }\n}\n"],"names":["createProduct","id","title","price","compareAtPrice","createShop","name","options","featuredImages","_","i","createPagination","hasNext","createProductList","products","makeMockMethod","key","result","params","makeMockActions","results","MinisContentStatus","UserState","mock","isMobile","userAgent","isIOS","isAndroid","injectMocks","force"],"mappings":";;AASO,MAAMA,IAAgB,CAC3BC,GACAC,GACAC,IAAQ,SACRC,OACa;AAAA,EACb,IAAAH;AAAA,EACA,OAAAC;AAAA,EACA,OAAO,EAAC,QAAQC,GAAO,cAAc,MAAK;AAAA,EAC1C,GAAIC,KAAkB;AAAA,IACpB,gBAAgB,EAAC,QAAQA,GAAgB,cAAc,MAAK;AAAA,EAC9D;AAAA,EACA,iBAAiB,EAAC,eAAe,KAAK,aAAa,GAAE;AAAA,EACrD,MAAMC,EAAW,SAAS,WAAW;AAAA,EACrC,kBAAkB,WAAWJ,CAAE;AAAA,EAC/B,aAAa;AAAA,EACb,eAAe;AAAA,IACb,KAAK;AAAA,IACL,SAASC;AAAA,EAAA;AAEb,IAEaG,IAAa,C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KAAKF,CAAS;AAE1C,SAAOC,KAASC;AAClB,GAEaC,IAAc,CAAC,EAAC,OAAAC,EAAK,IAAuB,OAAO;AAE1D,EAAAL,EAAA,KAAc,CAACK,KAId,OAAO,aACV,OAAO,WAAWV,EAAgB,GAClC,OAAO,cAAc;AAAA,IACnB,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"mocks.js","sources":["../src/mocks.ts"],"sourcesContent":["import {\n Product,\n Gender,\n UserState,\n MinisContentStatus,\n} from '@shopify/shop-minis-platform'\nimport {ShopActions} from '@shopify/shop-minis-platform/actions'\n\n// Helper functions for common data structures\nexport const createProduct = (\n id: string,\n title: string,\n price = '99.99',\n compareAtPrice?: string\n): Product => ({\n id,\n title,\n price: {amount: price, currencyCode: 'USD'},\n ...(compareAtPrice && {\n compareAtPrice: {amount: compareAtPrice, currencyCode: 'USD'},\n }),\n reviewAnalytics: {averageRating: 4.5, reviewCount: 10},\n shop: createShop('shop1', 'Mock Shop'),\n defaultVariantId: `variant-${id}`,\n isFavorited: false,\n featuredImage: {\n url: `https://cdn.shopify.com/static/sample-images/teapot.jpg`,\n altText: title,\n },\n})\n\nexport const createShop = (\n id: string,\n name: string,\n options?: {\n themeType?: 'coverImage' | 'brandColor' | 'logoColor' | 'none'\n withBrandSettings?: boolean\n primaryColor?: string\n logoDominantColor?: string\n logoAverageColor?: string\n coverDominantColor?: string\n wordmarkUrl?: string\n coverImageUrl?: string\n featuredImagesLimit?: number\n }\n) => {\n // Determine theme configuration\n const themeType = options?.themeType || 'none'\n const shouldHaveBrandSettings =\n options?.withBrandSettings || themeType !== 'none'\n\n // Generate featured images\n const featuredImagesCount = options?.featuredImagesLimit || 3\n const featuredImages = Array.from({length: featuredImagesCount}, (_, i) => ({\n url: `https://picsum.photos/400/400?random=${id}-${i}`,\n sensitive: false,\n altText: `${name} featured image ${i + 1}`,\n }))\n\n // Configure colors based on theme type\n const getThemeColors = () => {\n switch (themeType) {\n case 'coverImage':\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor || '#FF6B35',\n }\n case 'brandColor':\n return {\n primary: options?.primaryColor || '#27AE60',\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n case 'logoColor':\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor || '#E74C3C',\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n default:\n return {\n primary: options?.primaryColor,\n logoDominant: options?.logoDominantColor,\n logoAverage: options?.logoAverageColor,\n coverDominant: options?.coverDominantColor,\n }\n }\n }\n\n // Configure header theme\n const createHeaderTheme = () => {\n if (themeType === 'coverImage' || options?.coverImageUrl) {\n return {\n id: `header-theme-${id}`,\n coverImage: {\n url:\n options?.coverImageUrl ||\n 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800&h=400&fit=crop',\n altText: `${name} cover image`,\n sensitive: false,\n thumbhash: 'k9oGHQRnh493V4dIeHeXh4h3iIeI',\n },\n wordmark:\n options?.wordmarkUrl || themeType === 'coverImage'\n ? {\n url:\n options?.wordmarkUrl ||\n 'https://merrypeople.com/cdn/shop/files/Transparent_Background_1.png?v=1696465429&width=1024',\n altText: `${name} wordmark`,\n sensitive: false,\n }\n : undefined,\n }\n }\n\n if (options?.wordmarkUrl) {\n return {\n id: `header-theme-${id}`,\n wordmark: {\n url: options.wordmarkUrl,\n altText: `${name} wordmark`,\n sensitive: false,\n },\n }\n }\n\n return undefined\n }\n\n return {\n id,\n name,\n primaryDomain: {\n url: `https://${name.toLowerCase().replace(/\\s+/g, '-')}.com`,\n },\n reviewAnalytics: {averageRating: 4.3, reviewCount: 50},\n visualTheme: {\n id: `visual-theme-${id}`,\n featuredImages,\n logoImage: {\n url: `https://picsum.photos/100/100?random=${id}`,\n sensitive: false,\n },\n brandSettings: shouldHaveBrandSettings\n ? {\n id: `brand-settings-${id}`,\n colors: {\n id: `colors-${id}`,\n ...getThemeColors(),\n },\n headerTheme: createHeaderTheme(),\n }\n : undefined,\n },\n }\n}\n\nconst createPagination = (hasNext = false) => ({\n hasNextPage: hasNext,\n endCursor: hasNext ? 'cursor123' : null,\n})\n\nconst createProductList = (id: string, name: string, products: any[] = []) => ({\n id,\n publicId: `public-${id}`,\n name,\n products,\n})\n\n// Helper type to extract the data type from a ShopAction\ntype ShopActionDataType<T> = T extends (\n ...args: any[]\n) => Promise<{ok: true; data: infer R} | {ok: false; error: any}>\n ? R\n : never\n\nfunction makeMockMethod<K extends keyof ShopActions>(\n key: K,\n result: ShopActionDataType<ShopActions[K]>\n): ShopActions[K] {\n return ((params: Parameters<ShopActions[K]>[0]) => {\n console.log(`[Mock Action] ${String(key)}`, params)\n return Promise.resolve({ok: true as const, data: result})\n }) as ShopActions[K]\n}\n\nexport function makeMockActions(): ShopActions {\n const results: {\n [K in keyof ShopActions]: ShopActionDataType<ShopActions[K]>\n } = {\n translateContentUp: undefined,\n translateContentDown: undefined,\n followShop: true,\n unfollowShop: false,\n favorite: undefined,\n unfavorite: undefined,\n getShopAppInformation: {\n appVersion: '1.0.0',\n buildNumber: '12345',\n buildId: 'dev-build-123',\n },\n productRecommendationImpression: undefined,\n productRecommendationClick: undefined,\n hideEntryPoint: undefined,\n closeMini: undefined,\n getAccountInformation: {\n status: 'available',\n value: 'user@example.com',\n },\n getCurrentUser: {\n data: {\n displayName: 'John Doe',\n avatarImage: {url: 'https://example.com/avatar.jpg'},\n },\n },\n createOrderAttribution: undefined,\n addToCart: undefined,\n buyProduct: undefined,\n buyProducts: undefined,\n showErrorScreen: undefined,\n showErrorToast: undefined,\n getDeeplinkPaths: {\n matchers: ['/products', '/collections', '/cart'],\n },\n navigateToDeeplink: undefined,\n navigateToShop: undefined,\n navigateToProduct: undefined,\n navigateToOrder: undefined,\n navigateToCheckout: undefined,\n createImageUploadLink: {\n targets: [\n {\n url: 'https://example.com/upload',\n resourceUrl: 'https://example.com/resource',\n parameters: [{name: 'key', value: 'upload-123'}],\n },\n ],\n },\n completeImageUpload: {\n files: [\n {\n id: 'file-123',\n fileStatus: 'READY',\n image: {url: 'https://example.com/image.jpg'},\n },\n ],\n },\n getPersistedItem: 'stored-value',\n setPersistedItem: undefined,\n removePersistedItem: undefined,\n getAllPersistedKeys: ['key1', 'key2', 'key3'],\n clearPersistedItems: undefined,\n getInternalPersistedItem: 'internal-value',\n setInternalPersistedItem: undefined,\n removeInternalPersistedItem: undefined,\n getAllInternalPersistedKeys: ['internal-key1', 'internal-key2'],\n clearInternalPersistedItems: undefined,\n getSecret: 'secret-value',\n setSecret: undefined,\n removeSecret: undefined,\n reportInteraction: undefined,\n reportImpression: undefined,\n reportContentImpression: undefined,\n getProductLists: {\n data: [\n createProductList('list-1', 'Wishlist'),\n createProductList('list-2', 'Favorites'),\n ],\n pageInfo: createPagination(),\n },\n getProductList: {\n data: createProductList('list-1', 'Wishlist', [\n createProduct('prod-1', 'Sample Product'),\n ]),\n pageInfo: createPagination(),\n },\n addProductList: createProductList('list-3', 'New List'),\n removeProductList: undefined,\n renameProductList: createProductList('list-1', 'Updated Wishlist'),\n addProductListItem: undefined,\n removeProductListItem: undefined,\n getRecommendedProducts: {\n data: [\n createProduct('rec-1', 'Recommended Product 1', '79.99'),\n createProduct('rec-2', 'Recommended Product 2', '129.99'),\n createProduct('rec-3', 'Recommended Product 3', '129.99'),\n createProduct('rec-4', 'Recommended Product 4', '29.99'),\n createProduct('rec-5', 'Recommended Product 5', '39.99'),\n createProduct('rec-6', 'Recommended Product 6', '49.99'),\n createProduct('rec-7', 'Recommended Product 7', '59.99'),\n createProduct('rec-8', 'Recommended Product 8', '69.99'),\n createProduct('rec-9', 'Recommended Product 9', '129.99'),\n ],\n pageInfo: createPagination(),\n },\n getRecommendedShops: {\n data: [\n createShop('shop-1', 'Amazing Store'),\n createShop('shop-2', 'Best Deals Shop'),\n ],\n pageInfo: createPagination(),\n },\n searchProductsByShop: {\n data: [\n createProduct('search-1', 'Search Result 1', '59.99'),\n createProduct('search-2', 'Search Result 2', '89.99'),\n ],\n pageInfo: createPagination(),\n },\n getOrders: {\n data: [\n {\n id: 'order-1',\n name: '#1001',\n lineItems: [\n {\n productTitle: 'Sample Product',\n variantTitle: 'Medium',\n quantity: 2,\n product: null,\n },\n ],\n shop: createShop('shop-1', 'Sample Shop'),\n },\n ],\n pageInfo: createPagination(),\n },\n getBuyerAttributes: {\n data: {\n genderAffinity: 'NEUTRAL' as Gender,\n categoryAffinities: [\n {id: 'cat1', name: 'Electronics'},\n {id: 'cat2', name: 'Clothing'},\n ],\n },\n },\n showFeedbackSheet: undefined,\n getPopularProducts: {\n data: [\n createProduct('pop-1', 'The Hero Snowboard', '702.95'),\n createProduct('pop-2', 'Snow Jacket', '605.95', '702.00'),\n createProduct('pop-3', 'Winter Gloves', '89.95'),\n createProduct('pop-4', 'Summer Gloves', '89.95'),\n createProduct('pop-5', 'Spring Gloves', '89.95'),\n createProduct('pop-6', 'Playstation 5', '499.95'),\n createProduct('pop-7', 'Xbox Series X', '499.95'),\n createProduct('pop-8', 'Nintendo Switch', '299.95'),\n createProduct('pop-9', 'Playstation 4', '299.95'),\n createProduct('pop-10', 'Nintendo 3DS', '89.95'),\n ],\n pageInfo: createPagination(),\n },\n share: {\n message: 'Shared!',\n success: true,\n },\n shareSingle: {\n message: 'Shared!',\n success: true,\n },\n getCuratedProducts: {\n data: [\n createProduct('cur-1', 'Curated Product 1', '79.99'),\n createProduct('cur-2', 'Curated Product 2', '129.99'),\n ],\n pageInfo: createPagination(),\n },\n getSavedProducts: {\n data: [createProduct('saved-1', 'Saved Product 1', '49.99')],\n pageInfo: createPagination(),\n },\n getRecentProducts: {\n data: [createProduct('recent-1', 'Recent Product 1', '59.99')],\n pageInfo: createPagination(),\n },\n getProductSearch: {\n data: [createProduct('search-3', 'Search Product 3', '39.99')],\n pageInfo: createPagination(),\n },\n getProducts: {data: [createProduct('prod-2', 'Product 2', '19.99')]},\n getProduct: {data: createProduct('prod-1', 'Sample Product')},\n getProductVariants: {\n data: [\n {\n id: 'variant-1',\n title: 'Variant 1',\n isFavorited: false,\n image: {url: 'https://example.com/variant-1.jpg'},\n price: {amount: '19.99', currencyCode: 'USD'},\n compareAtPrice: {amount: '29.99', currencyCode: 'USD'},\n },\n ],\n pageInfo: createPagination(),\n },\n getProductMedia: {\n data: [\n {\n id: 'media-1',\n image: {url: 'https://example.com/media-1.jpg'},\n mediaContentType: 'IMAGE',\n alt: 'Sample product image',\n },\n ],\n pageInfo: createPagination(),\n },\n getShop: {data: createShop('shop-1', 'Sample Shop')},\n getRecentShops: {\n data: [createShop('recent-shop-1', 'Recent Shop 1')],\n pageInfo: createPagination(),\n },\n getFollowedShops: {\n data: [createShop('followed-shop-1', 'Followed Shop 1')],\n pageInfo: createPagination(),\n },\n previewProductInAr: undefined,\n createContent: {\n data: {\n publicId: 'content-123',\n externalId: null,\n image: {\n id: 'img-123',\n url: 'https://cdn.shopify.com/s/files/1/0633/6574/2742/files/Namnlosdesign-47.png?v=1740438079',\n width: 800,\n height: 600,\n },\n title: 'Mock Content',\n description: 'This is a mock content item',\n visibility: ['DISCOVERABLE'],\n shareableUrl: 'https://example.com/content/123',\n products: null,\n },\n },\n getContent: {\n data: [\n {\n publicId: 'content-123',\n image: {\n id: 'img-123',\n url: 'https://cdn.shopify.com/s/files/1/0633/6574/2742/files/Namnlosdesign-47.png?v=1740438079',\n width: 800,\n height: 600,\n },\n title: 'Mock Content',\n visibility: ['DISCOVERABLE'],\n status: MinisContentStatus.READY,\n },\n ],\n },\n generateUserToken: {\n data: {\n token: 'user-token-123',\n expiresAt: '2025-01-01',\n userState: UserState.VERIFIED,\n },\n },\n navigateToCart: undefined,\n requestPermission: {\n granted: true,\n },\n } as const\n\n const mock: Partial<ShopActions> = {}\n for (const key in results) {\n if (Object.prototype.hasOwnProperty.call(results, key)) {\n // @ts-expect-error: dynamic assignment is safe due to exhaustive mapping\n mock[key] = makeMockMethod(\n key as keyof ShopActions,\n results[key as keyof typeof results]\n )\n }\n }\n return mock as ShopActions\n}\n\n// Detect if running on a mobile device\nconst isMobile = (): boolean => {\n const userAgent = navigator.userAgent.toLowerCase()\n const isIOS = /iphone|ipad|ipod/.test(userAgent)\n const isAndroid = /android/.test(userAgent)\n\n return isIOS || isAndroid\n}\n\nexport const injectMocks = ({force}: {force?: boolean} = {}) => {\n // Only inject mocks if we aren't on a mobile device or we force it\n if (isMobile() && !force) {\n return\n }\n\n if (!window.minisSDK) {\n window.minisSDK = makeMockActions()\n window.minisParams = {\n handle: 'mock-handle',\n initialUrl: '/mock-initial-url',\n platform: 'web',\n }\n }\n}\n"],"names":["createProduct","id","title","price","compareAtPrice","createShop","name","options","featuredImages","_","i","createPagination","hasNext","createProductList","products","makeMockMethod","key","result","params","makeMockActions","results","MinisContentStatus","UserState","mock","isMobile","userAgent","isIOS","isAndroid","injectMocks","force"],"mappings":";;AASO,MAAMA,IAAgB,CAC3BC,GACAC,GACAC,IAAQ,SACRC,OACa;AAAA,EACb,IAAAH;AAAA,EACA,OAAAC;AAAA,EACA,OAAO,EAAC,QAAQC,GAAO,cAAc,MAAK;AAAA,EAC1C,GAAIC,KAAkB;AAAA,IACpB,gBAAgB,EAAC,QAAQA,GAAgB,cAAc,MAAK;AAAA,EAC9D;AAAA,EACA,iBAAiB,EAAC,eAAe,KAAK,aAAa,GAAE;AAAA,EACrD,MAAMC,EAAW,SAAS,WAAW;AAAA,EACrC,kBAAkB,WAAWJ,CAAE;AAAA,EAC/B,aAAa;AAAA,EACb,eAAe;AAAA,IACb,KAAK;AAAA,IACL,SAASC;AAAA,EAAA;AAEb,IAEaG,IAAa,CACxBJ,GACAK,GACAC,MAWG;AAQG,QAAAC,IAAiB,MAAM,KAAK,EAAC,QAAQ,EAAmB,GAAG,CAACC,GAAGC,OAAO;AAAA,IAC1E,KAAK,wCAAwCT,CAAE,IAAIS,CAAC;AAAA,IAC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O,WAAWV,EAAgB,GAClC,OAAO,cAAc;AAAA,IACnB,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AAEJ;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __module as q } from "../../../../../../../../_virtual/
|
|
1
|
+
import { __module as q } from "../../../../../../../../_virtual/index5.js";
|
|
2
2
|
import { __require as F } from "../../../../../global@4.4.0/node_modules/global/window.js";
|
|
3
3
|
import { __require as N } from "../../../../../@babel_runtime@7.27.6/node_modules/@babel/runtime/helpers/extends.js";
|
|
4
4
|
import { __require as J } from "../../../../../is-function@1.0.2/node_modules/is-function/index.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import * as c from "react";
|
|
3
|
+
import { useId as x, useRef as d, useContext as C, useInsertionEffect as R } from "react";
|
|
4
|
+
import { MotionConfigContext as $ } from "../../context/MotionConfigContext.js";
|
|
5
|
+
import { isHTMLElement as w } from "../../../../../motion-dom/dist/es/utils/is-html-element.js";
|
|
6
|
+
class P extends c.Component {
|
|
7
|
+
getSnapshotBeforeUpdate(i) {
|
|
8
|
+
const e = this.props.childRef.current;
|
|
9
|
+
if (e && i.isPresent && !this.props.isPresent) {
|
|
10
|
+
const r = e.offsetParent, o = w(r) && r.offsetWidth || 0, t = this.props.sizeRef.current;
|
|
11
|
+
t.height = e.offsetHeight || 0, t.width = e.offsetWidth || 0, t.top = e.offsetTop, t.left = e.offsetLeft, t.right = o - t.width - t.left;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Required with getSnapshotBeforeUpdate to stop React complaining.
|
|
17
|
+
*/
|
|
18
|
+
componentDidUpdate() {
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
return this.props.children;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function W({ children: s, isPresent: i, anchorX: e }) {
|
|
25
|
+
const r = x(), o = d(null), t = d({
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0,
|
|
28
|
+
top: 0,
|
|
29
|
+
left: 0,
|
|
30
|
+
right: 0
|
|
31
|
+
}), { nonce: p } = C($);
|
|
32
|
+
return R(() => {
|
|
33
|
+
const { width: f, height: h, top: l, left: m, right: a } = t.current;
|
|
34
|
+
if (i || !o.current || !f || !h)
|
|
35
|
+
return;
|
|
36
|
+
const u = e === "left" ? `left: ${m}` : `right: ${a}`;
|
|
37
|
+
o.current.dataset.motionPopId = r;
|
|
38
|
+
const n = document.createElement("style");
|
|
39
|
+
return p && (n.nonce = p), document.head.appendChild(n), n.sheet && n.sheet.insertRule(`
|
|
40
|
+
[data-motion-pop-id="${r}"] {
|
|
41
|
+
position: absolute !important;
|
|
42
|
+
width: ${f}px !important;
|
|
43
|
+
height: ${h}px !important;
|
|
44
|
+
${u}px !important;
|
|
45
|
+
top: ${l}px !important;
|
|
46
|
+
}
|
|
47
|
+
`), () => {
|
|
48
|
+
document.head.contains(n) && document.head.removeChild(n);
|
|
49
|
+
};
|
|
50
|
+
}, [i]), g(P, { isPresent: i, childRef: o, sizeRef: t, children: c.cloneElement(s, { ref: o }) });
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
W as PopChild
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=PopChild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PopChild.js","sources":["../../../../../../../../../../../../../../node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PopChild.mjs"],"sourcesContent":["\"use client\";\nimport { jsx } from 'react/jsx-runtime';\nimport * as React from 'react';\nimport { useId, useRef, useContext, useInsertionEffect } from 'react';\nimport { MotionConfigContext } from '../../context/MotionConfigContext.mjs';\nimport { isHTMLElement } from '../../../../../motion-dom/dist/es/utils/is-html-element.mjs';\n\n/**\n * Measurement functionality has to be within a separate component\n * to leverage snapshot lifecycle.\n */\nclass PopChildMeasure extends React.Component {\n getSnapshotBeforeUpdate(prevProps) {\n const element = this.props.childRef.current;\n if (element && prevProps.isPresent && !this.props.isPresent) {\n const parent = element.offsetParent;\n const parentWidth = isHTMLElement(parent)\n ? parent.offsetWidth || 0\n : 0;\n const size = this.props.sizeRef.current;\n size.height = element.offsetHeight || 0;\n size.width = element.offsetWidth || 0;\n size.top = element.offsetTop;\n size.left = element.offsetLeft;\n size.right = parentWidth - size.width - size.left;\n }\n return null;\n }\n /**\n * Required with getSnapshotBeforeUpdate to stop React complaining.\n */\n componentDidUpdate() { }\n render() {\n return this.props.children;\n }\n}\nfunction PopChild({ children, isPresent, anchorX }) {\n const id = useId();\n const ref = useRef(null);\n const size = useRef({\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n right: 0,\n });\n const { nonce } = useContext(MotionConfigContext);\n /**\n * We create and inject a style block so we can apply this explicit\n * sizing in a non-destructive manner by just deleting the style block.\n *\n * We can't apply size via render as the measurement happens\n * in getSnapshotBeforeUpdate (post-render), likewise if we apply the\n * styles directly on the DOM node, we might be overwriting\n * styles set via the style prop.\n */\n useInsertionEffect(() => {\n const { width, height, top, left, right } = size.current;\n if (isPresent || !ref.current || !width || !height)\n return;\n const x = anchorX === \"left\" ? `left: ${left}` : `right: ${right}`;\n ref.current.dataset.motionPopId = id;\n const style = document.createElement(\"style\");\n if (nonce)\n style.nonce = nonce;\n document.head.appendChild(style);\n if (style.sheet) {\n style.sheet.insertRule(`\n [data-motion-pop-id=\"${id}\"] {\n position: absolute !important;\n width: ${width}px !important;\n height: ${height}px !important;\n ${x}px !important;\n top: ${top}px !important;\n }\n `);\n }\n return () => {\n if (document.head.contains(style)) {\n document.head.removeChild(style);\n }\n };\n }, [isPresent]);\n return (jsx(PopChildMeasure, { isPresent: isPresent, childRef: ref, sizeRef: size, children: React.cloneElement(children, { ref }) }));\n}\n\nexport { PopChild };\n"],"names":["PopChildMeasure","React","prevProps","element","parent","parentWidth","isHTMLElement","size","PopChild","children","isPresent","anchorX","id","useId","ref","useRef","nonce","useContext","MotionConfigContext","useInsertionEffect","width","height","top","left","right","x","style","jsx"],"mappings":";;;;;AAWA,MAAMA,UAAwBC,EAAM,UAAU;AAAA,EAC1C,wBAAwBC,GAAW;AAC/B,UAAMC,IAAU,KAAK,MAAM,SAAS;AACpC,QAAIA,KAAWD,EAAU,aAAa,CAAC,KAAK,MAAM,WAAW;AACzD,YAAME,IAASD,EAAQ,cACjBE,IAAcC,EAAcF,CAAM,KAClCA,EAAO,eAAe,GAEtBG,IAAO,KAAK,MAAM,QAAQ;AAChC,MAAAA,EAAK,SAASJ,EAAQ,gBAAgB,GACtCI,EAAK,QAAQJ,EAAQ,eAAe,GACpCI,EAAK,MAAMJ,EAAQ,WACnBI,EAAK,OAAOJ,EAAQ,YACpBI,EAAK,QAAQF,IAAcE,EAAK,QAAQA,EAAK;AAAA,IACzD;AACQ,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAII,qBAAqB;AAAA,EAAA;AAAA,EACrB,SAAS;AACL,WAAO,KAAK,MAAM;AAAA,EAC1B;AACA;AACA,SAASC,EAAS,EAAE,UAAAC,GAAU,WAAAC,GAAW,SAAAC,EAAO,GAAI;AAChD,QAAMC,IAAKC,EAAO,GACZC,IAAMC,EAAO,IAAI,GACjBR,IAAOQ,EAAO;AAAA,IAChB,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,EACf,CAAK,GACK,EAAE,OAAAC,EAAK,IAAKC,EAAWC,CAAmB;AAUhD,SAAAC,EAAmB,MAAM;AACrB,UAAM,EAAE,OAAAC,GAAO,QAAAC,GAAQ,KAAAC,GAAK,MAAAC,GAAM,OAAAC,EAAK,IAAKjB,EAAK;AACjD,QAAIG,KAAa,CAACI,EAAI,WAAW,CAACM,KAAS,CAACC;AACxC;AACJ,UAAMI,IAAId,MAAY,SAAS,SAASY,CAAI,KAAK,UAAUC,CAAK;AAChE,IAAAV,EAAI,QAAQ,QAAQ,cAAcF;AAClC,UAAMc,IAAQ,SAAS,cAAc,OAAO;AAC5C,WAAIV,MACAU,EAAM,QAAQV,IAClB,SAAS,KAAK,YAAYU,CAAK,GAC3BA,EAAM,SACNA,EAAM,MAAM,WAAW;AAAA,iCACFd,CAAE;AAAA;AAAA,qBAEdQ,CAAK;AAAA,sBACJC,CAAM;AAAA,cACdI,CAAC;AAAA,mBACIH,CAAG;AAAA;AAAA,SAEb,GAEM,MAAM;AACT,MAAI,SAAS,KAAK,SAASI,CAAK,KAC5B,SAAS,KAAK,YAAYA,CAAK;AAAA,IAEtC;AAAA,EACT,GAAO,CAAChB,CAAS,CAAC,GACNiB,EAAI3B,GAAiB,EAAE,WAAWU,GAAW,UAAUI,GAAK,SAASP,GAAM,UAAUN,EAAM,aAAaQ,GAAU,EAAE,KAAAK,EAAK,CAAA,GAAG;AACxI;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import * as C from "react";
|
|
3
|
+
import { useId as v, useMemo as c } from "react";
|
|
4
|
+
import { PresenceContext as M } from "../../context/PresenceContext.js";
|
|
5
|
+
import { useConstant as w } from "../../utils/use-constant.js";
|
|
6
|
+
import { PopChild as x } from "./PopChild.js";
|
|
7
|
+
const X = ({ children: f, initial: i, isPresent: r, onExitComplete: t, custom: m, presenceAffectsLayout: p, mode: l, anchorX: d }) => {
|
|
8
|
+
const e = w(R), h = v();
|
|
9
|
+
let u = !0, s = c(() => (u = !1, {
|
|
10
|
+
id: h,
|
|
11
|
+
initial: i,
|
|
12
|
+
isPresent: r,
|
|
13
|
+
custom: m,
|
|
14
|
+
onExitComplete: (o) => {
|
|
15
|
+
e.set(o, !0);
|
|
16
|
+
for (const n of e.values())
|
|
17
|
+
if (!n)
|
|
18
|
+
return;
|
|
19
|
+
t && t();
|
|
20
|
+
},
|
|
21
|
+
register: (o) => (e.set(o, !1), () => e.delete(o))
|
|
22
|
+
}), [r, e, t]);
|
|
23
|
+
return p && u && (s = { ...s }), c(() => {
|
|
24
|
+
e.forEach((o, n) => e.set(n, !1));
|
|
25
|
+
}, [r]), C.useEffect(() => {
|
|
26
|
+
!r && !e.size && t && t();
|
|
27
|
+
}, [r]), l === "popLayout" && (f = a(x, { isPresent: r, anchorX: d, children: f })), a(M.Provider, { value: s, children: f });
|
|
28
|
+
};
|
|
29
|
+
function R() {
|
|
30
|
+
return /* @__PURE__ */ new Map();
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
X as PresenceChild
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=PresenceChild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresenceChild.js","sources":["../../../../../../../../../../../../../../node_modules/.pnpm/motion@12.17.3_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/motion/dist/es/framer-motion/dist/es/components/AnimatePresence/PresenceChild.mjs"],"sourcesContent":["\"use client\";\nimport { jsx } from 'react/jsx-runtime';\nimport * as React from 'react';\nimport { useId, useMemo } from 'react';\nimport { PresenceContext } from '../../context/PresenceContext.mjs';\nimport { useConstant } from '../../utils/use-constant.mjs';\nimport { PopChild } from './PopChild.mjs';\n\nconst PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, }) => {\n const presenceChildren = useConstant(newChildrenMap);\n const id = useId();\n let isReusedContext = true;\n let context = useMemo(() => {\n isReusedContext = false;\n return {\n id,\n initial,\n isPresent,\n custom,\n onExitComplete: (childId) => {\n presenceChildren.set(childId, true);\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete)\n return; // can stop searching when any is incomplete\n }\n onExitComplete && onExitComplete();\n },\n register: (childId) => {\n presenceChildren.set(childId, false);\n return () => presenceChildren.delete(childId);\n },\n };\n }, [isPresent, presenceChildren, onExitComplete]);\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n if (presenceAffectsLayout && isReusedContext) {\n context = { ...context };\n }\n useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false));\n }, [isPresent]);\n /**\n * If there's no `motion` components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n !isPresent &&\n !presenceChildren.size &&\n onExitComplete &&\n onExitComplete();\n }, [isPresent]);\n if (mode === \"popLayout\") {\n children = (jsx(PopChild, { isPresent: isPresent, anchorX: anchorX, children: children }));\n }\n return (jsx(PresenceContext.Provider, { value: context, children: children }));\n};\nfunction newChildrenMap() {\n return new Map();\n}\n\nexport { PresenceChild };\n"],"names":["PresenceChild","children","initial","isPresent","onExitComplete","custom","presenceAffectsLayout","mode","anchorX","presenceChildren","useConstant","newChildrenMap","id","useId","isReusedContext","context","useMemo","childId","isComplete","_","key","React","jsx","PopChild","PresenceContext"],"mappings":";;;;;;AAQK,MAACA,IAAgB,CAAC,EAAE,UAAAC,GAAU,SAAAC,GAAS,WAAAC,GAAW,gBAAAC,GAAgB,QAAAC,GAAQ,uBAAAC,GAAuB,MAAAC,GAAM,SAAAC,QAAe;AACvH,QAAMC,IAAmBC,EAAYC,CAAc,GAC7CC,IAAKC,EAAO;AAClB,MAAIC,IAAkB,IAClBC,IAAUC,EAAQ,OAClBF,IAAkB,IACX;AAAA,IACH,IAAAF;AAAA,IACA,SAAAV;AAAA,IACA,WAAAC;AAAA,IACA,QAAAE;AAAA,IACA,gBAAgB,CAACY,MAAY;AACzB,MAAAR,EAAiB,IAAIQ,GAAS,EAAI;AAClC,iBAAWC,KAAcT,EAAiB;AACtC,YAAI,CAACS;AACD;AAER,MAAAd,KAAkBA,EAAgB;AAAA,IACrC;AAAA,IACD,UAAU,CAACa,OACPR,EAAiB,IAAIQ,GAAS,EAAK,GAC5B,MAAMR,EAAiB,OAAOQ,CAAO;AAAA,EAEnD,IACF,CAACd,GAAWM,GAAkBL,CAAc,CAAC;AAMhD,SAAIE,KAAyBQ,MACzBC,IAAU,EAAE,GAAGA,EAAS,IAE5BC,EAAQ,MAAM;AACV,IAAAP,EAAiB,QAAQ,CAACU,GAAGC,MAAQX,EAAiB,IAAIW,GAAK,EAAK,CAAC;AAAA,EAC7E,GAAO,CAACjB,CAAS,CAAC,GAKdkB,EAAM,UAAU,MAAM;AAClB,KAAClB,KACG,CAACM,EAAiB,QAClBL,KACAA,EAAgB;AAAA,EAC5B,GAAO,CAACD,CAAS,CAAC,GACVI,MAAS,gBACTN,IAAYqB,EAAIC,GAAU,EAAE,WAAWpB,GAAW,SAASK,GAAS,UAAUP,EAAQ,CAAE,IAEpFqB,EAAIE,EAAgB,UAAU,EAAE,OAAOT,GAAS,UAAUd,GAAU;AAChF;AACA,SAASU,IAAiB;AACtB,SAAO,oBAAI,IAAK;AACpB;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as P, Fragment as K } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as M, useRef as g, useState as E, useContext as N } from "react";
|
|
3
|
+
import { LayoutGroupContext as T } from "../../context/LayoutGroupContext.js";
|
|
4
|
+
import { useConstant as F } from "../../utils/use-constant.js";
|
|
5
|
+
import { useIsomorphicLayoutEffect as G } from "../../utils/use-isomorphic-effect.js";
|
|
6
|
+
import { PresenceChild as O } from "./PresenceChild.js";
|
|
7
|
+
import { usePresence as S } from "./use-presence.js";
|
|
8
|
+
import { onlyElements as w, getChildKey as c } from "./utils.js";
|
|
9
|
+
const J = ({ children: m, custom: v, initial: R = !0, onExitComplete: a, presenceAffectsLayout: k = !0, mode: f = "sync", propagate: l = !1, anchorX: A = "left" }) => {
|
|
10
|
+
const [h, L] = S(l), n = M(() => w(m), [m]), o = l && !h ? [] : n.map(c), p = g(!0), C = g(n), s = F(() => /* @__PURE__ */ new Map()), [b, j] = E(n), [r, y] = E(n);
|
|
11
|
+
G(() => {
|
|
12
|
+
p.current = !1, C.current = n;
|
|
13
|
+
for (let t = 0; t < r.length; t++) {
|
|
14
|
+
const e = c(r[t]);
|
|
15
|
+
o.includes(e) ? s.delete(e) : s.get(e) !== !0 && s.set(e, !1);
|
|
16
|
+
}
|
|
17
|
+
}, [r, o.length, o.join("-")]);
|
|
18
|
+
const u = [];
|
|
19
|
+
if (n !== b) {
|
|
20
|
+
let t = [...n];
|
|
21
|
+
for (let e = 0; e < r.length; e++) {
|
|
22
|
+
const i = r[e], d = c(i);
|
|
23
|
+
o.includes(d) || (t.splice(e, 0, i), u.push(i));
|
|
24
|
+
}
|
|
25
|
+
return f === "wait" && u.length && (t = u), y(w(t)), j(n), null;
|
|
26
|
+
}
|
|
27
|
+
process.env.NODE_ENV !== "production" && f === "wait" && r.length > 1 && console.warn(`You're attempting to animate multiple children within AnimatePresence, but its mode is set to "wait". This will lead to odd visual behaviour.`);
|
|
28
|
+
const { forceRender: D } = N(T);
|
|
29
|
+
return P(K, { children: r.map((t) => {
|
|
30
|
+
const e = c(t), i = l && !h ? !1 : n === r || o.includes(e), d = () => {
|
|
31
|
+
if (s.has(e))
|
|
32
|
+
s.set(e, !0);
|
|
33
|
+
else
|
|
34
|
+
return;
|
|
35
|
+
let x = !0;
|
|
36
|
+
s.forEach((I) => {
|
|
37
|
+
I || (x = !1);
|
|
38
|
+
}), x && (D?.(), y(C.current), l && L?.(), a && a());
|
|
39
|
+
};
|
|
40
|
+
return P(O, { isPresent: i, initial: !p.current || R ? void 0 : !1, custom: v, presenceAffectsLayout: k, mode: f, onExitComplete: i ? void 0 : d, anchorX: A, children: t }, e);
|
|
41
|
+
}) });
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
J as AnimatePresence
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=index.js.map
|