@superwall/studio 1.2.0 → 1.3.0-beta.4
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-CEz-HnIH.js +11 -0
- package/dist/index.html +1 -1
- package/dist/lib/StudioApp.d.ts +4 -4
- package/dist/lib/components/PaywallToasts.d.ts +3 -0
- package/dist/lib/components/SurfaceCard.d.ts +4 -2
- package/dist/lib/components/{TopBar.d.ts → chrome/TopBar.d.ts} +1 -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 +14 -6
- package/dist/lib/index.js +1490 -998
- 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/studio-host.d.ts +34 -0
- package/dist/lib/lib/surfaces.d.ts +36 -0
- package/dist/lib/lib/variables.d.ts +12 -0
- package/dist/lib/products.js +26 -12
- package/dist/lib/screens/SurfaceEditor.d.ts +2 -3
- package/dist/lib/screens/SurfaceList.d.ts +2 -3
- package/package.json +5 -1
- package/src/StudioApp.tsx +25 -28
- package/src/components/PaywallToasts.tsx +162 -86
- package/src/components/SurfaceCard.tsx +9 -2
- package/src/components/chrome/TopBar.tsx +45 -0
- 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 +32 -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 +79 -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/studio-host.tsx +61 -0
- package/src/lib/surfaces.ts +43 -0
- package/src/lib/time.ts +1 -2
- package/src/lib/variables.ts +13 -0
- package/src/main.tsx +6 -5
- package/src/screens/SurfaceEditor.tsx +79 -70
- package/src/screens/SurfaceList.tsx +27 -12
- 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/components/TopBar.tsx +0 -41
- 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/{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/{MissingProducts.tsx → panels/MissingProducts.tsx} +0 -0
package/src/index.ts
CHANGED
|
@@ -3,26 +3,46 @@ import "./styles.css";
|
|
|
3
3
|
export { StudioApp } from "./StudioApp";
|
|
4
4
|
export { SurfaceEditor } from "./screens/SurfaceEditor";
|
|
5
5
|
export { SurfaceList } from "./screens/SurfaceList";
|
|
6
|
-
export { DeviceFrame } from "./components/DeviceFrame";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
6
|
+
export { DeviceFrame } from "./components/preview/DeviceFrame";
|
|
7
|
+
export { HostedIframe } from "./components/preview/HostedIframe";
|
|
8
|
+
export { PaywallToasts, createStudioDelegate, useStudioDelegate } from "./components/PaywallToasts";
|
|
9
|
+
export { StudioShell } from "./components/chrome/StudioShell";
|
|
10
|
+
export { TopBar } from "./components/chrome/TopBar";
|
|
11
|
+
export { VariablesPanel } from "./components/panels/VariablesPanel";
|
|
10
12
|
export { Segmented, Select, Switch } from "./components/controls";
|
|
11
13
|
export { DEFAULT_DEVICE_ID, deviceById, STUDIO_DEVICES } from "./lib/devices";
|
|
12
14
|
export type { StudioDevice } from "./lib/devices";
|
|
15
|
+
export { hostStateFor, studioDefaults } from "./lib/host";
|
|
16
|
+
export { hasActions } from "./lib/surfaces";
|
|
13
17
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
StudioHostProvider,
|
|
19
|
+
useStudioHome,
|
|
20
|
+
useStudioMode,
|
|
21
|
+
type StudioHome,
|
|
22
|
+
type StudioMode,
|
|
23
|
+
} from "./lib/studio-host";
|
|
24
|
+
export {
|
|
25
|
+
createHostState,
|
|
26
|
+
diffHostState,
|
|
27
|
+
hasIntroductoryOffer,
|
|
28
|
+
silentDelegate,
|
|
29
|
+
type HostDelegate,
|
|
30
|
+
type HostProduct,
|
|
31
|
+
type HostState,
|
|
32
|
+
} from "@superwall/host";
|
|
33
|
+
export type { HostInputs } from "./lib/host";
|
|
34
|
+
export { buildPreviewPath, hostedUrl, snapshotPreviewUrl, surfacePath } from "./lib/preview";
|
|
19
35
|
export { parseProjectPayload, type StudioProjectPayload } from "./lib/project";
|
|
20
36
|
export type {
|
|
21
|
-
|
|
37
|
+
AppScheme,
|
|
22
38
|
PreviewUrlBuilder,
|
|
23
|
-
SampleDefaults,
|
|
24
39
|
Samples,
|
|
40
|
+
StudioActionName,
|
|
41
|
+
StudioActionProgress,
|
|
42
|
+
StudioActionResult,
|
|
25
43
|
StudioSource,
|
|
44
|
+
StudioStatus,
|
|
26
45
|
StudioSurface,
|
|
27
46
|
StudioSurfaceKind,
|
|
28
|
-
} from "./lib/
|
|
47
|
+
} from "./lib/surfaces";
|
|
48
|
+
export type { SampleDefaults, VariableOverrides } from "./lib/variables";
|
package/src/lib/actions.ts
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type StudioActionName = "push" | "promote" | "publish";
|
|
2
|
+
|
|
3
|
+
export type StudioActionResult =
|
|
4
|
+
| { ok: true; version: number; live: boolean }
|
|
5
|
+
| { ok: false; error: string };
|
|
6
|
+
|
|
7
|
+
export type StudioActionProgress = (step: string, state: "start" | "done") => void;
|
|
8
|
+
|
|
9
|
+
export type StudioStatus = {
|
|
10
|
+
paywallId?: string;
|
|
11
|
+
identifier?: string;
|
|
12
|
+
liveUrl?: string;
|
|
13
|
+
active?: boolean;
|
|
14
|
+
updatedAt?: string;
|
|
15
|
+
unreachable?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Samples = {
|
|
19
|
+
device?: Record<string, unknown>;
|
|
20
|
+
user?: Record<string, unknown>;
|
|
21
|
+
products?: Record<string, Record<string, unknown>>;
|
|
22
|
+
live?: { device: boolean; user: boolean };
|
|
23
|
+
unreachable?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type AppScheme = {
|
|
27
|
+
scheme?: string;
|
|
28
|
+
source?: "dashboard" | "app";
|
|
29
|
+
blocksLocalNetworking?: string;
|
|
30
|
+
};
|
package/src/lib/devices.ts
CHANGED
|
@@ -25,7 +25,7 @@ const IPHONE_ISLAND: DeviceChromeSpec = {
|
|
|
25
25
|
homeIndicator: true,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const STUDIO_DEVICES: readonly StudioDevice[] = [
|
|
28
|
+
export const STUDIO_DEVICES: readonly [StudioDevice, ...StudioDevice[]] = [
|
|
29
29
|
{
|
|
30
30
|
id: "iphone-se",
|
|
31
31
|
name: "iPhone SE",
|
|
@@ -103,7 +103,8 @@ export const DEFAULT_DEVICE_ID = "iphone-17";
|
|
|
103
103
|
export const RESPONSIVE_ID = "responsive";
|
|
104
104
|
export const RESPONSIVE_DEFAULT = { width: 393, height: 852 };
|
|
105
105
|
|
|
106
|
+
const DEFAULT_DEVICE: StudioDevice =
|
|
107
|
+
STUDIO_DEVICES.find((device) => device.id === DEFAULT_DEVICE_ID) ?? STUDIO_DEVICES[0];
|
|
108
|
+
|
|
106
109
|
export const deviceById = (id: string): StudioDevice =>
|
|
107
|
-
STUDIO_DEVICES.find((device) => device.id === id) ??
|
|
108
|
-
STUDIO_DEVICES.find((device) => device.id === DEFAULT_DEVICE_ID) ??
|
|
109
|
-
STUDIO_DEVICES[0];
|
|
110
|
+
STUDIO_DEVICES.find((device) => device.id === id) ?? DEFAULT_DEVICE;
|
package/src/lib/host.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHostState,
|
|
3
|
+
DEFAULT_PARAMS,
|
|
4
|
+
DEFAULT_USER,
|
|
5
|
+
defaultDevice,
|
|
6
|
+
type HostProduct,
|
|
7
|
+
type HostState,
|
|
8
|
+
type HostVariables,
|
|
9
|
+
} from "@superwall/host";
|
|
10
|
+
import type { Samples, StudioSurface } from "./surfaces";
|
|
11
|
+
import type { SampleDefaults, VariableOverrides } from "./variables";
|
|
12
|
+
|
|
13
|
+
export type HostInputs = {
|
|
14
|
+
surface: StudioSurface;
|
|
15
|
+
defaults: SampleDefaults;
|
|
16
|
+
sourceSamples?: SampleDefaults;
|
|
17
|
+
samples: Samples;
|
|
18
|
+
frame?: Record<string, unknown>;
|
|
19
|
+
theme: "light" | "dark";
|
|
20
|
+
locale?: string;
|
|
21
|
+
edited: VariableOverrides;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const studioDefaults = (): SampleDefaults => ({
|
|
25
|
+
device: defaultDevice(),
|
|
26
|
+
user: DEFAULT_USER,
|
|
27
|
+
params: DEFAULT_PARAMS,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const hostStateFor = ({
|
|
31
|
+
surface,
|
|
32
|
+
defaults,
|
|
33
|
+
sourceSamples,
|
|
34
|
+
samples,
|
|
35
|
+
frame,
|
|
36
|
+
theme,
|
|
37
|
+
locale,
|
|
38
|
+
edited,
|
|
39
|
+
}: HostInputs): HostState => {
|
|
40
|
+
const device: HostVariables = {
|
|
41
|
+
...defaults.device,
|
|
42
|
+
...sourceSamples?.device,
|
|
43
|
+
...samples.device,
|
|
44
|
+
...frame,
|
|
45
|
+
interfaceStyle: theme === "dark" ? "Dark" : "Light",
|
|
46
|
+
...(locale ? { deviceLocale: locale, deviceLanguageCode: locale.split(/[-_]/)[0] } : {}),
|
|
47
|
+
...edited.device,
|
|
48
|
+
};
|
|
49
|
+
const user: HostVariables = {
|
|
50
|
+
...defaults.user,
|
|
51
|
+
...sourceSamples?.user,
|
|
52
|
+
...samples.user,
|
|
53
|
+
...edited.user,
|
|
54
|
+
};
|
|
55
|
+
const params: HostVariables = {
|
|
56
|
+
...defaults.params,
|
|
57
|
+
...sourceSamples?.params,
|
|
58
|
+
...edited.params,
|
|
59
|
+
};
|
|
60
|
+
const products: HostProduct[] = Object.entries(surface.products ?? {}).map(
|
|
61
|
+
([reference, productId]) => ({
|
|
62
|
+
reference,
|
|
63
|
+
productId,
|
|
64
|
+
variables: {
|
|
65
|
+
...samples.products?.[productId],
|
|
66
|
+
...edited.products?.[reference],
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
return createHostState({
|
|
71
|
+
paywallId: surface.paywallId ?? "0",
|
|
72
|
+
paywallIdentifier: surface.paywallIdentifier ?? surface.id,
|
|
73
|
+
device,
|
|
74
|
+
user,
|
|
75
|
+
params,
|
|
76
|
+
products,
|
|
77
|
+
introductoryOfferEligible: edited.introductoryOfferEligible,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { TIncomingMessage, TOutgoingMessage } from "@superwall/host";
|
|
2
|
+
|
|
3
|
+
export type PaywallEventName = TOutgoingMessage["event_name"];
|
|
4
|
+
|
|
5
|
+
export type PaywallMessageName = PaywallEventName | TIncomingMessage["event_name"];
|
|
6
|
+
|
|
7
|
+
export type EventNotice = {
|
|
8
|
+
action: PaywallEventName;
|
|
9
|
+
subject?: string;
|
|
10
|
+
tone: "info" | "success" | "warning";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const SILENT: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>([
|
|
14
|
+
"ping",
|
|
15
|
+
"page_view",
|
|
16
|
+
"page_styles",
|
|
17
|
+
"has_set_dom",
|
|
18
|
+
"haptic_feedback",
|
|
19
|
+
"var_click",
|
|
20
|
+
"purchase",
|
|
21
|
+
"restore",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const SUBJECT: Partial<Record<PaywallEventName, readonly string[]>> = {
|
|
25
|
+
open_url: ["url"],
|
|
26
|
+
open_url_external: ["url"],
|
|
27
|
+
open_deep_link: ["link"],
|
|
28
|
+
custom_placement: ["name"],
|
|
29
|
+
custom: ["name", "data"],
|
|
30
|
+
request_permission: ["permission_type"],
|
|
31
|
+
request_callback: ["name"],
|
|
32
|
+
schedule_notification: ["title"],
|
|
33
|
+
discount_redemption_result: ["code"],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const WARNING: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>(["close"]);
|
|
37
|
+
|
|
38
|
+
const SUCCESS: ReadonlySet<PaywallEventName> = new Set<PaywallEventName>([
|
|
39
|
+
"stripe_checkout_complete",
|
|
40
|
+
"post_checkout_complete",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const subjectOf = (event: TOutgoingMessage): string | undefined => {
|
|
44
|
+
for (const key of SUBJECT[event.event_name] ?? []) {
|
|
45
|
+
const value = Reflect.get(event, key);
|
|
46
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const noticeFor = (event: TOutgoingMessage): EventNotice | undefined => {
|
|
52
|
+
if (SILENT.has(event.event_name)) return undefined;
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
action: event.event_name,
|
|
56
|
+
subject: subjectOf(event),
|
|
57
|
+
tone: WARNING.has(event.event_name)
|
|
58
|
+
? "warning"
|
|
59
|
+
: SUCCESS.has(event.event_name)
|
|
60
|
+
? "success"
|
|
61
|
+
: "info",
|
|
62
|
+
};
|
|
63
|
+
};
|
package/src/lib/preview.ts
CHANGED
|
@@ -1,49 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
const overrideParams = (overrides: PreviewOverrides): URLSearchParams => {
|
|
4
|
-
const params = new URLSearchParams();
|
|
5
|
-
if (overrides.theme) params.set("theme", overrides.theme);
|
|
6
|
-
if (overrides.locale) params.set("locale", overrides.locale);
|
|
7
|
-
for (const [key, group] of [
|
|
8
|
-
["sw_device", overrides.device],
|
|
9
|
-
["sw_user", overrides.user],
|
|
10
|
-
["sw_params", overrides.params],
|
|
11
|
-
["sw_products", overrides.products],
|
|
12
|
-
] as const) {
|
|
13
|
-
if (group && Object.keys(group).length > 0) params.set(key, JSON.stringify(group));
|
|
14
|
-
}
|
|
15
|
-
if (overrides.trialEligible !== undefined) {
|
|
16
|
-
params.set("sw_trial", overrides.trialEligible ? "1" : "0");
|
|
17
|
-
}
|
|
18
|
-
return params;
|
|
19
|
-
};
|
|
1
|
+
import type { PreviewUrlBuilder, StudioSurface } from "./surfaces";
|
|
20
2
|
|
|
21
3
|
export const surfacePath = (surface: StudioSurface): string =>
|
|
22
4
|
`${surface.project ? `/${surface.project}` : ""}/${surface.kind}/${surface.id}`;
|
|
23
5
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const buildPreviewPath: PreviewUrlBuilder = (
|
|
28
|
-
surface: StudioSurface,
|
|
29
|
-
overrides: PreviewOverrides,
|
|
30
|
-
): string => {
|
|
31
|
-
const query = overrideParams(overrides).toString();
|
|
32
|
-
return `/preview${surfacePath(surface)}${query ? `?${query}` : ""}`;
|
|
6
|
+
export const hostedUrl = (url: string): string => {
|
|
7
|
+
if (/[?&]transport=editor(?:&|$)/.test(url)) return url;
|
|
8
|
+
return `${url}${url.includes("?") ? "&" : "?"}transport=editor`;
|
|
33
9
|
};
|
|
34
10
|
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
if (!query) return url;
|
|
38
|
-
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const withPreviewOptIn = (url: string): string => {
|
|
42
|
-
if (/[?&]sw_preview=/.test(url)) return url;
|
|
43
|
-
return `${url}${url.includes("?") ? "&" : "?"}sw_preview=1`;
|
|
44
|
-
};
|
|
11
|
+
export const buildPreviewPath: PreviewUrlBuilder = (surface) =>
|
|
12
|
+
hostedUrl(`/preview${surfacePath(surface)}`);
|
|
45
13
|
|
|
46
14
|
export const snapshotPreviewUrl =
|
|
47
15
|
(urlOf: (surface: StudioSurface) => string): PreviewUrlBuilder =>
|
|
48
|
-
(surface
|
|
49
|
-
|
|
16
|
+
(surface) =>
|
|
17
|
+
hostedUrl(urlOf(surface));
|
package/src/lib/products.ts
CHANGED
|
@@ -59,6 +59,25 @@ const PERIODLY: Record<string, string> = {
|
|
|
59
59
|
year: "yearly",
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
const PERIOD_UNITS: Record<string, { days: number; weeks: number; months: number; years: number }> =
|
|
63
|
+
{
|
|
64
|
+
day: { days: 1, weeks: 1 / 7, months: 1 / 30, years: 1 / 365 },
|
|
65
|
+
week: { days: 7, weeks: 1, months: 1 / 4, years: 1 / 52 },
|
|
66
|
+
month: { days: 30, weeks: 4, months: 1, years: 1 / 12 },
|
|
67
|
+
year: { days: 365, weeks: 52, months: 12, years: 1 },
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const periodCounts = (period: string, count: number): Record<string, number> | undefined => {
|
|
71
|
+
const units = PERIOD_UNITS[period];
|
|
72
|
+
if (!units) return undefined;
|
|
73
|
+
return {
|
|
74
|
+
periodDays: units.days * count,
|
|
75
|
+
periodWeeks: Math.round(units.weeks * count),
|
|
76
|
+
periodMonths: Math.floor(units.months * count),
|
|
77
|
+
periodYears: Math.floor(units.years * count),
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
62
81
|
export const productVariables = (product: DashboardProduct): Record<string, unknown> => {
|
|
63
82
|
const variables: Record<string, unknown> = {};
|
|
64
83
|
if (product.identifier) variables.identifier = product.identifier;
|
|
@@ -79,7 +98,7 @@ export const productVariables = (product: DashboardProduct): Record<string, unkn
|
|
|
79
98
|
const count = product.subscription?.period_count ?? 1;
|
|
80
99
|
variables.period = period;
|
|
81
100
|
variables.periodly = PERIODLY[period] ?? `${period}ly`;
|
|
82
|
-
|
|
101
|
+
Object.assign(variables, periodCounts(period, count) ?? {});
|
|
83
102
|
|
|
84
103
|
const perYear = (PER_YEAR[period] ?? 1) / count;
|
|
85
104
|
variables.yearlyPrice = money(value * perYear, currency);
|
package/src/lib/project.ts
CHANGED
package/src/lib/steps.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StudioActionName } from "./contract";
|
|
2
|
+
|
|
3
|
+
export type StudioStepState = "pending" | "active" | "done" | "failed";
|
|
4
|
+
|
|
5
|
+
export type StudioActionStep = "link" | "build" | "assets" | "push" | "source" | "promote";
|
|
6
|
+
|
|
7
|
+
export const ACTION_STEPS: Record<StudioActionName, StudioActionStep[]> = {
|
|
8
|
+
push: ["link", "build", "assets", "push", "source"],
|
|
9
|
+
publish: ["link", "build", "assets", "push", "source", "promote"],
|
|
10
|
+
promote: ["link", "promote"],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const STEP_LABELS: Record<StudioActionStep, string> = {
|
|
14
|
+
link: "Find paywall",
|
|
15
|
+
build: "Build snapshot",
|
|
16
|
+
assets: "Sync assets",
|
|
17
|
+
push: "Push version",
|
|
18
|
+
source: "Push source",
|
|
19
|
+
promote: "Promote to live",
|
|
20
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How the studio is being viewed.
|
|
5
|
+
*
|
|
6
|
+
* - `local` — served by `superwall dev` on a desktop browser.
|
|
7
|
+
* - `device` — the same server, opened on a phone: trimmed chrome, and every
|
|
8
|
+
* card is a real link because touch navigation is browser navigation.
|
|
9
|
+
* - `hosted` — embedded in the dashboard, where the studio is one route inside
|
|
10
|
+
* a larger app rather than the whole page.
|
|
11
|
+
*/
|
|
12
|
+
export type StudioMode = "local" | "device" | "hosted";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Where the logo goes.
|
|
16
|
+
*
|
|
17
|
+
* Two mechanisms for one destination: `href` is what the browser opens on a
|
|
18
|
+
* middle or modified click, and `navigate` is what a plain click runs in-app.
|
|
19
|
+
* A hosted studio needs both — following the href there would reload the whole
|
|
20
|
+
* dashboard.
|
|
21
|
+
*/
|
|
22
|
+
export type StudioHome = {
|
|
23
|
+
href: string;
|
|
24
|
+
navigate: () => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type StudioHostValue = {
|
|
28
|
+
mode: StudioMode;
|
|
29
|
+
home: StudioHome;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const StudioHostContext = React.createContext<StudioHostValue | undefined>(undefined);
|
|
33
|
+
|
|
34
|
+
const useStudioHost = (): StudioHostValue => {
|
|
35
|
+
const value = React.useContext(StudioHostContext);
|
|
36
|
+
if (!value) {
|
|
37
|
+
throw new Error("Studio components must be rendered inside <StudioHostProvider>.");
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const StudioHostProvider = ({
|
|
43
|
+
mode,
|
|
44
|
+
home,
|
|
45
|
+
children,
|
|
46
|
+
}: {
|
|
47
|
+
mode: StudioMode;
|
|
48
|
+
home: StudioHome;
|
|
49
|
+
children: React.ReactNode;
|
|
50
|
+
}) => {
|
|
51
|
+
const { href, navigate } = home;
|
|
52
|
+
const value = React.useMemo<StudioHostValue>(
|
|
53
|
+
() => ({ mode, home: { href, navigate } }),
|
|
54
|
+
[mode, href, navigate],
|
|
55
|
+
);
|
|
56
|
+
return <StudioHostContext.Provider value={value}>{children}</StudioHostContext.Provider>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const useStudioMode = (): StudioMode => useStudioHost().mode;
|
|
60
|
+
|
|
61
|
+
export const useStudioHome = (): StudioHome => useStudioHost().home;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SampleDefaults } from "./variables";
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
AppScheme,
|
|
5
|
+
Samples,
|
|
6
|
+
StudioActionName,
|
|
7
|
+
StudioActionProgress,
|
|
8
|
+
StudioActionResult,
|
|
9
|
+
StudioStatus,
|
|
10
|
+
} from "./contract";
|
|
11
|
+
|
|
12
|
+
export type StudioSurfaceKind = "paywall" | "funnel";
|
|
13
|
+
|
|
14
|
+
export type StudioSurface = {
|
|
15
|
+
kind: StudioSurfaceKind;
|
|
16
|
+
id: string;
|
|
17
|
+
project?: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
products?: Record<string, string>;
|
|
20
|
+
routes: string[];
|
|
21
|
+
locales: string[];
|
|
22
|
+
platforms?: string[];
|
|
23
|
+
paywallId?: string;
|
|
24
|
+
paywallIdentifier?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type PreviewUrlBuilder = (surface: StudioSurface) => string;
|
|
28
|
+
|
|
29
|
+
export type CompareTarget = { type: "live" } | { type: "surface"; surface: StudioSurface };
|
|
30
|
+
|
|
31
|
+
export type StudioSource = {
|
|
32
|
+
scheme?: string;
|
|
33
|
+
title: string;
|
|
34
|
+
surfaces: StudioSurface[];
|
|
35
|
+
diagnostics?: string[];
|
|
36
|
+
samples?: SampleDefaults;
|
|
37
|
+
previewUrl: PreviewUrlBuilder;
|
|
38
|
+
standaloneUrl?: PreviewUrlBuilder;
|
|
39
|
+
capabilities?: { actions: boolean };
|
|
40
|
+
compareHint?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const hasActions = (source: StudioSource): boolean => source.capabilities?.actions === true;
|
package/src/lib/time.ts
CHANGED
|
@@ -5,7 +5,6 @@ const UNITS: [number, Intl.RelativeTimeFormatUnit][] = [
|
|
|
5
5
|
[7, "day"],
|
|
6
6
|
[4.348, "week"],
|
|
7
7
|
[12, "month"],
|
|
8
|
-
[Number.POSITIVE_INFINITY, "year"],
|
|
9
8
|
];
|
|
10
9
|
|
|
11
10
|
export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
|
|
@@ -17,5 +16,5 @@ export const timeAgo = (iso: string, now = Date.now()): string | undefined => {
|
|
|
17
16
|
if (value < factor) return formatter.format(-Math.round(value), unit);
|
|
18
17
|
value /= factor;
|
|
19
18
|
}
|
|
20
|
-
return
|
|
19
|
+
return formatter.format(-Math.round(value), "year");
|
|
21
20
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SampleDefaults = {
|
|
2
|
+
device: Record<string, unknown>;
|
|
3
|
+
user: Record<string, unknown>;
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type VariableOverrides = {
|
|
8
|
+
device?: Record<string, unknown>;
|
|
9
|
+
user?: Record<string, unknown>;
|
|
10
|
+
params?: Record<string, unknown>;
|
|
11
|
+
products?: Record<string, Record<string, unknown>>;
|
|
12
|
+
introductoryOfferEligible?: boolean;
|
|
13
|
+
};
|
package/src/main.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { buildPreviewPath } from "./lib/preview";
|
|
3
|
+
import { buildPreviewPath, surfacePath } from "./lib/preview";
|
|
4
4
|
import { parseProjectPayload } from "./lib/project";
|
|
5
5
|
import { StudioApp } from "./StudioApp";
|
|
6
6
|
import "./styles.css";
|
|
7
|
-
import type {
|
|
7
|
+
import type { StudioMode } from "./lib/studio-host";
|
|
8
|
+
import type { StudioSource } from "./lib/surfaces";
|
|
8
9
|
|
|
9
10
|
const loadSource = async (): Promise<StudioSource> => {
|
|
10
11
|
const response = await fetch("/__studio/project.json");
|
|
@@ -12,7 +13,7 @@ const loadSource = async (): Promise<StudioSource> => {
|
|
|
12
13
|
throw new Error(`project data unavailable (${response.status})`);
|
|
13
14
|
}
|
|
14
15
|
const payload = parseProjectPayload(await response.json());
|
|
15
|
-
return { ...payload, previewUrl: buildPreviewPath };
|
|
16
|
+
return { ...payload, previewUrl: buildPreviewPath, standaloneUrl: surfacePath };
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
const Failure = ({ error }: { error: unknown }) => (
|
|
@@ -30,13 +31,13 @@ const Failure = ({ error }: { error: unknown }) => (
|
|
|
30
31
|
|
|
31
32
|
const root = createRoot(document.getElementById("root")!);
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const mode: StudioMode = /^\/device\/?$/.test(window.location.pathname) ? "device" : "local";
|
|
34
35
|
|
|
35
36
|
loadSource()
|
|
36
37
|
.then((source) => {
|
|
37
38
|
root.render(
|
|
38
39
|
<React.StrictMode>
|
|
39
|
-
<StudioApp source={source}
|
|
40
|
+
<StudioApp source={source} mode={mode} />
|
|
40
41
|
</React.StrictMode>,
|
|
41
42
|
);
|
|
42
43
|
})
|