@superwall/studio 1.6.1 → 1.6.2

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 (63) hide show
  1. package/README.md +27 -10
  2. package/dist/assets/index-BMe9fPdZ.css +1 -0
  3. package/dist/assets/index-Czsb6jZs.js +11 -0
  4. package/dist/index.html +3 -3
  5. package/dist/lib/components/Dialog.d.ts +7 -0
  6. package/dist/lib/components/EmptyState.d.ts +9 -0
  7. package/dist/lib/components/InlineCode.d.ts +2 -0
  8. package/dist/lib/components/PaywallToasts.d.ts +8 -0
  9. package/dist/lib/components/SuperwallLogo.d.ts +9 -0
  10. package/dist/lib/components/Tooltip.d.ts +3 -1
  11. package/dist/lib/components/chrome/TopBar.d.ts +2 -3
  12. package/dist/lib/components/controls.d.ts +10 -1
  13. package/dist/lib/components/icons.d.ts +30 -17
  14. package/dist/lib/components/menus/ActionMenu.d.ts +4 -1
  15. package/dist/lib/components/menus/Menu.d.ts +19 -0
  16. package/dist/lib/index.d.ts +3 -1
  17. package/dist/lib/index.js +2582 -2054
  18. package/dist/lib/lib/actions.d.ts +3 -2
  19. package/dist/lib/lib/contract.d.ts +4 -0
  20. package/dist/lib/lib/notify.d.ts +4 -1
  21. package/dist/lib/lib/promotion.d.ts +17 -0
  22. package/dist/lib/lib/steps.d.ts +2 -1
  23. package/dist/lib/lib/surfaces.d.ts +10 -4
  24. package/dist/lib/studio.css +1 -1
  25. package/package.json +2 -2
  26. package/src/StudioApp.tsx +3 -2
  27. package/src/components/Dialog.tsx +74 -0
  28. package/src/components/DownloadScreenshot.tsx +13 -20
  29. package/src/components/EmptyState.tsx +32 -0
  30. package/src/components/InlineCode.tsx +7 -0
  31. package/src/components/OpenInApp.tsx +15 -14
  32. package/src/components/PaywallToasts.tsx +44 -37
  33. package/src/components/PreviewOnDevice.tsx +61 -43
  34. package/src/components/SuperwallLogo.tsx +72 -0
  35. package/src/components/SurfaceCard.tsx +34 -18
  36. package/src/components/Tooltip.tsx +25 -2
  37. package/src/components/chrome/StudioShell.tsx +1 -1
  38. package/src/components/chrome/Toolbar.tsx +10 -8
  39. package/src/components/chrome/TopBar.tsx +21 -22
  40. package/src/components/controls.tsx +116 -31
  41. package/src/components/icons.tsx +140 -59
  42. package/src/components/menus/ActionMenu.tsx +221 -97
  43. package/src/components/menus/CompareMenu.tsx +48 -67
  44. package/src/components/menus/Menu.tsx +144 -0
  45. package/src/components/panels/MissingProducts.tsx +27 -34
  46. package/src/components/panels/SidePanel.tsx +9 -9
  47. package/src/components/panels/VariablesPanel.tsx +57 -49
  48. package/src/components/preview/DeviceFrame.tsx +4 -6
  49. package/src/index.ts +9 -0
  50. package/src/lib/actions.ts +13 -4
  51. package/src/lib/contract.ts +2 -0
  52. package/src/lib/notify.tsx +15 -18
  53. package/src/lib/project.ts +1 -0
  54. package/src/lib/promotion.ts +47 -0
  55. package/src/lib/steps.ts +9 -1
  56. package/src/lib/surfaces.ts +22 -2
  57. package/src/main.tsx +22 -10
  58. package/src/screens/SurfaceEditor.tsx +101 -63
  59. package/src/screens/SurfaceList.tsx +112 -69
  60. package/src/scroll-fade.css +425 -0
  61. package/src/styles.css +380 -182
  62. package/dist/assets/index-CTn2zVi-.js +0 -11
  63. package/dist/assets/index-DrsTCwot.css +0 -1
