@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.
Files changed (74) hide show
  1. package/README.md +27 -14
  2. package/dist/assets/index-CEz-HnIH.js +11 -0
  3. package/dist/index.html +1 -1
  4. package/dist/lib/StudioApp.d.ts +4 -4
  5. package/dist/lib/components/PaywallToasts.d.ts +3 -0
  6. package/dist/lib/components/SurfaceCard.d.ts +4 -2
  7. package/dist/lib/components/{TopBar.d.ts → chrome/TopBar.d.ts} +1 -2
  8. package/dist/lib/components/icons.d.ts +0 -2
  9. package/dist/lib/components/{ActionMenu.d.ts → menus/ActionMenu.d.ts} +2 -1
  10. package/dist/lib/components/{CompareMenu.d.ts → menus/CompareMenu.d.ts} +1 -1
  11. package/dist/lib/components/{VariablesPanel.d.ts → panels/VariablesPanel.d.ts} +3 -3
  12. package/dist/lib/components/{DeviceChrome.d.ts → preview/DeviceChrome.d.ts} +1 -1
  13. package/dist/lib/components/{DeviceFrame.d.ts → preview/DeviceFrame.d.ts} +5 -2
  14. package/dist/lib/components/preview/HostedIframe.d.ts +7 -0
  15. package/dist/lib/index.d.ts +14 -6
  16. package/dist/lib/index.js +1490 -998
  17. package/dist/lib/lib/actions.d.ts +1 -1
  18. package/dist/lib/lib/contract.d.ts +33 -0
  19. package/dist/lib/lib/devices.d.ts +1 -1
  20. package/dist/lib/lib/host.d.ts +15 -0
  21. package/dist/lib/lib/notices.d.ts +9 -0
  22. package/dist/lib/lib/preview.d.ts +2 -4
  23. package/dist/lib/lib/project.d.ts +2 -1
  24. package/dist/lib/lib/steps.d.ts +5 -0
  25. package/dist/lib/lib/studio-host.d.ts +34 -0
  26. package/dist/lib/lib/surfaces.d.ts +36 -0
  27. package/dist/lib/lib/variables.d.ts +12 -0
  28. package/dist/lib/products.js +26 -12
  29. package/dist/lib/screens/SurfaceEditor.d.ts +2 -3
  30. package/dist/lib/screens/SurfaceList.d.ts +2 -3
  31. package/package.json +5 -1
  32. package/src/StudioApp.tsx +25 -28
  33. package/src/components/PaywallToasts.tsx +162 -86
  34. package/src/components/SurfaceCard.tsx +9 -2
  35. package/src/components/chrome/TopBar.tsx +45 -0
  36. package/src/components/icons.tsx +0 -13
  37. package/src/components/{ActionMenu.tsx → menus/ActionMenu.tsx} +3 -3
  38. package/src/components/{CompareMenu.tsx → menus/CompareMenu.tsx} +2 -2
  39. package/src/components/{SidePanel.tsx → panels/SidePanel.tsx} +1 -1
  40. package/src/components/{VariablesPanel.tsx → panels/VariablesPanel.tsx} +4 -4
  41. package/src/components/{DeviceChrome.tsx → preview/DeviceChrome.tsx} +1 -1
  42. package/src/components/{DeviceFrame.tsx → preview/DeviceFrame.tsx} +14 -55
  43. package/src/components/preview/HostedIframe.tsx +46 -0
  44. package/src/index.ts +32 -12
  45. package/src/lib/actions.ts +1 -1
  46. package/src/lib/contract.ts +30 -0
  47. package/src/lib/devices.ts +5 -4
  48. package/src/lib/host.ts +79 -0
  49. package/src/lib/notices.ts +63 -0
  50. package/src/lib/preview.ts +8 -40
  51. package/src/lib/products.ts +20 -1
  52. package/src/lib/project.ts +2 -1
  53. package/src/lib/steps.ts +20 -0
  54. package/src/lib/studio-host.tsx +61 -0
  55. package/src/lib/surfaces.ts +43 -0
  56. package/src/lib/time.ts +1 -2
  57. package/src/lib/variables.ts +13 -0
  58. package/src/main.tsx +6 -5
  59. package/src/screens/SurfaceEditor.tsx +79 -70
  60. package/src/screens/SurfaceList.tsx +27 -12
  61. package/src/vite-env.d.ts +1 -0
  62. package/dist/assets/index-CVKQ82YR.js +0 -11
  63. package/dist/lib/lib/events.d.ts +0 -27
  64. package/dist/lib/lib/types.d.ts +0 -77
  65. package/src/components/TopBar.tsx +0 -41
  66. package/src/lib/events.ts +0 -86
  67. package/src/lib/types.ts +0 -87
  68. /package/dist/lib/components/{StudioShell.d.ts → chrome/StudioShell.d.ts} +0 -0
  69. /package/dist/lib/components/{Toolbar.d.ts → chrome/Toolbar.d.ts} +0 -0
  70. /package/dist/lib/components/{MissingProducts.d.ts → panels/MissingProducts.d.ts} +0 -0
  71. /package/dist/lib/components/{SidePanel.d.ts → panels/SidePanel.d.ts} +0 -0
  72. /package/src/components/{StudioShell.tsx → chrome/StudioShell.tsx} +0 -0
  73. /package/src/components/{Toolbar.tsx → chrome/Toolbar.tsx} +0 -0
  74. /package/src/components/{MissingProducts.tsx → panels/MissingProducts.tsx} +0 -0
