@superwall/studio 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +2 -2
  2. package/dist/assets/index-CljhSsYl.js +11 -0
  3. package/dist/assets/index-DrsTCwot.css +1 -0
  4. package/dist/index.html +2 -2
  5. package/dist/lib/components/chrome/Toolbar.d.ts +1 -0
  6. package/dist/lib/components/chrome/TopBar.d.ts +1 -0
  7. package/dist/lib/components/icons.d.ts +1 -0
  8. package/dist/lib/components/menus/CompareMenu.d.ts +2 -1
  9. package/dist/lib/components/preview/Canvas.d.ts +18 -0
  10. package/dist/lib/components/preview/DeviceFrame.d.ts +4 -4
  11. package/dist/lib/components/preview/ResizeHandles.d.ts +13 -0
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +2297 -1616
  14. package/dist/lib/lib/canvas.d.ts +27 -0
  15. package/dist/lib/lib/contract.d.ts +7 -1
  16. package/dist/lib/lib/devices.d.ts +9 -0
  17. package/dist/lib/lib/host.d.ts +2 -1
  18. package/dist/lib/lib/presentation.d.ts +23 -0
  19. package/dist/lib/lib/preview.d.ts +1 -0
  20. package/dist/lib/lib/surfaces.d.ts +23 -2
  21. package/dist/lib/studio.css +1 -1
  22. package/package.json +2 -2
  23. package/src/components/DownloadScreenshot.tsx +45 -18
  24. package/src/components/PaywallToasts.tsx +5 -3
  25. package/src/components/chrome/Toolbar.tsx +47 -6
  26. package/src/components/chrome/TopBar.tsx +37 -3
  27. package/src/components/icons.tsx +6 -0
  28. package/src/components/menus/ActionMenu.tsx +1 -1
  29. package/src/components/menus/CompareMenu.tsx +49 -30
  30. package/src/components/preview/Canvas.tsx +426 -0
  31. package/src/components/preview/DeviceFrame.tsx +83 -74
  32. package/src/components/preview/ResizeHandles.tsx +205 -0
  33. package/src/index.ts +2 -0
  34. package/src/lib/canvas.ts +60 -0
  35. package/src/lib/contract.ts +8 -1
  36. package/src/lib/devices.ts +52 -4
  37. package/src/lib/host.ts +7 -2
  38. package/src/lib/presentation.ts +102 -0
  39. package/src/lib/preview.ts +3 -0
  40. package/src/lib/project.ts +43 -1
  41. package/src/lib/surfaces.ts +39 -1
  42. package/src/main.tsx +5 -1
  43. package/src/screens/SurfaceEditor.tsx +215 -52
  44. package/src/styles.css +46 -0
  45. package/dist/assets/index-GB-RwJI6.js +0 -11
  46. package/dist/assets/index-Sz7S5UsH.css +0 -1
@@ -2,7 +2,14 @@ import * as React from "react";
2
2
  import { hasIntroductoryOffer, type HostDelegate, type HostState } from "@superwall/host";
3
3
  import { ActionMenu, type ActionProgress } from "../components/menus/ActionMenu";
4
4
  import { CompareMenu, type CompareOption } from "../components/menus/CompareMenu";
5
+ import {
6
+ Canvas,
7
+ useCanvasScale,
8
+ type CanvasHandle,
9
+ type CanvasZoom,
10
+ } from "../components/preview/Canvas";
5
11
  import { DeviceFrame, DevicePlaceholder } from "../components/preview/DeviceFrame";
12
+ import { type FrameSize, ResizeHandles } from "../components/preview/ResizeHandles";
6
13
  import { MissingProducts } from "../components/panels/MissingProducts";
7
14
  import { PaywallToasts, useStudioDelegate } from "../components/PaywallToasts";
8
15
  import { DownloadScreenshot } from "../components/DownloadScreenshot";
@@ -26,25 +33,36 @@ import {
26
33
  } from "../components/panels/VariablesPanel";
27
34
  import { fetchStatus, runAction } from "../lib/actions";
