create-nextblock 0.14.2 → 0.14.4

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 (29) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +375 -117
  3. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +2 -2
  4. package/templates/nextblock-template/app/cms/blocks/components/ColumnEditor.tsx +17 -22
  5. package/templates/nextblock-template/app/cms/blocks/components/EditableBlock.tsx +13 -19
  6. package/templates/nextblock-template/app/cms/blocks/editors/HeadingBlockEditor.tsx +45 -34
  7. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeEditor.tsx +382 -0
  8. package/templates/nextblock-template/app/cms/settings/global-css/components/ThemeManager.tsx +267 -0
  9. package/templates/nextblock-template/app/cms/settings/global-css/page.tsx +40 -24
  10. package/templates/nextblock-template/app/cms/settings/global-css/theme-actions.ts +259 -0
  11. package/templates/nextblock-template/app/layout.tsx +49 -0
  12. package/templates/nextblock-template/app/providers.tsx +16 -4
  13. package/templates/nextblock-template/components/blocks/renderers/HeadingBlockRenderer.tsx +7 -10
  14. package/templates/nextblock-template/components/theme-icon.tsx +78 -0
  15. package/templates/nextblock-template/components/theme-switcher.tsx +85 -90
  16. package/templates/nextblock-template/context/ThemeCatalogContext.tsx +44 -0
  17. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +77 -0
  18. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +114 -0
  19. package/templates/nextblock-template/lib/blocks/blockColors.ts +132 -0
  20. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +17 -1
  21. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +92 -87
  22. package/templates/nextblock-template/lib/themes/buildThemeCss.test.ts +163 -0
  23. package/templates/nextblock-template/lib/themes/buildThemeCss.ts +124 -0
  24. package/templates/nextblock-template/lib/themes/tokenColor.ts +31 -0
  25. package/templates/nextblock-template/lib/themes/tokens.ts +143 -0
  26. package/templates/nextblock-template/next-env.d.ts +2 -2
  27. package/templates/nextblock-template/package.json +1 -1
  28. package/templates/nextblock-template/scripts/verify-site-themes.ts +63 -0
  29. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -6,6 +6,7 @@ import { Button } from '@nextblock-cms/ui';
6
6
  import { PlusCircle, Trash2, Edit2, GripVertical, Image as ImageIcon } from "lucide-react";
7
7
  import { SectionBlockContent } from '../../../../lib/blocks/blockRegistry';
8
8
  import { availableBlockTypes, blockHasEditableContent, getBlockDefinition, getInitialContent, BlockType } from '../../../../lib/blocks/blockRegistry';
9
+ import { resolveTextAlign, resolveTextColor } from '../../../../lib/blocks/blockColors';
9
10
  import { useDroppable } from "@dnd-kit/core";
10
11
  import { useSortable } from "@dnd-kit/sortable";
11
12
  import { CSS } from "@dnd-kit/utilities";
