@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
@@ -0,0 +1,144 @@
1
+ import * as React from "react";
2
+ import { createPortal } from "react-dom";
3
+ import { CheckIcon } from "../icons";
4
+
5
+ export type PopupAlign = "start" | "end";
6
+
7
+ export const useDismiss = (
8
+ refs: readonly React.RefObject<HTMLElement | null>[],
9
+ open: boolean,
10
+ onDismiss: () => void,
11
+ ) => {
12
+ const dismiss = React.useRef(onDismiss);
13
+ dismiss.current = onDismiss;
14
+
15
+ React.useEffect(() => {
16
+ if (!open) return undefined;
17
+ const outside = (event: MouseEvent) => {
18
+ const path = event.composedPath();
19
+ if (!refs.some((ref) => ref.current && path.includes(ref.current))) dismiss.current();
20
+ };
21
+ const escape = (event: KeyboardEvent) => {
22
+ if (event.key === "Escape") dismiss.current();
23
+ };
24
+ window.addEventListener("mousedown", outside);
25
+ window.addEventListener("keydown", escape);
26
+ return () => {
27
+ window.removeEventListener("mousedown", outside);
28
+ window.removeEventListener("keydown", escape);
29
+ };
30
+ }, [refs, open]);
31
+ };
32
+
33
+ export const usePopupAlign = (
34
+ ref: React.RefObject<HTMLElement | null>,
35
+ open: boolean,
36
+ ): PopupAlign => {
37
+ const [align, setAlign] = React.useState<PopupAlign>("start");
38
+
39
+ React.useLayoutEffect(() => {
40
+ const anchor = ref.current;
41
+ if (!open || !anchor) return;
42
+ const box = anchor.getBoundingClientRect();
43
+ setAlign(box.left + box.width / 2 > window.innerWidth / 2 ? "end" : "start");
44
+ }, [ref, open]);
45
+
46
+ return align;
47
+ };
48
+
49
+ type Placement = Pick<React.CSSProperties, "top" | "bottom" | "left">;
50
+
51
+ const GUTTER = 12;
52
+
53
+ const portalRoot = (anchor: HTMLElement | null): Element | ShadowRoot => {
54
+ const studio = anchor?.closest(".sw-studio");
55
+ if (studio) return studio;
56
+ const root = anchor?.getRootNode();
57
+ return root instanceof ShadowRoot ? root : document.body;
58
+ };
59
+
60
+ export const MenuPopup = ({
61
+ popupRef,
62
+ anchor,
63
+ side,
64
+ align,
65
+ className = "",
66
+ children,
67
+ }: React.PropsWithChildren<{
68
+ popupRef: React.RefObject<HTMLDivElement | null>;
69
+ anchor: React.RefObject<HTMLElement | null>;
70
+ side: "top" | "bottom";
71
+ align: PopupAlign;
72
+ className?: string;
73
+ }>) => {
74
+ const [placement, setPlacement] = React.useState<Placement | undefined>(undefined);
75
+
76
+ React.useLayoutEffect(() => {
77
+ const place = () => {
78
+ const box = anchor.current?.getBoundingClientRect();
79
+ if (!box) return;
80
+ const width = popupRef.current?.offsetWidth ?? 0;
81
+ const desired = align === "end" ? box.right - width : box.left;
82
+ setPlacement({
83
+ ...(side === "top"
84
+ ? { bottom: window.innerHeight - box.top + 4 }
85
+ : { top: box.bottom + 4 }),
86
+ left: Math.max(GUTTER, Math.min(desired, window.innerWidth - GUTTER - width)),
87
+ });
88
+ };
89
+ place();
90
+ window.addEventListener("resize", place);
91
+ window.addEventListener("scroll", place, true);
92
+ return () => {
93
+ window.removeEventListener("resize", place);
94
+ window.removeEventListener("scroll", place, true);
95
+ };
96
+ }, [anchor, popupRef, side, align]);
97
+
98
+ return createPortal(
99
+ <div
100
+ ref={popupRef}
101
+ className={`fixed z-30 flex max-w-[calc(100vw-1.5rem)] flex-col overflow-hidden rounded-sm border border-border bg-popover text-foreground ${
102
+ placement ? "" : "invisible"
103
+ } ${className}`}
104
+ style={placement}
105
+ data-menu-popup=""
106
+ >
107
+ {children}
108
+ </div>,
109
+ portalRoot(anchor.current),
110
+ );
111
+ };
112
+
113
+ export const MenuItem = ({
114
+ label,
115
+ hint,
116
+ selected,
117
+ onSelect,
118
+ }: {
119
+ label: string;
120
+ hint?: string;
121
+ selected?: boolean;
122
+ onSelect: () => void;
123
+ }) => (
124
+ <button
125
+ type="button"
126
+ className={`grid w-full min-w-0 grid-cols-[1fr_0.875rem] items-center gap-2 rounded-sm border border-transparent ps-[calc(--spacing(2.5)-1px)] pe-2 text-left text-sm text-foreground outline-none hover:bg-accent focus-visible:bg-accent ${
127
+ hint ? "py-[calc(--spacing(1.5)-1px)]" : "py-[calc(--spacing(1)-1px)]"
128
+ }`}
129
+ aria-current={selected || undefined}
130
+ onClick={onSelect}
131
+ >
132
+ <span className="flex min-w-0 flex-col">
133
+ <span className="truncate">{label}</span>
134
+ {hint && <span className="truncate text-xs/4 text-fg-tertiary">{hint}</span>}
135
+ </span>
136
+ {selected ? <CheckIcon className="text-primary" /> : <span />}
137
+ </button>
138
+ );
139
+
140
+ export const MenuGroupLabel = ({ children }: React.PropsWithChildren) => (
141
+ <span className="block px-2.5 py-1.5 text-xs font-medium text-fg-tertiary">{children}</span>
142
+ );
143
+
144
+ export const MenuSeparator = () => <span className="mx-2.5 my-1 block h-px bg-border" />;
@@ -1,3 +1,5 @@
1
+ import { Dialog } from "../Dialog";
2
+
1
3
  export const MissingProducts = ({
2
4
  paywall,
3
5
  missing,
@@ -7,40 +9,31 @@ export const MissingProducts = ({
7
9
  missing: { reference: string; identifier: string }[];
8
10
  onDismiss: () => void;
9
11
  }) => (
10
- <div
11
- className="fixed inset-0 z-50 flex items-center justify-center bg-ink/70 p-6"
12
- role="dialog"
13
- aria-modal="true"
14
- aria-labelledby="sw-missing-products"
15
- >
16
- <div className="bg-panel flex w-full max-w-md flex-col gap-4 rounded border border-cream/20 p-5">
17
- <div className="flex flex-col gap-1.5">
18
- <span id="sw-missing-products" className="text-[0.9375rem] font-medium text-cream">
19
- {missing.length === 1 ? "A product is missing" : `${missing.length} products are missing`}
20
- </span>
21
- <span className="text-[0.8125rem] leading-relaxed text-cream/60">
22
- {`${paywall} declares ${missing.length === 1 ? "a product" : "products"} Superwall has no record of. Every variable on ${missing.length === 1 ? "it" : "them"} will be undefined here and on device.`}
23
- </span>
24
- </div>
25
-
26
- <ul className="flex flex-col gap-1.5 border-y border-cream/10 py-3">
27
- {missing.map((entry) => (
28
- <li key={entry.reference} className="flex items-baseline justify-between gap-3">
29
- <span className="font-mono text-[11px] text-cream/70">{entry.reference}</span>
30
- <span className="truncate font-mono text-[11px] text-cream/40">{entry.identifier}</span>
31
- </li>
32
- ))}
33
- </ul>
34
-
35
- <span className="text-xs text-cream/45">
36
- Add {missing.length === 1 ? "it" : "them"} in the Superwall dashboard, or point the config
37
- at{missing.length === 1 ? " a product" : " products"} that exists. Pushing is refused until
38
- then.
39
- </span>
40
-
41
- <button type="button" className="sw-btn sw-btn--primary self-end" onClick={onDismiss}>
12
+ <Dialog
13
+ title={missing.length === 1 ? "A product is missing" : `${missing.length} products are missing`}
14
+ description={`${paywall} declares ${missing.length === 1 ? "a product" : "products"} Superwall has no record of. Every variable on ${missing.length === 1 ? "it" : "them"} will be undefined here and on device.`}
15
+ onClose={onDismiss}
16
+ footer={
17
+ <button type="button" className="sw-btn sw-btn--primary" onClick={onDismiss}>
42
18
  View anyway
43
19
  </button>
44
- </div>
45
- </div>
20
+ }
21
+ >
22
+ <ul className="m-0 flex list-none flex-col divide-y divide-border overflow-hidden rounded-sm border border-border p-0">
23
+ {missing.map((entry) => (
24
+ <li
25
+ key={entry.reference}
26
+ className="flex items-center justify-between gap-4 px-3 py-2.5 text-sm"
27
+ >
28
+ <span className="truncate">{entry.reference}</span>
29
+ <span className="truncate text-fg-tertiary tabular-nums">{entry.identifier}</span>
30
+ </li>
31
+ ))}
32
+ </ul>
33
+ <p className="m-0 text-sm text-fg-secondary">
34
+ Add {missing.length === 1 ? "it" : "them"} in the Superwall dashboard, or point the config at
35
+ {missing.length === 1 ? " a product" : " products"} that exists. Pushing is refused until
36
+ then.
37
+ </p>
38
+ </Dialog>
46
39
  );
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CloseIcon } from "../icons";
2
+ import { XIcon } from "../icons";
3
3
 
4
4
  export const SidePanel = ({
5
5
  open,
@@ -12,25 +12,25 @@ export const SidePanel = ({
12
12
  onClose: () => void;
13
13
  }>) => (
14
14
  <aside
15
- className={`flex-none overflow-hidden transition-[width] duration-200 ease-out motion-reduce:transition-none ${
16
- open ? "w-72" : "w-0"
15
+ className={`flex-none overflow-hidden transition-[width] duration-move ease-out motion-reduce:transition-none ${
16
+ open ? "w-80" : "w-0"
17
17
  }`}
18
18
  aria-hidden={!open}
19
19
  inert={!open}
20
20
  >
21
- <div className="bg-bar flex h-full w-72 flex-col border-l border-cream/10">
22
- <div className="flex h-11 flex-none items-center justify-between border-b border-cream/10 px-3">
23
- <span className="text-[0.8125rem] font-medium text-cream">{title}</span>
21
+ <div className="flex h-full w-80 flex-col border-l border-border bg-background">
22
+ <div className="flex h-12 flex-none items-center justify-between border-b border-border ps-4 pe-2.5">
23
+ <span className="text-sm font-medium">{title}</span>
24
24
  <button
25
25
  type="button"
26
- className="sw-btn sw-btn--icon border-transparent"
26
+ className="sw-btn sw-btn--sm sw-btn--icon sw-btn--ghost"
27
27
  aria-label={`Close ${title.toLowerCase()}`}
28
28
  onClick={onClose}
29
29
  >
30
- <CloseIcon />
30
+ <XIcon />
31
31
  </button>
32
32
  </div>
33
- <div className="flex-1 overflow-y-auto px-4 py-2">{children}</div>
33
+ <div className="min-h-0 flex-1 scroll-fade overflow-y-auto">{children}</div>
34
34
  </div>
35
35
  </aside>
36
36
  );
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { Switch } from "../controls";
2
3
  import { ChevronDownIcon } from "../icons";
3
4
  import type { VariableOverrides } from "../../lib/variables";
4
5
 
@@ -15,7 +16,7 @@ const GROUPS: { key: VariableGroup; label: string; blurb: string }[] = [
15
16
  { key: "user", label: "User", blurb: "Attributes your app sets" },
16
17
  { key: "device", label: "Device", blurb: "Platform, locale, OS — the SDK fills these in" },
17
18
  { key: "params", label: "Params", blurb: "Passed in at the placement" },
18
- { key: "products", label: "Products", blurb: "Store data for this paywall's products" },
19
+ { key: "products", label: "Products", blurb: "Store data for this paywall’s products" },
19
20
  ];
20
21
 
21
22
  const display = (value: unknown): string =>
@@ -47,13 +48,13 @@ const Row = ({
47
48
  const current = overridden ? override : row.value;
48
49
 
49
50
  return (
50
- <div className="flex flex-col gap-1 py-1.5">
51
- <div className="flex items-baseline justify-between gap-2">
52
- <span className="truncate font-mono text-[11px] text-cream/70">{row.path}</span>
51
+ <div className="flex flex-col gap-2">
52
+ <div className="flex min-h-5 items-center justify-between gap-2">
53
+ <span className="truncate text-xs font-medium text-fg-tertiary">{row.path}</span>
53
54
  {overridden && (
54
55
  <button
55
56
  type="button"
56
- className="shrink-0 text-[11px] text-cream/40 hover:text-cream"
57
+ className="sw-btn sw-btn--plain shrink-0 text-xs"
57
58
  aria-label={`Reset ${row.path}`}
58
59
  onClick={() => onChange(undefined)}
59
60
  >
@@ -63,18 +64,11 @@ const Row = ({
63
64
  </div>
64
65
  {typeof current === "boolean" ? (
65
66
  <span className="flex h-7 items-center">
66
- <button
67
- type="button"
68
- className="sw-switch"
69
- role="switch"
70
- aria-checked={current}
71
- aria-label={row.path}
72
- onClick={() => onChange(!current)}
73
- />
67
+ <Switch label={row.path} checked={current} onChange={(checked) => onChange(checked)} />
74
68
  </span>
75
69
  ) : (
76
70
  <input
77
- className="sw-input w-full"
71
+ className="sw-input sw-input--sm"
78
72
  aria-label={row.path}
79
73
  value={display(current)}
80
74
  placeholder={display(row.value)}
@@ -101,53 +95,67 @@ const Group = ({
101
95
  overrideOf: (path: string) => unknown;
102
96
  onChange: (path: string, value: unknown) => void;
103
97
  }) => {
104
- const [open, setOpen] = React.useState(false);
98
+ const [state, setState] = React.useState<"closed" | "open" | "closing">("closed");
99
+ const open = state === "open";
105
100
  const overridden = rows.filter((row) => overrideOf(row.path) !== undefined).length;
106
101
 
107
102
  return (
108
- <section className="border-b border-cream/10 last:border-b-0">
103
+ <section className="border-b border-border">
109
104
  <button
110
105
  type="button"
111
- className="flex w-full items-center gap-2 py-3 text-left"
106
+ className="group relative flex w-full items-center gap-4 px-4 py-2.5 text-left transition-colors duration-hover before:pointer-events-none before:absolute before:inset-0 before:border before:border-transparent before:transition-colors before:duration-hover hover:bg-foreground/3 focus-visible:before:border-primary"
112
107
  aria-expanded={open}
113
- onClick={() => setOpen((current) => !current)}
108
+ onClick={() => setState((current) => (current === "open" ? "closing" : "open"))}
114
109
  >
115
- <span className="flex min-w-0 flex-col gap-0.5">
116
- <span className="flex items-baseline gap-2">
117
- <span className="text-[0.8125rem] font-medium text-cream">{label}</span>
118
- <span className="text-xs text-cream/40">
119
- {overridden > 0 ? (
120
- <span className="text-accent">{`${overridden} set`}</span>
121
- ) : (
122
- rows.length || null
123
- )}
124
- </span>
110
+ <span className="flex min-w-0 flex-1 flex-col">
111
+ <span className="flex items-center gap-1.5 text-sm font-medium">
112
+ {label}
113
+ {overridden > 0 ? (
114
+ <span className="font-normal text-primary tabular-nums">{`${overridden} set`}</span>
115
+ ) : (
116
+ rows.length > 0 && (
117
+ <span className="font-normal text-fg-tertiary tabular-nums">{rows.length}</span>
118
+ )
119
+ )}
125
120
  </span>
126
- <span className="truncate text-xs text-cream/55">{blurb}</span>
127
- </span>
128
- <span
129
- className={`ml-auto shrink-0 text-cream/40 transition-transform ${open ? "" : "-rotate-90"}`}
130
- aria-hidden="true"
131
- >
132
- <ChevronDownIcon />
121
+ <span className="truncate text-xs/4 text-fg-tertiary">{blurb}</span>
133
122
  </span>
123
+ <ChevronDownIcon
124
+ className={`icon-tertiary transition-disclosure group-hover:filter-none ${open ? "rotate-180" : ""}`}
125
+ />
134
126
  </button>
135
127
 
136
- {open &&
137
- (rows.length === 0 ? (
138
- <span className="block pb-3 text-xs text-cream/35">Nothing here for this paywall.</span>
139
- ) : (
140
- <div className="flex flex-col pb-2">
141
- {rows.map((row) => (
142
- <Row
143
- key={row.path}
144
- row={row}
145
- override={overrideOf(row.path)}
146
- onChange={(value) => onChange(row.path, value)}
147
- />
148
- ))}
128
+ {state !== "closed" && (
129
+ <div
130
+ className={`grid transition-[grid-template-rows,opacity] duration-move ease-out starting:grid-rows-[0fr] starting:opacity-0 ${
131
+ open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"
132
+ }`}
133
+ aria-hidden={open ? undefined : true}
134
+ inert={!open}
135
+ onTransitionEnd={(event) => {
136
+ if (event.target === event.currentTarget && state === "closing") setState("closed");
137
+ }}
138
+ >
139
+ <div className="min-h-0 overflow-hidden">
140
+ {rows.length === 0 ? (
141
+ <span className="block px-4 pb-4 text-xs text-fg-tertiary">
142
+ Nothing here for this paywall.
143
+ </span>
144
+ ) : (
145
+ <div className="flex flex-col gap-3 px-4 pt-1 pb-4">
146
+ {rows.map((row) => (
147
+ <Row
148
+ key={row.path}
149
+ row={row}
150
+ override={overrideOf(row.path)}
151
+ onChange={(value) => onChange(row.path, value)}
152
+ />
153
+ ))}
154
+ </div>
155
+ )}
149
156
  </div>
150
- ))}
157
+ </div>
158
+ )}
151
159
  </section>
152
160
  );
153
161
  };
@@ -16,7 +16,7 @@ export const DevicePlaceholder = ({
16
16
  height: number;
17
17
  }>) => (
18
18
  <div
19
- className="flex flex-none items-center justify-center overflow-hidden border border-dashed border-cream/20 p-6 text-center text-sm text-cream/55"
19
+ className="flex flex-none items-center justify-center overflow-hidden rounded-sm bg-background p-6 text-center text-sm text-fg-secondary outline outline-foreground/20"
20
20
  data-testid="device-placeholder"
21
21
  style={{ width, height }}
22
22
  >
@@ -95,11 +95,9 @@ export const DeviceFrame = ({
95
95
 
96
96
  return (
97
97
  <div
98
- className={`bg-panel relative flex-none overflow-hidden ${
99
- chrome ? "shadow-[0_0_0_1px] shadow-cream/25" : "border border-cream/20"
100
- }`}
98
+ className="relative flex-none overflow-hidden bg-background outline outline-foreground/20"
101
99
  data-testid="device-frame"
102
- style={{ width, height, borderRadius: chrome?.radius ?? 0 }}
100
+ style={{ width, height, borderRadius: chrome?.radius ?? 3 }}
103
101
  >
104
102
  {sheet && (
105
103
  <div
@@ -142,7 +140,7 @@ export const DeviceFrame = ({
142
140
  key={frame.generation}
143
141
  hostState={hostState}
144
142
  delegate={delegate}
145
- className={`absolute inset-0 border-0 bg-white transition-opacity duration-150 ${
143
+ className={`absolute inset-0 border-0 bg-white transition-opacity duration-hover ${
146
144
  frame === visible ? "opacity-100" : "opacity-0"
147
145
  }`}
148
146
  title={title}
package/src/index.ts CHANGED
@@ -17,6 +17,13 @@ export { DEFAULT_DEVICE_ID, deviceById, STUDIO_DEVICES } from "./lib/devices";
17
17
  export type { StudioDevice } from "./lib/devices";
18
18
  export { hostStateFor, studioDefaults } from "./lib/host";
19
19
  export { hasActions } from "./lib/surfaces";
20
+ export { devServerActions } from "./lib/actions";
21
+ export {
22
+ latestVersion,
23
+ liveVersion,
24
+ promotionDirection,
25
+ type PromotionDirection,
26
+ } from "./lib/promotion";
20
27
  export { devServerLink } from "./lib/scheme";
21
28
  export {
22
29
  StudioHostProvider,
@@ -43,7 +50,9 @@ export type {
43
50
  Samples,
44
51
  StudioActionName,
45
52
  StudioActionProgress,
53
+ StudioActionRequest,
46
54
  StudioActionResult,
55
+ StudioActions,
47
56
  StudioPresentation,
48
57
  StudioSource,
49
58
  StudioStatus,
@@ -1,23 +1,26 @@
1
1
  import { surfacePath } from "./preview";
2
2
  import type {
3
3
  Samples,
4
- StudioActionName,
4
+ StudioActionProgress,
5
+ StudioActionRequest,
5
6
  StudioActionResult,
7
+ StudioActions,
6
8
  StudioStatus,
7
9
  StudioSurface,
8
10
  } from "./surfaces";
9
11
 
10
12
  export const runAction = async (
11
13
  surface: StudioSurface,
12
- action: StudioActionName,
13
- onStep?: (step: string, state: "start" | "done") => void,
14
+ request: StudioActionRequest,
15
+ onStep?: StudioActionProgress,
14
16
  ): Promise<StudioActionResult> => {
15
17
  try {
16
18
  const response = await fetch("/__studio/action", {
17
19
  method: "POST",
18
20
  headers: { "Content-Type": "application/json" },
19
21
  body: JSON.stringify({
20
- action,
22
+ action: request.action,
23
+ version: request.version,
21
24
  kind: surface.kind,
22
25
  id: surface.id,
23
26
  project: surface.project,
@@ -68,6 +71,12 @@ export const fetchStatus = async (surface: StudioSurface): Promise<StudioStatus>
68
71
  }
69
72
  };
70
73
 
74
+ export const devServerActions: StudioActions = {
75
+ offered: ["push", "promote", "publish"],
76
+ run: runAction,
77
+ status: fetchStatus,
78
+ };
79
+
71
80
  export const fetchScreenshot = async (surface: StudioSurface): Promise<string | undefined> => {
72
81
  const response = await fetch(`/__studio/screenshot${surfacePath(surface)}`);
73
82
  const value = (await response.json()) as { url?: string; unreachable?: string };
@@ -1,5 +1,7 @@
1
1
  export type StudioActionName = "push" | "promote" | "publish";
2
2
 
3
+ export type StudioActionRequest = { action: StudioActionName; version?: number };
4
+
3
5
  export type StudioActionResult =
4
6
  | { ok: true; version: number; live: boolean }
5
7
  | { ok: false; error: string };
@@ -1,31 +1,28 @@
1
1
  import * as React from "react";
2
2
  import { toast } from "sonner";
3
- import { AlertTriangleIcon, CheckCircleIcon, InfoCircleIcon } from "../components/icons";
3
+ import { ToastCard } from "../components/PaywallToasts";
4
+ import {
5
+ AlertTriangleIcon,
6
+ CheckCircleIcon,
7
+ InfoCircleIcon,
8
+ type IconComponent,
9
+ } from "../components/icons";
4
10
 
5
11
  type Tone = "info" | "success" | "warning";
6
12
 
7
- const TINT: Record<Tone, string> = {
8
- info: "text-cream/45",
9
- success: "text-accent",
10
- warning: "text-red",
11
- };
12
-
13
- const ICON: Record<Tone, () => React.ReactElement> = {
13
+ const ICON: Record<Tone, IconComponent> = {
14
14
  info: InfoCircleIcon,
15
15
  success: CheckCircleIcon,
16
16
  warning: AlertTriangleIcon,
17
17
  };
18
18
 
19
- export const notify = (message: React.ReactNode, tone: Tone = "info") => {
20
- const Icon = ICON[tone];
19
+ export const notify = (
20
+ title: React.ReactNode,
21
+ { tone = "info", description }: { tone?: Tone; description?: React.ReactNode } = {},
22
+ ) => {
21
23
  toast.custom(() => (
22
- <div className="bg-panel font-sans w-[344px] rounded border border-cream/15 p-3">
23
- <div className="grid grid-cols-[14px_1fr] items-start gap-x-2.5">
24
- <span className={`flex h-5 items-center justify-center ${TINT[tone]}`}>
25
- <Icon />
26
- </span>
27
- <span className="text-[0.8125rem] leading-5 font-medium text-cream">{message}</span>
28
- </div>
29
- </div>
24
+ <ToastCard icon={ICON[tone]} tone={tone} description={description}>
25
+ {title}
26
+ </ToastCard>
30
27
  ));
31
28
  };
@@ -42,6 +42,7 @@ const parseSurface = (value: unknown): StudioSurface | undefined => {
42
42
  kind,
43
43
  id: value.id,
44
44
  ...(typeof value.project === "string" ? { project: value.project } : {}),
45
+ ...(typeof value.label === "string" && value.label !== "" ? { label: value.label } : {}),
45
46
  routes: isStringArray(value.routes) ? value.routes : [],
46
47
  products: isStringRecord(value.products) ? value.products : {},
47
48
  locales: isStringArray(value.locales) ? value.locales : [],
@@ -0,0 +1,47 @@
1
+ import type { StudioVersion } from "./contract";
2
+
3
+ export type PromotionDirection = "promote" | "rollback";
4
+
5
+ export type Promotion = {
6
+ target?: number;
7
+ live?: number;
8
+ versions: StudioVersion[];
9
+ pick?: (version: number) => void;
10
+ };
11
+
12
+ export const liveVersion = (versions: readonly StudioVersion[]): number | undefined =>
13
+ versions.find((entry) => entry.live)?.version;
14
+
15
+ export const latestVersion = (versions: readonly StudioVersion[]): number | undefined =>
16
+ versions.length === 0 ? undefined : Math.max(...versions.map((entry) => entry.version));
17
+
18
+ export const promotionDirection = (
19
+ target: number | undefined,
20
+ live: number | undefined,
21
+ ): PromotionDirection =>
22
+ target !== undefined && live !== undefined && target < live ? "rollback" : "promote";
23
+
24
+ export const PROMOTION_LABEL: Record<PromotionDirection, { label: string; running: string }> = {
25
+ promote: { label: "Promote", running: "Promoting…" },
26
+ rollback: { label: "Roll back", running: "Rolling back…" },
27
+ };
28
+
29
+ export const promotionHint = (promotion: Pick<Promotion, "target" | "live">): string => {
30
+ const { target, live } = promotion;
31
+ if (target === undefined) return "Make the latest push live";
32
+ if (live === undefined) return `Make v${target} live`;
33
+ if (target === live) return `v${live} is live today`;
34
+ return target < live
35
+ ? `Make v${target} live again, replacing v${live}`
36
+ : `Make v${target} live, replacing v${live}`;
37
+ };
38
+
39
+ export const promotionBlocker = (
40
+ promotion: Pick<Promotion, "target" | "live" | "versions">,
41
+ ): string | undefined => {
42
+ if (promotion.versions.length === 0) return "Nothing has been pushed yet";
43
+ if (promotion.target !== undefined && promotion.target === promotion.live) {
44
+ return `v${promotion.live} is already live`;
45
+ }
46
+ return undefined;
47
+ };
package/src/lib/steps.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { StudioActionName } from "./contract";
2
+ import type { PromotionDirection } from "./promotion";
2
3
 
3
4
  export type StudioStepState = "pending" | "active" | "done" | "failed";
4
5
 
@@ -10,7 +11,7 @@ export const ACTION_STEPS: Record<StudioActionName, StudioActionStep[]> = {
10
11
  promote: ["link", "promote"],
11
12
  };
12
13
 
13
- export const STEP_LABELS: Record<StudioActionStep, string> = {
14
+ const STEP_LABELS: Record<StudioActionStep, string> = {
14
15
  link: "Find paywall",
15
16
  build: "Build snapshot",
16
17
  assets: "Sync assets",
@@ -18,3 +19,10 @@ export const STEP_LABELS: Record<StudioActionStep, string> = {
18
19
  source: "Push source",
19
20
  promote: "Promote to live",
20
21
  };
22
+
23
+ export const stepLabel = (
24
+ step: StudioActionStep,
25
+ direction: PromotionDirection,
26
+ target: number | undefined,
27
+ ): string =>
28
+ step === "promote" && direction === "rollback" ? `Roll back to v${target}` : STEP_LABELS[step];