@superwall/studio 2.2.0 → 2.3.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.
@@ -24,7 +24,9 @@ import {
24
24
  RotateDeviceIcon,
25
25
  RotateIcon,
26
26
  SlidersIcon,
27
+ SmartphoneIcon,
27
28
  SunIcon,
29
+ CompassIcon,
28
30
  } from "../components/icons";
29
31
  import { Tooltip } from "../components/Tooltip";
30
32
  import { SidePanel } from "../components/panels/SidePanel";
@@ -36,6 +38,7 @@ import {
36
38
  type VariableRow,
37
39
  } from "../components/panels/VariablesPanel";
38
40
  import {
41
+ browserLayoutFor,
39
42
  chromeFor,
40
43
  DEFAULT_DEVICE_ID,
41
44
  deviceById,
@@ -46,6 +49,7 @@ import {
46
49
  RESPONSIVE_DEFAULT,
47
50
  RESPONSIVE_ID,
48
51
  STUDIO_DEVICES,
52
+ type BrowserLayout,
49
53
  type DeviceChromeSpec,
50
54
  } from "../lib/devices";
51
55
  import { hostStateFor, previewDevice, studioDefaults } from "../lib/host";
@@ -66,6 +70,7 @@ import {
66
70
  type StudioSurface,
67
71
  type StudioVersion,
68
72
  } from "../lib/surfaces";
73
+ import { usePreviewPlace, type PreviewPlace } from "../lib/teleport";
69
74
  import { timeAgo } from "../lib/time";
70
75
  import { type VariableOverrides } from "../lib/variables";
71
76
 
@@ -127,6 +132,8 @@ const StagePane = ({
127
132
  theme,
128
133
  onResize,
129
134
  canvas,
135
+ browser,
136
+ place,
130
137
  }: {
131
138
  label?: string;
132
139
  width: number;
@@ -144,6 +151,8 @@ const StagePane = ({
144
151
  theme?: "light" | "dark";
145
152
  onResize?: (next: FrameSize) => void;
146
153
  canvas?: React.RefObject<CanvasHandle | null>;
154
+ browser?: BrowserLayout;
155
+ place?: PreviewPlace;
147
156
  }) => {
148
157
  const scale = useCanvasScale();
149
158
  const [broken, setBroken] = React.useState(false);
@@ -159,6 +168,14 @@ const StagePane = ({
159
168
  </span>
160
169
  )}
161
170
  <div className="relative">
171
+ {place?.teleported && (
172
+ <div
173
+ className="absolute right-0 bottom-full mb-2 origin-bottom-right"
174
+ style={{ transform: `scale(${1 / scale})` }}
175
+ >
176
+ <PlaceBadge place={place} />
177
+ </div>
178
+ )}
162
179
  {image && !broken ? (
163
180
  <div
164
181
  className="flex flex-none items-center justify-center overflow-hidden bg-black"
@@ -186,6 +203,7 @@ const StagePane = ({
186
203
  presentation={presentation}
187
204
  landscape={landscape}
188
205
  theme={theme}
206
+ browser={browser}
189
207
  />
190
208
  ) : (
191
209
  <DevicePlaceholder width={width} height={height}>
@@ -207,6 +225,25 @@ const StagePane = ({
207
225
  );
208
226
  };
209
227
 
228
+ const PlaceBadge = ({ place }: { place: PreviewPlace }) => {
229
+ const browser = place.where === "browser";
230
+ const label = browser ? "In browser" : "In app";
231
+ return (
232
+ <span
233
+ role="status"
234
+ aria-label={label}
235
+ className={`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-colors duration-hover ${
236
+ browser
237
+ ? "border-primary/30 bg-primary/10 text-primary"
238
+ : "border-border bg-background text-fg-secondary"
239
+ }`}
240
+ >
241
+ {browser ? <CompassIcon /> : <SmartphoneIcon />}
242
+ {label}
243
+ </span>
244
+ );
245
+ };
246
+
210
247
  const CanvasFooter = ({ children }: React.PropsWithChildren) => {
211
248
  const scale = useCanvasScale();
212
249
  return (
@@ -220,6 +257,13 @@ const CanvasFooter = ({ children }: React.PropsWithChildren) => {
220
257
  );
221
258
  };
222
259
 
260
+ const compareKeyOf = (target: CompareTarget | undefined): string => {
261
+ if (target === undefined) return "";
262
+ if (target.type === "version") return `version:${target.version}`;
263
+ if (target.type === "origin") return "origin";
264
+ return `surface:${target.surface.kind}/${target.surface.id}`;
265
+ };
266
+
223
267
  const nameOf = (surface: StudioSurface): string => surface.label ?? `${surface.kind}/${surface.id}`;
224
268
 
225
269
  export const SurfaceEditor = ({
@@ -315,19 +359,40 @@ export const SurfaceEditor = ({
315
359
  () => deviceVariablesFor(device, web, landscape),
316
360
  [device, web, landscape],
317
361
  );
362
+ const webBrowser =
363
+ web && !responsive ? browserLayoutFor(device, { teleported: false, landscape }) : undefined;
318
364
  const upright = responsive
319
365
  ? size
320
- : web
366
+ : web && webBrowser === undefined
321
367
  ? webViewportFor(device)
322
368
  : { width: device.width, height: device.height };
323
369
  const presentation = web ? undefined : surface.presentation;
324
370
  const reminderScreen = notificationScreenFor(device, web || responsive);
325
- const delegate = useStudioDelegate({
371
+ const reminder = {
326
372
  platform: reminderScreen.platform,
327
373
  screenWidth: reminderScreen.width,
328
374
  app: source.app ?? { name: surface.project ?? source.title },
329
- });
375
+ };
376
+ const previewSrc = source.previewUrl(surface);
377
+ const local = usePreviewPlace(`${previewSrc}#${reloadKey}`);
378
+ const delegate = useStudioDelegate(reminder, local.tracker);
379
+ const comparing = usePreviewPlace(`${previewSrc}|${compareKeyOf(compareWith)}#${reloadKey}`);
380
+ const compareDelegate = useStudioDelegate(reminder, comparing.tracker);
381
+ const compareWeb =
382
+ compareWith?.type === "surface" ? isWebOnly(compareWith.surface.platforms) : web;
383
+ const browserFor = (place: PreviewPlace, paneWeb: boolean): BrowserLayout | undefined => {
384
+ if (responsive) return undefined;
385
+ if (paneWeb) return browserLayoutFor(device, { teleported: false, landscape });
386
+ return place.where === "browser"
387
+ ? browserLayoutFor(device, { teleported: true, landscape })
388
+ : undefined;
389
+ };
330
390
  const frame = landscape ? { width: upright.height, height: upright.width } : upright;
391
+ const chooseDevice = (id: string) => {
392
+ setDeviceId(id);
393
+ if (local.place.where === "browser" || comparing.place.where === "browser")
394
+ setReloadKey((key) => key + 1);
395
+ };
331
396
 
332
397
  const openPreview = () => {
333
398
  const standalone = source.standaloneUrl?.(surface);
@@ -360,8 +425,7 @@ export const SurfaceEditor = ({
360
425
  }),
361
426
  [surface, defaults, source.samples, samples, responsive, frameDevice, theme, locale, edited],
362
427
  );
363
- const chrome = responsive ? undefined : chromeFor(device, web);
364
- const previewSrc = source.previewUrl(surface);
428
+ const chrome = responsive ? undefined : chromeFor(device, web && webBrowser === undefined);
365
429
  const versions = status.versions ?? [];
366
430
  const promotion = {
367
431
  target: surface.version ?? picked ?? latestVersion(versions),
@@ -579,17 +643,21 @@ export const SurfaceEditor = ({
579
643
  src={"src" in comparePane ? comparePane.src : undefined}
580
644
  image={"image" in comparePane ? comparePane.image : undefined}
581
645
  presentation={
582
- compareWith?.type === "surface" && !web
583
- ? compareWith.surface.presentation
584
- : presentation
646
+ comparing.place.where === "browser"
647
+ ? undefined
648
+ : compareWith?.type === "surface" && !web
649
+ ? compareWith.surface.presentation
650
+ : presentation
585
651
  }
586
652
  hostState={hostState}
587
- delegate={delegate}
653
+ delegate={compareDelegate}
588
654
  reloadKey={reloadKey}
589
655
  empty={"empty" in comparePane ? comparePane.empty : undefined}
590
656
  chrome={chrome}
591
657
  landscape={landscape}
592
658
  theme={theme}
659
+ browser={browserFor(comparing.place, compareWeb)}
660
+ place={comparing.place}
593
661
  />
594
662
  )}
595
663
  <StagePane
@@ -598,13 +666,15 @@ export const SurfaceEditor = ({
598
666
  height={frame.height}
599
667
  title={`${surface.id} preview`}
600
668
  src={previewSrc}
601
- presentation={presentation}
669
+ presentation={local.place.where === "browser" ? undefined : presentation}
602
670
  hostState={hostState}
603
671
  delegate={delegate}
604
672
  reloadKey={reloadKey}
605
673
  chrome={chrome}
606
674
  landscape={landscape}
607
675
  theme={theme}
676
+ browser={browserFor(local.place, web)}
677
+ place={local.place}
608
678
  onResize={
609
679
  responsive
610
680
  ? (next) =>
@@ -677,7 +747,7 @@ export const SurfaceEditor = ({
677
747
  ...STUDIO_DEVICES.map((entry) => ({ value: entry.id, label: entry.name })),
678
748
  { value: RESPONSIVE_ID, label: "Responsive" },
679
749
  ]}
680
- onChange={setDeviceId}
750
+ onChange={chooseDevice}
681
751
  />
682
752
  <Tooltip
683
753
  side="top"