@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,93 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { surfacePath } from "../lib/preview";
|
|
3
|
+
import { timeAgo } from "../lib/time";
|
|
4
|
+
import type { StudioStatus, StudioSurface } from "../lib/types";
|
|
5
|
+
|
|
6
|
+
const PREVIEW_WIDTH = 390;
|
|
7
|
+
const PREVIEW_HEIGHT = 844;
|
|
8
|
+
|
|
9
|
+
const useElementWidth = (ref: React.RefObject<HTMLElement | null>): number => {
|
|
10
|
+
const [width, setWidth] = React.useState(0);
|
|
11
|
+
|
|
12
|
+
React.useLayoutEffect(() => {
|
|
13
|
+
const element = ref.current;
|
|
14
|
+
if (!element) return undefined;
|
|
15
|
+
const measure = () => setWidth(element.getBoundingClientRect().width);
|
|
16
|
+
measure();
|
|
17
|
+
if (typeof ResizeObserver === "undefined") return undefined;
|
|
18
|
+
const observer = new ResizeObserver(measure);
|
|
19
|
+
observer.observe(element);
|
|
20
|
+
return () => observer.disconnect();
|
|
21
|
+
}, [ref]);
|
|
22
|
+
|
|
23
|
+
return width;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SurfaceCard = ({
|
|
27
|
+
surface,
|
|
28
|
+
status,
|
|
29
|
+
previewSrc,
|
|
30
|
+
onOpen,
|
|
31
|
+
href,
|
|
32
|
+
}: {
|
|
33
|
+
surface: StudioSurface;
|
|
34
|
+
status?: StudioStatus;
|
|
35
|
+
previewSrc: string;
|
|
36
|
+
onOpen: () => void;
|
|
37
|
+
href?: string;
|
|
38
|
+
}) => {
|
|
39
|
+
const previewRef = React.useRef<HTMLDivElement>(null);
|
|
40
|
+
const width = useElementWidth(previewRef);
|
|
41
|
+
const scale = width > 0 ? width / PREVIEW_WIDTH : 0;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<a
|
|
45
|
+
className="group block"
|
|
46
|
+
href={href ?? surfacePath(surface)}
|
|
47
|
+
onClick={(event) => {
|
|
48
|
+
if (event.metaKey || event.ctrlKey) return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
onOpen();
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<div
|
|
54
|
+
className="bg-panel relative aspect-[390/844] overflow-hidden border border-cream/20 transition-colors group-hover:border-cream/35"
|
|
55
|
+
ref={previewRef}
|
|
56
|
+
>
|
|
57
|
+
{scale > 0 && (
|
|
58
|
+
<iframe
|
|
59
|
+
className="pointer-events-none block origin-top-left border-0 bg-white"
|
|
60
|
+
title={`${surface.project ? `${surface.project}/` : ""}${surface.id} preview`}
|
|
61
|
+
src={previewSrc}
|
|
62
|
+
loading="lazy"
|
|
63
|
+
tabIndex={-1}
|
|
64
|
+
width={PREVIEW_WIDTH}
|
|
65
|
+
height={PREVIEW_HEIGHT}
|
|
66
|
+
style={{ transform: `scale(${scale})` }}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
<div className="flex items-center justify-between gap-2 pt-2.5">
|
|
71
|
+
<div className="flex flex-col gap-0.5">
|
|
72
|
+
<span className="text-sm font-medium">
|
|
73
|
+
{surface.project && <span className="text-cream/45">{surface.project}/</span>}
|
|
74
|
+
{surface.id}
|
|
75
|
+
{surface.platforms && surface.platforms.length > 0 && (
|
|
76
|
+
<span className="text-cream/45"> · {surface.platforms.join(" · ")}</span>
|
|
77
|
+
)}
|
|
78
|
+
</span>
|
|
79
|
+
{status && (
|
|
80
|
+
<span className="text-xs text-cream/55">
|
|
81
|
+
{status.updatedAt ? `Edited ${timeAgo(status.updatedAt)}` : "Not published"}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
{status?.paywallId && (
|
|
86
|
+
<span className={`text-xs ${status.active ? "text-accent" : "text-cream/55"}`}>
|
|
87
|
+
{status.active ? "Active" : "Inactive"}
|
|
88
|
+
</span>
|
|
89
|
+
)}
|
|
90
|
+
</div>
|
|
91
|
+
</a>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export const Toolbar = ({ children }: React.PropsWithChildren) => (
|
|
4
|
+
<div className="bg-bar z-10 flex min-h-14 flex-none flex-wrap items-center justify-center gap-3 border-t border-cream/10 px-4 py-2.5">
|
|
5
|
+
{children}
|
|
6
|
+
</div>
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export const ToolbarGroup = ({ label, children }: React.PropsWithChildren<{ label: string }>) => (
|
|
10
|
+
<div className="flex items-center gap-2.5">
|
|
11
|
+
<span className="sw-tool-label">{label}</span>
|
|
12
|
+
{children}
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const ToolbarDivider = () => <span className="h-6 w-px bg-cream/10" />;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export const TopBar = ({
|
|
4
|
+
title,
|
|
5
|
+
onHome,
|
|
6
|
+
actions,
|
|
7
|
+
inset = false,
|
|
8
|
+
label = "Studio",
|
|
9
|
+
}: {
|
|
10
|
+
title: string;
|
|
11
|
+
onHome: () => void;
|
|
12
|
+
actions?: React.ReactNode;
|
|
13
|
+
inset?: boolean;
|
|
14
|
+
label?: string;
|
|
15
|
+
}) => (
|
|
16
|
+
<header className="relative z-10 flex h-11 flex-none items-center border-b border-cream/10 bg-ink">
|
|
17
|
+
<div
|
|
18
|
+
className={`flex h-full w-full items-center px-3 ${inset ? "mx-auto max-w-[1080px] sm:px-0" : ""}`}
|
|
19
|
+
>
|
|
20
|
+
<a
|
|
21
|
+
className="flex items-center gap-3 text-[0.9375rem] font-semibold tracking-[0.01em]"
|
|
22
|
+
href="/"
|
|
23
|
+
onClick={(event) => {
|
|
24
|
+
if (event.metaKey || event.ctrlKey) return;
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
onHome();
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<span className="whitespace-nowrap">
|
|
30
|
+
<em className="text-accent not-italic">$UPER</em>WALL
|
|
31
|
+
</span>
|
|
32
|
+
<span className="h-4 w-px bg-cream/20" />
|
|
33
|
+
<span className="font-normal">{label}</span>
|
|
34
|
+
</a>
|
|
35
|
+
<span className="absolute left-1/2 hidden -translate-x-1/2 text-sm font-medium whitespace-nowrap sm:block">
|
|
36
|
+
{title}
|
|
37
|
+
</span>
|
|
38
|
+
<div className="ml-auto flex items-center gap-2">{actions}</div>
|
|
39
|
+
</div>
|
|
40
|
+
</header>
|
|
41
|
+
);
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ChevronDownIcon } from "./icons";
|
|
3
|
+
import type { PreviewOverrides } from "../lib/types";
|
|
4
|
+
|
|
5
|
+
export type VariableGroup = "user" | "device" | "params" | "products";
|
|
6
|
+
|
|
7
|
+
export type VariableRow = {
|
|
8
|
+
path: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type VariableGroups = Partial<Record<VariableGroup, VariableRow[]>>;
|
|
13
|
+
|
|
14
|
+
const GROUPS: { key: VariableGroup; label: string; blurb: string }[] = [
|
|
15
|
+
{ key: "user", label: "User", blurb: "Attributes your app sets" },
|
|
16
|
+
{ key: "device", label: "Device", blurb: "Platform, locale, OS — the SDK fills these in" },
|
|
17
|
+
{ key: "params", label: "Params", blurb: "Passed in at the placement" },
|
|
18
|
+
{ key: "products", label: "Products", blurb: "Store data for this paywall's products" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const display = (value: unknown): string =>
|
|
22
|
+
value === undefined || value === null
|
|
23
|
+
? ""
|
|
24
|
+
: typeof value === "string"
|
|
25
|
+
? value
|
|
26
|
+
: JSON.stringify(value);
|
|
27
|
+
|
|
28
|
+
const parse = (value: string): unknown => {
|
|
29
|
+
if (value === "true") return true;
|
|
30
|
+
if (value === "false") return false;
|
|
31
|
+
if (value.trim() !== "" && Number.isFinite(Number(value))) return Number(value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const leaf = (path: string): string => path.slice(path.indexOf(".") + 1);
|
|
36
|
+
|
|
37
|
+
const Row = ({
|
|
38
|
+
row,
|
|
39
|
+
override,
|
|
40
|
+
onChange,
|
|
41
|
+
}: {
|
|
42
|
+
row: VariableRow;
|
|
43
|
+
override: unknown;
|
|
44
|
+
onChange: (value: unknown) => void;
|
|
45
|
+
}) => {
|
|
46
|
+
const overridden = override !== undefined;
|
|
47
|
+
const current = overridden ? override : row.value;
|
|
48
|
+
|
|
49
|
+
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>
|
|
53
|
+
{overridden && (
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
className="shrink-0 text-[11px] text-cream/40 hover:text-cream"
|
|
57
|
+
aria-label={`Reset ${row.path}`}
|
|
58
|
+
onClick={() => onChange(undefined)}
|
|
59
|
+
>
|
|
60
|
+
Reset
|
|
61
|
+
</button>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
{typeof current === "boolean" ? (
|
|
65
|
+
<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
|
+
/>
|
|
74
|
+
</span>
|
|
75
|
+
) : (
|
|
76
|
+
<input
|
|
77
|
+
className="sw-input w-full"
|
|
78
|
+
aria-label={row.path}
|
|
79
|
+
value={display(current)}
|
|
80
|
+
placeholder={display(row.value)}
|
|
81
|
+
onChange={(event) => {
|
|
82
|
+
const next = event.target.value;
|
|
83
|
+
onChange(next === "" ? undefined : parse(next));
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const Group = ({
|
|
92
|
+
label,
|
|
93
|
+
blurb,
|
|
94
|
+
rows,
|
|
95
|
+
overrideOf,
|
|
96
|
+
onChange,
|
|
97
|
+
}: {
|
|
98
|
+
label: string;
|
|
99
|
+
blurb: string;
|
|
100
|
+
rows: VariableRow[];
|
|
101
|
+
overrideOf: (path: string) => unknown;
|
|
102
|
+
onChange: (path: string, value: unknown) => void;
|
|
103
|
+
}) => {
|
|
104
|
+
const [open, setOpen] = React.useState(false);
|
|
105
|
+
const overridden = rows.filter((row) => overrideOf(row.path) !== undefined).length;
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<section className="border-b border-cream/10 last:border-b-0">
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
className="flex w-full items-center gap-2 py-3 text-left"
|
|
112
|
+
aria-expanded={open}
|
|
113
|
+
onClick={() => setOpen((current) => !current)}
|
|
114
|
+
>
|
|
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>
|
|
125
|
+
</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 />
|
|
133
|
+
</span>
|
|
134
|
+
</button>
|
|
135
|
+
|
|
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
|
+
))}
|
|
149
|
+
</div>
|
|
150
|
+
))}
|
|
151
|
+
</section>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const VariablesPanel = ({
|
|
156
|
+
overrides,
|
|
157
|
+
groups,
|
|
158
|
+
onChange,
|
|
159
|
+
}: {
|
|
160
|
+
overrides: PreviewOverrides;
|
|
161
|
+
groups: VariableGroups;
|
|
162
|
+
onChange: (overrides: PreviewOverrides) => void;
|
|
163
|
+
}) => {
|
|
164
|
+
const update = (group: VariableGroup, path: string, value: unknown) => {
|
|
165
|
+
if (group !== "products") {
|
|
166
|
+
const current = { ...overrides[group] } as Record<string, unknown>;
|
|
167
|
+
if (value === undefined) delete current[leaf(path)];
|
|
168
|
+
else current[leaf(path)] = value;
|
|
169
|
+
onChange({ ...overrides, [group]: current });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const [, reference = "", key = ""] = path.split(".");
|
|
174
|
+
const slot = { ...overrides.products?.[reference] };
|
|
175
|
+
if (value === undefined) delete slot[key];
|
|
176
|
+
else slot[key] = value;
|
|
177
|
+
const next = { ...overrides.products, [reference]: slot };
|
|
178
|
+
if (Object.keys(slot).length === 0) delete next[reference];
|
|
179
|
+
onChange({ ...overrides, products: next });
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div className="flex flex-col">
|
|
184
|
+
{GROUPS.map((group) => (
|
|
185
|
+
<Group
|
|
186
|
+
key={group.key}
|
|
187
|
+
label={group.label}
|
|
188
|
+
blurb={group.blurb}
|
|
189
|
+
rows={groups[group.key] ?? []}
|
|
190
|
+
overrideOf={(path) =>
|
|
191
|
+
group.key === "products"
|
|
192
|
+
? overrides.products?.[path.split(".")[1] ?? ""]?.[path.split(".")[2] ?? ""]
|
|
193
|
+
: (overrides[group.key] as Record<string, unknown> | undefined)?.[leaf(path)]
|
|
194
|
+
}
|
|
195
|
+
onChange={(path, value) => update(group.key, path, value)}
|
|
196
|
+
/>
|
|
197
|
+
))}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export const Segmented = <TValue extends string>({
|
|
4
|
+
value,
|
|
5
|
+
options,
|
|
6
|
+
onChange,
|
|
7
|
+
label,
|
|
8
|
+
}: {
|
|
9
|
+
value: TValue;
|
|
10
|
+
options: readonly { value: TValue; label: React.ReactNode }[];
|
|
11
|
+
onChange: (value: TValue) => void;
|
|
12
|
+
label: string;
|
|
13
|
+
}) => (
|
|
14
|
+
<div className="sw-segmented" role="group" aria-label={label}>
|
|
15
|
+
{options.map((option) => (
|
|
16
|
+
<button
|
|
17
|
+
key={option.value}
|
|
18
|
+
type="button"
|
|
19
|
+
aria-pressed={option.value === value}
|
|
20
|
+
onClick={() => onChange(option.value)}
|
|
21
|
+
>
|
|
22
|
+
{option.label}
|
|
23
|
+
</button>
|
|
24
|
+
))}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const Select = ({
|
|
29
|
+
value,
|
|
30
|
+
options,
|
|
31
|
+
onChange,
|
|
32
|
+
label,
|
|
33
|
+
}: {
|
|
34
|
+
value: string;
|
|
35
|
+
options: readonly { value: string; label: string }[];
|
|
36
|
+
onChange: (value: string) => void;
|
|
37
|
+
label: string;
|
|
38
|
+
}) => (
|
|
39
|
+
<select
|
|
40
|
+
className="sw-select"
|
|
41
|
+
aria-label={label}
|
|
42
|
+
value={value}
|
|
43
|
+
onChange={(event) => onChange(event.target.value)}
|
|
44
|
+
>
|
|
45
|
+
{options.map((option) => (
|
|
46
|
+
<option key={option.value} value={option.value}>
|
|
47
|
+
{option.label}
|
|
48
|
+
</option>
|
|
49
|
+
))}
|
|
50
|
+
</select>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export const Switch = ({
|
|
54
|
+
checked,
|
|
55
|
+
onChange,
|
|
56
|
+
label,
|
|
57
|
+
}: {
|
|
58
|
+
checked: boolean;
|
|
59
|
+
onChange: (checked: boolean) => void;
|
|
60
|
+
label: string;
|
|
61
|
+
}) => (
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
role="switch"
|
|
65
|
+
aria-checked={checked}
|
|
66
|
+
aria-label={label}
|
|
67
|
+
className="sw-switch"
|
|
68
|
+
onClick={() => onChange(!checked)}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
const Icon = ({ children }: React.PropsWithChildren) => (
|
|
4
|
+
<svg className="sw-icon" viewBox="0 0 24 24" aria-hidden="true">
|
|
5
|
+
{children}
|
|
6
|
+
</svg>
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export const ChevronLeftIcon = () => (
|
|
10
|
+
<Icon>
|
|
11
|
+
<path d="m15 18-6-6 6-6" />
|
|
12
|
+
</Icon>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const RotateIcon = () => (
|
|
16
|
+
<Icon>
|
|
17
|
+
<path d="M21 12a9 9 0 1 1-2.64-6.36" />
|
|
18
|
+
<path d="M21 3v6h-6" />
|
|
19
|
+
</Icon>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const ExternalIcon = () => (
|
|
23
|
+
<Icon>
|
|
24
|
+
<path d="M15 3h6v6" />
|
|
25
|
+
<path d="M10 14 21 3" />
|
|
26
|
+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
|
|
27
|
+
</Icon>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const SunIcon = () => (
|
|
31
|
+
<Icon>
|
|
32
|
+
<circle cx="12" cy="12" r="4" />
|
|
33
|
+
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" />
|
|
34
|
+
</Icon>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export const MoonIcon = () => (
|
|
38
|
+
<Icon>
|
|
39
|
+
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
|
40
|
+
</Icon>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const ResetIcon = () => (
|
|
44
|
+
<Icon>
|
|
45
|
+
<path d="M3 12a9 9 0 1 0 2.64-6.36" />
|
|
46
|
+
<path d="M3 3v6h6" />
|
|
47
|
+
</Icon>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const SlidersIcon = () => (
|
|
51
|
+
<Icon>
|
|
52
|
+
<path d="M21 4h-7M10 4H3M21 12h-9M8 12H3M21 20h-5M12 20H3" />
|
|
53
|
+
<path d="M14 2v4M8 10v4M16 18v4" />
|
|
54
|
+
</Icon>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const CloseIcon = () => (
|
|
58
|
+
<Icon>
|
|
59
|
+
<path d="M18 6 6 18M6 6l12 12" />
|
|
60
|
+
</Icon>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const ChevronDownIcon = () => (
|
|
64
|
+
<Icon>
|
|
65
|
+
<path d="m6 9 6 6 6-6" />
|
|
66
|
+
</Icon>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
export const ColumnsIcon = () => (
|
|
70
|
+
<Icon>
|
|
71
|
+
<rect x="3" y="4" width="18" height="16" />
|
|
72
|
+
<path d="M12 4v16" />
|
|
73
|
+
</Icon>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export const CheckCircleIcon = () => (
|
|
77
|
+
<Icon>
|
|
78
|
+
<circle cx="12" cy="12" r="9" />
|
|
79
|
+
<path d="m8.5 12 2.5 2.5 4.5-5" />
|
|
80
|
+
</Icon>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const AlertTriangleIcon = () => (
|
|
84
|
+
<Icon>
|
|
85
|
+
<path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z" />
|
|
86
|
+
<path d="M12 9v4" />
|
|
87
|
+
<path d="M12 17h.01" />
|
|
88
|
+
</Icon>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const InfoCircleIcon = () => (
|
|
92
|
+
<Icon>
|
|
93
|
+
<circle cx="12" cy="12" r="9" />
|
|
94
|
+
<path d="M12 11v5" />
|
|
95
|
+
<path d="M12 8h.01" />
|
|
96
|
+
</Icon>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const BoltIcon = () => (
|
|
100
|
+
<Icon>
|
|
101
|
+
<path d="M13 2 4.5 13H11l-1 9 8.5-11H12l1-9Z" />
|
|
102
|
+
</Icon>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
export const CartIcon = () => (
|
|
106
|
+
<Icon>
|
|
107
|
+
<circle cx="9" cy="20" r="1" />
|
|
108
|
+
<circle cx="18" cy="20" r="1" />
|
|
109
|
+
<path d="M2 3h2.5l2.2 11.2a2 2 0 0 0 2 1.6h8.4a2 2 0 0 0 2-1.6L21 7H5.4" />
|
|
110
|
+
</Icon>
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
export const BellIcon = () => (
|
|
114
|
+
<Icon>
|
|
115
|
+
<path d="M18 8a6 6 0 1 0-12 0c0 6-2 8-2 8h16s-2-2-2-8" />
|
|
116
|
+
<path d="M13.7 21a2 2 0 0 1-3.4 0" />
|
|
117
|
+
</Icon>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
export const StarIcon = () => (
|
|
121
|
+
<Icon>
|
|
122
|
+
<path d="m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1L3.2 9.5l6.1-.9L12 3Z" />
|
|
123
|
+
</Icon>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
export const UserIcon = () => (
|
|
127
|
+
<Icon>
|
|
128
|
+
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
|
|
129
|
+
<circle cx="12" cy="7" r="4" />
|
|
130
|
+
</Icon>
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
export const RotateDeviceIcon = () => (
|
|
134
|
+
<Icon>
|
|
135
|
+
<rect x="4" y="2" width="10" height="16" rx="2" />
|
|
136
|
+
<path d="M17 12a5 5 0 0 1-5 9H9" />
|
|
137
|
+
<path d="m11 19-2 2 2 2" />
|
|
138
|
+
</Icon>
|
|
139
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./styles.css";
|
|
2
|
+
|
|
3
|
+
export { StudioApp } from "./StudioApp";
|
|
4
|
+
export { SurfaceEditor } from "./screens/SurfaceEditor";
|
|
5
|
+
export { SurfaceList } from "./screens/SurfaceList";
|
|
6
|
+
export { DeviceFrame } from "./components/DeviceFrame";
|
|
7
|
+
export { TopBar } from "./components/TopBar";
|
|
8
|
+
export { VariablesPanel } from "./components/VariablesPanel";
|
|
9
|
+
export { Segmented, Select, Switch } from "./components/controls";
|
|
10
|
+
export { DEFAULT_DEVICE_ID, deviceById, STUDIO_DEVICES } from "./lib/devices";
|
|
11
|
+
export type { StudioDevice } from "./lib/devices";
|
|
12
|
+
export { buildPreviewPath } from "./lib/preview";
|
|
13
|
+
export { parseProjectPayload, type StudioProjectPayload } from "./lib/project";
|
|
14
|
+
export type {
|
|
15
|
+
PreviewOverrides,
|
|
16
|
+
PreviewUrlBuilder,
|
|
17
|
+
StudioSource,
|
|
18
|
+
StudioSurface,
|
|
19
|
+
StudioSurfaceKind,
|
|
20
|
+
} from "./lib/types";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { surfacePath } from "./preview";
|
|
2
|
+
import type {
|
|
3
|
+
Samples,
|
|
4
|
+
StudioActionName,
|
|
5
|
+
StudioActionResult,
|
|
6
|
+
StudioStatus,
|
|
7
|
+
StudioSurface,
|
|
8
|
+
} from "./types";
|
|
9
|
+
|
|
10
|
+
export const runAction = async (
|
|
11
|
+
surface: StudioSurface,
|
|
12
|
+
action: StudioActionName,
|
|
13
|
+
onStep?: (step: string, state: "start" | "done") => void,
|
|
14
|
+
): Promise<StudioActionResult> => {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch("/__studio/action", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "Content-Type": "application/json" },
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
action,
|
|
21
|
+
kind: surface.kind,
|
|
22
|
+
id: surface.id,
|
|
23
|
+
project: surface.project,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
if (!response.body) {
|
|
27
|
+
return (await response.json()) as StudioActionResult;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const reader = response.body.getReader();
|
|
31
|
+
const decoder = new TextDecoder();
|
|
32
|
+
let buffered = "";
|
|
33
|
+
let result: StudioActionResult | undefined;
|
|
34
|
+
|
|
35
|
+
const consume = (line: string) => {
|
|
36
|
+
if (!line.trim()) return;
|
|
37
|
+
const event = JSON.parse(line) as {
|
|
38
|
+
step?: string;
|
|
39
|
+
state?: "start" | "done";
|
|
40
|
+
result?: StudioActionResult;
|
|
41
|
+
};
|
|
42
|
+
if (event.result) result = event.result;
|
|
43
|
+
else if (event.step && event.state) onStep?.(event.step, event.state);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
for (;;) {
|
|
47
|
+
const { done, value } = await reader.read();
|
|
48
|
+
if (done) break;
|
|
49
|
+
buffered += decoder.decode(value, { stream: true });
|
|
50
|
+
const lines = buffered.split("\n");
|
|
51
|
+
buffered = lines.pop() ?? "";
|
|
52
|
+
for (const line of lines) consume(line);
|
|
53
|
+
}
|
|
54
|
+
consume(buffered);
|
|
55
|
+
|
|
56
|
+
return result ?? { ok: false, error: "The dev server closed without a result." };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const fetchStatus = async (surface: StudioSurface): Promise<StudioStatus> => {
|
|
63
|
+
try {
|
|
64
|
+
const response = await fetch(`/__studio/status${surfacePath(surface)}`);
|
|
65
|
+
return (await response.json()) as StudioStatus;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return { unreachable: error instanceof Error ? error.message : String(error) };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const fetchSamples = async (): Promise<Samples> => {
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch("/__studio/samples.json");
|
|
74
|
+
const value: unknown = await response.json();
|
|
75
|
+
return typeof value === "object" && value !== null ? (value as Samples) : {};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return { unreachable: error instanceof Error ? error.message : String(error) };
|
|
78
|
+
}
|
|
79
|
+
};
|