@superwall/studio 1.1.0 → 1.2.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 (50) hide show
  1. package/README.md +93 -14
  2. package/dist/assets/index-CVKQ82YR.js +11 -0
  3. package/dist/assets/index-_HCp6gCi.css +1 -0
  4. package/dist/index.html +2 -2
  5. package/dist/lib/StudioApp.d.ts +7 -0
  6. package/dist/lib/components/ActionMenu.d.ts +13 -0
  7. package/dist/lib/components/CompareMenu.d.ts +13 -0
  8. package/dist/lib/components/DeviceChrome.d.ts +12 -0
  9. package/dist/lib/components/DeviceFrame.d.ts +18 -0
  10. package/dist/lib/components/MissingProducts.d.ts +8 -0
  11. package/dist/lib/components/OpenInApp.d.ts +5 -0
  12. package/dist/lib/components/PaywallToasts.d.ts +5 -0
  13. package/dist/lib/components/SidePanel.d.ts +6 -0
  14. package/dist/lib/components/StudioShell.d.ts +4 -0
  15. package/dist/lib/components/SurfaceCard.d.ts +9 -0
  16. package/dist/lib/components/Toolbar.d.ts +6 -0
  17. package/dist/lib/components/TopBar.d.ts +8 -0
  18. package/dist/lib/components/VariablesPanel.d.ts +13 -0
  19. package/dist/lib/components/controls.d.ts +24 -0
  20. package/dist/lib/components/icons.d.ts +20 -0
  21. package/dist/lib/icon.svg +5 -0
  22. package/dist/lib/index.d.ts +14 -0
  23. package/dist/lib/index.js +1746 -0
  24. package/dist/lib/lib/actions.d.ts +4 -0
  25. package/dist/lib/lib/devices.d.ts +26 -0
  26. package/dist/lib/lib/events.d.ts +27 -0
  27. package/dist/lib/lib/preview.d.ts +7 -0
  28. package/dist/lib/lib/products.d.ts +16 -0
  29. package/dist/lib/lib/project.d.ts +12 -0
  30. package/dist/lib/lib/time.d.ts +1 -0
  31. package/dist/lib/lib/types.d.ts +77 -0
  32. package/dist/lib/products.js +51 -0
  33. package/dist/lib/screens/SurfaceEditor.d.ts +9 -0
  34. package/dist/lib/screens/SurfaceList.d.ts +7 -0
  35. package/dist/lib/studio.css +1 -0
  36. package/package.json +15 -4
  37. package/src/StudioApp.tsx +3 -2
  38. package/src/components/ActionMenu.tsx +1 -1
  39. package/src/components/CompareMenu.tsx +1 -1
  40. package/src/components/PaywallToasts.tsx +1 -0
  41. package/src/components/StudioShell.tsx +12 -0
  42. package/src/index.ts +9 -1
  43. package/src/lib/events.ts +10 -1
  44. package/src/lib/preview.ts +10 -0
  45. package/src/lib/products.ts +97 -0
  46. package/src/lib/types.ts +2 -0
  47. package/src/screens/SurfaceEditor.tsx +31 -12
  48. package/src/styles.css +8 -6
  49. package/dist/assets/index-CVKGrx00.js +0 -11
  50. package/dist/assets/index-D4RIpSbg.css +0 -1
@@ -22,6 +22,7 @@ import {
22
22
  type VariableRow,
23
23
  } from "../components/VariablesPanel";
24
24
  import { fetchStatus, runAction } from "../lib/actions";
