@superwall/studio 2.1.0 → 2.2.0
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/assets/index-DQ--wQrM.js +11 -0
- package/dist/assets/index-FbZPTKMZ.css +1 -0
- package/dist/index.html +2 -2
- package/dist/lib/components/NotificationPreview.d.ts +18 -0
- package/dist/lib/components/PaywallToasts.d.ts +8 -2
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1653 -1359
- package/dist/lib/lib/actions.d.ts +2 -2
- package/dist/lib/lib/contract.d.ts +4 -0
- package/dist/lib/lib/devices.d.ts +4 -0
- package/dist/lib/lib/project.d.ts +2 -1
- package/dist/lib/lib/surfaces.d.ts +8 -3
- package/dist/lib/lib/time.d.ts +1 -0
- package/dist/lib/studio.css +1 -1
- package/package.json +2 -2
- package/src/components/DownloadScreenshot.tsx +93 -31
- package/src/components/NotificationPreview.tsx +228 -0
- package/src/components/PaywallToasts.tsx +92 -5
- package/src/components/preview/Canvas.tsx +67 -10
- package/src/index.ts +2 -0
- package/src/lib/actions.ts +6 -3
- package/src/lib/contract.ts +5 -0
- package/src/lib/devices.ts +12 -0
- package/src/lib/notices.ts +0 -1
- package/src/lib/project.ts +11 -0
- package/src/lib/surfaces.ts +9 -1
- package/src/lib/time.ts +13 -6
- package/src/screens/SurfaceEditor.tsx +7 -1
- package/dist/assets/index-0QL9585B.js +0 -11
- package/dist/assets/index-DVQfR2L6.css +0 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export type NotificationPlatform = "iOS" | "Android";
|
|
4
|
+
|
|
5
|
+
export type NotificationContent = {
|
|
6
|
+
title: string;
|
|
7
|
+
subtitle?: string;
|
|
8
|
+
body: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type NotificationApp = {
|
|
12
|
+
name: string;
|
|
13
|
+
iconUrl?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const IOS_FONT = 'system-ui, BlinkMacSystemFont, -apple-system, "SF Pro Text", sans-serif';
|
|
17
|
+
const ANDROID_FONT = '"Google Sans Text", Roboto, system-ui, sans-serif';
|
|
18
|
+
|
|
19
|
+
const INSET: Record<NotificationPlatform, number> = { iOS: 14, Android: 12 };
|
|
20
|
+
|
|
21
|
+
const WALLPAPER: Record<NotificationPlatform, string> = {
|
|
22
|
+
iOS: "linear-gradient(160deg, #262a45 0%, #121423 55%, #1b1f33 100%)",
|
|
23
|
+
Android: "linear-gradient(160deg, #1d1b26 0%, #0f0e14 60%, #17151d 100%)",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const notificationWidth = (platform: NotificationPlatform, screenWidth: number): number =>
|
|
27
|
+
Math.max(0, screenWidth - INSET[platform] * 2);
|
|
28
|
+
|
|
29
|
+
const clamp = (lines: number): React.CSSProperties => ({
|
|
30
|
+
display: "-webkit-box",
|
|
31
|
+
WebkitBoxOrient: "vertical",
|
|
32
|
+
WebkitLineClamp: lines,
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
overflowWrap: "anywhere",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const oneLine: React.CSSProperties = {
|
|
38
|
+
overflow: "hidden",
|
|
39
|
+
textOverflow: "ellipsis",
|
|
40
|
+
whiteSpace: "nowrap",
|
|
41
|
+
minWidth: 0,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
45
|
+
|
|
46
|
+
const initialOf = (name: string): string => {
|
|
47
|
+
const [first] = segmenter.segment(name.trim());
|
|
48
|
+
return first ? first.segment.toUpperCase() : "?";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const AppIcon = ({
|
|
52
|
+
app,
|
|
53
|
+
size,
|
|
54
|
+
radius,
|
|
55
|
+
}: {
|
|
56
|
+
app: NotificationApp;
|
|
57
|
+
size: number;
|
|
58
|
+
radius: number | string;
|
|
59
|
+
}) => {
|
|
60
|
+
const [failed, setFailed] = React.useState(false);
|
|
61
|
+
const shape: React.CSSProperties = {
|
|
62
|
+
width: size,
|
|
63
|
+
height: size,
|
|
64
|
+
borderRadius: radius,
|
|
65
|
+
flexShrink: 0,
|
|
66
|
+
};
|
|
67
|
+
if (app.iconUrl && !failed) {
|
|
68
|
+
return (
|
|
69
|
+
<img
|
|
70
|
+
src={app.iconUrl}
|
|
71
|
+
alt=""
|
|
72
|
+
data-testid="notification-icon"
|
|
73
|
+
style={{ ...shape, objectFit: "cover" }}
|
|
74
|
+
onError={() => setFailed(true)}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return (
|
|
79
|
+
<span
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
data-testid="notification-icon-fallback"
|
|
82
|
+
style={{
|
|
83
|
+
...shape,
|
|
84
|
+
display: "flex",
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
justifyContent: "center",
|
|
87
|
+
fontSize: size * 0.45,
|
|
88
|
+
fontWeight: 600,
|
|
89
|
+
background: "linear-gradient(180deg, #4a4a50 0%, #2c2c30 100%)",
|
|
90
|
+
color: "#fff",
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{initialOf(app.name)}
|
|
94
|
+
</span>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const IosNotification = ({
|
|
99
|
+
app,
|
|
100
|
+
notification,
|
|
101
|
+
}: {
|
|
102
|
+
app: NotificationApp;
|
|
103
|
+
notification: NotificationContent;
|
|
104
|
+
}) => (
|
|
105
|
+
<div
|
|
106
|
+
data-platform="iOS"
|
|
107
|
+
style={{
|
|
108
|
+
display: "flex",
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
gap: 12,
|
|
111
|
+
padding: "11.5px 17px 12.7px 14px",
|
|
112
|
+
borderRadius: 24,
|
|
113
|
+
background: "rgba(66, 66, 74, 0.5)",
|
|
114
|
+
backdropFilter: "blur(24px) saturate(1.6)",
|
|
115
|
+
WebkitBackdropFilter: "blur(24px) saturate(1.6)",
|
|
116
|
+
boxShadow: "inset 0 0 0 0.5px rgba(255, 255, 255, 0.16)",
|
|
117
|
+
color: "rgba(255, 255, 255, 0.93)",
|
|
118
|
+
fontFamily: IOS_FONT,
|
|
119
|
+
fontSize: 15,
|
|
120
|
+
lineHeight: "17.9px",
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<AppIcon app={app} size={38} radius={8} />
|
|
124
|
+
<div style={{ flex: 1, minWidth: 0 }}>
|
|
125
|
+
<div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
|
|
126
|
+
<span data-part="title" style={{ ...oneLine, flex: 1, fontWeight: 600 }}>
|
|
127
|
+
{notification.title}
|
|
128
|
+
</span>
|
|
129
|
+
<span style={{ flexShrink: 0, fontSize: 13, color: "rgba(255, 255, 255, 0.6)" }}>now</span>
|
|
130
|
+
</div>
|
|
131
|
+
{notification.subtitle && (
|
|
132
|
+
<div data-part="subtitle" style={{ ...oneLine, fontWeight: 600 }}>
|
|
133
|
+
{notification.subtitle}
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
<div data-part="body" style={clamp(4)}>
|
|
137
|
+
{notification.body}
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const AndroidNotification = ({
|
|
144
|
+
app,
|
|
145
|
+
notification,
|
|
146
|
+
}: {
|
|
147
|
+
app: NotificationApp;
|
|
148
|
+
notification: NotificationContent;
|
|
149
|
+
}) => (
|
|
150
|
+
<div
|
|
151
|
+
data-platform="Android"
|
|
152
|
+
style={{
|
|
153
|
+
display: "flex",
|
|
154
|
+
alignItems: "flex-start",
|
|
155
|
+
gap: 12,
|
|
156
|
+
padding: 16,
|
|
157
|
+
borderRadius: 28,
|
|
158
|
+
background: "#2b2930",
|
|
159
|
+
color: "#e6e0e9",
|
|
160
|
+
fontFamily: ANDROID_FONT,
|
|
161
|
+
fontSize: 14,
|
|
162
|
+
lineHeight: "20px",
|
|
163
|
+
}}
|
|
164
|
+
>
|
|
165
|
+
<AppIcon app={app} size={36} radius="50%" />
|
|
166
|
+
<div style={{ flex: 1, minWidth: 0 }}>
|
|
167
|
+
<div
|
|
168
|
+
data-part="header"
|
|
169
|
+
style={{
|
|
170
|
+
display: "flex",
|
|
171
|
+
gap: 4,
|
|
172
|
+
fontSize: 12,
|
|
173
|
+
lineHeight: "16px",
|
|
174
|
+
color: "#cac4d0",
|
|
175
|
+
}}
|
|
176
|
+
>
|
|
177
|
+
<span style={{ ...oneLine, flexShrink: 0, maxWidth: "50%" }}>{app.name}</span>
|
|
178
|
+
{notification.subtitle && (
|
|
179
|
+
<>
|
|
180
|
+
<span aria-hidden="true">•</span>
|
|
181
|
+
<span data-part="subtitle" style={oneLine}>
|
|
182
|
+
{notification.subtitle}
|
|
183
|
+
</span>
|
|
184
|
+
</>
|
|
185
|
+
)}
|
|
186
|
+
<span aria-hidden="true">•</span>
|
|
187
|
+
<span style={{ flexShrink: 0 }}>now</span>
|
|
188
|
+
</div>
|
|
189
|
+
<div data-part="title" style={{ ...oneLine, marginTop: 2, fontWeight: 500 }}>
|
|
190
|
+
{notification.title}
|
|
191
|
+
</div>
|
|
192
|
+
<div data-part="body" style={{ ...clamp(2), color: "#cac4d0" }}>
|
|
193
|
+
{notification.body}
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
export const NotificationPreview = ({
|
|
200
|
+
platform,
|
|
201
|
+
screenWidth,
|
|
202
|
+
app,
|
|
203
|
+
notification,
|
|
204
|
+
}: {
|
|
205
|
+
platform: NotificationPlatform;
|
|
206
|
+
screenWidth: number;
|
|
207
|
+
app: NotificationApp;
|
|
208
|
+
notification: NotificationContent;
|
|
209
|
+
}) => (
|
|
210
|
+
<div
|
|
211
|
+
data-testid="notification-preview"
|
|
212
|
+
className="rounded-sm"
|
|
213
|
+
style={{
|
|
214
|
+
width: screenWidth,
|
|
215
|
+
padding: `14px ${INSET[platform]}px`,
|
|
216
|
+
background: WALLPAPER[platform],
|
|
217
|
+
colorScheme: "dark",
|
|
218
|
+
}}
|
|
219
|
+
>
|
|
220
|
+
<div data-part="card" style={{ width: notificationWidth(platform, screenWidth) }}>
|
|
221
|
+
{platform === "iOS" ? (
|
|
222
|
+
<IosNotification app={app} notification={notification} />
|
|
223
|
+
) : (
|
|
224
|
+
<AndroidNotification app={app} notification={notification} />
|
|
225
|
+
)}
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { toast, Toaster } from "sonner";
|
|
3
|
-
import type { HostDelegate } from "@superwall/host";
|
|
3
|
+
import type { HostDelegate, TOutgoingMessage } from "@superwall/host";
|
|
4
4
|
import {
|
|
5
5
|
AlertTriangleIcon,
|
|
6
6
|
BellIcon,
|
|
@@ -16,7 +16,14 @@ import {
|
|
|
16
16
|
type IconComponent,
|
|
17
17
|
} from "./icons";
|
|
18
18
|
import { InlineCode } from "./InlineCode";
|
|
19
|
+
import {
|
|
20
|
+
NotificationPreview,
|
|
21
|
+
type NotificationApp,
|
|
22
|
+
type NotificationPlatform,
|
|
23
|
+
} from "./NotificationPreview";
|
|
24
|
+
import { DEFAULT_DEVICE_ID, deviceById, notificationScreenFor } from "../lib/devices";
|
|
19
25
|
import { noticeFor, type EventNotice, type PaywallMessageName } from "../lib/notices";
|
|
26
|
+
import { timeUntil } from "../lib/time";
|
|
20
27
|
|
|
21
28
|
const TINT: Record<EventNotice["tone"], string> = {
|
|
22
29
|
info: "text-info",
|
|
@@ -43,11 +50,12 @@ const ICON: Partial<Record<PaywallMessageName, IconComponent>> = {
|
|
|
43
50
|
custom: BoltIcon,
|
|
44
51
|
request_permission: BoltIcon,
|
|
45
52
|
request_callback: BoltIcon,
|
|
46
|
-
schedule_notification: BellIcon,
|
|
47
53
|
request_store_review: StarIcon,
|
|
48
54
|
user_attribute_updated: UserIcon,
|
|
49
55
|
};
|
|
50
56
|
|
|
57
|
+
const SURFACE = "rounded-sm border border-border bg-popover font-sans text-sm text-foreground";
|
|
58
|
+
|
|
51
59
|
export const ToastCard = ({
|
|
52
60
|
icon: Icon,
|
|
53
61
|
tone,
|
|
@@ -60,7 +68,7 @@ export const ToastCard = ({
|
|
|
60
68
|
description?: React.ReactNode;
|
|
61
69
|
actions?: React.ReactNode;
|
|
62
70
|
}>) => (
|
|
63
|
-
<div className=
|
|
71
|
+
<div className={`w-90 max-w-[calc(100vw-2rem)] py-3 ps-[calc(--spacing(3)-1px)] pe-3 ${SURFACE}`}>
|
|
64
72
|
<div className="grid grid-cols-[0.875rem_1fr] items-start gap-x-2">
|
|
65
73
|
<span className={`flex h-5 items-center justify-center ${TINT[tone]}`}>
|
|
66
74
|
<Icon />
|
|
@@ -223,6 +231,75 @@ const CALLBACK: readonly Choice<"success" | "failure">[] = [
|
|
|
223
231
|
},
|
|
224
232
|
];
|
|
225
233
|
|
|
234
|
+
export type ReminderTarget = {
|
|
235
|
+
platform: NotificationPlatform;
|
|
236
|
+
screenWidth: number;
|
|
237
|
+
app: NotificationApp;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const defaultScreen = notificationScreenFor(deviceById(DEFAULT_DEVICE_ID), false);
|
|
241
|
+
|
|
242
|
+
const DEFAULT_TARGET: ReminderTarget = {
|
|
243
|
+
platform: defaultScreen.platform,
|
|
244
|
+
screenWidth: defaultScreen.width,
|
|
245
|
+
app: { name: "superwall" },
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
type ScheduledNotification = Extract<TOutgoingMessage, { event_name: "schedule_notification" }>;
|
|
249
|
+
|
|
250
|
+
const TOAST_FRAME = 26;
|
|
251
|
+
|
|
252
|
+
const ReminderToast = ({
|
|
253
|
+
message,
|
|
254
|
+
target,
|
|
255
|
+
onDismiss,
|
|
256
|
+
}: {
|
|
257
|
+
message: ScheduledNotification;
|
|
258
|
+
target: ReminderTarget;
|
|
259
|
+
onDismiss: () => void;
|
|
260
|
+
}) => (
|
|
261
|
+
<div
|
|
262
|
+
className={`relative left-1/2 -translate-x-1/2 p-3 ${SURFACE}`}
|
|
263
|
+
style={{ width: target.screenWidth + TOAST_FRAME }}
|
|
264
|
+
>
|
|
265
|
+
<div className="mb-3 grid grid-cols-[0.875rem_1fr_auto] items-center gap-x-2">
|
|
266
|
+
<span className={`flex h-5 items-center justify-center ${TINT.info}`}>
|
|
267
|
+
<BellIcon />
|
|
268
|
+
</span>
|
|
269
|
+
<span className="min-w-0 font-medium">
|
|
270
|
+
Trial reminder scheduled{" "}
|
|
271
|
+
<span className="font-normal text-fg-secondary">· {timeUntil(message.delay)}</span>
|
|
272
|
+
</span>
|
|
273
|
+
<button
|
|
274
|
+
type="button"
|
|
275
|
+
aria-label="Dismiss"
|
|
276
|
+
className="sw-btn sw-btn--xs sw-btn--icon sw-btn--ghost"
|
|
277
|
+
onClick={onDismiss}
|
|
278
|
+
>
|
|
279
|
+
<XIcon />
|
|
280
|
+
</button>
|
|
281
|
+
</div>
|
|
282
|
+
<NotificationPreview
|
|
283
|
+
platform={target.platform}
|
|
284
|
+
screenWidth={target.screenWidth}
|
|
285
|
+
app={target.app}
|
|
286
|
+
notification={{
|
|
287
|
+
title: message.title,
|
|
288
|
+
...(message.subtitle === undefined ? {} : { subtitle: message.subtitle }),
|
|
289
|
+
body: message.body,
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
</div>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const showReminder = (message: ScheduledNotification, target: ReminderTarget) => {
|
|
296
|
+
const id = `reminder-${message.id}`;
|
|
297
|
+
toast.custom(
|
|
298
|
+
() => <ReminderToast message={message} target={target} onDismiss={() => toast.dismiss(id)} />,
|
|
299
|
+
{ id, duration: Number.POSITIVE_INFINITY },
|
|
300
|
+
);
|
|
301
|
+
};
|
|
302
|
+
|
|
226
303
|
let asked = 0;
|
|
227
304
|
|
|
228
305
|
const ask = <T,>(
|
|
@@ -251,8 +328,14 @@ const ask = <T,>(
|
|
|
251
328
|
);
|
|
252
329
|
});
|
|
253
330
|
|
|
254
|
-
export const createStudioDelegate = (
|
|
331
|
+
export const createStudioDelegate = (
|
|
332
|
+
reminderTarget: () => ReminderTarget = () => DEFAULT_TARGET,
|
|
333
|
+
): HostDelegate => ({
|
|
255
334
|
event: (message) => {
|
|
335
|
+
if (message.event_name === "schedule_notification") {
|
|
336
|
+
showReminder(message, reminderTarget());
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
256
339
|
const notice = noticeFor(message);
|
|
257
340
|
if (notice) toast.custom(() => <Notice notice={notice} />);
|
|
258
341
|
},
|
|
@@ -267,7 +350,11 @@ export const createStudioDelegate = (): HostDelegate => ({
|
|
|
267
350
|
ask("request_callback", "callback", name, CALLBACK).then((status) => ({ status })),
|
|
268
351
|
});
|
|
269
352
|
|
|
270
|
-
export const useStudioDelegate = (): HostDelegate =>
|
|
353
|
+
export const useStudioDelegate = (reminderTarget?: ReminderTarget): HostDelegate => {
|
|
354
|
+
const latest = React.useRef(reminderTarget);
|
|
355
|
+
latest.current = reminderTarget;
|
|
356
|
+
return React.useMemo(() => createStudioDelegate(() => latest.current ?? DEFAULT_TARGET), []);
|
|
357
|
+
};
|
|
271
358
|
|
|
272
359
|
export const PaywallToasts = ({
|
|
273
360
|
surfaceKey,
|
|
@@ -13,9 +13,21 @@ const WHEEL_ZOOM_SENSITIVITY = 0.01;
|
|
|
13
13
|
const WHEEL_ZOOM_STEP_LIMIT = { min: 0.6, max: 1.6 };
|
|
14
14
|
const DRAG_THRESHOLD = 4;
|
|
15
15
|
const GRAB_STYLE_ATTRIBUTE = "data-studio-grab";
|
|
16
|
+
const WHEEL_GESTURE_GAP_MS = 120;
|
|
17
|
+
const WHEEL_GESTURE_DECIDE_PX = 8;
|
|
18
|
+
const WHEEL_PAGE_AXIS_BIAS = 2;
|
|
19
|
+
const WHEEL_LINE_PX = 16;
|
|
20
|
+
const WHEEL_PAGE_PX = 800;
|
|
16
21
|
|
|
17
22
|
type Point = { x: number; y: number };
|
|
18
23
|
|
|
24
|
+
type Axes = { x: boolean; y: boolean };
|
|
25
|
+
|
|
26
|
+
type WheelGesture = { at: number; sum: Point; pans: Axes | null };
|
|
27
|
+
|
|
28
|
+
const PANS_NONE: Axes = { x: false, y: false };
|
|
29
|
+
const PANS_BOTH: Axes = { x: true, y: true };
|
|
30
|
+
|
|
19
31
|
type Mode = { kind: "fit" } | { kind: "manual"; transform: CanvasTransform };
|
|
20
32
|
|
|
21
33
|
type Pinch = { span: number; midpoint: Point };
|
|
@@ -77,15 +89,33 @@ const claimsWheel = (element: Element, axis: "x" | "y"): boolean => {
|
|
|
77
89
|
);
|
|
78
90
|
};
|
|
79
91
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const axis = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? "x" : "y";
|
|
92
|
+
const pageClaimedAxes = (event: WheelEvent): Axes => {
|
|
93
|
+
const claimed = { x: false, y: false };
|
|
83
94
|
for (let node = isElement(event.target) ? event.target : null; node; node = node.parentElement) {
|
|
84
|
-
|
|
95
|
+
claimed.x ||= claimsWheel(node, "x");
|
|
96
|
+
claimed.y ||= claimsWheel(node, "y");
|
|
85
97
|
}
|
|
86
|
-
return
|
|
98
|
+
return claimed;
|
|
87
99
|
};
|
|
88
100
|
|
|
101
|
+
const wheelPixels = (event: WheelEvent): Point => {
|
|
102
|
+
const unit = event.deltaMode === 1 ? WHEEL_LINE_PX : event.deltaMode === 2 ? WHEEL_PAGE_PX : 1;
|
|
103
|
+
return { x: event.deltaX * unit, y: event.deltaY * unit };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const ownerOverPage = (sum: Point, claimed: Axes): Axes => {
|
|
107
|
+
const x = Math.abs(sum.x);
|
|
108
|
+
const y = Math.abs(sum.y);
|
|
109
|
+
const pageTakes =
|
|
110
|
+
(claimed.y && y * WHEEL_PAGE_AXIS_BIAS >= x) || (claimed.x && x * WHEEL_PAGE_AXIS_BIAS >= y);
|
|
111
|
+
return pageTakes ? PANS_NONE : { x: !claimed.x, y: !claimed.y };
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const panDelta = (event: WheelEvent, pans: Axes): Point => ({
|
|
115
|
+
x: pans.x ? -event.deltaX : 0,
|
|
116
|
+
y: pans.y ? -event.deltaY : 0,
|
|
117
|
+
});
|
|
118
|
+
|
|
89
119
|
const useSize = (element: HTMLElement | null): Size => {
|
|
90
120
|
const [size, setSize] = React.useState<Size>({ width: 0, height: 0 });
|
|
91
121
|
|
|
@@ -167,6 +197,18 @@ export const Canvas = ({
|
|
|
167
197
|
const pointers = React.useRef(new Map<number, Point>());
|
|
168
198
|
const pinch = React.useRef<Pinch | null>(null);
|
|
169
199
|
const lastFitKey = React.useRef(fitKey);
|
|
200
|
+
const gesture = React.useRef<WheelGesture | null>(null);
|
|
201
|
+
|
|
202
|
+
const wheelGesture = React.useCallback((): WheelGesture => {
|
|
203
|
+
const now = performance.now();
|
|
204
|
+
const ongoing = gesture.current;
|
|
205
|
+
if (ongoing && now - ongoing.at <= WHEEL_GESTURE_GAP_MS) {
|
|
206
|
+
ongoing.at = now;
|
|
207
|
+
return ongoing;
|
|
208
|
+
}
|
|
209
|
+
gesture.current = { at: now, sum: { x: 0, y: 0 }, pans: null };
|
|
210
|
+
return gesture.current;
|
|
211
|
+
}, []);
|
|
170
212
|
|
|
171
213
|
const apply = React.useCallback((next: CanvasTransform) => {
|
|
172
214
|
setMode({ kind: "manual", transform: next });
|
|
@@ -232,15 +274,20 @@ export const Canvas = ({
|
|
|
232
274
|
if (!viewport) return undefined;
|
|
233
275
|
const onWheel = (event: WheelEvent) => {
|
|
234
276
|
if (isZoomGesture(event)) {
|
|
277
|
+
gesture.current = null;
|
|
235
278
|
zoomWheel(event, toViewport(event.clientX, event.clientY));
|
|
236
279
|
return;
|
|
237
280
|
}
|
|
281
|
+
const current = wheelGesture();
|
|
282
|
+
current.pans ??= PANS_BOTH;
|
|
283
|
+
if (!current.pans.x && !current.pans.y) return;
|
|
238
284
|
event.preventDefault();
|
|
239
|
-
|
|
285
|
+
const delta = panDelta(event, current.pans);
|
|
286
|
+
apply(panBy(latest.current, delta.x, delta.y));
|
|
240
287
|
};
|
|
241
288
|
viewport.addEventListener("wheel", onWheel, { passive: false });
|
|
242
289
|
return () => viewport.removeEventListener("wheel", onWheel);
|
|
243
|
-
}, [viewport, apply, latest, toViewport, zoomWheel]);
|
|
290
|
+
}, [viewport, apply, latest, toViewport, zoomWheel, wheelGesture]);
|
|
244
291
|
|
|
245
292
|
React.useEffect(() => {
|
|
246
293
|
if (!content) return undefined;
|
|
@@ -254,6 +301,7 @@ export const Canvas = ({
|
|
|
254
301
|
const { signal } = controller;
|
|
255
302
|
const onWheel = (event: WheelEvent) => {
|
|
256
303
|
if (isZoomGesture(event)) {
|
|
304
|
+
gesture.current = null;
|
|
257
305
|
const rect = frame.getBoundingClientRect();
|
|
258
306
|
const scale = latest.current.scale;
|
|
259
307
|
zoomWheel(
|
|
@@ -262,9 +310,18 @@ export const Canvas = ({
|
|
|
262
310
|
);
|
|
263
311
|
return;
|
|
264
312
|
}
|
|
265
|
-
|
|
313
|
+
const current = wheelGesture();
|
|
314
|
+
if (event.defaultPrevented) return;
|
|
315
|
+
if (!current.pans) {
|
|
316
|
+
const pixels = wheelPixels(event);
|
|
317
|
+
current.sum = { x: current.sum.x + pixels.x, y: current.sum.y + pixels.y };
|
|
318
|
+
if (Math.hypot(current.sum.x, current.sum.y) < WHEEL_GESTURE_DECIDE_PX) return;
|
|
319
|
+
current.pans = ownerOverPage(current.sum, pageClaimedAxes(event));
|
|
320
|
+
}
|
|
321
|
+
if (!current.pans.x && !current.pans.y) return;
|
|
266
322
|
event.preventDefault();
|
|
267
|
-
|
|
323
|
+
const delta = panDelta(event, current.pans);
|
|
324
|
+
apply(panBy(latest.current, delta.x, delta.y));
|
|
268
325
|
};
|
|
269
326
|
let press: { at: Point; panning: boolean } | null = null;
|
|
270
327
|
let grabStyle: HTMLStyleElement | null = null;
|
|
@@ -321,7 +378,7 @@ export const Canvas = ({
|
|
|
321
378
|
content.removeEventListener("load", onLoad, true);
|
|
322
379
|
attached.forEach((detach) => detach());
|
|
323
380
|
};
|
|
324
|
-
}, [content, apply, latest, toViewport, zoomWheel]);
|
|
381
|
+
}, [content, apply, latest, toViewport, zoomWheel, wheelGesture]);
|
|
325
382
|
|
|
326
383
|
React.useEffect(() => {
|
|
327
384
|
const onKey = (event: KeyboardEvent) => {
|
package/src/index.ts
CHANGED
package/src/lib/actions.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
StudioActionRequest,
|
|
6
6
|
StudioActionResult,
|
|
7
7
|
StudioActions,
|
|
8
|
+
StudioScreenshot,
|
|
8
9
|
StudioStatus,
|
|
9
10
|
StudioSurface,
|
|
10
11
|
} from "./surfaces";
|
|
@@ -77,11 +78,13 @@ export const devServerActions: StudioActions = {
|
|
|
77
78
|
status: fetchStatus,
|
|
78
79
|
};
|
|
79
80
|
|
|
80
|
-
export const
|
|
81
|
+
export const fetchScreenshots = async (
|
|
82
|
+
surface: StudioSurface,
|
|
83
|
+
): Promise<StudioScreenshot[] | undefined> => {
|
|
81
84
|
const response = await fetch(`/__studio/screenshot${surfacePath(surface)}`);
|
|
82
|
-
const value = (await response.json()) as {
|
|
85
|
+
const value = (await response.json()) as { shots?: StudioScreenshot[]; unreachable?: string };
|
|
83
86
|
if (value.unreachable !== undefined) throw new Error(value.unreachable);
|
|
84
|
-
return value.
|
|
87
|
+
return value.shots;
|
|
85
88
|
};
|
|
86
89
|
|
|
87
90
|
export const fetchSamples = async (): Promise<Samples> => {
|
package/src/lib/contract.ts
CHANGED
package/src/lib/devices.ts
CHANGED
|
@@ -200,3 +200,15 @@ const DEFAULT_DEVICE: StudioDevice =
|
|
|
200
200
|
|
|
201
201
|
export const deviceById = (id: string): StudioDevice =>
|
|
202
202
|
STUDIO_DEVICES.find((device) => device.id === id) ?? DEFAULT_DEVICE;
|
|
203
|
+
|
|
204
|
+
const WIDEST_PHONE = 440;
|
|
205
|
+
|
|
206
|
+
export const notificationScreenFor = (
|
|
207
|
+
device: StudioDevice,
|
|
208
|
+
web: boolean,
|
|
209
|
+
): { platform: "iOS" | "Android"; width: number } => {
|
|
210
|
+
const host = web ? undefined : device.device;
|
|
211
|
+
return host
|
|
212
|
+
? { platform: host.platform, width: Math.min(device.width, WIDEST_PHONE) }
|
|
213
|
+
: { platform: "iOS", width: DEFAULT_DEVICE.width };
|
|
214
|
+
};
|
package/src/lib/notices.ts
CHANGED
|
@@ -29,7 +29,6 @@ const SUBJECT: Partial<Record<PaywallEventName, readonly string[]>> = {
|
|
|
29
29
|
custom: ["name", "data"],
|
|
30
30
|
request_permission: ["permission_type"],
|
|
31
31
|
request_callback: ["name"],
|
|
32
|
-
schedule_notification: ["title"],
|
|
33
32
|
discount_redemption_result: ["code"],
|
|
34
33
|
};
|
|
35
34
|
|
package/src/lib/project.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parsePresentation } from "./presentation";
|
|
2
2
|
import type {
|
|
3
|
+
StudioAppIdentity,
|
|
3
4
|
StudioOrigin,
|
|
4
5
|
StudioScreenFramework,
|
|
5
6
|
StudioSurface,
|
|
@@ -9,6 +10,7 @@ import type { SampleDefaults } from "./variables";
|
|
|
9
10
|
|
|
10
11
|
export type StudioProjectPayload = {
|
|
11
12
|
title: string;
|
|
13
|
+
app?: StudioAppIdentity;
|
|
12
14
|
scheme?: string;
|
|
13
15
|
networkOrigin?: string;
|
|
14
16
|
surfaces: StudioSurface[];
|
|
@@ -53,6 +55,13 @@ const parseSurface = (value: unknown): StudioSurface | undefined => {
|
|
|
53
55
|
};
|
|
54
56
|
};
|
|
55
57
|
|
|
58
|
+
const parseApp = (value: unknown): StudioAppIdentity | undefined => {
|
|
59
|
+
if (!isRecord(value) || typeof value.name !== "string" || value.name === "") return undefined;
|
|
60
|
+
return typeof value.iconUrl === "string" && value.iconUrl !== ""
|
|
61
|
+
? { name: value.name, iconUrl: value.iconUrl }
|
|
62
|
+
: { name: value.name };
|
|
63
|
+
};
|
|
64
|
+
|
|
56
65
|
const isFileName = (value: unknown): value is string =>
|
|
57
66
|
typeof value === "string" && value !== "" && !/[\\/]/.test(value) && !value.startsWith(".");
|
|
58
67
|
|
|
@@ -94,8 +103,10 @@ export const parseProjectPayload = (data: unknown): StudioProjectPayload => {
|
|
|
94
103
|
const samples = isRecord(data.samples) ? data.samples : {};
|
|
95
104
|
const group = (key: string): Record<string, unknown> =>
|
|
96
105
|
isRecord(samples[key]) ? (samples[key] as Record<string, unknown>) : {};
|
|
106
|
+
const app = parseApp(data.app);
|
|
97
107
|
return {
|
|
98
108
|
title: typeof data.title === "string" ? data.title : "superwall",
|
|
109
|
+
...(app === undefined ? {} : { app }),
|
|
99
110
|
scheme: typeof data.scheme === "string" ? data.scheme : undefined,
|
|
100
111
|
networkOrigin: typeof data.networkOrigin === "string" ? data.networkOrigin : undefined,
|
|
101
112
|
surfaces,
|
package/src/lib/surfaces.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
StudioActionProgress,
|
|
4
4
|
StudioActionRequest,
|
|
5
5
|
StudioActionResult,
|
|
6
|
+
StudioScreenshot,
|
|
6
7
|
StudioStatus,
|
|
7
8
|
} from "./contract";
|
|
8
9
|
import type { StudioPresentation } from "./presentation";
|
|
@@ -17,6 +18,7 @@ export type {
|
|
|
17
18
|
StudioActionProgress,
|
|
18
19
|
StudioActionRequest,
|
|
19
20
|
StudioActionResult,
|
|
21
|
+
StudioScreenshot,
|
|
20
22
|
StudioStatus,
|
|
21
23
|
StudioVersion,
|
|
22
24
|
} from "./contract";
|
|
@@ -86,10 +88,16 @@ export type StudioActions = {
|
|
|
86
88
|
pick?(version: number): void;
|
|
87
89
|
};
|
|
88
90
|
|
|
91
|
+
export type StudioAppIdentity = {
|
|
92
|
+
name: string;
|
|
93
|
+
iconUrl?: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
89
96
|
export type StudioSource = {
|
|
90
97
|
scheme?: string;
|
|
91
98
|
networkOrigin?: string;
|
|
92
99
|
title: string;
|
|
100
|
+
app?: StudioAppIdentity;
|
|
93
101
|
surfaces: StudioSurface[];
|
|
94
102
|
diagnostics?: string[];
|
|
95
103
|
samples?: SampleDefaults;
|
|
@@ -97,7 +105,7 @@ export type StudioSource = {
|
|
|
97
105
|
standaloneUrl?: PreviewUrlBuilder;
|
|
98
106
|
actions?: StudioActions;
|
|
99
107
|
previewLink?: (surface: StudioSurface) => Promise<string>;
|
|
100
|
-
|
|
108
|
+
screenshots?: (surface: StudioSurface) => Promise<StudioScreenshot[] | undefined>;
|
|
101
109
|
compareHint?: string;
|
|
102
110
|
};
|
|
103
111
|
|