@@ -1,3 +1,10 @@
1
+ import type {
2
+ StudioActionName,
3
+ StudioActionProgress,
4
+ StudioActionRequest,
5
+ StudioActionResult,
6
+ StudioStatus,
7
+ } from "./contract";
1
8
  import type { StudioPresentation } from "./presentation";
2
9
  import type { SampleDefaults } from "./variables";
3
10
 
@@ -8,6 +15,7 @@ export type {
8
15
  Samples,
9
16
  StudioActionName,
10
17
  StudioActionProgress,
18
+ StudioActionRequest,
11
19
  StudioActionResult,
12
20
  StudioStatus,
13
21
  StudioVersion,
@@ -20,6 +28,7 @@ export type StudioSurface = {
20
28
  id: string;
21
29
  project?: string;
22
30
  label?: string;
31
+ version?: number;
23
32
  products?: Record<string, string>;
24
33
  routes: string[];
25
34
  locales: string[];
@@ -66,6 +75,17 @@ export type CompareTarget =
66
75
  | { type: "surface"; surface: StudioSurface }
67
76
  | { type: "origin" };
68
77
 
78
+ export type StudioActions = {
79
+ offered: readonly StudioActionName[];
80
+ run(
81
+ surface: StudioSurface,
82
+ request: StudioActionRequest,
83
+ onStep?: StudioActionProgress,
84
+ ): Promise<StudioActionResult>;
85
+ status(surface: StudioSurface): Promise<StudioStatus>;
86
+ pick?(version: number): void;
87
+ };
88
+
69
89
  export type StudioSource = {
70
90
  scheme?: string;
71
91
  networkOrigin?: string;
@@ -75,10 +95,10 @@ export type StudioSource = {
75
95
  samples?: SampleDefaults;
76
96
  previewUrl: PreviewUrlBuilder;
77
97
  standaloneUrl?: PreviewUrlBuilder;
78
- capabilities?: { actions: boolean };
98
+ actions?: StudioActions;
79
99
  previewLink?: (surface: StudioSurface) => Promise<string>;
80
100
  screenshotUrl?: (surface: StudioSurface) => Promise<string | undefined>;
81
101
  compareHint?: string;
82
102
  };
83
103
 
84
- export const hasActions = (source: StudioSource): boolean => source.capabilities?.actions === true;
104
+ export const hasActions = (source: StudioSource): boolean => source.actions !== undefined;
package/src/main.tsx CHANGED
@@ -1,5 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { createRoot } from "react-dom/client";
3
+ import { StudioShell } from "./components/chrome/StudioShell";
4
+ import { EmptyState } from "./components/EmptyState";
5
+ import { AlertTriangleIcon } from "./components/icons";
6
+ import { InlineCode } from "./components/InlineCode";
7
+ import { devServerActions } from "./lib/actions";
3
8
  import { buildPreviewPath, surfacePath } from "./lib/preview";
4
9
  import { parseProjectPayload } from "./lib/project";
5
10
  import { StudioApp } from "./StudioApp";
@@ -12,25 +17,32 @@ const loadSource = async (): Promise<StudioSource> => {
12
17
  if (!response.ok) {
13
18
  throw new Error(`project data unavailable (${response.status})`);
14
19
  }
15
- const payload = parseProjectPayload(await response.json());
20
+ const { capabilities, ...payload } = parseProjectPayload(await response.json());
16
21
  return {
17
22
  ...payload,
23
+ ...(capabilities.actions ? { actions: devServerActions } : {}),
18
24
  previewUrl: buildPreviewPath,
19
25
  standaloneUrl: (surface) => `/preview${surfacePath(surface)}`,
20
26
  };
21
27
  };
22
28
 
23
29
  const Failure = ({ error }: { error: unknown }) => (
24
- <div className="bg-ink text-cream fixed inset-0 flex font-sans antialiased">
25
- <div className="m-auto flex flex-col items-center gap-3 text-center text-sm text-cream/55">
26
- <span className="sw-chip font-mono text-[0.6875rem]">studio</span>
27
- <p className="m-0">{String(error)}</p>
28
- <p className="m-0 text-cream/55">
29
- Is <code className="font-mono text-[0.8125rem] text-cream">superwall dev</code> running in a
30
- project directory?
31
- </p>
30
+ <StudioShell>
31
+ <div className="m-auto">
32
+ <EmptyState
33
+ size="lg"
34
+ tone="destructive"
35
+ icon={<AlertTriangleIcon />}
36
+ title="Couldn’t load the studio"
37
+ description={
38
+ <>
39
+ {String(error)}. Is <InlineCode>superwall dev</InlineCode> running in a project
40
+ directory?
41
+ </>
42
+ }
43
+ />
32
44
  </div>
33
- </div>
45
+ </StudioShell>
34
46
  );
35
47
 
36
48
  const root = createRoot(document.getElementById("root")!);
@@ -16,13 +16,17 @@ import { DownloadScreenshot } from "../components/DownloadScreenshot";
16
16
  import { PreviewOnDevice } from "../components/PreviewOnDevice";
17
17
  import { Segmented, Select, Switch } from "../components/controls";
18
18
  import {
19
+ AlertTriangleIcon,
19
20
  ExternalIcon,
21
+ MinusIcon,
20
22
  MoonIcon,
23
+ PlusIcon,
21
24
  RotateDeviceIcon,
22
25
  RotateIcon,
23
26
  SlidersIcon,
24
27
  SunIcon,
25
28
  } from "../components/icons";
29
+ import { Tooltip } from "../components/Tooltip";
26
30
  import { SidePanel } from "../components/panels/SidePanel";
27
31
  import { Toolbar, ToolbarDivider, ToolbarGroup } from "../components/chrome/Toolbar";
28
32
  import { TopBar } from "../components/chrome/TopBar";
@@ -31,7 +35,6 @@ import {
31
35
  type VariableGroups,
32
36
  type VariableRow,
33
37
  } from "../components/panels/VariablesPanel";
34
- import { fetchStatus, runAction } from "../lib/actions";
35
38
  import {
36
39
  chromeFor,
37
40
  DEFAULT_DEVICE_ID,
@@ -47,9 +50,9 @@ import {
47
50
  import { hostStateFor, previewDevice, studioDefaults } from "../lib/host";
48
51
  import { percent } from "../lib/canvas";
49
52
  import { hostedUrl, originalUrl } from "../lib/preview";
53
+ import { latestVersion, liveVersion } from "../lib/promotion";
50
54
  import { ACTION_STEPS, type StudioActionStep, type StudioStepState } from "../lib/steps";
51
55
  import {
52
- hasActions,
53
56
  hasOriginal,
54
57
  isScreenOrigin,
55
58
  SCREEN_FRAMEWORK_LABEL,
@@ -65,6 +68,9 @@ import {
65
68
  import { timeAgo } from "../lib/time";
66
69
  import { type VariableOverrides } from "../lib/variables";
67
70
 
71
+ const STEPPER =
72
+ "flex w-8 items-center justify-center outline-none transition-colors duration-hover hover:bg-accent focus-visible:bg-accent hover:[&>svg]:filter-none focus-visible:[&>svg]:filter-none";
73
+
68
74
  const clampSize = (value: number, fallback: number): number =>
69
75
  Number.isFinite(value) ? Math.min(3000, Math.max(200, Math.round(value))) : fallback;
70
76
 
@@ -90,7 +96,7 @@ const SizeInput = ({
90
96
 
91
97
  return (
92
98
  <input
93
- className="sw-input w-16 text-center"
99
+ className="sw-input w-16 text-center tabular-nums"
94
100
  type="number"
95
101
  aria-label={label}
96
102
  value={draft}
@@ -145,7 +151,7 @@ const StagePane = ({
145
151
  <div className="flex flex-none flex-col gap-2">
146
152
  {label && (
147
153
  <span
148
- className="origin-bottom-left text-xs whitespace-nowrap text-cream/55"
154
+ className="origin-bottom-left text-xs whitespace-nowrap text-fg-tertiary"
149
155
  style={{ transform: `scale(${1 / scale})` }}
150
156
  >
151
157
  {label}
@@ -229,32 +235,36 @@ export const SurfaceEditor = ({
229
235
  const canvas = React.useRef<CanvasHandle>(null);
230
236
  const [zoom, setZoom] = React.useState<CanvasZoom>({ scale: 1, fitted: true });
231
237
  const [status, setStatus] = React.useState<StudioStatus>({});
238
+ const [picked, setPicked] = React.useState<number | undefined>(undefined);
232
239
  const [progress, setProgress] = React.useState<ActionProgress | undefined>(undefined);
233
240
  const dismissTimer = React.useRef<number | undefined>(undefined);
234
241
  React.useEffect(() => () => window.clearTimeout(dismissTimer.current), []);
235
242
 
236
- const actionsEnabled = hasActions(source);
243
+ const shipping = source.actions;
237
244
  const delegate = useStudioDelegate();
238
245
  const defaults = React.useMemo(studioDefaults, [surface]);
239
246
 
240
247
  const locales = surface.locales;
241
248
 
242
249
  React.useEffect(() => {
243
- if (!actionsEnabled) return;
250
+ if (!shipping) return;
244
251
  let cancelled = false;
245
- fetchStatus(surface).then((value) => {
252
+ setPicked(undefined);
253
+ shipping.status(surface).then((value) => {
246
254
  if (!cancelled) setStatus(value);
247
255
  });
248
256
  return () => {
249
257
  cancelled = true;
250
258
  };
251
- }, [actionsEnabled, surface]);
259
+ }, [shipping, surface]);
252
260
 
253
261
  const ship = async (action: StudioActionName) => {
262
+ if (!shipping) return;
254
263
  window.clearTimeout(dismissTimer.current);
255
264
  setProgress({ action, steps: {} });
256
265
 
257
- const result = await runAction(surface, action, (step, state) => {
266
+ const version = action === "promote" ? (surface.version ?? picked) : undefined;
267
+ const result = await shipping.run(surface, { action, version }, (step, state) => {
258
268
  setProgress((current) =>
259
269
  current?.action === action
260
270
  ? {
@@ -270,7 +280,8 @@ export const SurfaceEditor = ({
270
280
  ACTION_STEPS[action].map((step) => [step, "done"]),
271
281
  ) as Partial<Record<StudioActionStep, StudioStepState>>;
272
282
  setProgress({ action, steps });
273
- setStatus(await fetchStatus(surface));
283
+ setPicked(undefined);
284
+ setStatus(await shipping.status(surface));
274
285
  dismissTimer.current = window.setTimeout(() => setProgress(undefined), 1600);
275
286
  } else {
276
287
  setProgress((current) => {
@@ -330,7 +341,13 @@ export const SurfaceEditor = ({
330
341
  const chrome = responsive ? undefined : chromeFor(device, web);
331
342
  const previewSrc = source.previewUrl(surface);
332
343
  const versions = status.versions ?? [];
333
- const versionLabel = (entry: StudioVersion) => `v${entry.version}${entry.live ? " · live" : ""}`;
344
+ const promotion = {
345
+ target: surface.version ?? picked ?? latestVersion(versions),
346
+ live: liveVersion(versions),
347
+ versions,
348
+ pick: surface.version === undefined ? setPicked : shipping?.pick,
349
+ };
350
+ const versionLabel = (entry: StudioVersion) => `v${entry.version}${entry.live ? " · Live" : ""}`;
334
351
  const pushedHint = (entry: StudioVersion) => {
335
352
  if (entry.live) return "What SDKs receive today";
336
353
  const ago = entry.pushedAt ? timeAgo(entry.pushedAt) : undefined;
@@ -366,7 +383,7 @@ export const SurfaceEditor = ({
366
383
  .filter((option) => option.target.surface !== surface),
367
384
  ];
368
385
  const compareNotice = status.unreachable
369
- ? `Couldn't read the pushed versions — ${status.unreachable}`
386
+ ? `Couldn’t read the pushed versions — ${status.unreachable}`
370
387
  : undefined;
371
388
  const compared =
372
389
  compareWith?.type === "version"
@@ -391,7 +408,7 @@ export const SurfaceEditor = ({
391
408
  title: `${surface.id} original`,
392
409
  empty:
393
410
  surface.origin && isScreenOrigin(surface.origin)
394
- ? "The original's screenshot is missing — capture it again with `superwall migrate --screen <path> --screenshot <file>`."
411
+ ? "The original’s screenshot is missing — capture it again with `superwall migrate --screen <path> --screenshot <file>`."
395
412
  : "This paywall was not rebuilt from a dashboard paywall or a native screen.",
396
413
  }
397
414
  : {
@@ -454,34 +471,42 @@ export const SurfaceEditor = ({
454
471
  />
455
472
  )}
456
473
  <TopBar
457
- title={`${surface.project ?? source.title} / ${surface.id}${
458
- surface.label ? ` · ${surface.label}` : ""
474
+ title={`${surface.project ?? source.title} / ${surface.label ?? surface.id}${
475
+ surface.label ? ` · ${surface.id}` : ""
459
476
  }`}
460
477
  actions={
461
478
  <>
462
479
  {actions}
463
- <button
464
- type="button"
465
- className="sw-btn sw-btn--icon"
466
- aria-label="Reload preview"
467
- onClick={() => setReloadKey((key) => key + 1)}
468
- >
469
- <RotateIcon />
470
- </button>
471
- {source.standaloneUrl && (
472
- <button
473
- type="button"
474
- className="sw-btn sw-btn--icon"
475
- aria-label="Open preview"
476
- onClick={openPreview}
477
- >
478
- <ExternalIcon />
479
- </button>
480
- )}
481
- <DownloadScreenshot source={source} surface={surface} />
480
+ <span className="flex items-center gap-0.5">
481
+ <Tooltip hint="Reload preview">
482
+ <button
483
+ type="button"
484
+ className="sw-btn sw-btn--sm sw-btn--icon sw-btn--ghost"
485
+ aria-label="Reload preview"
486
+ onClick={() => setReloadKey((key) => key + 1)}
487
+ >
488
+ <RotateIcon />
489
+ </button>
490
+ </Tooltip>
491
+ {source.standaloneUrl && (
492
+ <Tooltip hint="Open preview">
493
+ <button
494
+ type="button"
495
+ className="sw-btn sw-btn--sm sw-btn--icon sw-btn--ghost"
496
+ aria-label="Open preview"
497
+ onClick={openPreview}
498
+ >
499
+ <ExternalIcon />
500
+ </button>
501
+ </Tooltip>
502
+ )}
503
+ <DownloadScreenshot source={source} surface={surface} />
504
+ </span>
482
505
  <PreviewOnDevice source={source} surface={surface} />
483
- {actionsEnabled && (
506
+ {shipping && (
484
507
  <ActionMenu
508
+ offered={shipping.offered}
509
+ promotion={promotion}
485
510
  progress={progress}
486
511
  blocked={
487
512
  shippable
@@ -500,9 +525,13 @@ export const SurfaceEditor = ({
500
525
  {unverified && (
501
526
  <div
502
527
  role="status"
503
- className="relative z-10 flex-none border-b border-cream/10 bg-[color-mix(in_srgb,var(--color-red)_10%,var(--color-ink))] px-4 py-1.5 text-[0.8125rem] text-cream/75"
528
+ className="relative z-10 flex flex-none items-center gap-2 border-b border-border bg-warning/8 px-4 py-2 text-sm text-warning-foreground"
504
529
  >
505
- Couldn't check this paywall's products — {unverified}
530
+ <AlertTriangleIcon />
531
+ <span className="min-w-0 truncate">
532
+ Couldn’t check this paywall’s products{" "}
533
+ <span className="text-warning-foreground/80">· {unverified}</span>
534
+ </span>
506
535
  </div>
507
536
  )}
508
537
 
@@ -581,51 +610,60 @@ export const SurfaceEditor = ({
581
610
  label="Theme"
582
611
  value={theme}
583
612
  options={[
584
- { value: "light", label: <SunIcon /> },
585
- { value: "dark", label: <MoonIcon /> },
613
+ { value: "light", label: <SunIcon />, name: "Light" },
614
+ { value: "dark", label: <MoonIcon />, name: "Dark" },
586
615
  ]}
587
616
  onChange={setTheme}
588
617
  />
589
- <button
590
- type="button"
591
- className="sw-btn sw-btn--icon"
592
- aria-label="Rotate device"
593
- aria-pressed={landscape}
594
- title={landscape ? "Back to portrait" : "Rotate to landscape"}
595
- onClick={() => setLandscape((value) => !value)}
618
+ <Tooltip
619
+ side="top"
620
+ align="center"
621
+ hint={landscape ? "Back to portrait" : "Rotate to landscape"}
596
622
  >
597
- <span
598
- className={`flex transition-transform duration-200 ${landscape ? "-rotate-90" : ""}`}
623
+ <button
624
+ type="button"
625
+ className="sw-btn sw-btn--icon"
626
+ aria-label="Rotate device"
627
+ aria-pressed={landscape}
628
+ onClick={() => setLandscape((value) => !value)}
599
629
  >
600
- <RotateDeviceIcon />
601
- </span>
602
- </button>
630
+ <RotateDeviceIcon
631
+ className={`transition-disclosure ${landscape ? "-rotate-90" : ""}`}
632
+ />
633
+ </button>
634
+ </Tooltip>
603
635
  </ToolbarGroup>
604
636
  <ToolbarDivider />
605
637
  <ToolbarGroup label="Zoom">
606
- <div className="sw-stepper" role="group" aria-label="Zoom">
638
+ <div
639
+ className="flex h-8 flex-none overflow-hidden rounded-sm border border-border transition-colors duration-hover has-[:focus-visible]:border-primary"
640
+ role="group"
641
+ aria-label="Zoom"
642
+ >
607
643
  <button
608
644
  type="button"
645
+ className={STEPPER}
609
646
  aria-label="Zoom out"
610
647
  onClick={() => canvas.current?.zoomStep(-1)}
611
648
  >
612
- <svg viewBox="0 0 24 24" aria-hidden="true">
613
- <path d="M5 12h14" />
614
- </svg>
649
+ <MinusIcon className="icon-tertiary" />
615
650
  </button>
616
651
  <button
617
652
  type="button"
618
- className="min-w-12 px-2 font-mono text-xs tabular-nums"
653
+ className="min-w-14 border-x border-border px-2 text-sm tabular-nums outline-none transition-colors duration-hover hover:bg-accent focus-visible:bg-accent"
619
654
  aria-label="Fit to view"
620
655
  aria-pressed={zoom.fitted}
621
656
  onClick={() => canvas.current?.fit()}
622
657
  >
623
658
  {percent(zoom.scale)}
624
659
  </button>
625
- <button type="button" aria-label="Zoom in" onClick={() => canvas.current?.zoomStep(1)}>
626
- <svg viewBox="0 0 24 24" aria-hidden="true">
627
- <path d="M12 5v14M5 12h14" />
628
- </svg>
660
+ <button
661
+ type="button"
662
+ className={STEPPER}
663
+ aria-label="Zoom in"
664
+ onClick={() => canvas.current?.zoomStep(1)}
665
+ >
666
+ <PlusIcon className="icon-tertiary" />
629
667
  </button>
630
668
  </div>
631
669
  </ToolbarGroup>
@@ -646,7 +684,7 @@ export const SurfaceEditor = ({
646
684
  value={frame.width}
647
685
  onCommit={(width) => setSize((current) => ({ ...current, width }))}
648
686
  />
649
- <span className="text-cream/55">×</span>
687
+ <span className="text-fg-tertiary">×</span>
650
688
  <SizeInput
651
689
  label="Preview height"
652
690
  value={frame.height}
@@ -669,7 +707,7 @@ export const SurfaceEditor = ({
669
707
  </ToolbarGroup>
670
708
  )}
671
709
  <ToolbarDivider />
672
- {(actionsEnabled || compareOptions.length > 0) && (
710
+ {(shipping || compareOptions.length > 0) && (
673
711
  <CompareMenu
674
712
  active={compareWith}
675
713
  options={compareOptions}
@@ -685,7 +723,7 @@ export const SurfaceEditor = ({
685
723
  >
686
724
  <SlidersIcon />
687
725
  Variables
688
- {overrideCount > 0 && <span className="text-accent">{overrideCount}</span>}
726
+ {overrideCount > 0 && <span className="text-primary tabular-nums">{overrideCount}</span>}
689
727
  </button>
690
728
  </Toolbar>
691
729
  </>