@@ -1,9 +1,10 @@
1
1
  import * as React from "react";
2
- import { ActionMenu, type ActionProgress } from "../components/ActionMenu";
3
- import { CompareMenu, type CompareOption } from "../components/CompareMenu";
4
- import { DeviceFrame, DevicePlaceholder } from "../components/DeviceFrame";
5
- import { MissingProducts } from "../components/MissingProducts";
6
- import { PaywallToasts } from "../components/PaywallToasts";
2
+ import { hasIntroductoryOffer, type HostDelegate, type HostState } from "@superwall/host";
3
+ import { ActionMenu, type ActionProgress } from "../components/menus/ActionMenu";
4
+ import { CompareMenu, type CompareOption } from "../components/menus/CompareMenu";
5
+ import { DeviceFrame, DevicePlaceholder } from "../components/preview/DeviceFrame";
6
+ import { MissingProducts } from "../components/panels/MissingProducts";
7
+ import { PaywallToasts, useStudioDelegate } from "../components/PaywallToasts";
7
8
  import { Segmented, Select, Switch } from "../components/controls";
8
9
  import {
9
10
  ExternalIcon,
@@ -13,16 +14,15 @@ import {
13
14
  SlidersIcon,
14
15
  SunIcon,
15
16
  } from "../components/icons";
16
- import { SidePanel } from "../components/SidePanel";
17
- import { Toolbar, ToolbarDivider, ToolbarGroup } from "../components/Toolbar";
18
- import { TopBar } from "../components/TopBar";
17
+ import { SidePanel } from "../components/panels/SidePanel";
18
+ import { Toolbar, ToolbarDivider, ToolbarGroup } from "../components/chrome/Toolbar";
19
+ import { TopBar } from "../components/chrome/TopBar";
19
20
  import {
20
21
  VariablesPanel,
21
22
  type VariableGroups,
22
23
  type VariableRow,
23
- } from "../components/VariablesPanel";
24
+ } from "../components/panels/VariablesPanel";
24
25
  import { fetchStatus, runAction } from "../lib/actions";
25
- import { localesAnnounced } from "../lib/events";
26
26
  import {
27
27
  DEFAULT_DEVICE_ID,
28
28
  deviceById,
@@ -31,19 +31,19 @@ import {
31
31
  STUDIO_DEVICES,
32
32
  type DeviceChromeSpec,
33
33
  } from "../lib/devices";
34
- import { withOverrides } from "../lib/preview";
34
+ import { hostStateFor, studioDefaults } from "../lib/host";
35
+ import { hostedUrl } from "../lib/preview";
36
+ import { ACTION_STEPS, type StudioActionStep, type StudioStepState } from "../lib/steps";
35
37
  import {
36
- ACTION_STEPS,
38
+ hasActions,
37
39
  type CompareTarget,
38
- type PreviewOverrides,
39
- type StudioActionName,
40
- type StudioActionStep,
41
40
  type Samples,
41
+ type StudioActionName,
42
42
  type StudioSource,
43
43
  type StudioStatus,
44
- type StudioStepState,
45
44
  type StudioSurface,
46
- } from "../lib/types";
45
+ } from "../lib/surfaces";
46
+ import { type VariableOverrides } from "../lib/variables";
47
47
 
48
48
  const clampSize = (value: number, fallback: number): number =>
49
49
  Number.isFinite(value) ? Math.min(3000, Math.max(200, Math.round(value))) : fallback;