28
35
  import {
36
+ chromeFor,
29
37
  DEFAULT_DEVICE_ID,
30
38
  deviceById,
39
+ deviceVariablesFor,
40
+ isWebOnly,
41
+ webViewportFor,
31
42
  RESPONSIVE_DEFAULT,
32
43
  RESPONSIVE_ID,
33
44
  STUDIO_DEVICES,
34
45
  type DeviceChromeSpec,
35
46
  } from "../lib/devices";
36
- import { hostStateFor, studioDefaults } from "../lib/host";
37
- import { hostedUrl } from "../lib/preview";
47
+ import { hostStateFor, previewDevice, studioDefaults } from "../lib/host";
48
+ import { percent } from "../lib/canvas";
49
+ import { hostedUrl, originalUrl } from "../lib/preview";
38
50
  import { ACTION_STEPS, type StudioActionStep, type StudioStepState } from "../lib/steps";
39
51
  import {
40
52
  hasActions,
53
+ hasOriginal,
54
+ isScreenOrigin,
55
+ SCREEN_FRAMEWORK_LABEL,
41
56
  type CompareTarget,
42
57
  type Samples,
43
58
  type StudioActionName,
59
+ type StudioPresentation,
44
60
  type StudioSource,
45
61
  type StudioStatus,
46
62
  type StudioSurface,
63
+ type StudioVersion,
47
64
  } from "../lib/surfaces";
65
+ import { timeAgo } from "../lib/time";
48
66
  import { type VariableOverrides } from "../lib/variables";
49
67
 
50
68
  const clampSize = (value: number, fallback: number): number =>
