@superwall/studio 1.1.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.
- package/LICENSE +105 -0
- package/README.md +78 -0
- package/dist/assets/index-CVKGrx00.js +11 -0
- package/dist/assets/index-D4RIpSbg.css +1 -0
- package/dist/icon.svg +5 -0
- package/dist/index.html +23 -0
- package/package.json +66 -0
- package/src/StudioApp.tsx +78 -0
- package/src/components/ActionMenu.tsx +174 -0
- package/src/components/CompareMenu.tsx +147 -0
- package/src/components/DeviceChrome.tsx +124 -0
- package/src/components/DeviceFrame.tsx +210 -0
- package/src/components/MissingProducts.tsx +46 -0
- package/src/components/OpenInApp.tsx +68 -0
- package/src/components/PaywallToasts.tsx +208 -0
- package/src/components/SidePanel.tsx +36 -0
- package/src/components/SurfaceCard.tsx +93 -0
- package/src/components/Toolbar.tsx +16 -0
- package/src/components/TopBar.tsx +41 -0
- package/src/components/VariablesPanel.tsx +200 -0
- package/src/components/controls.tsx +70 -0
- package/src/components/icons.tsx +139 -0
- package/src/index.ts +20 -0
- package/src/lib/actions.ts +79 -0
- package/src/lib/devices.ts +109 -0
- package/src/lib/events.ts +77 -0
- package/src/lib/preview.ts +39 -0
- package/src/lib/project.ts +64 -0
- package/src/lib/time.ts +21 -0
- package/src/lib/types.ts +85 -0
- package/src/main.tsx +49 -0
- package/src/screens/SurfaceEditor.tsx +498 -0
- package/src/screens/SurfaceList.tsx +156 -0
- package/src/styles.css +221 -0
|
@@ -0,0 +1,498 @@
|
|
|
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";
|
|
7
|
+
import { Segmented, Select, Switch } from "../components/controls";
|
|
8
|
+
import {
|
|
9
|
+
ExternalIcon,
|
|
10
|
+
MoonIcon,
|
|
11
|
+
RotateDeviceIcon,
|
|
12
|
+
RotateIcon,
|
|
13
|
+
SlidersIcon,
|
|
14
|
+
SunIcon,
|
|
15
|
+
} from "../components/icons";
|
|
16
|
+
import { SidePanel } from "../components/SidePanel";
|
|
17
|
+
import { Toolbar, ToolbarDivider, ToolbarGroup } from "../components/Toolbar";
|
|
18
|
+
import { TopBar } from "../components/TopBar";
|
|
19
|
+
import {
|
|
20
|
+
VariablesPanel,
|
|
21
|
+
type VariableGroups,
|
|
22
|
+
type VariableRow,
|
|
23
|
+
} from "../components/VariablesPanel";
|
|
24
|
+
import { fetchStatus, runAction } from "../lib/actions";
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_DEVICE_ID,
|
|
27
|
+
deviceById,
|
|
28
|
+
RESPONSIVE_DEFAULT,
|
|
29
|
+
RESPONSIVE_ID,
|
|
30
|
+
STUDIO_DEVICES,
|
|
31
|
+
type DeviceChromeSpec,
|
|
32
|
+
} from "../lib/devices";
|
|
33
|
+
import { withOverrides } from "../lib/preview";
|
|
34
|
+
import {
|
|
35
|
+
ACTION_STEPS,
|
|
36
|
+
type CompareTarget,
|
|
37
|
+
type PreviewOverrides,
|
|
38
|
+
type StudioActionName,
|
|
39
|
+
type StudioActionStep,
|
|
40
|
+
type Samples,
|
|
41
|
+
type StudioSource,
|
|
42
|
+
type StudioStatus,
|
|
43
|
+
type StudioStepState,
|
|
44
|
+
type StudioSurface,
|
|
45
|
+
} from "../lib/types";
|
|
46
|
+
|
|
47
|
+
const clampSize = (value: number, fallback: number): number =>
|
|
48
|
+
Number.isFinite(value) ? Math.min(3000, Math.max(200, Math.round(value))) : fallback;
|
|
49
|
+
|
|
50
|
+
const SizeInput = ({
|
|
51
|
+
label,
|
|
52
|
+
value,
|
|
53
|
+
onCommit,
|
|
54
|
+
}: {
|
|
55
|
+
label: string;
|
|
56
|
+
value: number;
|
|
57
|
+
onCommit: (value: number) => void;
|
|
58
|
+
}) => {
|
|
59
|
+
const [draft, setDraft] = React.useState(String(value));
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
setDraft(String(value));
|
|
62
|
+
}, [value]);
|
|
63
|
+
|
|
64
|
+
const commit = () => {
|
|
65
|
+
const next = clampSize(Number(draft), value);
|
|
66
|
+
setDraft(String(next));
|
|
67
|
+
onCommit(next);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<input
|
|
72
|
+
className="sw-input w-16 text-center"
|
|
73
|
+
type="number"
|
|
74
|
+
aria-label={label}
|
|
75
|
+
value={draft}
|
|
76
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
77
|
+
onBlur={commit}
|
|
78
|
+
onKeyDown={(event) => {
|
|
79
|
+
if (event.key === "Enter") (event.target as HTMLInputElement).blur();
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const StagePane = ({
|
|
86
|
+
label,
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
title,
|
|
90
|
+
src,
|
|
91
|
+
reloadKey,
|
|
92
|
+
empty,
|
|
93
|
+
chrome,
|
|
94
|
+
landscape,
|
|
95
|
+
theme,
|
|
96
|
+
}: {
|
|
97
|
+
label?: string;
|
|
98
|
+
width: number;
|
|
99
|
+
height: number;
|
|
100
|
+
title: string;
|
|
101
|
+
src?: string;
|
|
102
|
+
reloadKey: number;
|
|
103
|
+
empty?: string;
|
|
104
|
+
chrome?: DeviceChromeSpec;
|
|
105
|
+
landscape?: boolean;
|
|
106
|
+
theme?: "light" | "dark";
|
|
107
|
+
}) => {
|
|
108
|
+
const paneRef = React.useRef<HTMLDivElement>(null);
|
|
109
|
+
return (
|
|
110
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col items-center justify-center" ref={paneRef}>
|
|
111
|
+
<div className="flex flex-col gap-2">
|
|
112
|
+
{label && <span className="text-xs text-cream/55">{label}</span>}
|
|
113
|
+
{src ? (
|
|
114
|
+
<DeviceFrame
|
|
115
|
+
width={width}
|
|
116
|
+
height={height}
|
|
117
|
+
title={title}
|
|
118
|
+
src={src}
|
|
119
|
+
stageRef={paneRef}
|
|
120
|
+
reloadKey={reloadKey}
|
|
121
|
+
chrome={chrome}
|
|
122
|
+
landscape={landscape}
|
|
123
|
+
theme={theme}
|
|
124
|
+
/>
|
|
125
|
+
) : (
|
|
126
|
+
<DevicePlaceholder width={width} height={height} stageRef={paneRef}>
|
|
127
|
+
{empty ?? "Nothing live yet — publish to compare against production."}
|
|
128
|
+
</DevicePlaceholder>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const SurfaceEditor = ({
|
|
136
|
+
source,
|
|
137
|
+
surface,
|
|
138
|
+
samples,
|
|
139
|
+
onBack,
|
|
140
|
+
}: {
|
|
141
|
+
source: StudioSource;
|
|
142
|
+
surface: StudioSurface;
|
|
143
|
+
samples: Samples;
|
|
144
|
+
onBack: () => void;
|
|
145
|
+
}) => {
|
|
146
|
+
const [deviceId, setDeviceId] = React.useState(DEFAULT_DEVICE_ID);
|
|
147
|
+
const [size, setSize] = React.useState(RESPONSIVE_DEFAULT);
|
|
148
|
+
const [theme, setTheme] = React.useState<"light" | "dark">("light");
|
|
149
|
+
const [locale, setLocale] = React.useState<string | undefined>(undefined);
|
|
150
|
+
const [edited, setEdited] = React.useState<PreviewOverrides>({});
|
|
151
|
+
const [panelOpen, setPanelOpen] = React.useState(false);
|
|
152
|
+
const [compareWith, setCompareWith] = React.useState<CompareTarget | undefined>(undefined);
|
|
153
|
+
const [reloadKey, setReloadKey] = React.useState(0);
|
|
154
|
+
const [landscape, setLandscape] = React.useState(false);
|
|
155
|
+
const [status, setStatus] = React.useState<StudioStatus>({});
|
|
156
|
+
const [progress, setProgress] = React.useState<ActionProgress | undefined>(undefined);
|
|
157
|
+
const dismissTimer = React.useRef<number | undefined>(undefined);
|
|
158
|
+
React.useEffect(() => () => window.clearTimeout(dismissTimer.current), []);
|
|
159
|
+
|
|
160
|
+
const actionsEnabled = source.capabilities?.actions === true;
|
|
161
|
+
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
if (!actionsEnabled) return;
|
|
164
|
+
let cancelled = false;
|
|
165
|
+
fetchStatus(surface).then((value) => {
|
|
166
|
+
if (!cancelled) setStatus(value);
|
|
167
|
+
});
|
|
168
|
+
return () => {
|
|
169
|
+
cancelled = true;
|
|
170
|
+
};
|
|
171
|
+
}, [actionsEnabled, surface]);
|
|
172
|
+
|
|
173
|
+
const ship = async (action: StudioActionName) => {
|
|
174
|
+
window.clearTimeout(dismissTimer.current);
|
|
175
|
+
setProgress({ action, steps: {} });
|
|
176
|
+
|
|
177
|
+
const result = await runAction(surface, action, (step, state) => {
|
|
178
|
+
setProgress((current) =>
|
|
179
|
+
current?.action === action
|
|
180
|
+
? {
|
|
181
|
+
...current,
|
|
182
|
+
steps: { ...current.steps, [step]: state === "start" ? "active" : "done" },
|
|
183
|
+
}
|
|
184
|
+
: current,
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (result.ok) {
|
|
189
|
+
const steps = Object.fromEntries(
|
|
190
|
+
ACTION_STEPS[action].map((step) => [step, "done"]),
|
|
191
|
+
) as Partial<Record<StudioActionStep, StudioStepState>>;
|
|
192
|
+
setProgress({ action, steps });
|
|
193
|
+
setStatus(await fetchStatus(surface));
|
|
194
|
+
dismissTimer.current = window.setTimeout(() => setProgress(undefined), 1600);
|
|
195
|
+
} else {
|
|
196
|
+
setProgress((current) => {
|
|
197
|
+
if (!current) return current;
|
|
198
|
+
const steps = { ...current.steps };
|
|
199
|
+
for (const step of ACTION_STEPS[action]) {
|
|
200
|
+
if (steps[step] === "active") steps[step] = "failed";
|
|
201
|
+
}
|
|
202
|
+
return { ...current, steps, error: result.error };
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const openPreview = () => {
|
|
208
|
+
if (frame.width > 768) {
|
|
209
|
+
window.open(previewSrc, "_blank");
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const left = Math.max(0, window.screen.width / 2 - frame.width / 2);
|
|
213
|
+
const top = Math.max(0, window.screen.height / 2 - frame.height / 2);
|
|
214
|
+
const popup = window.open(
|
|
215
|
+
previewSrc,
|
|
216
|
+
"superwall-preview",
|
|
217
|
+
`toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=${frame.width},height=${frame.height},top=${top},left=${left}`,
|
|
218
|
+
);
|
|
219
|
+
if (!popup) window.open(previewSrc, "_blank");
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const responsive = deviceId === RESPONSIVE_ID;
|
|
223
|
+
const device = deviceById(deviceId);
|
|
224
|
+
const upright = responsive ? size : { width: device.width, height: device.height };
|
|
225
|
+
const frame = landscape ? { width: upright.height, height: upright.width } : upright;
|
|
226
|
+
|
|
227
|
+
const overrides: PreviewOverrides = {
|
|
228
|
+
theme,
|
|
229
|
+
locale,
|
|
230
|
+
user: edited.user,
|
|
231
|
+
params: edited.params,
|
|
232
|
+
products: edited.products,
|
|
233
|
+
trialEligible: edited.trialEligible,
|
|
234
|
+
device: {
|
|
235
|
+
...(responsive ? {} : device.device),
|
|
236
|
+
...edited.device,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
const chrome = responsive ? undefined : device.chrome;
|
|
240
|
+
const previewSrc = source.previewUrl(surface, overrides);
|
|
241
|
+
const liveSrc = status.liveUrl ? withOverrides(status.liveUrl, overrides) : undefined;
|
|
242
|
+
|
|
243
|
+
const compareOptions: CompareOption[] = [
|
|
244
|
+
...(actionsEnabled
|
|
245
|
+
? [
|
|
246
|
+
{
|
|
247
|
+
key: "live",
|
|
248
|
+
label: "Live version",
|
|
249
|
+
hint: "What SDKs receive today",
|
|
250
|
+
target: { type: "live" } as const,
|
|
251
|
+
},
|
|
252
|
+
]
|
|
253
|
+
: []),
|
|
254
|
+
...source.surfaces
|
|
255
|
+
.filter((candidate) => candidate !== surface)
|
|
256
|
+
.map((candidate) => ({
|
|
257
|
+
key: `surface:${candidate.kind}/${candidate.id}`,
|
|
258
|
+
label: `${candidate.kind}/${candidate.id}`,
|
|
259
|
+
hint: "Local preview",
|
|
260
|
+
target: { type: "surface", surface: candidate } as const,
|
|
261
|
+
})),
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
const comparePane =
|
|
265
|
+
compareWith &&
|
|
266
|
+
(compareWith.type === "live"
|
|
267
|
+
? {
|
|
268
|
+
label: "Live",
|
|
269
|
+
src: liveSrc,
|
|
270
|
+
title: `${surface.id} live`,
|
|
271
|
+
empty: status.unreachable
|
|
272
|
+
? `Couldn't read the live version — ${status.unreachable}`
|
|
273
|
+
: undefined,
|
|
274
|
+
}
|
|
275
|
+
: {
|
|
276
|
+
label: `${compareWith.surface.kind}/${compareWith.surface.id}`,
|
|
277
|
+
src: source.previewUrl(compareWith.surface, overrides),
|
|
278
|
+
title: `${compareWith.surface.id} preview`,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const groups = React.useMemo((): VariableGroups => {
|
|
282
|
+
const rows = (prefix: string, record: Record<string, unknown> | undefined): VariableRow[] =>
|
|
283
|
+
Object.entries(record ?? {})
|
|
284
|
+
.map(([key, value]) => ({ path: `${prefix}.${key}`, value }))
|
|
285
|
+
.toSorted((a, b) => a.path.localeCompare(b.path));
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
user: rows("user", { ...source.samples?.user, ...samples.user }),
|
|
289
|
+
device: rows("device", {
|
|
290
|
+
...source.samples?.device,
|
|
291
|
+
...samples.device,
|
|
292
|
+
...(device.device as Record<string, unknown>),
|
|
293
|
+
}),
|
|
294
|
+
params: rows("params", source.samples?.params),
|
|
295
|
+
products: Object.entries(surface.products ?? {}).flatMap(([reference, identifier]) =>
|
|
296
|
+
rows(`products.${reference}`, samples.products?.[identifier]),
|
|
297
|
+
),
|
|
298
|
+
};
|
|
299
|
+
}, [source.samples, samples, device.device, surface.products]);
|
|
300
|
+
|
|
301
|
+
const missingProducts = React.useMemo(() => {
|
|
302
|
+
if (!samples.products) return [];
|
|
303
|
+
return Object.entries(surface.products ?? {})
|
|
304
|
+
.filter(([, identifier]) => samples.products?.[identifier] === undefined)
|
|
305
|
+
.map(([reference, identifier]) => ({ reference, identifier }));
|
|
306
|
+
}, [samples.products, surface.products]);
|
|
307
|
+
|
|
308
|
+
const [dismissedProducts, setDismissedProducts] = React.useState(false);
|
|
309
|
+
React.useEffect(() => setDismissedProducts(false), [surface]);
|
|
310
|
+
const unverified = samples.unreachable;
|
|
311
|
+
const shippable = missingProducts.length === 0;
|
|
312
|
+
const overrideCount =
|
|
313
|
+
Object.keys(edited.user ?? {}).length +
|
|
314
|
+
Object.keys(edited.params ?? {}).length +
|
|
315
|
+
Object.keys(edited.device ?? {}).length;
|
|
316
|
+
|
|
317
|
+
return (
|
|
318
|
+
<>
|
|
319
|
+
<PaywallToasts
|
|
320
|
+
surfaceKey={`${surface.project ?? ""}/${surface.id}`}
|
|
321
|
+
raised={Boolean(unverified)}
|
|
322
|
+
/>
|
|
323
|
+
{missingProducts.length > 0 && !dismissedProducts && (
|
|
324
|
+
<MissingProducts
|
|
325
|
+
paywall={surface.id}
|
|
326
|
+
missing={missingProducts}
|
|
327
|
+
onDismiss={() => setDismissedProducts(true)}
|
|
328
|
+
/>
|
|
329
|
+
)}
|
|
330
|
+
{unverified && (
|
|
331
|
+
<div className="border-b border-cream/10 bg-red/10 px-4 py-1.5 text-[0.8125rem] text-cream/75">
|
|
332
|
+
Couldn't check this paywall's products — {unverified}
|
|
333
|
+
</div>
|
|
334
|
+
)}
|
|
335
|
+
<TopBar
|
|
336
|
+
title={`${surface.project ?? source.title} / ${surface.id}`}
|
|
337
|
+
onHome={onBack}
|
|
338
|
+
actions={
|
|
339
|
+
<>
|
|
340
|
+
<button
|
|
341
|
+
type="button"
|
|
342
|
+
className="sw-btn sw-btn--icon"
|
|
343
|
+
aria-label="Reload preview"
|
|
344
|
+
onClick={() => setReloadKey((key) => key + 1)}
|
|
345
|
+
>
|
|
346
|
+
<RotateIcon />
|
|
347
|
+
</button>
|
|
348
|
+
<button
|
|
349
|
+
type="button"
|
|
350
|
+
className="sw-btn sw-btn--icon"
|
|
351
|
+
aria-label="Open preview"
|
|
352
|
+
onClick={openPreview}
|
|
353
|
+
>
|
|
354
|
+
<ExternalIcon />
|
|
355
|
+
</button>
|
|
356
|
+
{actionsEnabled && (
|
|
357
|
+
<ActionMenu
|
|
358
|
+
progress={progress}
|
|
359
|
+
blocked={
|
|
360
|
+
shippable
|
|
361
|
+
? undefined
|
|
362
|
+
: `Superwall has no product for ${missingProducts
|
|
363
|
+
.map((entry) => entry.reference)
|
|
364
|
+
.join(", ")}`
|
|
365
|
+
}
|
|
366
|
+
onRun={ship}
|
|
367
|
+
onBlocked={() => setDismissedProducts(false)}
|
|
368
|
+
/>
|
|
369
|
+
)}
|
|
370
|
+
</>
|
|
371
|
+
}
|
|
372
|
+
/>
|
|
373
|
+
|
|
374
|
+
<div className="flex min-h-0 flex-1">
|
|
375
|
+
<div className="flex min-w-0 flex-1">
|
|
376
|
+
{comparePane && (
|
|
377
|
+
<StagePane
|
|
378
|
+
label={comparePane.label}
|
|
379
|
+
width={frame.width}
|
|
380
|
+
height={frame.height}
|
|
381
|
+
title={comparePane.title}
|
|
382
|
+
src={comparePane.src}
|
|
383
|
+
reloadKey={reloadKey}
|
|
384
|
+
empty={"empty" in comparePane ? comparePane.empty : undefined}
|
|
385
|
+
chrome={chrome}
|
|
386
|
+
landscape={landscape}
|
|
387
|
+
theme={theme}
|
|
388
|
+
/>
|
|
389
|
+
)}
|
|
390
|
+
<StagePane
|
|
391
|
+
label={comparePane ? "Local" : undefined}
|
|
392
|
+
width={frame.width}
|
|
393
|
+
height={frame.height}
|
|
394
|
+
title={`${surface.id} preview`}
|
|
395
|
+
src={previewSrc}
|
|
396
|
+
reloadKey={reloadKey}
|
|
397
|
+
chrome={chrome}
|
|
398
|
+
landscape={landscape}
|
|
399
|
+
theme={theme}
|
|
400
|
+
/>
|
|
401
|
+
</div>
|
|
402
|
+
|
|
403
|
+
<SidePanel open={panelOpen} title="Variables" onClose={() => setPanelOpen(false)}>
|
|
404
|
+
<VariablesPanel overrides={edited} groups={groups} onChange={setEdited} />
|
|
405
|
+
</SidePanel>
|
|
406
|
+
</div>
|
|
407
|
+
|
|
408
|
+
<Toolbar>
|
|
409
|
+
<ToolbarGroup label="Trial">
|
|
410
|
+
<Switch
|
|
411
|
+
label="Trial eligibility"
|
|
412
|
+
checked={edited.trialEligible ?? false}
|
|
413
|
+
onChange={(checked) => setEdited((current) => ({ ...current, trialEligible: checked }))}
|
|
414
|
+
/>
|
|
415
|
+
</ToolbarGroup>
|
|
416
|
+
<ToolbarGroup label="Theme">
|
|
417
|
+
<Segmented
|
|
418
|
+
label="Theme"
|
|
419
|
+
value={theme}
|
|
420
|
+
options={[
|
|
421
|
+
{ value: "light", label: <SunIcon /> },
|
|
422
|
+
{ value: "dark", label: <MoonIcon /> },
|
|
423
|
+
]}
|
|
424
|
+
onChange={setTheme}
|
|
425
|
+
/>
|
|
426
|
+
<button
|
|
427
|
+
type="button"
|
|
428
|
+
className="sw-btn sw-btn--icon"
|
|
429
|
+
aria-label="Rotate device"
|
|
430
|
+
aria-pressed={landscape}
|
|
431
|
+
title={landscape ? "Back to portrait" : "Rotate to landscape"}
|
|
432
|
+
onClick={() => setLandscape((value) => !value)}
|
|
433
|
+
>
|
|
434
|
+
<span
|
|
435
|
+
className={`flex transition-transform duration-200 ${landscape ? "-rotate-90" : ""}`}
|
|
436
|
+
>
|
|
437
|
+
<RotateDeviceIcon />
|
|
438
|
+
</span>
|
|
439
|
+
</button>
|
|
440
|
+
</ToolbarGroup>
|
|
441
|
+
<ToolbarDivider />
|
|
442
|
+
<ToolbarGroup label="Device">
|
|
443
|
+
<Select
|
|
444
|
+
label="Device"
|
|
445
|
+
value={deviceId}
|
|
446
|
+
options={[
|
|
447
|
+
...STUDIO_DEVICES.map((entry) => ({ value: entry.id, label: entry.name })),
|
|
448
|
+
{ value: RESPONSIVE_ID, label: "Responsive" },
|
|
449
|
+
]}
|
|
450
|
+
onChange={setDeviceId}
|
|
451
|
+
/>
|
|
452
|
+
{responsive && (
|
|
453
|
+
<span className="flex items-center gap-1.5">
|
|
454
|
+
<SizeInput
|
|
455
|
+
label="Preview width"
|
|
456
|
+
value={frame.width}
|
|
457
|
+
onCommit={(width) => setSize((current) => ({ ...current, width }))}
|
|
458
|
+
/>
|
|
459
|
+
<span className="text-cream/55">×</span>
|
|
460
|
+
<SizeInput
|
|
461
|
+
label="Preview height"
|
|
462
|
+
value={frame.height}
|
|
463
|
+
onCommit={(height) => setSize((current) => ({ ...current, height }))}
|
|
464
|
+
/>
|
|
465
|
+
</span>
|
|
466
|
+
)}
|
|
467
|
+
</ToolbarGroup>
|
|
468
|
+
{surface.locales.length > 1 && (
|
|
469
|
+
<ToolbarGroup label="Locale">
|
|
470
|
+
<Select
|
|
471
|
+
label="Locale"
|
|
472
|
+
value={locale ?? "default"}
|
|
473
|
+
options={[
|
|
474
|
+
{ value: "default", label: "Device" },
|
|
475
|
+
...surface.locales.map((entry) => ({ value: entry, label: entry })),
|
|
476
|
+
]}
|
|
477
|
+
onChange={(value) => setLocale(value === "default" ? undefined : value)}
|
|
478
|
+
/>
|
|
479
|
+
</ToolbarGroup>
|
|
480
|
+
)}
|
|
481
|
+
<ToolbarDivider />
|
|
482
|
+
{compareOptions.length > 0 && (
|
|
483
|
+
<CompareMenu active={compareWith} options={compareOptions} onSelect={setCompareWith} />
|
|
484
|
+
)}
|
|
485
|
+
<button
|
|
486
|
+
type="button"
|
|
487
|
+
className="sw-btn"
|
|
488
|
+
aria-expanded={panelOpen}
|
|
489
|
+
onClick={() => setPanelOpen((open) => !open)}
|
|
490
|
+
>
|
|
491
|
+
<SlidersIcon />
|
|
492
|
+
Variables
|
|
493
|
+
{overrideCount > 0 && <span className="text-accent">{overrideCount}</span>}
|
|
494
|
+
</button>
|
|
495
|
+
</Toolbar>
|
|
496
|
+
</>
|
|
497
|
+
);
|
|
498
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { OpenInApp } from "../components/OpenInApp";
|
|
3
|
+
import { SurfaceCard } from "../components/SurfaceCard";
|
|
4
|
+
import { TopBar } from "../components/TopBar";
|
|
5
|
+
import { fetchStatus } from "../lib/actions";
|
|
6
|
+
import type { StudioSource, StudioStatus, StudioSurface } from "../lib/types";
|
|
7
|
+
import { devicePreviewPath, surfacePath } from "../lib/preview";
|
|
8
|
+
|
|
9
|
+
let lastScroll = 0;
|
|
10
|
+
|
|
11
|
+
export const SurfaceList = ({
|
|
12
|
+
source,
|
|
13
|
+
onOpen,
|
|
14
|
+
device = false,
|
|
15
|
+
}: {
|
|
16
|
+
source: StudioSource;
|
|
17
|
+
onOpen: (surface: StudioSurface) => void;
|
|
18
|
+
device?: boolean;
|
|
19
|
+
}) => {
|
|
20
|
+
const [statuses, setStatuses] = React.useState<Record<string, StudioStatus>>({});
|
|
21
|
+
|
|
22
|
+
React.useEffect(() => {
|
|
23
|
+
if (source.capabilities?.actions !== true) return;
|
|
24
|
+
let cancelled = false;
|
|
25
|
+
for (const surface of source.surfaces) {
|
|
26
|
+
void fetchStatus(surface).then((status) => {
|
|
27
|
+
if (cancelled) return;
|
|
28
|
+
setStatuses((current) => ({ ...current, [surfacePath(surface)]: status }));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
cancelled = true;
|
|
33
|
+
};
|
|
34
|
+
}, [source]);
|
|
35
|
+
|
|
36
|
+
const [queries, setQueries] = React.useState<Record<string, string>>({});
|
|
37
|
+
const scroller = React.useRef<HTMLDivElement>(null);
|
|
38
|
+
|
|
39
|
+
React.useLayoutEffect(() => {
|
|
40
|
+
const element = scroller.current;
|
|
41
|
+
if (!element) return undefined;
|
|
42
|
+
element.scrollTop = lastScroll;
|
|
43
|
+
const remember = () => {
|
|
44
|
+
lastScroll = element.scrollTop;
|
|
45
|
+
};
|
|
46
|
+
element.addEventListener("scroll", remember, { passive: true });
|
|
47
|
+
return () => {
|
|
48
|
+
remember();
|
|
49
|
+
element.removeEventListener("scroll", remember);
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
const sections = (
|
|
54
|
+
[
|
|
55
|
+
["Paywalls", "paywall"],
|
|
56
|
+
["Funnels", "funnel"],
|
|
57
|
+
] as const
|
|
58
|
+
)
|
|
59
|
+
.map(([sectionLabel, kind]) => {
|
|
60
|
+
const all = source.surfaces.filter((surface) => surface.kind === kind);
|
|
61
|
+
const needle = (queries[kind] ?? "").trim().toLowerCase();
|
|
62
|
+
return {
|
|
63
|
+
label: sectionLabel,
|
|
64
|
+
kind,
|
|
65
|
+
all,
|
|
66
|
+
needle,
|
|
67
|
+
surfaces: all.filter(
|
|
68
|
+
(surface) =>
|
|
69
|
+
needle === "" ||
|
|
70
|
+
`${surface.project ?? ""} ${surface.id}`.toLowerCase().includes(needle),
|
|
71
|
+
),
|
|
72
|
+
};
|
|
73
|
+
})
|
|
74
|
+
.filter((section) => section.all.length > 0);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<>
|
|
78
|
+
<TopBar
|
|
79
|
+
title={source.title}
|
|
80
|
+
onHome={() => {}}
|
|
81
|
+
inset
|
|
82
|
+
label={device ? "Preview" : undefined}
|
|
83
|
+
actions={
|
|
84
|
+
device ? <OpenInApp origin={window.location.origin} scheme={source.scheme} /> : undefined
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
<div className="flex-1 overflow-y-auto px-3 pt-6 pb-16 sm:px-6 sm:pt-10" ref={scroller}>
|
|
89
|
+
<div className="mx-auto max-w-[1080px]">
|
|
90
|
+
{source.diagnostics && source.diagnostics.length > 0 && (
|
|
91
|
+
<div className="border-red bg-red/10 mb-6 border-l-2 px-4 py-3 text-[0.8125rem] whitespace-pre-wrap">
|
|
92
|
+
{source.diagnostics.join("\n")}
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
{sections.map((section) => (
|
|
97
|
+
<section key={section.kind} className="mt-10 first:mt-0">
|
|
98
|
+
<div className="mb-4 flex items-center gap-2">
|
|
99
|
+
<span className="text-[1.0625rem] font-medium">{section.label}</span>
|
|
100
|
+
<span className="text-[0.8125rem] text-cream/55 tabular-nums">
|
|
101
|
+
{section.surfaces.length}
|
|
102
|
+
</span>
|
|
103
|
+
{section.all.length > 1 && (
|
|
104
|
+
<input
|
|
105
|
+
className="sw-input ml-auto w-48"
|
|
106
|
+
type="search"
|
|
107
|
+
value={queries[section.kind] ?? ""}
|
|
108
|
+
placeholder={`Search ${section.label.toLowerCase()}`}
|
|
109
|
+
aria-label={`Search ${section.label.toLowerCase()}`}
|
|
110
|
+
onChange={(event) =>
|
|
111
|
+
setQueries((current) => ({ ...current, [section.kind]: event.target.value }))
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
<div className="grid grid-cols-2 gap-3 sm:grid-cols-[repeat(auto-fill,minmax(200px,1fr))] sm:gap-6">
|
|
117
|
+
{section.surfaces.map((surface) => (
|
|
118
|
+
<SurfaceCard
|
|
119
|
+
key={surfacePath(surface)}
|
|
120
|
+
surface={surface}
|
|
121
|
+
status={statuses[surfacePath(surface)]}
|
|
122
|
+
previewSrc={source.previewUrl(surface, {})}
|
|
123
|
+
onOpen={() => onOpen(surface)}
|
|
124
|
+
href={device ? devicePreviewPath(surface) : undefined}
|
|
125
|
+
/>
|
|
126
|
+
))}
|
|
127
|
+
</div>
|
|
128
|
+
{section.surfaces.length === 0 && (
|
|
129
|
+
<span className="block text-[0.8125rem] text-cream/45">
|
|
130
|
+
{`Nothing matches “${(queries[section.kind] ?? "").trim()}”.`}
|
|
131
|
+
</span>
|
|
132
|
+
)}
|
|
133
|
+
</section>
|
|
134
|
+
))}
|
|
135
|
+
|
|
136
|
+
{source.surfaces.length === 0 && (
|
|
137
|
+
<div className="border border-dashed border-cream/20 p-12 text-center text-cream/55">
|
|
138
|
+
No paywalls yet — create{" "}
|
|
139
|
+
<code className="font-mono text-[0.8125rem] text-cream">
|
|
140
|
+
superwall/paywalls/<id>/app/page.tsx
|
|
141
|
+
</code>{" "}
|
|
142
|
+
and it appears here.
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
{!device && (
|
|
149
|
+
<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.
|
|
152
|
+
</footer>
|
|
153
|
+
)}
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
};
|