25
+ import { localesAnnounced } from "../lib/events";
25
26
  import {
26
27
  DEFAULT_DEVICE_ID,
27
28
  deviceById,
@@ -132,16 +133,20 @@ const StagePane = ({
132
133
  );
133
134
  };
134
135
 
136
+ const nameOf = (surface: StudioSurface): string => surface.label ?? `${surface.kind}/${surface.id}`;
137
+
135
138
  export const SurfaceEditor = ({
136
139
  source,
137
140
  surface,
138
141
  samples,
139
142
  onBack,
143
+ actions,
140
144
  }: {
141
145
  source: StudioSource;
142
146
  surface: StudioSurface;
143
147
  samples: Samples;
144
148
  onBack: () => void;
149
+ actions?: React.ReactNode;
145
150
  }) => {
146
151
  const [deviceId, setDeviceId] = React.useState(DEFAULT_DEVICE_ID);
147
152
  const [size, setSize] = React.useState(RESPONSIVE_DEFAULT);
@@ -159,6 +164,17 @@ export const SurfaceEditor = ({
159
164
 
160
165
  const actionsEnabled = source.capabilities?.actions === true;
161
166
 
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;
177
+
162
178
  React.useEffect(() => {
163
179
  if (!actionsEnabled) return;
164
180
  let cancelled = false;
@@ -252,13 +268,13 @@ export const SurfaceEditor = ({
252
268
  ]
253
269
  : []),
254
270
  ...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",
271
+ .map((candidate, index) => ({
272
+ key: `surface:${index}`,
273
+ label: nameOf(candidate),
274
+ hint: source.compareHint ?? "Local preview",
260
275
  target: { type: "surface", surface: candidate } as const,
261
- })),
276
+ }))
277
+ .filter((option) => option.target.surface !== surface),
262
278
  ];
263
279
 
264
280
  const comparePane =
@@ -273,9 +289,9 @@ export const SurfaceEditor = ({
273
289
  : undefined,
274
290
  }
275
291
  : {
276
- label: `${compareWith.surface.kind}/${compareWith.surface.id}`,
292
+ label: nameOf(compareWith.surface),
277
293
  src: source.previewUrl(compareWith.surface, overrides),
278
- title: `${compareWith.surface.id} preview`,
294
+ title: `${nameOf(compareWith.surface)} preview`,
279
295
  });
280
296
 
281
297
  const groups = React.useMemo((): VariableGroups => {
@@ -333,10 +349,13 @@ export const SurfaceEditor = ({
333
349
  </div>
334
350
  )}
335
351
  <TopBar
336
- title={`${surface.project ?? source.title} / ${surface.id}`}
352
+ title={`${surface.project ?? source.title} / ${surface.id}${
353
+ surface.label ? ` · ${surface.label}` : ""
354
+ }`}
337
355
  onHome={onBack}
338
356
  actions={
339
357
  <>
358
+ {actions}
340
359
  <button
341
360
  type="button"
342
361
  className="sw-btn sw-btn--icon"
@@ -388,7 +407,7 @@ export const SurfaceEditor = ({
388
407
  />
389
408
  )}
390
409
  <StagePane
391
- label={comparePane ? "Local" : undefined}
410
+ label={comparePane ? (surface.label ?? "Local") : undefined}
392
411
  width={frame.width}
393
412
  height={frame.height}
394
413
  title={`${surface.id} preview`}
@@ -465,14 +484,14 @@ export const SurfaceEditor = ({
465
484
  </span>
466
485
  )}
467
486
  </ToolbarGroup>
468
- {surface.locales.length > 1 && (
487
+ {locales.length > 1 && (
469
488
  <ToolbarGroup label="Locale">
470
489
  <Select
471
490
  label="Locale"
472
491
  value={locale ?? "default"}
473
492
  options={[
474
493
  { value: "default", label: "Device" },
475
- ...surface.locales.map((entry) => ({ value: entry, label: entry })),
494
+ ...locales.map((entry) => ({ value: entry, label: entry })),
476
495
  ]}
477
496
  onChange={(value) => setLocale(value === "default" ? undefined : value)}
478
497
  />
package/src/styles.css CHANGED
@@ -12,28 +12,30 @@
12
12
  }
13
13
 
14
14
  @layer base {
15
- :root {
15
+ .sw-studio {
16
16
  color-scheme: dark;
17
17
  }
18
18
 
19
- ::selection {
19
+ .sw-studio ::selection {
20
20
  background: color-mix(in srgb, var(--color-accent) 50%, transparent);
21
21
  }
22
22
 
23
- :focus-visible {
23
+ .sw-studio :focus-visible {
24
24
  outline: 2px solid var(--color-accent);
25
25
  outline-offset: -2px;
26
26
  }
27
27
 
28
- button {
28
+ .sw-studio button {
29
29
  cursor: pointer;
30
30
  }
31
31
 
32
- * {
32
+ .sw-studio,
33
+ .sw-studio * {
33
34
  scrollbar-width: none;
34
35
  }
35
36
 
36
- *::-webkit-scrollbar {
37
+ .sw-studio::-webkit-scrollbar,
38
+ .sw-studio *::-webkit-scrollbar {
37
39
  width: 0;
38
40
  height: 0;
39
41
  display: none;