@@ -91,33 +109,64 @@ const StagePane = ({
91
109
  height,
92
110
  title,
93
111
  src,
112
+ image,
94
113
  hostState,
95
114
  delegate,
96
115
  reloadKey,
97
116
  empty,
98
117
  chrome,
118
+ presentation,
99
119
  landscape,
100
120
  theme,
121
+ onResize,
122
+ canvas,
101
123
  }: {
102
124
  label?: string;
103
125
  width: number;
104
126
  height: number;
105
127
  title: string;
106
128
  src?: string;
129
+ image?: string;
107
130
  hostState: HostState;
108
131
  delegate: HostDelegate;
109
132
  reloadKey: number;
110
133
  empty?: string;
111
134
  chrome?: DeviceChromeSpec;
135
+ presentation?: StudioPresentation;
112
136
  landscape?: boolean;
113
137
  theme?: "light" | "dark";
138
+ onResize?: (next: FrameSize) => void;
139
+ canvas?: React.RefObject<CanvasHandle | null>;
114
140
  }) => {
115
- const paneRef = React.useRef<HTMLDivElement>(null);
141
+ const scale = useCanvasScale();
142
+ const [broken, setBroken] = React.useState(false);
143
+ React.useEffect(() => setBroken(false), [image]);
116
144
  return (
117
- <div className="flex min-h-0 min-w-0 flex-1 flex-col items-center justify-center" ref={paneRef}>
118
- <div className="flex flex-col gap-2">
119
- {label && <span className="text-xs text-cream/55">{label}</span>}
120
- {src ? (
145
+ <div className="flex flex-none flex-col gap-2">
146
+ {label && (
147
+ <span
148
+ className="origin-bottom-left text-xs whitespace-nowrap text-cream/55"
149
+ style={{ transform: `scale(${1 / scale})` }}
150
+ >
151
+ {label}
152
+ </span>
153
+ )}
154
+ <div className="relative">
155
+ {image && !broken ? (
156
+ <div
157
+ className="flex flex-none items-center justify-center overflow-hidden bg-black"
158
+ style={{ width, height }}
159
+ >
160
+ <img
161
+ src={image}
162
+ alt={title}
163
+ title={title}
164
+ className="max-h-full max-w-full object-contain"
165
+ draggable={false}
166
+ onError={() => setBroken(true)}
167
+ />
168
+ </div>
169
+ ) : src ? (
121
170
  <DeviceFrame
122
171
  width={width}
123
172
  height={height}
@@ -125,17 +174,27 @@ const StagePane = ({
125
174
  src={src}
126
175
  hostState={hostState}
127
176
  delegate={delegate}
128
- stageRef={paneRef}
129
177
  reloadKey={reloadKey}
130
178
  chrome={chrome}
179
+ presentation={presentation}
131
180
  landscape={landscape}
132
181
  theme={theme}
133
182
  />
134
183
  ) : (
135
- <DevicePlaceholder width={width} height={height} stageRef={paneRef}>
184
+ <DevicePlaceholder width={width} height={height}>
136
185
  {empty ?? "Nothing live yet — publish to compare against production."}
137
186
  </DevicePlaceholder>
138
187
  )}
188
+ {onResize && (
189
+ <ResizeHandles
190
+ size={{ width, height }}
191
+ scale={scale}
192
+ clamp={clampSize}
193
+ onResize={onResize}
194
+ onDragStart={() => canvas?.current?.hold()}
195
+ onShift={(dx, dy) => canvas?.current?.pan(dx, dy)}
196
+ />
197
+ )}
139
198
  </div>
140
199
  </div>
141
200
  );
@@ -160,9 +219,15 @@ export const SurfaceEditor = ({
160
219
  const [locale, setLocale] = React.useState<string | undefined>(undefined);
161
220
  const [edited, setEdited] = React.useState<VariableOverrides>({});
162
221
  const [panelOpen, setPanelOpen] = React.useState(false);
163
- const [compareWith, setCompareWith] = React.useState<CompareTarget | undefined>(undefined);
222
+ const [compareWith, setCompareWith] = React.useState<CompareTarget | undefined>(() =>
223
+ hasOriginal(surface) && new URLSearchParams(window.location.search).get("compare") === "origin"
224
+ ? { type: "origin" }
225
+ : undefined,
226
+ );
164
227
  const [reloadKey, setReloadKey] = React.useState(0);
165
228
  const [landscape, setLandscape] = React.useState(false);
229
+ const canvas = React.useRef<CanvasHandle>(null);
230
+ const [zoom, setZoom] = React.useState<CanvasZoom>({ scale: 1, fitted: true });
166
231
  const [status, setStatus] = React.useState<StudioStatus>({});
167
232
  const [progress, setProgress] = React.useState<ActionProgress | undefined>(undefined);
168
233
  const dismissTimer = React.useRef<number | undefined>(undefined);
@@ -221,7 +286,14 @@ export const SurfaceEditor = ({
221
286
 
222
287
  const responsive = deviceId === RESPONSIVE_ID;
223
288
  const device = deviceById(deviceId);
224
- const upright = responsive ? size : { width: device.width, height: device.height };
289
+ const web = isWebOnly(surface.platforms);
290
+ const frameDevice = React.useMemo(() => deviceVariablesFor(device, web), [device, web]);
291
+ const upright = responsive
292
+ ? size
293
+ : web
294
+ ? webViewportFor(device)
295
+ : { width: device.width, height: device.height };
296
+ const presentation = web ? undefined : surface.presentation;
225
297
  const frame = landscape ? { width: upright.height, height: upright.width } : upright;
226
298
 
227
299
  const openPreview = () => {
@@ -248,54 +320,85 @@ export const SurfaceEditor = ({
248
320
  defaults,
249
321
  sourceSamples: source.samples,
250
322
  samples,
251
- frame: responsive ? undefined : device.device,
323
+ frame: responsive ? undefined : frameDevice,
252
324
  theme,
253
325
  locale,
254
326
  edited,
255
327
  }),
256
- [surface, defaults, source.samples, samples, responsive, device.device, theme, locale, edited],
328
+ [surface, defaults, source.samples, samples, responsive, frameDevice, theme, locale, edited],
257
329
  );
258
- const chrome = responsive ? undefined : device.chrome;
330
+ const chrome = responsive ? undefined : chromeFor(device, web);
259
331
  const previewSrc = source.previewUrl(surface);
260
- const liveSrc = status.liveUrl ? hostedUrl(status.liveUrl) : undefined;
332
+ const versions = status.versions ?? [];
333
+ const versionLabel = (entry: StudioVersion) => `v${entry.version}${entry.live ? " · live" : ""}`;
334
+ const pushedHint = (entry: StudioVersion) => {
335
+ if (entry.live) return "What SDKs receive today";
336
+ const ago = entry.pushedAt ? timeAgo(entry.pushedAt) : undefined;
337
+ return ago ? `Pushed ${ago}` : "Pushed snapshot";
338
+ };
261
339
 
262
340
  const compareOptions: CompareOption[] = [
263
- ...(actionsEnabled
341
+ ...(surface.origin && hasOriginal(surface)
264
342
  ? [
265
343
  {
266
- key: "live",
267
- label: "Live version",
268
- hint: "What SDKs receive today",
269
- target: { type: "live" } as const,
344
+ key: "origin",
345
+ label: "Original",
346
+ hint: isScreenOrigin(surface.origin)
347
+ ? `${SCREEN_FRAMEWORK_LABEL[surface.origin.framework]} screen ${surface.origin.path}, as captured in the simulator`
348
+ : `Dashboard paywall ${surface.origin.paywallId}, as it serves today`,
349
+ target: { type: "origin" } as const,
270
350
  },
271
351
  ]
272
352
  : []),
353
+ ...versions.map((entry) => ({
354
+ key: `version:${entry.version}`,
355
+ label: versionLabel(entry),
356
+ hint: pushedHint(entry),
357
+ target: { type: "version", version: entry.version } as const,
358
+ })),
273
359
  ...source.surfaces
274
- .map((candidate, index) => ({
275
- key: `surface:${index}`,
360
+ .map((candidate) => ({
361
+ key: `surface:${candidate.kind}/${candidate.id}`,
276
362
  label: nameOf(candidate),
277
363
  hint: source.compareHint ?? "Local preview",
278
364
  target: { type: "surface", surface: candidate } as const,
279
365
  }))
280
366
  .filter((option) => option.target.surface !== surface),
281
367
  ];
368
+ const compareNotice = status.unreachable
369
+ ? `Couldn't read the pushed versions — ${status.unreachable}`
370
+ : undefined;
371
+ const compared =
372
+ compareWith?.type === "version"
373
+ ? versions.find((entry) => entry.version === compareWith.version)
374
+ : undefined;
282
375
 
283
376
  const comparePane =
284
377
  compareWith &&
285
- (compareWith.type === "live"
378
+ (compareWith.type === "version"
286
379
  ? {
287
- label: "Live",
288
- src: liveSrc,
289
- title: `${surface.id} live`,
290
- empty: status.unreachable
291
- ? `Couldn't read the live version — ${status.unreachable}`
292
- : undefined,
380
+ label: compared ? versionLabel(compared) : `v${compareWith.version}`,
381
+ src: compared ? hostedUrl(compared.url) : undefined,
382
+ title: `${surface.id} v${compareWith.version}`,
383
+ empty: compareNotice ?? "This version is no longer on the dashboard.",
293
384
  }
294
- : {
295
- label: nameOf(compareWith.surface),
296
- src: source.previewUrl(compareWith.surface),
297
- title: `${nameOf(compareWith.surface)} preview`,
298
- });
385
+ : compareWith.type === "origin"
386
+ ? {
387
+ label: "Original",
388
+ ...(surface.origin && isScreenOrigin(surface.origin)
389
+ ? { image: surface.origin.screenshot ? originalUrl(surface) : undefined }
390
+ : { src: surface.origin?.url }),
391
+ title: `${surface.id} original`,
392
+ empty:
393
+ surface.origin && isScreenOrigin(surface.origin)
394
+ ? "The original's screenshot is missing — capture it again with `superwall migrate --screen <path> --screenshot <file>`."
395
+ : "This paywall was not rebuilt from a dashboard paywall or a native screen.",
396
+ }
397
+ : {
398
+ label: nameOf(compareWith.surface),
399
+ src: source.previewUrl(compareWith.surface),
400
+ title: `${nameOf(compareWith.surface)} preview`,
401
+ });
299
402
 
300
403
  const groups = React.useMemo((): VariableGroups => {
301
404
  const rows = (prefix: string, record: Record<string, unknown> | undefined): VariableRow[] =>
@@ -305,18 +408,21 @@ export const SurfaceEditor = ({
305
408
 
306
409
  return {
307
410
  user: rows("user", { ...defaults.user, ...source.samples?.user, ...samples.user }),
308
- device: rows("device", {
309
- ...defaults.device,
310
- ...source.samples?.device,
311
- ...samples.device,
312
- ...(device.device as Record<string, unknown>),
313
- }),
411
+ device: rows(
412
+ "device",
413
+ previewDevice({
414
+ ...defaults.device,
415
+ ...source.samples?.device,
416
+ ...samples.device,
417
+ ...frameDevice,
418
+ }),
419
+ ),
314
420
  params: rows("params", { ...defaults.params, ...source.samples?.params }),
315
421
  products: Object.entries(surface.products ?? {}).flatMap(([reference, identifier]) =>
316
422
  rows(`products.${reference}`, samples.products?.[identifier]),
317
423
  ),
318
424
  };
319
- }, [defaults, source.samples, samples, device.device, surface.products]);
425
+ }, [defaults, source.samples, samples, frameDevice, surface.products]);
320
426
 
321
427
  const missingProducts = React.useMemo(() => {
322
428
  if (!samples.products) return [];
@@ -347,11 +453,6 @@ export const SurfaceEditor = ({
347
453
  onDismiss={() => setDismissedProducts(true)}
348
454
  />
349
455
  )}
350
- {unverified && (
351
- <div className="border-b border-cream/10 bg-red/10 px-4 py-1.5 text-[0.8125rem] text-cream/75">
352
- Couldn't check this paywall's products — {unverified}
353
- </div>
354
- )}
355
456
  <TopBar
356
457
  title={`${surface.project ?? source.title} / ${surface.id}${
357
458
  surface.label ? ` · ${surface.label}` : ""
@@ -396,16 +497,39 @@ export const SurfaceEditor = ({
396
497
  </>
397
498
  }
398
499
  />
500
+ {unverified && (
501
+ <div
502
+ 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"
504
+ >
505
+ Couldn't check this paywall's products — {unverified}
506
+ </div>
507
+ )}
399
508
 
400
- <div className="flex min-h-0 flex-1">
401
- <div className="flex min-w-0 flex-1">
509
+ <div className="relative flex min-h-0 flex-1">
510
+ <Canvas
511
+ ref={canvas}
512
+ onZoom={setZoom}
513
+ fitKey={[
514
+ deviceId,
515
+ responsive ? "" : `${frame.width}x${frame.height}`,
516
+ comparePane ? "compare" : "single",
517
+ presentation?.style ?? "",
518
+ ].join(":")}
519
+ >
402
520
  {comparePane && (
403
521
  <StagePane
404
522
  label={comparePane.label}
405
523
  width={frame.width}
406
524
  height={frame.height}
407
525
  title={comparePane.title}
408
- src={comparePane.src}
526
+ src={"src" in comparePane ? comparePane.src : undefined}
527
+ image={"image" in comparePane ? comparePane.image : undefined}
528
+ presentation={
529
+ compareWith?.type === "surface" && !web
530
+ ? compareWith.surface.presentation
531
+ : presentation
532
+ }
409
533
  hostState={hostState}
410
534
  delegate={delegate}
411
535
  reloadKey={reloadKey}
@@ -421,14 +545,21 @@ export const SurfaceEditor = ({
421
545
  height={frame.height}
422
546
  title={`${surface.id} preview`}
423
547
  src={previewSrc}
548
+ presentation={presentation}
424
549
  hostState={hostState}
425
550
  delegate={delegate}
426
551
  reloadKey={reloadKey}
427
552
  chrome={chrome}
428
553
  landscape={landscape}
429
554
  theme={theme}
555
+ onResize={
556
+ responsive
557
+ ? (next) => setSize(landscape ? { width: next.height, height: next.width } : next)
558
+ : undefined
559
+ }
560
+ canvas={canvas}
430
561
  />
431
- </div>
562
+ </Canvas>
432
563
 
433
564
  <SidePanel open={panelOpen} title="Variables" onClose={() => setPanelOpen(false)}>
434
565
  <VariablesPanel overrides={edited} groups={groups} onChange={setEdited} />
@@ -471,6 +602,33 @@ export const SurfaceEditor = ({
471
602
  </button>
472
603
  </ToolbarGroup>
473
604
  <ToolbarDivider />
605
+ <ToolbarGroup label="Zoom">
606
+ <div className="sw-stepper" role="group" aria-label="Zoom">
607
+ <button
608
+ type="button"
609
+ aria-label="Zoom out"
610
+ onClick={() => canvas.current?.zoomStep(-1)}
611
+ >
612
+ <svg viewBox="0 0 24 24" aria-hidden="true">
613
+ <path d="M5 12h14" />
614
+ </svg>
615
+ </button>
616
+ <button
617
+ type="button"
618
+ className="min-w-12 px-2 font-mono text-xs tabular-nums"
619
+ aria-label="Fit to view"
620
+ aria-pressed={zoom.fitted}
621
+ onClick={() => canvas.current?.fit()}
622
+ >
623
+ {percent(zoom.scale)}
624
+ </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>
629
+ </button>
630
+ </div>
631
+ </ToolbarGroup>
474
632
  <ToolbarGroup label="Device">
475
633
  <Select
476
634
  label="Device"
@@ -511,8 +669,13 @@ export const SurfaceEditor = ({
511
669
  </ToolbarGroup>
512
670
  )}
513
671
  <ToolbarDivider />
514
- {compareOptions.length > 0 && (
515
- <CompareMenu active={compareWith} options={compareOptions} onSelect={setCompareWith} />
672
+ {(actionsEnabled || compareOptions.length > 0) && (
673
+ <CompareMenu
674
+ active={compareWith}
675
+ options={compareOptions}
676
+ notice={compareNotice}
677
+ onSelect={setCompareWith}
678
+ />
516
679
  )}
517
680
  <button
518
681
  type="button"
package/src/styles.css CHANGED
@@ -205,6 +205,52 @@
205
205
  color: var(--color-ink);
206
206
  }
207
207
 
208
+ .sw-stepper {
209
+ border-radius: var(--radius);
210
+ display: inline-flex;
211
+ border: 1px solid var(--edge);
212
+ height: 30px;
213
+ }
214
+
215
+ .sw-stepper button {
216
+ display: inline-flex;
217
+ align-items: center;
218
+ justify-content: center;
219
+ color: var(--color-cream);
220
+ transition: background-color 150ms ease;
221
+ }
222
+
223
+ .sw-stepper button:hover {
224
+ background: color-mix(in srgb, var(--color-cream) 5%, transparent);
225
+ }
226
+
227
+ .sw-stepper button + button {
228
+ border-left: 1px solid var(--edge);
229
+ }
230
+
231
+ .sw-stepper > button:first-child,
232
+ .sw-stepper > button:last-child {
233
+ width: 28px;
234
+ }
235
+
236
+ .sw-stepper > button:first-child {
237
+ border-radius: calc(var(--radius) - 1px) 0 0 calc(var(--radius) - 1px);
238
+ }
239
+
240
+ .sw-stepper > button:last-child {
241
+ border-radius: 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0;
242
+ }
243
+
244
+ .sw-stepper svg {
245
+ width: 14px;
246
+ height: 14px;
247
+ stroke: currentColor;
248
+ fill: none;
249
+ stroke-width: 1.5;
250
+ stroke-linecap: round;
251
+ stroke-linejoin: round;
252
+ }
253
+
208
254
  input[type="search"]::-webkit-search-cancel-button,
209
255
  input[type="search"]::-webkit-search-decoration,
210
256
  input[type="search"]::-webkit-search-results-button,