@@ -89,6 +89,8 @@ const StagePane = ({
89
89
  height,
90
90
  title,
91
91
  src,
92
+ hostState,
93
+ delegate,
92
94
  reloadKey,
93
95
  empty,
94
96
  chrome,
@@ -100,6 +102,8 @@ const StagePane = ({
100
102
  height: number;
101
103
  title: string;
102
104
  src?: string;
105
+ hostState: HostState;
106
+ delegate: HostDelegate;
103
107
  reloadKey: number;
104
108
  empty?: string;
105
109
  chrome?: DeviceChromeSpec;
@@ -117,6 +121,8 @@ const StagePane = ({
117
121
  height={height}
118
122
  title={title}
119
123
  src={src}
124
+ hostState={hostState}
125
+ delegate={delegate}
120
126
  stageRef={paneRef}
121
127
  reloadKey={reloadKey}
122
128
  chrome={chrome}
@@ -139,20 +145,18 @@ export const SurfaceEditor = ({
139
145
  source,
140
146
  surface,
141
147
  samples,
142
- onBack,
143
148
  actions,
144
149
  }: {
145
150
  source: StudioSource;
146
151
  surface: StudioSurface;
147
152
  samples: Samples;
148
- onBack: () => void;
149
153
  actions?: React.ReactNode;
150
154
  }) => {
151
155
  const [deviceId, setDeviceId] = React.useState(DEFAULT_DEVICE_ID);
152
156
  const [size, setSize] = React.useState(RESPONSIVE_DEFAULT);
153
157
  const [theme, setTheme] = React.useState<"light" | "dark">("light");
154
158
  const [locale, setLocale] = React.useState<string | undefined>(undefined);
155
- const [edited, setEdited] = React.useState<PreviewOverrides>({});
159
+ const [edited, setEdited] = React.useState<VariableOverrides>({});
156
160
  const [panelOpen, setPanelOpen] = React.useState(false);
157
161
  const [compareWith, setCompareWith] = React.useState<CompareTarget | undefined>(undefined);
158
162
  const [reloadKey, setReloadKey] = React.useState(0);
@@ -162,18 +166,11 @@ export const SurfaceEditor = ({
162
166
  const dismissTimer = React.useRef<number | undefined>(undefined);
163
167
  React.useEffect(() => () => window.clearTimeout(dismissTimer.current), []);
164
168
 
165
- const actionsEnabled = source.capabilities?.actions === true;
169
+ const actionsEnabled = hasActions(source);
170
+ const delegate = useStudioDelegate();
171
+ const defaults = React.useMemo(studioDefaults, [surface]);
166
172
 
167
- const [announced, setAnnounced] = React.useState<string[]>([]);
168
- React.useEffect(() => {
169
- const onMessage = (event: MessageEvent) => {
170
- const locales = localesAnnounced(event.data);
171
- if (locales) setAnnounced(locales);
172
- };
173
- window.addEventListener("message", onMessage);
174
- return () => window.removeEventListener("message", onMessage);
175
- }, []);
176
- const locales = surface.locales.length > 0 ? surface.locales : announced;
173
+ const locales = surface.locales;
177
174
 
178
175
  React.useEffect(() => {
179
176
  if (!actionsEnabled) return;
@@ -220,41 +217,45 @@ export const SurfaceEditor = ({
220
217
  }
221
218
  };
222
219
 
220
+ const responsive = deviceId === RESPONSIVE_ID;
221
+ const device = deviceById(deviceId);
222
+ const upright = responsive ? size : { width: device.width, height: device.height };
223
+ const frame = landscape ? { width: upright.height, height: upright.width } : upright;
224
+
223
225
  const openPreview = () => {
226
+ const standalone = source.standaloneUrl?.(surface);
227
+ if (standalone === undefined) return;
224
228
  if (frame.width > 768) {
225
- window.open(previewSrc, "_blank");
229
+ window.open(standalone, "_blank");
226
230
  return;
227
231
  }
228
232
  const left = Math.max(0, window.screen.width / 2 - frame.width / 2);
229
233
  const top = Math.max(0, window.screen.height / 2 - frame.height / 2);
230
234
  const popup = window.open(
231
- previewSrc,
235
+ standalone,
232
236
  "superwall-preview",
233
237
  `toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=${frame.width},height=${frame.height},top=${top},left=${left}`,
234
238
  );
235
- if (!popup) window.open(previewSrc, "_blank");
239
+ if (!popup) window.open(standalone, "_blank");
236
240
  };
237
241
 
238
- const responsive = deviceId === RESPONSIVE_ID;
239
- const device = deviceById(deviceId);
240
- const upright = responsive ? size : { width: device.width, height: device.height };
241
- const frame = landscape ? { width: upright.height, height: upright.width } : upright;
242
-
243
- const overrides: PreviewOverrides = {
244
- theme,
245
- locale,
246
- user: edited.user,
247
- params: edited.params,
248
- products: edited.products,
249
- trialEligible: edited.trialEligible,
250
- device: {
251
- ...(responsive ? {} : device.device),
252
- ...edited.device,
253
- },
254
- };
242
+ const hostState = React.useMemo(
243
+ () =>
244
+ hostStateFor({
245
+ surface,
246
+ defaults,
247
+ sourceSamples: source.samples,
248
+ samples,
249
+ frame: responsive ? undefined : device.device,
250
+ theme,
251
+ locale,
252
+ edited,
253
+ }),
254
+ [surface, defaults, source.samples, samples, responsive, device.device, theme, locale, edited],
255
+ );
255
256
  const chrome = responsive ? undefined : device.chrome;
256
- const previewSrc = source.previewUrl(surface, overrides);
257
- const liveSrc = status.liveUrl ? withOverrides(status.liveUrl, overrides) : undefined;
257
+ const previewSrc = source.previewUrl(surface);
258
+ const liveSrc = status.liveUrl ? hostedUrl(status.liveUrl) : undefined;
258
259
 
259
260
  const compareOptions: CompareOption[] = [
260
261
  ...(actionsEnabled
@@ -290,7 +291,7 @@ export const SurfaceEditor = ({
290
291
  }
291
292
  : {
292
293
  label: nameOf(compareWith.surface),
293
- src: source.previewUrl(compareWith.surface, overrides),
294
+ src: source.previewUrl(compareWith.surface),
294
295
  title: `${nameOf(compareWith.surface)} preview`,
295
296
  });
296
297
 
@@ -301,18 +302,19 @@ export const SurfaceEditor = ({
301
302
  .toSorted((a, b) => a.path.localeCompare(b.path));
302
303
 
303
304
  return {
304
- user: rows("user", { ...source.samples?.user, ...samples.user }),
305
+ user: rows("user", { ...defaults.user, ...source.samples?.user, ...samples.user }),
305
306
  device: rows("device", {
307
+ ...defaults.device,
306
308
  ...source.samples?.device,
307
309
  ...samples.device,
308
310
  ...(device.device as Record<string, unknown>),
309
311
  }),
310
- params: rows("params", source.samples?.params),
312
+ params: rows("params", { ...defaults.params, ...source.samples?.params }),
311
313
  products: Object.entries(surface.products ?? {}).flatMap(([reference, identifier]) =>
312
314
  rows(`products.${reference}`, samples.products?.[identifier]),
313
315
  ),
314
316
  };
315
- }, [source.samples, samples, device.device, surface.products]);
317
+ }, [defaults, source.samples, samples, device.device, surface.products]);
316
318
 
317
319
  const missingProducts = React.useMemo(() => {
318
320
  if (!samples.products) return [];
@@ -352,7 +354,6 @@ export const SurfaceEditor = ({
352
354
  title={`${surface.project ?? source.title} / ${surface.id}${
353
355
  surface.label ? ` · ${surface.label}` : ""
354
356
  }`}
355
- onHome={onBack}
356
357
  actions={
357
358
  <>
358
359
  {actions}
@@ -364,14 +365,16 @@ export const SurfaceEditor = ({
364
365
  >
365
366
  <RotateIcon />
366
367
  </button>
367
- <button
368
- type="button"
369
- className="sw-btn sw-btn--icon"
370
- aria-label="Open preview"
371
- onClick={openPreview}
372
- >
373
- <ExternalIcon />
374
- </button>
368
+ {source.standaloneUrl && (
369
+ <button
370
+ type="button"
371
+ className="sw-btn sw-btn--icon"
372
+ aria-label="Open preview"
373
+ onClick={openPreview}
374
+ >
375
+ <ExternalIcon />
376
+ </button>
377
+ )}
375
378
  {actionsEnabled && (
376
379
  <ActionMenu
377
380
  progress={progress}
@@ -399,6 +402,8 @@ export const SurfaceEditor = ({
399
402
  height={frame.height}
400
403
  title={comparePane.title}
401
404
  src={comparePane.src}
405
+ hostState={hostState}
406
+ delegate={delegate}
402
407
  reloadKey={reloadKey}
403
408
  empty={"empty" in comparePane ? comparePane.empty : undefined}
404
409
  chrome={chrome}
@@ -412,6 +417,8 @@ export const SurfaceEditor = ({
412
417
  height={frame.height}
413
418
  title={`${surface.id} preview`}
414
419
  src={previewSrc}
420
+ hostState={hostState}
421
+ delegate={delegate}
415
422
  reloadKey={reloadKey}
416
423
  chrome={chrome}
417
424
  landscape={landscape}
@@ -425,11 +432,13 @@ export const SurfaceEditor = ({
425
432
  </div>
426
433
 
427
434
  <Toolbar>
428
- <ToolbarGroup label="Trial">
435
+ <ToolbarGroup label="Intro offer">
429
436
  <Switch
430
- label="Trial eligibility"
431
- checked={edited.trialEligible ?? false}
432
- onChange={(checked) => setEdited((current) => ({ ...current, trialEligible: checked }))}
437
+ label="Introductory offer"
438
+ checked={hasIntroductoryOffer(hostState)}
439
+ onChange={(checked) =>
440
+ setEdited((current) => ({ ...current, introductoryOfferEligible: checked }))
441
+ }
433
442
  />
434
443
  </ToolbarGroup>
435
444
  <ToolbarGroup label="Theme">
@@ -1,26 +1,34 @@
1
1
  import * as React from "react";
2
2
  import { OpenInApp } from "../components/OpenInApp";
3
3
  import { SurfaceCard } from "../components/SurfaceCard";
4
- import { TopBar } from "../components/TopBar";
4
+ import { TopBar } from "../components/chrome/TopBar";
5
5
  import { fetchStatus } from "../lib/actions";
6
- import type { StudioSource, StudioStatus, StudioSurface } from "../lib/types";
7
- import { devicePreviewPath, surfacePath } from "../lib/preview";
6
+ import {
7
+ hasActions,
8
+ type StudioSource,
9
+ type StudioStatus,
10
+ type StudioSurface,
11
+ } from "../lib/surfaces";
12
+ import { hostStateFor, studioDefaults } from "../lib/host";
13
+ import { surfacePath } from "../lib/preview";
14
+ import { useStudioMode } from "../lib/studio-host";
8
15
 
9
16
  let lastScroll = 0;
10
17
 
11
18
  export const SurfaceList = ({
12
19
  source,
13
20
  onOpen,
14
- device = false,
15
21
  }: {
16
22
  source: StudioSource;
17
23
  onOpen: (surface: StudioSurface) => void;
18
- device?: boolean;
19
24
  }) => {
25
+ const device = useStudioMode() === "device";
26
+ const actions = hasActions(source);
20
27
  const [statuses, setStatuses] = React.useState<Record<string, StudioStatus>>({});
28
+ const defaults = React.useMemo(studioDefaults, [source]);
21
29
 
22
30
  React.useEffect(() => {
23
- if (source.capabilities?.actions !== true) return;
31
+ if (!actions) return;
24
32
  let cancelled = false;
25
33
  for (const surface of source.surfaces) {
26
34
  void fetchStatus(surface).then((status) => {
@@ -31,7 +39,7 @@ export const SurfaceList = ({
31
39
  return () => {
32
40
  cancelled = true;
33
41
  };
34
- }, [source]);
42
+ }, [source, actions]);
35
43
 
36
44
  const [queries, setQueries] = React.useState<Record<string, string>>({});
37
45
  const scroller = React.useRef<HTMLDivElement>(null);
@@ -77,7 +85,6 @@ export const SurfaceList = ({
77
85
  <>
78
86
  <TopBar
79
87
  title={source.title}
80
- onHome={() => {}}
81
88
  inset
82
89
  label={device ? "Preview" : undefined}
83
90
  actions={
@@ -119,9 +126,17 @@ export const SurfaceList = ({
119
126
  key={surfacePath(surface)}
120
127
  surface={surface}
121
128
  status={statuses[surfacePath(surface)]}
122
- previewSrc={source.previewUrl(surface, {})}
129
+ previewSrc={source.previewUrl(surface)}
130
+ hostState={hostStateFor({
131
+ surface,
132
+ defaults,
133
+ sourceSamples: source.samples,
134
+ samples: {},
135
+ theme: "light",
136
+ edited: {},
137
+ })}
123
138
  onOpen={() => onOpen(surface)}
124
- href={device ? devicePreviewPath(surface) : undefined}
139
+ href={device ? surfacePath(surface) : undefined}
125
140
  />
126
141
  ))}
127
142
  </div>
@@ -147,8 +162,8 @@ export const SurfaceList = ({
147
162
 
148
163
  {!device && (
149
164
  <footer className="bg-bar flex h-11 flex-none items-center justify-center border-t border-cream/10 text-xs text-cream/55">
150
- Previews run against the simulated SDK host. Edit files under superwall/ and they update
151
- live.
165
+ Previews run against a real SDK host — you choose the outcomes. Edit files under
166
+ superwall/ and they update live.
152
167
  </footer>
153
168
  )}
154
169
  </>
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />