@superwall/studio 1.2.0 → 1.3.0-beta.3
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/README.md +27 -14
- package/dist/assets/index-DyLb5fiB.js +11 -0
- package/dist/index.html +1 -1
- package/dist/lib/StudioApp.d.ts +2 -3
- package/dist/lib/components/PaywallToasts.d.ts +3 -0
- package/dist/lib/components/SurfaceCard.d.ts +4 -2
- package/dist/lib/components/icons.d.ts +0 -2
- package/dist/lib/components/{ActionMenu.d.ts → menus/ActionMenu.d.ts} +2 -1
- package/dist/lib/components/{CompareMenu.d.ts → menus/CompareMenu.d.ts} +1 -1
- package/dist/lib/components/{VariablesPanel.d.ts → panels/VariablesPanel.d.ts} +3 -3
- package/dist/lib/components/{DeviceChrome.d.ts → preview/DeviceChrome.d.ts} +1 -1
- package/dist/lib/components/{DeviceFrame.d.ts → preview/DeviceFrame.d.ts} +5 -2
- package/dist/lib/components/preview/HostedIframe.d.ts +7 -0
- package/dist/lib/index.d.ts +12 -6
- package/dist/lib/index.js +1467 -945
- package/dist/lib/lib/actions.d.ts +1 -1
- package/dist/lib/lib/contract.d.ts +33 -0
- package/dist/lib/lib/devices.d.ts +1 -1
- package/dist/lib/lib/host.d.ts +15 -0
- package/dist/lib/lib/notices.d.ts +9 -0
- package/dist/lib/lib/preview.d.ts +2 -4
- package/dist/lib/lib/project.d.ts +2 -1
- package/dist/lib/lib/steps.d.ts +5 -0
- package/dist/lib/lib/surfaces.d.ts +35 -0
- package/dist/lib/lib/variables.d.ts +12 -0
- package/dist/lib/products.js +26 -12
- package/dist/lib/screens/SurfaceEditor.d.ts +1 -1
- package/dist/lib/screens/SurfaceList.d.ts +1 -1
- package/package.json +5 -1
- package/src/StudioApp.tsx +6 -10
- package/src/components/PaywallToasts.tsx +162 -86
- package/src/components/SurfaceCard.tsx +9 -2
- package/src/components/icons.tsx +0 -13
- package/src/components/{ActionMenu.tsx → menus/ActionMenu.tsx} +3 -3
- package/src/components/{CompareMenu.tsx → menus/CompareMenu.tsx} +2 -2
- package/src/components/{SidePanel.tsx → panels/SidePanel.tsx} +1 -1
- package/src/components/{VariablesPanel.tsx → panels/VariablesPanel.tsx} +4 -4
- package/src/components/{DeviceChrome.tsx → preview/DeviceChrome.tsx} +1 -1
- package/src/components/{DeviceFrame.tsx → preview/DeviceFrame.tsx} +14 -55
- package/src/components/preview/HostedIframe.tsx +46 -0
- package/src/index.ts +24 -12
- package/src/lib/actions.ts +1 -1
- package/src/lib/contract.ts +30 -0
- package/src/lib/devices.ts +5 -4
- package/src/lib/host.ts +80 -0
- package/src/lib/notices.ts +63 -0
- package/src/lib/preview.ts +8 -40
- package/src/lib/products.ts +20 -1
- package/src/lib/project.ts +2 -1
- package/src/lib/steps.ts +20 -0
- package/src/lib/surfaces.ts +41 -0
- package/src/lib/time.ts +1 -2
- package/src/lib/variables.ts +13 -0
- package/src/main.tsx +3 -3
- package/src/screens/SurfaceEditor.tsx +77 -66
- package/src/screens/SurfaceList.tsx +17 -7
- package/src/vite-env.d.ts +1 -0
- package/dist/assets/index-CVKQ82YR.js +0 -11
- package/dist/lib/lib/events.d.ts +0 -27
- package/dist/lib/lib/types.d.ts +0 -77
- package/src/lib/events.ts +0 -86
- package/src/lib/types.ts +0 -87
- /package/dist/lib/components/{StudioShell.d.ts → chrome/StudioShell.d.ts} +0 -0
- /package/dist/lib/components/{Toolbar.d.ts → chrome/Toolbar.d.ts} +0 -0
- /package/dist/lib/components/{TopBar.d.ts → chrome/TopBar.d.ts} +0 -0
- /package/dist/lib/components/{MissingProducts.d.ts → panels/MissingProducts.d.ts} +0 -0
- /package/dist/lib/components/{SidePanel.d.ts → panels/SidePanel.d.ts} +0 -0
- /package/src/components/{StudioShell.tsx → chrome/StudioShell.tsx} +0 -0
- /package/src/components/{Toolbar.tsx → chrome/Toolbar.tsx} +0 -0
- /package/src/components/{TopBar.tsx → chrome/TopBar.tsx} +0 -0
- /package/src/components/{MissingProducts.tsx → panels/MissingProducts.tsx} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Samples, StudioActionName, StudioActionResult, StudioStatus, StudioSurface } from "./
|
|
1
|
+
import type { Samples, StudioActionName, StudioActionResult, StudioStatus, StudioSurface } from "./surfaces";
|
|
2
2
|
export declare const runAction: (surface: StudioSurface, action: StudioActionName, onStep?: (step: string, state: "start" | "done") => void) => Promise<StudioActionResult>;
|
|
3
3
|
export declare const fetchStatus: (surface: StudioSurface) => Promise<StudioStatus>;
|
|
4
4
|
export declare const fetchSamples: () => Promise<Samples>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type StudioActionName = "push" | "promote" | "publish";
|
|
2
|
+
export type StudioActionResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
version: number;
|
|
5
|
+
live: boolean;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
export type StudioActionProgress = (step: string, state: "start" | "done") => void;
|
|
11
|
+
export type StudioStatus = {
|
|
12
|
+
paywallId?: string;
|
|
13
|
+
identifier?: string;
|
|
14
|
+
liveUrl?: string;
|
|
15
|
+
active?: boolean;
|
|
16
|
+
updatedAt?: string;
|
|
17
|
+
unreachable?: string;
|
|
18
|
+
};
|
|
19
|
+
export type Samples = {
|
|
20
|
+
device?: Record<string, unknown>;
|
|
21
|
+
user?: Record<string, unknown>;
|
|
22
|
+
products?: Record<string, Record<string, unknown>>;
|
|
23
|
+
live?: {
|
|
24
|
+
device: boolean;
|
|
25
|
+
user: boolean;
|
|
26
|
+
};
|
|
27
|
+
unreachable?: string;
|
|
28
|
+
};
|
|
29
|
+
export type AppScheme = {
|
|
30
|
+
scheme?: string;
|
|
31
|
+
source?: "dashboard" | "app";
|
|
32
|
+
blocksLocalNetworking?: string;
|
|
33
|
+
};
|
|
@@ -16,7 +16,7 @@ export type StudioDevice = {
|
|
|
16
16
|
};
|
|
17
17
|
chrome?: DeviceChromeSpec;
|
|
18
18
|
};
|
|
19
|
-
export declare const STUDIO_DEVICES: readonly StudioDevice[];
|
|
19
|
+
export declare const STUDIO_DEVICES: readonly [StudioDevice, ...StudioDevice[]];
|
|
20
20
|
export declare const DEFAULT_DEVICE_ID = "iphone-17";
|
|
21
21
|
export declare const RESPONSIVE_ID = "responsive";
|
|
22
22
|
export declare const RESPONSIVE_DEFAULT: {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type HostState } from "@superwall/host";
|
|
2
|
+
import type { Samples, StudioSurface } from "./surfaces";
|
|
3
|
+
import type { SampleDefaults, VariableOverrides } from "./variables";
|
|
4
|
+
export type HostInputs = {
|
|
5
|
+
surface: StudioSurface;
|
|
6
|
+
defaults: SampleDefaults;
|
|
7
|
+
sourceSamples?: SampleDefaults;
|
|
8
|
+
samples: Samples;
|
|
9
|
+
frame?: Record<string, unknown>;
|
|
10
|
+
theme: "light" | "dark";
|
|
11
|
+
locale?: string;
|
|
12
|
+
edited: VariableOverrides;
|
|
13
|
+
};
|
|
14
|
+
export declare const studioDefaults: () => SampleDefaults;
|
|
15
|
+
export declare const hostStateFor: ({ surface, defaults, sourceSamples, samples, frame, theme, locale, edited, }: HostInputs) => HostState;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TIncomingMessage, TOutgoingMessage } from "@superwall/host";
|
|
2
|
+
export type PaywallEventName = TOutgoingMessage["event_name"];
|
|
3
|
+
export type PaywallMessageName = PaywallEventName | TIncomingMessage["event_name"];
|
|
4
|
+
export type EventNotice = {
|
|
5
|
+
action: PaywallEventName;
|
|
6
|
+
subject?: string;
|
|
7
|
+
tone: "info" | "success" | "warning";
|
|
8
|
+
};
|
|
9
|
+
export declare const noticeFor: (event: TOutgoingMessage) => EventNotice | undefined;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PreviewUrlBuilder, StudioSurface } from "./surfaces";
|
|
2
2
|
export declare const surfacePath: (surface: StudioSurface) => string;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const hostedUrl: (url: string) => string;
|
|
4
4
|
export declare const buildPreviewPath: PreviewUrlBuilder;
|
|
5
|
-
export declare const withOverrides: (url: string, overrides: PreviewOverrides) => string;
|
|
6
|
-
export declare const withPreviewOptIn: (url: string) => string;
|
|
7
5
|
export declare const snapshotPreviewUrl: (urlOf: (surface: StudioSurface) => string) => PreviewUrlBuilder;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StudioActionName } from "./contract";
|
|
2
|
+
export type StudioStepState = "pending" | "active" | "done" | "failed";
|
|
3
|
+
export type StudioActionStep = "link" | "build" | "assets" | "push" | "source" | "promote";
|
|
4
|
+
export declare const ACTION_STEPS: Record<StudioActionName, StudioActionStep[]>;
|
|
5
|
+
export declare const STEP_LABELS: Record<StudioActionStep, string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SampleDefaults } from "./variables";
|
|
2
|
+
export type { AppScheme, Samples, StudioActionName, StudioActionProgress, StudioActionResult, StudioStatus, } from "./contract";
|
|
3
|
+
export type StudioSurfaceKind = "paywall" | "funnel";
|
|
4
|
+
export type StudioSurface = {
|
|
5
|
+
kind: StudioSurfaceKind;
|
|
6
|
+
id: string;
|
|
7
|
+
project?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
products?: Record<string, string>;
|
|
10
|
+
routes: string[];
|
|
11
|
+
locales: string[];
|
|
12
|
+
platforms?: string[];
|
|
13
|
+
paywallId?: string;
|
|
14
|
+
paywallIdentifier?: string;
|
|
15
|
+
};
|
|
16
|
+
export type PreviewUrlBuilder = (surface: StudioSurface) => string;
|
|
17
|
+
export type CompareTarget = {
|
|
18
|
+
type: "live";
|
|
19
|
+
} | {
|
|
20
|
+
type: "surface";
|
|
21
|
+
surface: StudioSurface;
|
|
22
|
+
};
|
|
23
|
+
export type StudioSource = {
|
|
24
|
+
scheme?: string;
|
|
25
|
+
title: string;
|
|
26
|
+
surfaces: StudioSurface[];
|
|
27
|
+
diagnostics?: string[];
|
|
28
|
+
samples?: SampleDefaults;
|
|
29
|
+
previewUrl: PreviewUrlBuilder;
|
|
30
|
+
standaloneUrl?: PreviewUrlBuilder;
|
|
31
|
+
capabilities?: {
|
|
32
|
+
actions: boolean;
|
|
33
|
+
};
|
|
34
|
+
compareHint?: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type SampleDefaults = {
|
|
2
|
+
device: Record<string, unknown>;
|
|
3
|
+
user: Record<string, unknown>;
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export type VariableOverrides = {
|
|
7
|
+
device?: Record<string, unknown>;
|
|
8
|
+
user?: Record<string, unknown>;
|
|
9
|
+
params?: Record<string, unknown>;
|
|
10
|
+
products?: Record<string, Record<string, unknown>>;
|
|
11
|
+
introductoryOfferEligible?: boolean;
|
|
12
|
+
};
|
package/dist/lib/products.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const l = {
|
|
2
2
|
USD: "$",
|
|
3
3
|
CAD: "$",
|
|
4
4
|
AUD: "$",
|
|
@@ -19,30 +19,44 @@ const p = {
|
|
|
19
19
|
TRY: "₺",
|
|
20
20
|
RUB: "₽",
|
|
21
21
|
ZAR: "R"
|
|
22
|
-
},
|
|
22
|
+
}, p = 100, m = { day: 365, week: 52, month: 12, year: 1 }, d = (r) => l[r.toUpperCase()] ?? "", i = (r, e) => {
|
|
23
23
|
try {
|
|
24
24
|
return new Intl.NumberFormat("en-US", { style: "currency", currency: e }).format(r);
|
|
25
25
|
} catch {
|
|
26
|
-
return `${
|
|
26
|
+
return `${d(e)}${r.toFixed(2)}`;
|
|
27
27
|
}
|
|
28
|
-
},
|
|
28
|
+
}, u = {
|
|
29
29
|
day: "daily",
|
|
30
30
|
week: "weekly",
|
|
31
31
|
month: "monthly",
|
|
32
32
|
year: "yearly"
|
|
33
|
+
}, h = {
|
|
34
|
+
day: { days: 1, weeks: 1 / 7, months: 1 / 30, years: 1 / 365 },
|
|
35
|
+
week: { days: 7, weeks: 1, months: 1 / 4, years: 1 / 52 },
|
|
36
|
+
month: { days: 30, weeks: 4, months: 1, years: 1 / 12 },
|
|
37
|
+
year: { days: 365, weeks: 52, months: 12, years: 1 }
|
|
38
|
+
}, k = (r, e) => {
|
|
39
|
+
const o = h[r];
|
|
40
|
+
if (o)
|
|
41
|
+
return {
|
|
42
|
+
periodDays: o.days * e,
|
|
43
|
+
periodWeeks: Math.round(o.weeks * e),
|
|
44
|
+
periodMonths: Math.floor(o.months * e),
|
|
45
|
+
periodYears: Math.floor(o.years * e)
|
|
46
|
+
};
|
|
33
47
|
}, R = (r) => {
|
|
34
48
|
const e = {};
|
|
35
49
|
r.identifier && (e.identifier = r.identifier);
|
|
36
50
|
const o = r.price;
|
|
37
51
|
if (!o || typeof o.amount != "number" || !o.currency) return e;
|
|
38
|
-
const
|
|
39
|
-
e.price =
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
e.period =
|
|
44
|
-
const
|
|
45
|
-
e.yearlyPrice =
|
|
52
|
+
const s = o.currency.toUpperCase(), t = o.amount / p;
|
|
53
|
+
e.price = i(t, s), e.rawPrice = t, e.currencyCode = s, e.currencySymbol = d(s);
|
|
54
|
+
const n = r.subscription?.period;
|
|
55
|
+
if (!n) return e;
|
|
56
|
+
const c = r.subscription?.period_count ?? 1;
|
|
57
|
+
e.period = n, e.periodly = u[n] ?? `${n}ly`, Object.assign(e, k(n, c) ?? {});
|
|
58
|
+
const a = (m[n] ?? 1) / c;
|
|
59
|
+
e.yearlyPrice = i(t * a, s), e.monthlyPrice = i(t * a / 12, s), e.weeklyPrice = i(t * a / 52, s), e.dailyPrice = i(t * a / 365, s);
|
|
46
60
|
const y = r.subscription?.trial_period_days;
|
|
47
61
|
return typeof y == "number" && y > 0 && (e.trialPeriodDays = y, e.trialPeriodText = `${y}-day`), e;
|
|
48
62
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { type Samples, type StudioSource, type StudioSurface } from "../lib/
|
|
2
|
+
import { type Samples, type StudioSource, type StudioSurface } from "../lib/surfaces";
|
|
3
3
|
export declare const SurfaceEditor: ({ source, surface, samples, onBack, actions, }: {
|
|
4
4
|
source: StudioSource;
|
|
5
5
|
surface: StudioSurface;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type { StudioSource, StudioSurface } from "../lib/
|
|
2
|
+
import type { StudioSource, StudioSurface } from "../lib/surfaces";
|
|
3
3
|
export declare const SurfaceList: ({ source, onOpen, device, }: {
|
|
4
4
|
source: StudioSource;
|
|
5
5
|
onOpen: (surface: StudioSurface) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superwall/studio",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.3",
|
|
4
4
|
"description": "The Superwall studio: paywall browsing, device preview, and editing surfaces. Shared between `superwall dev` (local studio) and the hosted dashboard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paywall",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"types": "./dist/lib/lib/products.d.ts",
|
|
36
36
|
"default": "./dist/lib/products.js"
|
|
37
37
|
},
|
|
38
|
+
"./contract": {
|
|
39
|
+
"types": "./dist/lib/lib/contract.d.ts"
|
|
40
|
+
},
|
|
38
41
|
"./studio.css": "./dist/lib/studio.css",
|
|
39
42
|
"./styles.css": "./src/styles.css",
|
|
40
43
|
"./package.json": "./package.json"
|
|
@@ -53,6 +56,7 @@
|
|
|
53
56
|
"clean": "rm -rf dist coverage"
|
|
54
57
|
},
|
|
55
58
|
"dependencies": {
|
|
59
|
+
"@superwall/host": "1.3.0-beta.3",
|
|
56
60
|
"sonner": "^2.0.7"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
package/src/StudioApp.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { StudioShell } from "./components/StudioShell";
|
|
2
|
+
import { StudioShell } from "./components/chrome/StudioShell";
|
|
3
3
|
import { SurfaceEditor } from "./screens/SurfaceEditor";
|
|
4
4
|
import { SurfaceList } from "./screens/SurfaceList";
|
|
5
|
-
import {
|
|
5
|
+
import { surfacePath } from "./lib/preview";
|
|
6
6
|
import { fetchSamples } from "./lib/actions";
|
|
7
|
-
import type { Samples, StudioSource, StudioSurface } from "./lib/
|
|
7
|
+
import type { Samples, StudioSource, StudioSurface } from "./lib/surfaces";
|
|
8
8
|
|
|
9
9
|
const surfaceFromPath = (
|
|
10
10
|
surfaces: StudioSurface[],
|
|
@@ -23,11 +23,9 @@ const surfaceFromPath = (
|
|
|
23
23
|
export const StudioApp = ({
|
|
24
24
|
source,
|
|
25
25
|
device = false,
|
|
26
|
-
openPreview = (url) => window.location.assign(url),
|
|
27
26
|
}: {
|
|
28
27
|
source: StudioSource;
|
|
29
28
|
device?: boolean;
|
|
30
|
-
openPreview?: (url: string) => void;
|
|
31
29
|
}) => {
|
|
32
30
|
const [pathname, setPathname] = React.useState(() => window.location.pathname);
|
|
33
31
|
const [samples, setSamples] = React.useState<Samples>({});
|
|
@@ -54,7 +52,7 @@ export const StudioApp = ({
|
|
|
54
52
|
setPathname(path);
|
|
55
53
|
};
|
|
56
54
|
|
|
57
|
-
const active =
|
|
55
|
+
const active = surfaceFromPath(source.surfaces, pathname);
|
|
58
56
|
|
|
59
57
|
return (
|
|
60
58
|
<StudioShell>
|
|
@@ -63,15 +61,13 @@ export const StudioApp = ({
|
|
|
63
61
|
source={source}
|
|
64
62
|
surface={active}
|
|
65
63
|
samples={samples}
|
|
66
|
-
onBack={() => navigate("/")}
|
|
64
|
+
onBack={() => navigate(device ? "/device" : "/")}
|
|
67
65
|
/>
|
|
68
66
|
) : (
|
|
69
67
|
<SurfaceList
|
|
70
68
|
source={source}
|
|
71
69
|
device={device}
|
|
72
|
-
onOpen={(surface) =>
|
|
73
|
-
device ? openPreview(devicePreviewPath(surface)) : navigate(surfacePath(surface))
|
|
74
|
-
}
|
|
70
|
+
onOpen={(surface) => navigate(surfacePath(surface))}
|
|
75
71
|
/>
|
|
76
72
|
)}
|
|
77
73
|
</StudioShell>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { toast, Toaster } from "sonner";
|
|
3
|
+
import type { HostDelegate } from "@superwall/host";
|
|
3
4
|
import {
|
|
4
5
|
AlertTriangleIcon,
|
|
5
6
|
BellIcon,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
StarIcon,
|
|
14
15
|
UserIcon,
|
|
15
16
|
} from "./icons";
|
|
16
|
-
import {
|
|
17
|
+
import { noticeFor, type EventNotice, type PaywallMessageName } from "../lib/notices";
|
|
17
18
|
|
|
18
19
|
const TINT: Record<EventNotice["tone"], string> = {
|
|
19
20
|
info: "text-cream/45",
|
|
@@ -21,7 +22,7 @@ const TINT: Record<EventNotice["tone"], string> = {
|
|
|
21
22
|
warning: "text-red",
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
const ICON: Record<
|
|
25
|
+
const ICON: Partial<Record<PaywallMessageName, () => React.ReactElement>> = {
|
|
25
26
|
purchase: CartIcon,
|
|
26
27
|
transaction_complete: CheckCircleIcon,
|
|
27
28
|
freeTrial_start: CheckCircleIcon,
|
|
@@ -29,6 +30,8 @@ const ICON: Record<string, () => React.ReactElement> = {
|
|
|
29
30
|
transaction_fail: AlertTriangleIcon,
|
|
30
31
|
close: CloseIcon,
|
|
31
32
|
restore: RotateIcon,
|
|
33
|
+
restore_complete: CheckCircleIcon,
|
|
34
|
+
restore_fail: AlertTriangleIcon,
|
|
32
35
|
open_url: ExternalIcon,
|
|
33
36
|
open_url_external: ExternalIcon,
|
|
34
37
|
open_deep_link: ExternalIcon,
|
|
@@ -59,7 +62,7 @@ const Toast = ({
|
|
|
59
62
|
children,
|
|
60
63
|
actions,
|
|
61
64
|
}: React.PropsWithChildren<{
|
|
62
|
-
action:
|
|
65
|
+
action: PaywallMessageName;
|
|
63
66
|
tone: EventNotice["tone"];
|
|
64
67
|
actions?: React.ReactNode;
|
|
65
68
|
}>) => {
|
|
@@ -92,67 +95,170 @@ const Notice = ({ notice }: { notice: EventNotice }) => (
|
|
|
92
95
|
</Toast>
|
|
93
96
|
);
|
|
94
97
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const Outcome = ({ outcome, subject }: { outcome: string; subject: string }) => {
|
|
105
|
-
const spec = OUTCOME[outcome] ?? OUTCOME.completed;
|
|
106
|
-
return (
|
|
107
|
-
<Toast action={spec?.action ?? "purchase"} tone={spec?.tone ?? "info"}>
|
|
108
|
-
<Pill>{subject}</Pill> {spec?.label}
|
|
109
|
-
</Toast>
|
|
110
|
-
);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const ASK: Record<string, { action: string; verb: string; no: string; yes: string }> = {
|
|
114
|
-
purchase: { action: "purchase", verb: "purchase", no: "Abandon", yes: "Complete" },
|
|
115
|
-
permission: { action: "request_permission", verb: "permission", no: "Deny", yes: "Grant" },
|
|
116
|
-
callback: { action: "request_callback", verb: "callback", no: "Fail", yes: "Succeed" },
|
|
98
|
+
type Choice<T> = {
|
|
99
|
+
label: string;
|
|
100
|
+
value: T;
|
|
101
|
+
primary?: boolean;
|
|
102
|
+
action: PaywallMessageName;
|
|
103
|
+
tone: EventNotice["tone"];
|
|
104
|
+
done: string;
|
|
117
105
|
};
|
|
118
106
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
const Outcome = <T,>({ choice, subject }: { choice: Choice<T>; subject: string }) => (
|
|
108
|
+
<Toast action={choice.action} tone={choice.tone}>
|
|
109
|
+
<Pill>{subject}</Pill> {choice.done}
|
|
110
|
+
</Toast>
|
|
111
|
+
);
|
|
124
112
|
|
|
125
|
-
const Ask = ({
|
|
126
|
-
|
|
113
|
+
const Ask = <T,>({
|
|
114
|
+
action,
|
|
115
|
+
verb,
|
|
127
116
|
subject,
|
|
117
|
+
choices,
|
|
128
118
|
onAnswer,
|
|
129
119
|
}: {
|
|
130
|
-
|
|
120
|
+
action: PaywallMessageName;
|
|
121
|
+
verb: string;
|
|
131
122
|
subject: string;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
choices: readonly Choice<T>[];
|
|
124
|
+
onAnswer: (choice: Choice<T>) => void;
|
|
125
|
+
}) => (
|
|
126
|
+
<Toast
|
|
127
|
+
action={action}
|
|
128
|
+
tone="info"
|
|
129
|
+
actions={choices.map((choice) => (
|
|
130
|
+
<button
|
|
131
|
+
key={choice.label}
|
|
132
|
+
type="button"
|
|
133
|
+
className={choice.primary ? "sw-btn sw-btn--primary" : "sw-btn"}
|
|
134
|
+
onClick={() => onAnswer(choice)}
|
|
135
|
+
>
|
|
136
|
+
{choice.label}
|
|
137
|
+
</button>
|
|
138
|
+
))}
|
|
139
|
+
>
|
|
140
|
+
Tap triggered a <Pill>{verb}</Pill> for <Pill>{subject}</Pill>.
|
|
141
|
+
</Toast>
|
|
142
|
+
);
|
|
136
143
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
const PURCHASE: readonly Choice<"completed" | "abandoned" | "failed">[] = [
|
|
145
|
+
{
|
|
146
|
+
label: "Abandon",
|
|
147
|
+
value: "abandoned",
|
|
148
|
+
action: "transaction_abandon",
|
|
149
|
+
tone: "warning",
|
|
150
|
+
done: "purchase abandoned.",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
label: "Fail",
|
|
154
|
+
value: "failed",
|
|
155
|
+
action: "transaction_fail",
|
|
156
|
+
tone: "warning",
|
|
157
|
+
done: "purchase failed.",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
label: "Complete",
|
|
161
|
+
value: "completed",
|
|
162
|
+
primary: true,
|
|
163
|
+
action: "transaction_complete",
|
|
164
|
+
tone: "success",
|
|
165
|
+
done: "purchase completed.",
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
const RESTORE: readonly Choice<"restored" | "failed">[] = [
|
|
170
|
+
{
|
|
171
|
+
label: "Nothing",
|
|
172
|
+
value: "failed",
|
|
173
|
+
action: "restore_fail",
|
|
174
|
+
tone: "warning",
|
|
175
|
+
done: "nothing to restore.",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
label: "Restore",
|
|
179
|
+
value: "restored",
|
|
180
|
+
primary: true,
|
|
181
|
+
action: "restore_complete",
|
|
182
|
+
tone: "success",
|
|
183
|
+
done: "restored.",
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
const PERMISSION: readonly Choice<"granted" | "denied">[] = [
|
|
188
|
+
{
|
|
189
|
+
label: "Deny",
|
|
190
|
+
value: "denied",
|
|
191
|
+
action: "request_permission",
|
|
192
|
+
tone: "warning",
|
|
193
|
+
done: "denied.",
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
label: "Grant",
|
|
197
|
+
value: "granted",
|
|
198
|
+
primary: true,
|
|
199
|
+
action: "request_permission",
|
|
200
|
+
tone: "success",
|
|
201
|
+
done: "granted.",
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
const CALLBACK: readonly Choice<"success" | "failure">[] = [
|
|
206
|
+
{ label: "Fail", value: "failure", action: "request_callback", tone: "warning", done: "failed." },
|
|
207
|
+
{
|
|
208
|
+
label: "Succeed",
|
|
209
|
+
value: "success",
|
|
210
|
+
primary: true,
|
|
211
|
+
action: "request_callback",
|
|
212
|
+
tone: "success",
|
|
213
|
+
done: "succeeded.",
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
let asked = 0;
|
|
218
|
+
|
|
219
|
+
const ask = <T,>(
|
|
220
|
+
action: PaywallMessageName,
|
|
221
|
+
verb: string,
|
|
222
|
+
subject: string,
|
|
223
|
+
choices: readonly Choice<T>[],
|
|
224
|
+
): Promise<T> =>
|
|
225
|
+
new Promise((resolve) => {
|
|
226
|
+
const id = `${action}-${(asked += 1)}`;
|
|
227
|
+
toast.custom(
|
|
228
|
+
() => (
|
|
229
|
+
<Ask
|
|
230
|
+
action={action}
|
|
231
|
+
verb={verb}
|
|
232
|
+
subject={subject}
|
|
233
|
+
choices={choices}
|
|
234
|
+
onAnswer={(choice) => {
|
|
235
|
+
toast.dismiss(id);
|
|
236
|
+
toast.custom(() => <Outcome choice={choice} subject={subject} />);
|
|
237
|
+
resolve(choice.value);
|
|
238
|
+
}}
|
|
239
|
+
/>
|
|
240
|
+
),
|
|
241
|
+
{ id, duration: Number.POSITIVE_INFINITY },
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
export const createStudioDelegate = (): HostDelegate => ({
|
|
246
|
+
event: (message) => {
|
|
247
|
+
const notice = noticeFor(message);
|
|
248
|
+
if (notice) toast.custom(() => <Notice notice={notice} />);
|
|
249
|
+
},
|
|
250
|
+
purchase: (product) => ask("purchase", "purchase", product.reference, PURCHASE),
|
|
251
|
+
restore: () => ask("restore", "restore", "purchases", RESTORE),
|
|
252
|
+
close: () => {},
|
|
253
|
+
openUrl: () => {},
|
|
254
|
+
custom: () => {},
|
|
255
|
+
customPlacement: () => {},
|
|
256
|
+
permission: (type) => ask("request_permission", "permission", type, PERMISSION),
|
|
257
|
+
callback: (name) =>
|
|
258
|
+
ask("request_callback", "callback", name, CALLBACK).then((status) => ({ status })),
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
export const useStudioDelegate = (): HostDelegate => React.useMemo(createStudioDelegate, []);
|
|
156
262
|
|
|
157
263
|
export const PaywallToasts = ({
|
|
158
264
|
surfaceKey,
|
|
@@ -165,36 +271,6 @@ export const PaywallToasts = ({
|
|
|
165
271
|
toast.dismiss();
|
|
166
272
|
}, [surfaceKey]);
|
|
167
273
|
|
|
168
|
-
React.useEffect(() => {
|
|
169
|
-
const onMessage = (event: MessageEvent) => {
|
|
170
|
-
if (!isBridgeMessage(event.data)) return;
|
|
171
|
-
|
|
172
|
-
if (event.data.type === "ask") {
|
|
173
|
-
const { id, kind, subject } = event.data;
|
|
174
|
-
const answer = (outcome: string) => {
|
|
175
|
-
(event.source as Window | null)?.postMessage(
|
|
176
|
-
{ channel: STUDIO_CHANNEL, type: "answer", id, outcome },
|
|
177
|
-
"*",
|
|
178
|
-
);
|
|
179
|
-
toast.dismiss(id);
|
|
180
|
-
toast.custom(() => <Outcome outcome={outcome} subject={subject} />);
|
|
181
|
-
};
|
|
182
|
-
toast.custom(() => <Ask kind={kind} subject={subject} onAnswer={answer} />, {
|
|
183
|
-
id,
|
|
184
|
-
duration: Number.POSITIVE_INFINITY,
|
|
185
|
-
});
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (event.data.type !== "event") return;
|
|
190
|
-
const notice = noticeFor(event.data.message);
|
|
191
|
-
if (notice) toast.custom(() => <Notice notice={notice} />);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
window.addEventListener("message", onMessage);
|
|
195
|
-
return () => window.removeEventListener("message", onMessage);
|
|
196
|
-
}, []);
|
|
197
|
-
|
|
198
274
|
return (
|
|
199
275
|
<Toaster
|
|
200
276
|
position="top-center"
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { silentDelegate, type HostState } from "@superwall/host";
|
|
3
|
+
import { HostedIframe } from "./preview/HostedIframe";
|
|
2
4
|
import { surfacePath } from "../lib/preview";
|
|
3
5
|
import { timeAgo } from "../lib/time";
|
|
4
|
-
import type { StudioStatus, StudioSurface } from "../lib/
|
|
6
|
+
import type { StudioStatus, StudioSurface } from "../lib/surfaces";
|
|
5
7
|
|
|
6
8
|
const PREVIEW_WIDTH = 390;
|
|
7
9
|
const PREVIEW_HEIGHT = 844;
|
|
@@ -27,18 +29,21 @@ export const SurfaceCard = ({
|
|
|
27
29
|
surface,
|
|
28
30
|
status,
|
|
29
31
|
previewSrc,
|
|
32
|
+
hostState,
|
|
30
33
|
onOpen,
|
|
31
34
|
href,
|
|
32
35
|
}: {
|
|
33
36
|
surface: StudioSurface;
|
|
34
37
|
status?: StudioStatus;
|
|
35
38
|
previewSrc: string;
|
|
39
|
+
hostState: HostState;
|
|
36
40
|
onOpen: () => void;
|
|
37
41
|
href?: string;
|
|
38
42
|
}) => {
|
|
39
43
|
const previewRef = React.useRef<HTMLDivElement>(null);
|
|
40
44
|
const width = useElementWidth(previewRef);
|
|
41
45
|
const scale = width > 0 ? width / PREVIEW_WIDTH : 0;
|
|
46
|
+
const delegate = React.useMemo(silentDelegate, []);
|
|
42
47
|
|
|
43
48
|
return (
|
|
44
49
|
<a
|
|
@@ -55,7 +60,9 @@ export const SurfaceCard = ({
|
|
|
55
60
|
ref={previewRef}
|
|
56
61
|
>
|
|
57
62
|
{scale > 0 && (
|
|
58
|
-
<
|
|
63
|
+
<HostedIframe
|
|
64
|
+
hostState={hostState}
|
|
65
|
+
delegate={delegate}
|
|
59
66
|
className="pointer-events-none block origin-top-left border-0 bg-white"
|
|
60
67
|
title={`${surface.project ? `${surface.project}/` : ""}${surface.id} preview`}
|
|
61
68
|
src={previewSrc}
|