@@ -136,9 +137,8 @@ function SortableColumnBlock({ block, index, columnIndex, onEdit, onDelete, bloc
136
137
  case 'heading': {
137
138
  const content = block.content as any;
138
139
  const level = content.level || 1;
139
- const headingAlign = content.textAlign || 'left';
140
140
  const textColor = content.textColor || 'foreground';
141
-
141
+
142
142
  const sizeClasses: Record<number, string> = {
143
143
  1: "text-4xl font-extrabold",
144
144
  2: "text-3xl font-bold",
@@ -148,32 +148,27 @@ function SortableColumnBlock({ block, index, columnIndex, onEdit, onDelete, bloc
148
148
  6: "text-base font-semibold",
149
149
  };
150
150
 
151
- const colorClasses: Record<string, string> = {
152
- primary: "text-primary",
153
- secondary: "text-secondary",
154
- accent: "text-accent",
155
- destructive: "text-destructive",
156
- muted: "text-muted-foreground",
157
- background: "text-background",
158
- foreground: "text-foreground"
159
- };
160
-
161
- // Override for dark background if color is basic
162
- let appliedColorClass = colorClasses[textColor] || "text-foreground";
163
- if (isDarkBackground) {
151
+ // Shared with HeadingBlockRenderer so the preview cannot drift.
152
+ const { className: resolvedColorClass, style: colorStyle } = resolveTextColor(textColor);
153
+ let appliedColorClass = resolvedColorClass ?? (colorStyle ? undefined : "text-foreground");
154
+ // A custom colour is literal — only the theme tokens get the dark-surface
155
+ // legibility override, since only they are ambiguous against it.
156
+ if (isDarkBackground && !colorStyle) {
164
157
  if (textColor === 'foreground') appliedColorClass = 'text-white/90';
165
158
  if (textColor === 'muted') appliedColorClass = 'text-white/70';
166
159
  }
167
160
 
168
161
  return (
169
162
  <div className="flex gap-3">
170
- <div className={cn(
171
- "w-full leading-tight",
172
- sizeClasses[level] || sizeClasses[1],
173
- appliedColorClass,
174
- headingAlign === 'center' && 'text-center',
175
- headingAlign === 'right' && 'text-right'
176
- )}>
163
+ <div
164
+ style={colorStyle}
165
+ className={cn(
166
+ "w-full leading-tight",
167
+ sizeClasses[level] || sizeClasses[1],
168
+ appliedColorClass,
169
+ resolveTextAlign(content.textAlign)
170
+ )}
171
+ >
177
172
  {content.text_content || <span className={cn("text-muted-foreground font-normal text-sm italic", isDarkBackground && "text-white/50")}>Empty heading</span>}
178
173
  </div>
179
174
  </div>
@@ -9,6 +9,7 @@ type Block = Database['public']['Tables']['blocks']['Row'];
9
9
  import { Button, Card, CardContent, Avatar, AvatarImage, AvatarFallback } from "@nextblock-cms/ui";
10
10
  import { GripVertical, Edit2, Image as ImageIcon, MessageSquareQuote } from "lucide-react";
11
11
  import { blockHasEditableContent, getBlockDefinition, blockRegistry, BlockType } from '../../../../lib/blocks/blockRegistry';
12
+ import { resolveTextAlign, resolveTextColor } from '../../../../lib/blocks/blockColors';
12
13
  import { BlockEditorModal } from './BlockEditorModal';
13
14
  import { DeleteBlockButtonClient } from './DeleteBlockButtonClient';
14
15
  import { cn } from '@nextblock-cms/utils';
@@ -161,9 +162,7 @@ export default function EditableBlock({
161
162
  case 'heading': {
162
163
  const content = (block.content || {}) as any;
163
164
  const level = content.level || 1;
164
- const headingAlign = content.textAlign || 'left';
165
- const textColor = content.textColor || 'foreground';
166
-
165
+
167
166
  const sizeClasses: Record<number, string> = {
168
167
  1: "text-4xl font-extrabold",
169
168
  2: "text-3xl font-bold",
@@ -173,25 +172,20 @@ export default function EditableBlock({
173
172
  6: "text-base font-semibold",
174
173
  };
175
174
 
176
- const colorClasses: Record<string, string> = {
177
- primary: "text-primary",
178
- secondary: "text-secondary",
179
- accent: "text-accent",
180
- destructive: "text-destructive",
181
- muted: "text-muted-foreground",
182
- background: "text-background",
183
- foreground: "text-foreground"
184
- };
175
+ // Shared with HeadingBlockRenderer so the preview cannot drift.
176
+ const { className: colorClass, style: colorStyle } = resolveTextColor(content.textColor);
185
177
 
186
178
  return (
187
179
  <div className="py-2">
188
- <div className={cn(
189
- "w-full leading-tight",
190
- sizeClasses[level] || sizeClasses[1],
191
- colorClasses[textColor] || "text-foreground",
192
- headingAlign === 'center' && 'text-center',
193
- headingAlign === 'right' && 'text-right'
194
- )}>
180
+ <div
181
+ style={colorStyle}
182
+ className={cn(
183
+ "w-full leading-tight",
184
+ sizeClasses[level] || sizeClasses[1],
185
+ colorClass ?? (colorStyle ? undefined : "text-foreground"),
186
+ resolveTextAlign(content.textAlign)
187
+ )}
188
+ >
195
189
  {content.text_content || <span className="text-muted-foreground italic text-sm font-normal">Empty heading</span>}
196
190
  </div>
197
191
  </div>
@@ -4,11 +4,27 @@
4
4
  import React from "react";
5
5
  import { Label } from "@nextblock-cms/ui";
6
6
  import { Input } from "@nextblock-cms/ui";
7
+ import { ColorField } from "@nextblock-cms/ui";
7
8
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@nextblock-cms/ui";
8
9
  import { HeadingBlockContent } from '../../../../lib/blocks/blockRegistry';
10
+ import { TEXT_COLOR_TOKEN_OPTIONS } from '../../../../lib/blocks/blockColors';
9
11
  import { BlockEditorProps } from '../components/BlockEditorModal';
10
12
 
11
- export default function HeadingBlockEditor({ content, onChange }: BlockEditorProps<Partial<HeadingBlockContent>>) {
13
+ /** Handy starting points that are not in the theme — brand-neutral and legible. */
14
+ const HEADING_COLOR_PRESETS = [
15
+ '#0F172A',
16
+ '#334155',
17
+ '#DC2626',
18
+ '#EA580C',
19
+ '#CA8A04',
20
+ '#16A34A',
21
+ '#0891B2',
22
+ '#2563EB',
23
+ '#7C3AED',
24
+ '#DB2777',
25
+ ] as const;
26
+
27
+ export default function HeadingBlockEditor({ content, onChange, sectionBackground }: BlockEditorProps<Partial<HeadingBlockContent>>) {
12
28
  const idPrefix = React.useId();
13
29
 
14
30
  const handleTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -21,24 +37,26 @@ export default function HeadingBlockEditor({ content, onChange }: BlockEditorPro
21
37
 
22
38
  const textAlignOptions = ['left', 'center', 'right', 'justify'] as const;
23
39
 
24
- const textColorOptions = [
25
- { value: 'primary', label: 'Primary', swatchClass: 'bg-primary' },
26
- { value: 'secondary', label: 'Secondary', swatchClass: 'bg-secondary' },
27
- { value: 'accent', label: 'Accent', swatchClass: 'bg-accent' },
28
- { value: 'muted', label: 'Muted', swatchClass: 'bg-muted-foreground' }, // Using muted-foreground for swatch as text-muted is for text
29
- { value: 'destructive', label: 'Destructive', swatchClass: 'bg-destructive' },
30
- { value: 'background', label: 'Background', swatchClass: 'bg-background' },
31
- ] as const;
32
-
33
40
  const handleTextAlignChange = (value: string) => {
34
41
  onChange({ ...content, textAlign: value as HeadingBlockContent['textAlign'] });
35
42
  };
36
43
 
37
- const handleTextColorChange = (value: string) => {
38
- const newTextColor = value === "" ? undefined : value as HeadingBlockContent['textColor'];
39
- onChange({ ...content, textColor: newTextColor });
44
+ const handleTextColorChange = (value: string | undefined) => {
45
+ onChange({ ...content, textColor: value as HeadingBlockContent['textColor'] });
40
46
  };
41
47
 
48
+ // Measure contrast against the real section backdrop when there is one, so the
49
+ // warning reflects what the visitor will actually see.
50
+ const contrastAgainst = React.useMemo(() => {
51
+ if (sectionBackground?.type === 'solid') return sectionBackground.solid_color;
52
+ if (sectionBackground?.type === 'theme' && sectionBackground.theme) {
53
+ return `hsl(var(--${sectionBackground.theme}))`;
54
+ }
55
+ if (!sectionBackground || sectionBackground.type === 'none') return 'hsl(var(--background))';
56
+ // Gradients and images have no single backdrop colour to measure against.
57
+ return undefined;
58
+ }, [sectionBackground]);
59
+
42
60
  return (
43
61
  <div className="space-y-3 p-3 border-t mt-2">
44
62
  <div>
@@ -85,27 +103,20 @@ export default function HeadingBlockEditor({ content, onChange }: BlockEditorPro
85
103
  </SelectContent>
86
104
  </Select>
87
105
  </div>
88
- <div>
89
- <Label htmlFor={`heading-text-color-${idPrefix}`}>Text Color</Label>
90
- <Select
91
- value={content.textColor || ""} // Use empty string if no color is selected initially
92
- onValueChange={handleTextColorChange}
93
- >
94
- <SelectTrigger id={`heading-text-color-${idPrefix}`} className="mt-1">
95
- <SelectValue placeholder="Select color (optional)" />
96
- </SelectTrigger>
97
- <SelectContent>
98
- {textColorOptions.map(color => (
99
- <SelectItem key={color.value} value={color.value}>
100
- <div className="flex items-center">
101
- <div className={`w-4 h-4 rounded-sm mr-2 border ${color.swatchClass}`}></div>
102
- {color.label}
103
- </div>
104
- </SelectItem>
105
- ))}
106
- </SelectContent>
107
- </Select>
108
- </div>
106
+ <ColorField
107
+ id={`heading-text-color-${idPrefix}`}
108
+ label="Text Color"
109
+ description="Theme colours follow light/dark mode. Custom colours stay fixed."
110
+ value={content.textColor}
111
+ onChange={handleTextColorChange}
112
+ tokens={TEXT_COLOR_TOKEN_OPTIONS}
113
+ presets={HEADING_COLOR_PRESETS}
114
+ contrastAgainst={contrastAgainst}
115
+ largeText
116
+ enableAlpha
117
+ clearLabel="Inherit from theme"
118
+ placeholder="Inherit from theme"
119
+ />
109
120
  </div>
110
121
  );
111
122
  }
@@ -0,0 +1,382 @@
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+ import {
5
+ Button,
6
+ ColorField,
7
+ Input,
8
+ Label,
9
+ Select,
10
+ SelectContent,
11
+ SelectItem,
12
+ SelectTrigger,
13
+ SelectValue,
14
+ } from '@nextblock-cms/ui';
15
+ import { contrastRatio, parseCssColor, rateContrast } from '@nextblock-cms/utils';
16
+ import { AlertTriangle, Check } from 'lucide-react';
17
+ import type { SiteTheme } from '../../../../../lib/themes/buildThemeCss';
18
+ import { THEME_TOKEN_GROUPS, type ThemeTokenDef } from '../../../../../lib/themes/tokens';
19
+ import {
20
+ cssColorToTokenValue,
21
+ tokenValueToCss,
22
+ tokenValueToHex,
23
+ } from '../../../../../lib/themes/tokenColor';
24
+ import { THEME_ICON_NAMES, ThemeIcon } from '../../../../../components/theme-icon';
25
+
26
+ export interface ThemeDraft {
27
+ name: string;
28
+ description: string;
29
+ icon: string;
30
+ color_scheme: 'light' | 'dark';
31
+ tokens: Record<string, string>;
32
+ extra_css: string;
33
+ is_active: boolean;
34
+ }
35
+
36
+ export function themeToDraft(theme: SiteTheme): ThemeDraft {
37
+ return {
38
+ name: theme.name,
39
+ description: theme.description ?? '',
40
+ icon: theme.icon || 'Palette',
41
+ color_scheme: theme.color_scheme,
42
+ tokens: { ...(theme.tokens ?? {}) },
43
+ extra_css: theme.extra_css ?? '',
44
+ is_active: theme.is_active,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Live contrast readout for a foreground/background token pair. Headings and
50
+ * body copy both come from these tokens, so a bad pair here is a site-wide
51
+ * legibility bug — surfacing it at edit time is the whole point.
52
+ */
53
+ function ContrastBadge({ fg, bg }: { fg?: string; bg?: string }) {
54
+ const result = React.useMemo(() => {
55
+ if (!fg || !bg) return null;
56
+ const f = parseCssColor(tokenValueToCss(fg));
57
+ const b = parseCssColor(tokenValueToCss(bg));
58
+ if (!f || !b) return null;
59
+ const ratio = contrastRatio(f, b);
60
+ return { ratio, rating: rateContrast(ratio) };
61
+ }, [fg, bg]);
62
+
63
+ if (!result) return null;
64
+ const failing = result.rating === 'Fail';
65
+ return (
66
+ <span
67
+ title={`Contrast against its paired surface: ${result.ratio}:1 (WCAG ${result.rating})`}
68
+ className={
69
+ failing
70
+ ? 'inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-destructive/10 text-destructive'
71
+ : 'inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-muted text-muted-foreground'
72
+ }
73
+ >
74
+ {failing ? <AlertTriangle className="h-3 w-3" /> : <Check className="h-3 w-3" />}
75
+ {result.ratio}:1 {result.rating}
76
+ </span>
77
+ );
78
+ }
79
+
80
+ function TokenRow({
81
+ token,
82
+ draft,
83
+ onTokenChange,
84
+ }: {
85
+ token: ThemeTokenDef;
86
+ draft: ThemeDraft;
87
+ onTokenChange: (key: string, value: string | undefined) => void;
88
+ }) {
89
+ const raw = draft.tokens[token.key];
90
+
91
+ if (token.kind === 'length') {
92
+ return (
93
+ <div className="space-y-1.5">
94
+ <Label htmlFor={`token-${token.key}`} className="text-sm">
95
+ {token.label}
96
+ </Label>
97
+ <Input
98
+ id={`token-${token.key}`}
99
+ value={raw ?? ''}
100
+ onChange={(event) => onTokenChange(token.key, event.target.value || undefined)}
101
+ placeholder="0.75rem"
102
+ className="h-9 font-mono text-xs"
103
+ />
104
+ {token.hint ? <p className="text-[11px] text-muted-foreground">{token.hint}</p> : null}
105
+ </div>
106
+ );
107
+ }
108
+
109
+ const hex = raw ? tokenValueToHex(raw) : null;
110
+ const pairedValue = token.pairedWith ? draft.tokens[token.pairedWith] : undefined;
111
+
112
+ return (
113
+ <div className="space-y-1">
114
+ <div className="flex items-center justify-between gap-2">
115
+ <Label htmlFor={`token-${token.key}`} className="text-sm">
116
+ {token.label}
117
+ </Label>
118
+ {token.pairedWith ? <ContrastBadge fg={raw} bg={pairedValue} /> : null}
119
+ </div>
120
+ <ColorField
121
+ id={`token-${token.key}`}
122
+ value={hex ?? undefined}
123
+ placeholder="Not set"
124
+ clearLabel="Unset"
125
+ onChange={(next) => {
126
+ if (!next) {
127
+ onTokenChange(token.key, undefined);
128
+ return;
129
+ }
130
+ const triplet = cssColorToTokenValue(next);
131
+ onTokenChange(token.key, triplet ?? undefined);
132
+ }}
133
+ // Theme tokens ARE the palette, so there is nothing to offer as a token
134
+ // shortcut here — this is the custom picker only.
135
+ tokens={[]}
136
+ contrastAgainst={pairedValue ? tokenValueToCss(pairedValue) : undefined}
137
+ />
138
+ <p className="font-mono text-[10px] text-muted-foreground">
139
+ --{token.key}: {raw ?? <span className="italic">inherited</span>}
140
+ </p>
141
+ </div>
142
+ );
143
+ }
144
+
145
+ export function ThemeEditor({
146
+ theme,
147
+ draft,
148
+ onDraftChange,
149
+ }: {
150
+ theme: SiteTheme;
151
+ draft: ThemeDraft;
152
+ onDraftChange: (next: ThemeDraft) => void;
153
+ }) {
154
+ const set = <K extends keyof ThemeDraft>(key: K, value: ThemeDraft[K]) =>
155
+ onDraftChange({ ...draft, [key]: value });
156
+
157
+ const onTokenChange = (key: string, value: string | undefined) => {
158
+ const tokens = { ...draft.tokens };
159
+ if (value === undefined) delete tokens[key];
160
+ else tokens[key] = value;
161
+ onDraftChange({ ...draft, tokens });
162
+ };
163
+
164
+ return (
165
+ <div className="space-y-6">
166
+ <div className="grid gap-4 sm:grid-cols-2">
167
+ <div className="space-y-1.5">
168
+ <Label htmlFor="theme-name">Name</Label>
169
+ <Input
170
+ id="theme-name"
171
+ value={draft.name}
172
+ onChange={(event) => set('name', event.target.value)}
173
+ placeholder="Midnight"
174
+ />
175
+ </div>
176
+ <div className="space-y-1.5">
177
+ <Label htmlFor="theme-icon">Switcher icon</Label>
178
+ <Select value={draft.icon} onValueChange={(value) => set('icon', value)}>
179
+ <SelectTrigger id="theme-icon">
180
+ <SelectValue />
181
+ </SelectTrigger>
182
+ <SelectContent className="max-h-64">
183
+ {THEME_ICON_NAMES.map((name) => (
184
+ <SelectItem key={name} value={name}>
185
+ <span className="flex items-center gap-2">
186
+ <ThemeIcon name={name} size={14} />
187
+ {name}
188
+ </span>
189
+ </SelectItem>
190
+ ))}
191
+ </SelectContent>
192
+ </Select>
193
+ </div>
194
+ <div className="space-y-1.5">
195
+ <Label htmlFor="theme-description">Description</Label>
196
+ <Input
197
+ id="theme-description"
198
+ value={draft.description}
199
+ onChange={(event) => set('description', event.target.value)}
200
+ placeholder="What this theme is for"
201
+ />
202
+ </div>
203
+ <div className="space-y-1.5">
204
+ <Label htmlFor="theme-scheme">Colour scheme</Label>
205
+ <Select
206
+ value={draft.color_scheme}
207
+ onValueChange={(value) => set('color_scheme', value as 'light' | 'dark')}
208
+ >
209
+ <SelectTrigger id="theme-scheme">
210
+ <SelectValue />
211
+ </SelectTrigger>
212
+ <SelectContent>
213
+ <SelectItem value="light">Light</SelectItem>
214
+ <SelectItem value="dark">Dark</SelectItem>
215
+ </SelectContent>
216
+ </Select>
217
+ <p className="text-[11px] text-muted-foreground">
218
+ Sets the CSS <code>color-scheme</code> for native controls. Dark also applies Tailwind&apos;s{' '}
219
+ <code>dark:</code> variants.
220
+ </p>
221
+ </div>
222
+ </div>
223
+
224
+ <div className="space-y-1.5">
225
+ <div className="flex items-center gap-2">
226
+ <input
227
+ id="theme-active"
228
+ type="checkbox"
229
+ className="h-4 w-4 rounded border-input"
230
+ checked={draft.is_active}
231
+ onChange={(event) => set('is_active', event.target.checked)}
232
+ disabled={theme.is_default}
233
+ />
234
+ <Label htmlFor="theme-active" className="text-sm font-normal">
235
+ Show in the theme switcher
236
+ </Label>
237
+ </div>
238
+ {theme.is_default ? (
239
+ <p className="text-[11px] text-muted-foreground">The default theme is always visible.</p>
240
+ ) : null}
241
+ </div>
242
+
243
+ {THEME_TOKEN_GROUPS.map((group) => (
244
+ <section key={group.id} className="space-y-3">
245
+ <div>
246
+ <h3 className="text-sm font-semibold">{group.label}</h3>
247
+ <p className="text-[11px] text-muted-foreground">{group.description}</p>
248
+ </div>
249
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
250
+ {group.tokens.map((token) => (
251
+ <TokenRow key={token.key} token={token} draft={draft} onTokenChange={onTokenChange} />
252
+ ))}
253
+ </div>
254
+ </section>
255
+ ))}
256
+
257
+ <section className="space-y-2">
258
+ <Label htmlFor="theme-extra-css">Extra CSS for this theme</Label>
259
+ <p className="text-[11px] text-muted-foreground">
260
+ Scoped automatically to this theme — start selectors with <code>&amp;</code>, e.g.{' '}
261
+ <code>&amp; h1 {'{'} text-shadow: 0 0 5px hsl(var(--primary)); {'}'}</code>
262
+ </p>
263
+ <textarea
264
+ id="theme-extra-css"
265
+ value={draft.extra_css}
266
+ onChange={(event) => set('extra_css', event.target.value)}
267
+ spellCheck={false}
268
+ className="flex min-h-[140px] w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
269
+ placeholder={'& h1 {\n letter-spacing: -0.02em;\n}'}
270
+ />
271
+ </section>
272
+ </div>
273
+ );
274
+ }
275
+
276
+ /** Renders the draft as a self-contained preview card, scoped by inline vars. */
277
+ export function ThemePreview({ draft }: { draft: ThemeDraft }) {
278
+ const style = React.useMemo(() => {
279
+ const vars: Record<string, string> = {};
280
+ for (const [key, value] of Object.entries(draft.tokens)) {
281
+ vars[`--${key}`] = value;
282
+ }
283
+ return vars as React.CSSProperties;
284
+ }, [draft.tokens]);
285
+
286
+ return (
287
+ <div
288
+ style={style}
289
+ className="rounded-lg border p-4"
290
+ // The preview paints with the draft's own tokens, so it updates live
291
+ // without saving and without touching the surrounding CMS chrome.
292
+ >
293
+ <div className="rounded-md p-4" style={{ background: 'hsl(var(--background))' }}>
294
+ <p className="text-sm font-semibold" style={{ color: 'hsl(var(--foreground))' }}>
295
+ {draft.name || 'Untitled theme'}
296
+ </p>
297
+ <p className="mt-1 text-xs" style={{ color: 'hsl(var(--muted-foreground))' }}>
298
+ {draft.description || 'The quick brown fox jumps over the lazy dog.'}
299
+ </p>
300
+ <div className="mt-3 flex flex-wrap gap-2">
301
+ <span
302
+ className="rounded px-2.5 py-1 text-xs font-medium"
303
+ style={{
304
+ background: 'hsl(var(--primary))',
305
+ color: 'hsl(var(--primary-foreground))',
306
+ borderRadius: 'var(--radius)',
307
+ }}
308
+ >
309
+ Primary
310
+ </span>
311
+ <span
312
+ className="rounded px-2.5 py-1 text-xs font-medium"
313
+ style={{
314
+ background: 'hsl(var(--secondary))',
315
+ color: 'hsl(var(--secondary-foreground))',
316
+ borderRadius: 'var(--radius)',
317
+ }}
318
+ >
319
+ Secondary
320
+ </span>
321
+ <span
322
+ className="rounded px-2.5 py-1 text-xs font-medium"
323
+ style={{
324
+ background: 'hsl(var(--accent))',
325
+ color: 'hsl(var(--accent-foreground))',
326
+ borderRadius: 'var(--radius)',
327
+ }}
328
+ >
329
+ Accent
330
+ </span>
331
+ <span
332
+ className="rounded px-2.5 py-1 text-xs font-medium"
333
+ style={{
334
+ background: 'hsl(var(--destructive))',
335
+ color: 'hsl(var(--destructive-foreground))',
336
+ borderRadius: 'var(--radius)',
337
+ }}
338
+ >
339
+ Destructive
340
+ </span>
341
+ <span
342
+ className="rounded px-2.5 py-1 text-xs font-medium"
343
+ style={{
344
+ background: 'hsl(var(--warning))',
345
+ color: 'hsl(var(--warning-foreground))',
346
+ borderRadius: 'var(--radius)',
347
+ }}
348
+ >
349
+ Warning
350
+ </span>
351
+ </div>
352
+ <div
353
+ className="mt-3 rounded-md border p-3"
354
+ style={{
355
+ background: 'hsl(var(--card))',
356
+ color: 'hsl(var(--card-foreground))',
357
+ borderColor: 'hsl(var(--border))',
358
+ borderRadius: 'var(--radius)',
359
+ }}
360
+ >
361
+ <p className="text-xs font-medium">Card surface</p>
362
+ <div
363
+ className="mt-2 h-8 rounded-md border px-2 text-xs leading-8"
364
+ style={{
365
+ borderColor: 'hsl(var(--input))',
366
+ color: 'hsl(var(--muted-foreground))',
367
+ borderRadius: 'var(--radius)',
368
+ }}
369
+ >
370
+ Input field
371
+ </div>
372
+ </div>
373
+ </div>
374
+ </div>
375
+ );
376
+ }
377
+
378
+ export function ThemePreviewActions({ children }: { children: React.ReactNode }) {
379
+ return <div className="flex flex-wrap items-center gap-2">{children}</div>;
380
+ }
381
+
382
+ export { Button };