@cmssy/cli 0.3.0 → 0.4.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/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +4 -54
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +79 -918
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +30 -40
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/publish.js +97 -114
- package/dist/commands/publish.js.map +1 -1
- package/dist/utils/block-config.d.ts.map +1 -1
- package/dist/utils/block-config.js +0 -1
- package/dist/utils/block-config.js.map +1 -1
- package/dist/utils/dev-generator.d.ts +12 -0
- package/dist/utils/dev-generator.d.ts.map +1 -0
- package/dist/utils/dev-generator.js +1647 -0
- package/dist/utils/dev-generator.js.map +1 -0
- package/dist/utils/graphql.d.ts +1 -1
- package/dist/utils/graphql.d.ts.map +1 -1
- package/dist/utils/graphql.js +0 -2
- package/dist/utils/graphql.js.map +1 -1
- package/dist/utils/publish-helpers.d.ts +0 -5
- package/dist/utils/publish-helpers.d.ts.map +1 -1
- package/dist/utils/publish-helpers.js +0 -29
- package/dist/utils/publish-helpers.js.map +1 -1
- package/dist/utils/versions.d.ts.map +1 -0
- package/dist/utils/versions.js.map +1 -0
- package/package.json +14 -8
|
@@ -0,0 +1,1647 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const DEV_DIR = ".cmssy/dev";
|
|
4
|
+
/**
|
|
5
|
+
* Generate the .cmssy/dev/ Next.js app structure for cmssy dev.
|
|
6
|
+
* This creates a minimal Next.js app that imports blocks directly,
|
|
7
|
+
* enabling "use client" boundaries, next/image, and SSR in dev preview.
|
|
8
|
+
*/
|
|
9
|
+
export function generateDevApp(projectRoot, resources) {
|
|
10
|
+
const devRoot = path.join(projectRoot, DEV_DIR);
|
|
11
|
+
// Clean and recreate
|
|
12
|
+
fs.removeSync(devRoot);
|
|
13
|
+
fs.mkdirSync(path.join(devRoot, "app/preview"), { recursive: true });
|
|
14
|
+
fs.mkdirSync(path.join(devRoot, "app/api/blocks"), { recursive: true });
|
|
15
|
+
fs.mkdirSync(path.join(devRoot, "app/api/preview"), { recursive: true });
|
|
16
|
+
fs.mkdirSync(path.join(devRoot, "app/api/workspaces"), { recursive: true });
|
|
17
|
+
// Generate all files
|
|
18
|
+
generateNextConfig(devRoot, projectRoot);
|
|
19
|
+
generateTsConfig(devRoot, projectRoot);
|
|
20
|
+
generateRootLayout(devRoot);
|
|
21
|
+
generateGlobalsCss(devRoot, projectRoot);
|
|
22
|
+
generateHomePage(devRoot);
|
|
23
|
+
generateBlocksApiRoute(devRoot);
|
|
24
|
+
generateBlockConfigApiRoute(devRoot);
|
|
25
|
+
generatePreviewApiRoute(devRoot);
|
|
26
|
+
generateWorkspacesApiRoute(devRoot);
|
|
27
|
+
generatePreviewPages(devRoot, projectRoot, resources);
|
|
28
|
+
return devRoot;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Regenerate only the preview pages (called when new blocks are detected).
|
|
32
|
+
*/
|
|
33
|
+
export function regeneratePreviewPages(projectRoot, resources) {
|
|
34
|
+
const devRoot = path.join(projectRoot, DEV_DIR);
|
|
35
|
+
const previewDir = path.join(devRoot, "app/preview");
|
|
36
|
+
// Remove old preview pages
|
|
37
|
+
if (fs.existsSync(previewDir)) {
|
|
38
|
+
fs.removeSync(previewDir);
|
|
39
|
+
}
|
|
40
|
+
fs.mkdirSync(previewDir, { recursive: true });
|
|
41
|
+
generatePreviewPages(devRoot, projectRoot, resources);
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// File Generators
|
|
45
|
+
// ============================================================================
|
|
46
|
+
function generateNextConfig(devRoot, projectRoot) {
|
|
47
|
+
const rel = path.relative(devRoot, projectRoot);
|
|
48
|
+
const content = `import { resolve, dirname } from "path";
|
|
49
|
+
import { fileURLToPath } from "url";
|
|
50
|
+
|
|
51
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
52
|
+
|
|
53
|
+
/** @type {import('next').NextConfig} */
|
|
54
|
+
const nextConfig = {
|
|
55
|
+
turbopack: {
|
|
56
|
+
root: resolve(__dirname, "${rel}"),
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
allowedDevOrigins: ['*'],
|
|
60
|
+
|
|
61
|
+
images: {
|
|
62
|
+
remotePatterns: [{ protocol: 'https', hostname: '**' }],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default nextConfig;
|
|
67
|
+
`;
|
|
68
|
+
fs.writeFileSync(path.join(devRoot, "next.config.mjs"), content);
|
|
69
|
+
}
|
|
70
|
+
function generateTsConfig(devRoot, projectRoot) {
|
|
71
|
+
// Paths must be relative to tsconfig location (.cmssy/dev/)
|
|
72
|
+
const rel = path.relative(devRoot, projectRoot);
|
|
73
|
+
// Read project tsconfig to forward user-defined path aliases and includes
|
|
74
|
+
const projectTsConfigPath = path.join(projectRoot, "tsconfig.json");
|
|
75
|
+
let userPaths = {};
|
|
76
|
+
let userIncludes = [];
|
|
77
|
+
if (fs.existsSync(projectTsConfigPath)) {
|
|
78
|
+
try {
|
|
79
|
+
const projectTsConfig = JSON.parse(fs.readFileSync(projectTsConfigPath, "utf-8"));
|
|
80
|
+
const rawPaths = projectTsConfig.compilerOptions?.paths || {};
|
|
81
|
+
// Re-map user paths relative to .cmssy/dev/ (project tsconfig uses baseUrl: ".")
|
|
82
|
+
for (const [alias, targets] of Object.entries(rawPaths)) {
|
|
83
|
+
// Skip cmssy-cli/config — we handle it ourselves
|
|
84
|
+
if (alias === "cmssy-cli/config")
|
|
85
|
+
continue;
|
|
86
|
+
userPaths[alias] = targets.map((t) => `${rel}/${t}`);
|
|
87
|
+
}
|
|
88
|
+
// Re-map user includes relative to .cmssy/dev/
|
|
89
|
+
const rawIncludes = projectTsConfig.include || [];
|
|
90
|
+
userIncludes = rawIncludes.map((inc) => `${rel}/${inc}`);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Ignore parse errors — fall back to defaults
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const tsConfig = {
|
|
97
|
+
compilerOptions: {
|
|
98
|
+
target: "ES2020",
|
|
99
|
+
lib: ["dom", "dom.iterable", "esnext"],
|
|
100
|
+
allowJs: true,
|
|
101
|
+
skipLibCheck: true,
|
|
102
|
+
strict: true,
|
|
103
|
+
noEmit: true,
|
|
104
|
+
esModuleInterop: true,
|
|
105
|
+
module: "esnext",
|
|
106
|
+
moduleResolution: "bundler",
|
|
107
|
+
resolveJsonModule: true,
|
|
108
|
+
isolatedModules: true,
|
|
109
|
+
jsx: "preserve",
|
|
110
|
+
incremental: true,
|
|
111
|
+
plugins: [{ name: "next" }],
|
|
112
|
+
paths: {
|
|
113
|
+
// User-defined aliases from project tsconfig (e.g. @/* for shadcn)
|
|
114
|
+
...userPaths,
|
|
115
|
+
// Cmssy built-in aliases (override user if conflicting)
|
|
116
|
+
"@blocks/*": [`${rel}/blocks/*`],
|
|
117
|
+
"@templates/*": [`${rel}/templates/*`],
|
|
118
|
+
"@styles/*": [`${rel}/styles/*`],
|
|
119
|
+
"@lib/*": [`${rel}/lib/*`],
|
|
120
|
+
"cmssy-cli/config": [`${rel}/node_modules/cmssy-cli/config`],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
include: [
|
|
124
|
+
"next-env.d.ts",
|
|
125
|
+
"**/*.ts",
|
|
126
|
+
"**/*.tsx",
|
|
127
|
+
".next/types/**/*.ts",
|
|
128
|
+
`${rel}/blocks/**/*.ts`,
|
|
129
|
+
`${rel}/blocks/**/*.tsx`,
|
|
130
|
+
`${rel}/templates/**/*.ts`,
|
|
131
|
+
`${rel}/templates/**/*.tsx`,
|
|
132
|
+
// User-defined includes from project tsconfig (e.g. components/**/*, lib/**/*)
|
|
133
|
+
...userIncludes,
|
|
134
|
+
],
|
|
135
|
+
exclude: ["node_modules"],
|
|
136
|
+
};
|
|
137
|
+
fs.writeFileSync(path.join(devRoot, "tsconfig.json"), JSON.stringify(tsConfig, null, 2) + "\n");
|
|
138
|
+
}
|
|
139
|
+
function generateRootLayout(devRoot) {
|
|
140
|
+
const content = `import type { Metadata } from "next";
|
|
141
|
+
import "./globals.css";
|
|
142
|
+
|
|
143
|
+
export const metadata: Metadata = {
|
|
144
|
+
title: "Cmssy Dev Server",
|
|
145
|
+
icons: {
|
|
146
|
+
icon: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect width='100' height='100' rx='20' fill='%23667eea'/%3E%3Ctext x='50' y='70' font-size='60' font-weight='bold' text-anchor='middle' fill='white' font-family='system-ui'%3EC%3C/text%3E%3C/svg%3E",
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default function RootLayout({
|
|
151
|
+
children,
|
|
152
|
+
}: {
|
|
153
|
+
children: React.ReactNode;
|
|
154
|
+
}) {
|
|
155
|
+
return (
|
|
156
|
+
<html lang="en">
|
|
157
|
+
<body>{children}</body>
|
|
158
|
+
</html>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
fs.writeFileSync(path.join(devRoot, "app/layout.tsx"), content);
|
|
163
|
+
}
|
|
164
|
+
function generateGlobalsCss(devRoot, projectRoot) {
|
|
165
|
+
const rel = path.relative(path.join(devRoot, "app"), projectRoot);
|
|
166
|
+
// Check for project CSS files that contain Tailwind / theme
|
|
167
|
+
const cssFiles = ["styles/main.css", "styles/globals.css", "app/globals.css"];
|
|
168
|
+
const projectCssFile = cssFiles.find((f) => fs.existsSync(path.join(projectRoot, f)));
|
|
169
|
+
// Import the project's main CSS (Tailwind + theme) if it exists
|
|
170
|
+
const projectCssImport = projectCssFile
|
|
171
|
+
? `@import "${rel}/${projectCssFile}";\n\n`
|
|
172
|
+
: "";
|
|
173
|
+
const content = `${projectCssImport}*,
|
|
174
|
+
*::before,
|
|
175
|
+
*::after {
|
|
176
|
+
box-sizing: border-box;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
html,
|
|
180
|
+
body {
|
|
181
|
+
height: 100%;
|
|
182
|
+
margin: 0;
|
|
183
|
+
padding: 0;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
body {
|
|
187
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
188
|
+
background: #f5f5f5;
|
|
189
|
+
line-height: 1.5;
|
|
190
|
+
-webkit-font-smoothing: antialiased;
|
|
191
|
+
}
|
|
192
|
+
`;
|
|
193
|
+
fs.writeFileSync(path.join(devRoot, "app/globals.css"), content);
|
|
194
|
+
}
|
|
195
|
+
function generateHomePage(devRoot) {
|
|
196
|
+
// The home page embeds the dev UI as a client component
|
|
197
|
+
// It uses an iframe-based architecture: left sidebar (block list),
|
|
198
|
+
// center (preview iframe), right sidebar (editor)
|
|
199
|
+
const content = `"use client";
|
|
200
|
+
|
|
201
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
202
|
+
|
|
203
|
+
interface Block {
|
|
204
|
+
type: "block" | "template";
|
|
205
|
+
name: string;
|
|
206
|
+
displayName: string;
|
|
207
|
+
description?: string;
|
|
208
|
+
category?: string;
|
|
209
|
+
tags?: string[];
|
|
210
|
+
version: string;
|
|
211
|
+
hasConfig?: boolean;
|
|
212
|
+
schema?: Record<string, any>;
|
|
213
|
+
pages?: Array<{ name: string; slug: string; blocksCount: number }>;
|
|
214
|
+
layoutPositions?: Array<{ position: string; type: string }>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default function DevHome() {
|
|
218
|
+
const [blocks, setBlocks] = useState<Block[]>([]);
|
|
219
|
+
const [selected, setSelected] = useState<Block | null>(null);
|
|
220
|
+
const [previewData, setPreviewData] = useState<Record<string, unknown>>({});
|
|
221
|
+
const [configLoading, setConfigLoading] = useState(false);
|
|
222
|
+
const configDataRef = useRef<Record<string, unknown>>({});
|
|
223
|
+
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
224
|
+
const iframeLoadedRef = useRef(false);
|
|
225
|
+
const [isDirty, setIsDirty] = useState(false);
|
|
226
|
+
const [showBlockList, setShowBlockList] = useState(true);
|
|
227
|
+
const [showEditor, setShowEditor] = useState(true);
|
|
228
|
+
|
|
229
|
+
// Load blocks list
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
fetch("/api/blocks")
|
|
232
|
+
.then((r) => r.json())
|
|
233
|
+
.then(setBlocks)
|
|
234
|
+
.catch(console.error);
|
|
235
|
+
}, []);
|
|
236
|
+
|
|
237
|
+
// Load config when block selected
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (!selected || selected.type === "template") return;
|
|
240
|
+
setConfigLoading(true);
|
|
241
|
+
fetch(\`/api/blocks/\${selected.name}/config\`)
|
|
242
|
+
.then((r) => r.json())
|
|
243
|
+
.then((config) => {
|
|
244
|
+
setSelected((prev) =>
|
|
245
|
+
prev ? { ...prev, schema: config.schema } : null
|
|
246
|
+
);
|
|
247
|
+
const data = config.previewData || {};
|
|
248
|
+
configDataRef.current = data;
|
|
249
|
+
setPreviewData(data);
|
|
250
|
+
setConfigLoading(false);
|
|
251
|
+
})
|
|
252
|
+
.catch(() => setConfigLoading(false));
|
|
253
|
+
}, [selected?.name]);
|
|
254
|
+
|
|
255
|
+
// Select block — templates redirect to full-page preview
|
|
256
|
+
const handleSelect = useCallback((block: Block) => {
|
|
257
|
+
if (block.type === "template") {
|
|
258
|
+
window.location.href = \`/preview/\${block.name}\`;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
setSelected(block);
|
|
262
|
+
setPreviewData({});
|
|
263
|
+
configDataRef.current = {};
|
|
264
|
+
setIsDirty(false);
|
|
265
|
+
iframeLoadedRef.current = false;
|
|
266
|
+
}, []);
|
|
267
|
+
|
|
268
|
+
// Send props to iframe
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
if (!iframeRef.current?.contentWindow || !iframeLoadedRef.current) return;
|
|
271
|
+
if (!previewData || Object.keys(previewData).length === 0) return;
|
|
272
|
+
iframeRef.current.contentWindow.postMessage(
|
|
273
|
+
{ type: "UPDATE_PROPS", props: previewData },
|
|
274
|
+
"*"
|
|
275
|
+
);
|
|
276
|
+
}, [previewData]);
|
|
277
|
+
|
|
278
|
+
// Auto-save preview data
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
if (!isDirty || !selected || Object.keys(configDataRef.current).length === 0) return;
|
|
281
|
+
const t = setTimeout(async () => {
|
|
282
|
+
const dataToSave = { ...configDataRef.current, ...previewData };
|
|
283
|
+
await fetch(\`/api/preview/\${selected.name}\`, {
|
|
284
|
+
method: "POST",
|
|
285
|
+
headers: { "Content-Type": "application/json" },
|
|
286
|
+
body: JSON.stringify(dataToSave),
|
|
287
|
+
});
|
|
288
|
+
setIsDirty(false);
|
|
289
|
+
}, 500);
|
|
290
|
+
return () => clearTimeout(t);
|
|
291
|
+
}, [previewData, selected, isDirty]);
|
|
292
|
+
|
|
293
|
+
// URL state
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
if (blocks.length === 0) return;
|
|
296
|
+
const params = new URLSearchParams(window.location.search);
|
|
297
|
+
const name = params.get("block") || params.get("template");
|
|
298
|
+
if (name) {
|
|
299
|
+
const b = blocks.find((x) => x.name === name);
|
|
300
|
+
if (b) handleSelect(b);
|
|
301
|
+
}
|
|
302
|
+
}, [blocks, handleSelect]);
|
|
303
|
+
|
|
304
|
+
const previewUrl = selected ? \`/preview/\${selected.name}\` : null;
|
|
305
|
+
|
|
306
|
+
function renderField(field: any, value: any, onChange: (val: any) => void) {
|
|
307
|
+
if (field.type === "multiLine" || field.type === "richText") {
|
|
308
|
+
return (
|
|
309
|
+
<textarea
|
|
310
|
+
value={(value as string) || ""}
|
|
311
|
+
onChange={(e) => onChange(e.target.value)}
|
|
312
|
+
placeholder={field.placeholder}
|
|
313
|
+
style={{ width: "100%", padding: "8px", border: "1px solid #ddd", borderRadius: "4px", fontSize: "13px", minHeight: "60px", resize: "vertical", fontFamily: "inherit" }}
|
|
314
|
+
/>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
if (field.type === "boolean") {
|
|
318
|
+
return (
|
|
319
|
+
<label style={{ display: "flex", alignItems: "center", gap: "8px", cursor: "pointer" }}>
|
|
320
|
+
<input
|
|
321
|
+
type="checkbox"
|
|
322
|
+
checked={!!value}
|
|
323
|
+
onChange={(e) => onChange(e.target.checked)}
|
|
324
|
+
/>
|
|
325
|
+
{field.label}
|
|
326
|
+
</label>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
if (field.type === "select") {
|
|
330
|
+
return (
|
|
331
|
+
<select
|
|
332
|
+
value={(value as string) || ""}
|
|
333
|
+
onChange={(e) => onChange(e.target.value)}
|
|
334
|
+
style={{ width: "100%", padding: "8px", border: "1px solid #ddd", borderRadius: "4px", fontSize: "13px" }}
|
|
335
|
+
>
|
|
336
|
+
<option value="">Select...</option>
|
|
337
|
+
{field.options?.map((opt: any) => (
|
|
338
|
+
<option key={opt.value} value={opt.value}>{opt.label}</option>
|
|
339
|
+
))}
|
|
340
|
+
</select>
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
if (field.type === "multiselect") {
|
|
344
|
+
const selected = Array.isArray(value) ? value : [];
|
|
345
|
+
return (
|
|
346
|
+
<div style={{ border: "1px solid #ddd", borderRadius: "4px", padding: "8px", display: "flex", flexWrap: "wrap", gap: "6px" }}>
|
|
347
|
+
{field.options?.map((opt: any) => (
|
|
348
|
+
<label key={opt.value} style={{ display: "flex", alignItems: "center", gap: "4px", fontSize: "13px", cursor: "pointer" }}>
|
|
349
|
+
<input
|
|
350
|
+
type="checkbox"
|
|
351
|
+
checked={selected.includes(opt.value)}
|
|
352
|
+
onChange={(e) => {
|
|
353
|
+
const next = e.target.checked
|
|
354
|
+
? [...selected, opt.value]
|
|
355
|
+
: selected.filter((v: string) => v !== opt.value);
|
|
356
|
+
onChange(next);
|
|
357
|
+
}}
|
|
358
|
+
/>
|
|
359
|
+
{opt.label}
|
|
360
|
+
</label>
|
|
361
|
+
))}
|
|
362
|
+
{!field.options?.length && <span style={{ color: "#999", fontSize: "12px" }}>No options defined</span>}
|
|
363
|
+
</div>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
if (field.type === "date") {
|
|
367
|
+
return (
|
|
368
|
+
<input
|
|
369
|
+
type="date"
|
|
370
|
+
value={(value as string) || ""}
|
|
371
|
+
onChange={(e) => onChange(e.target.value)}
|
|
372
|
+
style={{ width: "100%", padding: "8px", border: "1px solid #ddd", borderRadius: "4px", fontSize: "13px" }}
|
|
373
|
+
/>
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
if (field.type === "slider") {
|
|
377
|
+
const min = field.min ?? 0;
|
|
378
|
+
const max = field.max ?? 100;
|
|
379
|
+
const step = field.step ?? 1;
|
|
380
|
+
return (
|
|
381
|
+
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
|
382
|
+
<input
|
|
383
|
+
type="range"
|
|
384
|
+
min={min}
|
|
385
|
+
max={max}
|
|
386
|
+
step={step}
|
|
387
|
+
value={value ?? min}
|
|
388
|
+
onChange={(e) => onChange(Number(e.target.value))}
|
|
389
|
+
style={{ flex: 1 }}
|
|
390
|
+
/>
|
|
391
|
+
<span style={{ fontSize: "13px", fontWeight: 500, minWidth: "32px", textAlign: "right" }}>{value ?? min}</span>
|
|
392
|
+
</div>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
if (field.type === "media") {
|
|
396
|
+
return (
|
|
397
|
+
<div>
|
|
398
|
+
{value && (
|
|
399
|
+
<div style={{ marginBottom: "6px", borderRadius: "4px", overflow: "hidden", border: "1px solid #ddd" }}>
|
|
400
|
+
<img src={value as string} alt="" style={{ maxWidth: "100%", maxHeight: "120px", objectFit: "contain", display: "block" }} />
|
|
401
|
+
</div>
|
|
402
|
+
)}
|
|
403
|
+
<input
|
|
404
|
+
type="text"
|
|
405
|
+
value={(value as string) || ""}
|
|
406
|
+
onChange={(e) => onChange(e.target.value)}
|
|
407
|
+
placeholder="Image URL"
|
|
408
|
+
style={{ width: "100%", padding: "8px", border: "1px solid #ddd", borderRadius: "4px", fontSize: "13px" }}
|
|
409
|
+
/>
|
|
410
|
+
</div>
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
if (field.type === "repeater" && field.schema) {
|
|
414
|
+
const items = (Array.isArray(value) ? value : []) as any[];
|
|
415
|
+
return (
|
|
416
|
+
<div style={{ border: "1px solid #ddd", borderRadius: "6px", overflow: "hidden" }}>
|
|
417
|
+
{items.map((item: any, idx: number) => (
|
|
418
|
+
<div key={idx} style={{ padding: "12px", borderBottom: "1px solid #eee", background: idx % 2 === 0 ? "#fafafa" : "#fff" }}>
|
|
419
|
+
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "8px" }}>
|
|
420
|
+
<span style={{ fontSize: "12px", fontWeight: 600, color: "#888" }}>#{idx + 1}</span>
|
|
421
|
+
<button
|
|
422
|
+
type="button"
|
|
423
|
+
onClick={() => {
|
|
424
|
+
const newItems = [...items];
|
|
425
|
+
newItems.splice(idx, 1);
|
|
426
|
+
onChange(newItems);
|
|
427
|
+
}}
|
|
428
|
+
style={{ fontSize: "11px", color: "#e53935", background: "none", border: "none", cursor: "pointer" }}
|
|
429
|
+
>× Remove</button>
|
|
430
|
+
</div>
|
|
431
|
+
{Object.entries(field.schema).map(([subKey, subField]: [string, any]) => (
|
|
432
|
+
<div key={subKey} style={{ marginBottom: "8px" }}>
|
|
433
|
+
<label style={{ display: "block", fontSize: "11px", fontWeight: 500, marginBottom: "4px", color: "#666" }}>
|
|
434
|
+
{subField.label || subKey}
|
|
435
|
+
</label>
|
|
436
|
+
{renderField(subField, item[subKey], (subVal) => {
|
|
437
|
+
const newItems = [...items];
|
|
438
|
+
newItems[idx] = { ...newItems[idx], [subKey]: subVal };
|
|
439
|
+
onChange(newItems);
|
|
440
|
+
})}
|
|
441
|
+
</div>
|
|
442
|
+
))}
|
|
443
|
+
</div>
|
|
444
|
+
))}
|
|
445
|
+
<button
|
|
446
|
+
type="button"
|
|
447
|
+
onClick={() => {
|
|
448
|
+
const newItem: any = {};
|
|
449
|
+
Object.entries(field.schema).forEach(([k, f]: [string, any]) => {
|
|
450
|
+
newItem[k] = (f as any).type === "repeater" ? [] : "";
|
|
451
|
+
});
|
|
452
|
+
onChange([...items, newItem]);
|
|
453
|
+
}}
|
|
454
|
+
style={{ width: "100%", padding: "10px", fontSize: "13px", color: "#667eea", background: "none", border: "none", cursor: "pointer", fontWeight: 500 }}
|
|
455
|
+
>+ Add item</button>
|
|
456
|
+
</div>
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
// singleLine, link, numeric, color, form, emailTemplate, emailConfiguration, pageSelector
|
|
460
|
+
return (
|
|
461
|
+
<input
|
|
462
|
+
type={field.type === "numeric" ? "number" : field.type === "color" ? "color" : field.type === "link" ? "url" : "text"}
|
|
463
|
+
value={(value as string) || ""}
|
|
464
|
+
onChange={(e) => onChange(field.type === "numeric" ? Number(e.target.value) : e.target.value)}
|
|
465
|
+
placeholder={field.placeholder || (field.type === "link" ? "https://..." : field.type === "form" || field.type === "emailTemplate" || field.type === "emailConfiguration" || field.type === "pageSelector" ? "Enter ID..." : "")}
|
|
466
|
+
style={{ width: "100%", padding: "8px", border: "1px solid #ddd", borderRadius: "4px", fontSize: "13px" }}
|
|
467
|
+
/>
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return (
|
|
472
|
+
<div style={{ display: "grid", gridTemplateColumns: \`\${showBlockList ? "280px" : "0px"} 1fr \${showEditor ? "400px" : "0px"}\`, height: "100vh", transition: "grid-template-columns 0.2s ease" }}>
|
|
473
|
+
{/* Block List */}
|
|
474
|
+
<div style={{ background: "#fff", borderRight: showBlockList ? "1px solid #e0e0e0" : "none", overflow: showBlockList ? "auto" : "hidden", width: showBlockList ? "auto" : 0 }}>
|
|
475
|
+
<div style={{ padding: "16px", borderBottom: "1px solid #e0e0e0", background: "#fafafa" }}>
|
|
476
|
+
<h1 style={{ fontSize: "18px", fontWeight: 600, margin: 0 }}>Cmssy Dev</h1>
|
|
477
|
+
<p style={{ fontSize: "13px", color: "#666", margin: "4px 0 0" }}>
|
|
478
|
+
{blocks.length} blocks
|
|
479
|
+
</p>
|
|
480
|
+
</div>
|
|
481
|
+
<div style={{ padding: "12px" }}>
|
|
482
|
+
{blocks.map((b) => (
|
|
483
|
+
<div
|
|
484
|
+
key={b.name}
|
|
485
|
+
onClick={() => {
|
|
486
|
+
handleSelect(b);
|
|
487
|
+
const url = new URL(window.location.href);
|
|
488
|
+
url.searchParams.set(b.type === "template" ? "template" : "block", b.name);
|
|
489
|
+
window.history.replaceState({}, "", url.toString());
|
|
490
|
+
}}
|
|
491
|
+
style={{
|
|
492
|
+
padding: "12px 16px",
|
|
493
|
+
marginBottom: "4px",
|
|
494
|
+
borderRadius: "8px",
|
|
495
|
+
cursor: "pointer",
|
|
496
|
+
background: selected?.name === b.name ? "#667eea" : "transparent",
|
|
497
|
+
color: selected?.name === b.name ? "white" : "inherit",
|
|
498
|
+
}}
|
|
499
|
+
>
|
|
500
|
+
<div style={{ fontSize: "14px", fontWeight: 500 }}>{b.displayName}</div>
|
|
501
|
+
<div style={{ fontSize: "12px", opacity: 0.7 }}>
|
|
502
|
+
{b.type} · v{b.version}
|
|
503
|
+
</div>
|
|
504
|
+
</div>
|
|
505
|
+
))}
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
|
|
509
|
+
{/* Preview */}
|
|
510
|
+
<div style={{ background: "#fafafa", display: "flex", flexDirection: "column" }}>
|
|
511
|
+
<div style={{ padding: "10px 16px", background: "white", borderBottom: "1px solid #e0e0e0", display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px" }}>
|
|
512
|
+
<button
|
|
513
|
+
type="button"
|
|
514
|
+
onClick={() => setShowBlockList(!showBlockList)}
|
|
515
|
+
title={showBlockList ? "Hide block list" : "Show block list"}
|
|
516
|
+
style={{ background: showBlockList ? "#f0f0f0" : "#667eea", color: showBlockList ? "#333" : "#fff", border: "1px solid #ddd", borderRadius: "6px", padding: "6px 10px", cursor: "pointer", fontSize: "13px", fontWeight: 500, whiteSpace: "nowrap" }}
|
|
517
|
+
>{showBlockList ? "\u2190 Blocks" : "\u2192 Blocks"}</button>
|
|
518
|
+
<div style={{ flex: 1, fontSize: "16px", fontWeight: 600, textAlign: "center", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
|
519
|
+
{selected?.displayName || "Preview"}
|
|
520
|
+
</div>
|
|
521
|
+
<button
|
|
522
|
+
type="button"
|
|
523
|
+
onClick={() => setShowEditor(!showEditor)}
|
|
524
|
+
title={showEditor ? "Hide editor" : "Show editor"}
|
|
525
|
+
style={{ background: showEditor ? "#f0f0f0" : "#667eea", color: showEditor ? "#333" : "#fff", border: "1px solid #ddd", borderRadius: "6px", padding: "6px 10px", cursor: "pointer", fontSize: "13px", fontWeight: 500, whiteSpace: "nowrap" }}
|
|
526
|
+
>{showEditor ? "Editor \u2192" : "Editor \u2190"}</button>
|
|
527
|
+
</div>
|
|
528
|
+
<div style={{ flex: 1, padding: "24px", display: "flex", alignItems: "center", justifyContent: "center" }}>
|
|
529
|
+
{previewUrl ? (
|
|
530
|
+
<div style={{ width: "100%", height: "100%", background: "white", borderRadius: "12px", boxShadow: "0 2px 8px rgba(0,0,0,0.1)", overflow: "hidden" }}>
|
|
531
|
+
<iframe
|
|
532
|
+
ref={iframeRef}
|
|
533
|
+
src={previewUrl}
|
|
534
|
+
key={previewUrl}
|
|
535
|
+
onLoad={() => { iframeLoadedRef.current = true; }}
|
|
536
|
+
style={{ width: "100%", height: "100%", border: "none" }}
|
|
537
|
+
/>
|
|
538
|
+
</div>
|
|
539
|
+
) : (
|
|
540
|
+
<div style={{ textAlign: "center", color: "#999" }}>
|
|
541
|
+
<p>Select a block to preview</p>
|
|
542
|
+
</div>
|
|
543
|
+
)}
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
|
|
547
|
+
{/* Editor */}
|
|
548
|
+
<div style={{ background: "#fff", borderLeft: showEditor ? "1px solid #e0e0e0" : "none", overflow: showEditor ? "auto" : "hidden", width: showEditor ? "auto" : 0 }}>
|
|
549
|
+
<div style={{ padding: "16px", borderBottom: "1px solid #e0e0e0", background: "#fafafa" }}>
|
|
550
|
+
<h2 style={{ fontSize: "16px", fontWeight: 600, margin: 0 }}>Editor</h2>
|
|
551
|
+
</div>
|
|
552
|
+
<div style={{ padding: "20px" }}>
|
|
553
|
+
{!selected && <p style={{ color: "#999" }}>Select a block to edit</p>}
|
|
554
|
+
{selected && configLoading && <p style={{ color: "#999" }}>Loading...</p>}
|
|
555
|
+
{selected && !configLoading && selected.schema && (
|
|
556
|
+
<div>
|
|
557
|
+
{Object.entries(selected.schema).map(([key, field]: [string, any]) => (
|
|
558
|
+
<div key={key} style={{ marginBottom: "20px" }}>
|
|
559
|
+
<label style={{ display: "block", fontSize: "13px", fontWeight: 500, marginBottom: "6px" }}>
|
|
560
|
+
{field.label || key}
|
|
561
|
+
{field.required && <span style={{ color: "#e53935" }}> *</span>}
|
|
562
|
+
</label>
|
|
563
|
+
{renderField(field, previewData[key], (val) => {
|
|
564
|
+
setPreviewData({ ...previewData, [key]: val });
|
|
565
|
+
setIsDirty(true);
|
|
566
|
+
})}
|
|
567
|
+
{field.helpText && (
|
|
568
|
+
<div style={{ fontSize: "12px", color: "#666", marginTop: "4px" }}>{field.helpText}</div>
|
|
569
|
+
)}
|
|
570
|
+
</div>
|
|
571
|
+
))}
|
|
572
|
+
</div>
|
|
573
|
+
)}
|
|
574
|
+
</div>
|
|
575
|
+
</div>
|
|
576
|
+
</div>
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
`;
|
|
580
|
+
fs.writeFileSync(path.join(devRoot, "app/page.tsx"), content);
|
|
581
|
+
}
|
|
582
|
+
function generateBlocksApiRoute(devRoot) {
|
|
583
|
+
const content = `import { NextResponse } from "next/server";
|
|
584
|
+
import fs from "fs";
|
|
585
|
+
import path from "path";
|
|
586
|
+
|
|
587
|
+
// Project root is passed via env var set by cmssy dev
|
|
588
|
+
const projectRoot = process.env.CMSSY_PROJECT_ROOT || process.cwd();
|
|
589
|
+
|
|
590
|
+
export async function GET() {
|
|
591
|
+
const blocks: any[] = [];
|
|
592
|
+
|
|
593
|
+
// Scan blocks/
|
|
594
|
+
const blocksDir = path.join(projectRoot, "blocks");
|
|
595
|
+
if (fs.existsSync(blocksDir)) {
|
|
596
|
+
const dirs = fs.readdirSync(blocksDir, { withFileTypes: true })
|
|
597
|
+
.filter((d) => d.isDirectory());
|
|
598
|
+
|
|
599
|
+
for (const dir of dirs) {
|
|
600
|
+
const pkgPath = path.join(blocksDir, dir.name, "package.json");
|
|
601
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(fs.readFileSync(pkgPath, "utf-8")) : {};
|
|
602
|
+
blocks.push({
|
|
603
|
+
type: "block",
|
|
604
|
+
name: dir.name,
|
|
605
|
+
displayName: pkg.cmssy?.displayName || dir.name,
|
|
606
|
+
version: pkg.version || "1.0.0",
|
|
607
|
+
category: pkg.cmssy?.category || "other",
|
|
608
|
+
tags: pkg.cmssy?.tags || [],
|
|
609
|
+
description: pkg.description || "",
|
|
610
|
+
hasConfig: fs.existsSync(path.join(blocksDir, dir.name, "block.config.ts")),
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Scan templates/
|
|
616
|
+
const templatesDir = path.join(projectRoot, "templates");
|
|
617
|
+
if (fs.existsSync(templatesDir)) {
|
|
618
|
+
const dirs = fs.readdirSync(templatesDir, { withFileTypes: true })
|
|
619
|
+
.filter((d) => d.isDirectory());
|
|
620
|
+
|
|
621
|
+
for (const dir of dirs) {
|
|
622
|
+
const pkgPath = path.join(templatesDir, dir.name, "package.json");
|
|
623
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(fs.readFileSync(pkgPath, "utf-8")) : {};
|
|
624
|
+
blocks.push({
|
|
625
|
+
type: "template",
|
|
626
|
+
name: dir.name,
|
|
627
|
+
displayName: pkg.cmssy?.displayName || dir.name,
|
|
628
|
+
version: pkg.version || "1.0.0",
|
|
629
|
+
category: pkg.cmssy?.category || "pages",
|
|
630
|
+
tags: pkg.cmssy?.tags || [],
|
|
631
|
+
description: pkg.description || "",
|
|
632
|
+
hasConfig: fs.existsSync(path.join(templatesDir, dir.name, "block.config.ts")),
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return NextResponse.json(blocks);
|
|
638
|
+
}
|
|
639
|
+
`;
|
|
640
|
+
fs.mkdirSync(path.join(devRoot, "app/api/blocks"), { recursive: true });
|
|
641
|
+
fs.writeFileSync(path.join(devRoot, "app/api/blocks/route.ts"), content);
|
|
642
|
+
}
|
|
643
|
+
function generateBlockConfigApiRoute(devRoot) {
|
|
644
|
+
const dir = path.join(devRoot, "app/api/blocks/[name]/config");
|
|
645
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
646
|
+
const content = `import { NextResponse } from "next/server";
|
|
647
|
+
import fs from "fs";
|
|
648
|
+
import path from "path";
|
|
649
|
+
import { execSync } from "child_process";
|
|
650
|
+
|
|
651
|
+
const projectRoot = process.env.CMSSY_PROJECT_ROOT || process.cwd();
|
|
652
|
+
|
|
653
|
+
function loadBlockConfig(blockPath: string): Record<string, unknown> | null {
|
|
654
|
+
const configPath = path.join(blockPath, "block.config.ts");
|
|
655
|
+
if (!fs.existsSync(configPath)) return null;
|
|
656
|
+
|
|
657
|
+
try {
|
|
658
|
+
// Find tsx binary
|
|
659
|
+
const tsxPaths = [
|
|
660
|
+
path.join(projectRoot, "node_modules", ".bin", "tsx"),
|
|
661
|
+
path.join(projectRoot, "node_modules", "cmssy-cli", "node_modules", ".bin", "tsx"),
|
|
662
|
+
];
|
|
663
|
+
const tsxBinary = tsxPaths.find((p) => fs.existsSync(p)) || "npx -y tsx";
|
|
664
|
+
|
|
665
|
+
// Create mock cmssy-cli/config module
|
|
666
|
+
const cacheDir = path.join(projectRoot, ".cmssy", "cache");
|
|
667
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
668
|
+
|
|
669
|
+
const mockConfigPath = path.join(cacheDir, "cmssy-cli-config.mjs");
|
|
670
|
+
fs.writeFileSync(mockConfigPath,
|
|
671
|
+
"export const defineBlock = (config) => config;\\nexport const defineTemplate = (config) => config;"
|
|
672
|
+
);
|
|
673
|
+
|
|
674
|
+
// Replace import path in config
|
|
675
|
+
const configContent = fs.readFileSync(configPath, "utf-8");
|
|
676
|
+
const modified = configContent.replace(
|
|
677
|
+
/from\\s+['"]cmssy-cli\\/config['"]/g,
|
|
678
|
+
\`from '\${mockConfigPath.replace(/\\\\\\\\/g, "/")}'\`
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
const tempPath = path.join(cacheDir, "temp-block-config.ts");
|
|
682
|
+
fs.writeFileSync(tempPath, modified);
|
|
683
|
+
|
|
684
|
+
const evalCode = \`import cfg from '\${tempPath.replace(/\\\\\\\\/g, "/")}'; console.log(JSON.stringify(cfg.default || cfg));\`;
|
|
685
|
+
const cmd = tsxBinary.includes("npx")
|
|
686
|
+
? \`\${tsxBinary} --eval "\${evalCode}"\`
|
|
687
|
+
: \`"\${tsxBinary}" --eval "\${evalCode}"\`;
|
|
688
|
+
|
|
689
|
+
const output = execSync(cmd, {
|
|
690
|
+
encoding: "utf-8",
|
|
691
|
+
cwd: projectRoot,
|
|
692
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
// Clean up
|
|
696
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
697
|
+
try { fs.unlinkSync(mockConfigPath); } catch {}
|
|
698
|
+
|
|
699
|
+
const lines = output.trim().split("\\n");
|
|
700
|
+
return JSON.parse(lines[lines.length - 1]);
|
|
701
|
+
} catch {
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export async function GET(
|
|
707
|
+
_request: Request,
|
|
708
|
+
{ params }: { params: Promise<{ name: string }> }
|
|
709
|
+
) {
|
|
710
|
+
const { name } = await params;
|
|
711
|
+
|
|
712
|
+
// Look in blocks/ first, then templates/
|
|
713
|
+
let blockPath = path.join(projectRoot, "blocks", name);
|
|
714
|
+
if (!fs.existsSync(blockPath)) {
|
|
715
|
+
blockPath = path.join(projectRoot, "templates", name);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (!fs.existsSync(blockPath)) {
|
|
719
|
+
return NextResponse.json({ error: "Block not found" }, { status: 404 });
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// Load preview data
|
|
723
|
+
const previewPath = path.join(blockPath, "preview.json");
|
|
724
|
+
const previewData = fs.existsSync(previewPath)
|
|
725
|
+
? JSON.parse(fs.readFileSync(previewPath, "utf-8"))
|
|
726
|
+
: {};
|
|
727
|
+
|
|
728
|
+
// Load block.config.ts schema
|
|
729
|
+
const config = loadBlockConfig(blockPath);
|
|
730
|
+
|
|
731
|
+
// Check for pages.json (templates)
|
|
732
|
+
const pagesJsonPath = path.join(blockPath, "pages.json");
|
|
733
|
+
const pagesData = fs.existsSync(pagesJsonPath)
|
|
734
|
+
? JSON.parse(fs.readFileSync(pagesJsonPath, "utf-8"))
|
|
735
|
+
: null;
|
|
736
|
+
|
|
737
|
+
return NextResponse.json({
|
|
738
|
+
name,
|
|
739
|
+
schema: config?.schema || {},
|
|
740
|
+
previewData,
|
|
741
|
+
pages: config?.pages,
|
|
742
|
+
layoutPositions: config?.layoutPositions,
|
|
743
|
+
pagesData,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
`;
|
|
747
|
+
fs.writeFileSync(path.join(dir, "route.ts"), content);
|
|
748
|
+
}
|
|
749
|
+
function generatePreviewApiRoute(devRoot) {
|
|
750
|
+
const dir = path.join(devRoot, "app/api/preview/[blockName]");
|
|
751
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
752
|
+
const content = `import { NextResponse } from "next/server";
|
|
753
|
+
import fs from "fs";
|
|
754
|
+
import path from "path";
|
|
755
|
+
|
|
756
|
+
const projectRoot = process.env.CMSSY_PROJECT_ROOT || process.cwd();
|
|
757
|
+
|
|
758
|
+
export async function GET(
|
|
759
|
+
_request: Request,
|
|
760
|
+
{ params }: { params: Promise<{ blockName: string }> }
|
|
761
|
+
) {
|
|
762
|
+
const { blockName } = await params;
|
|
763
|
+
let blockPath = path.join(projectRoot, "blocks", blockName);
|
|
764
|
+
if (!fs.existsSync(blockPath)) {
|
|
765
|
+
blockPath = path.join(projectRoot, "templates", blockName);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const previewPath = path.join(blockPath, "preview.json");
|
|
769
|
+
const data = fs.existsSync(previewPath)
|
|
770
|
+
? JSON.parse(fs.readFileSync(previewPath, "utf-8"))
|
|
771
|
+
: {};
|
|
772
|
+
|
|
773
|
+
return NextResponse.json(data);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
export async function POST(
|
|
777
|
+
request: Request,
|
|
778
|
+
{ params }: { params: Promise<{ blockName: string }> }
|
|
779
|
+
) {
|
|
780
|
+
const { blockName } = await params;
|
|
781
|
+
const body = await request.json();
|
|
782
|
+
|
|
783
|
+
let blockPath = path.join(projectRoot, "blocks", blockName);
|
|
784
|
+
if (!fs.existsSync(blockPath)) {
|
|
785
|
+
blockPath = path.join(projectRoot, "templates", blockName);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const previewPath = path.join(blockPath, "preview.json");
|
|
789
|
+
fs.writeFileSync(previewPath, JSON.stringify(body, null, 2));
|
|
790
|
+
|
|
791
|
+
return NextResponse.json({ success: true });
|
|
792
|
+
}
|
|
793
|
+
`;
|
|
794
|
+
fs.writeFileSync(path.join(dir, "route.ts"), content);
|
|
795
|
+
}
|
|
796
|
+
function generateWorkspacesApiRoute(devRoot) {
|
|
797
|
+
const content = `import { NextResponse } from "next/server";
|
|
798
|
+
|
|
799
|
+
export async function GET() {
|
|
800
|
+
// Workspace listing requires API token - return empty for now
|
|
801
|
+
// The full implementation uses GraphQL client with cmssy configure credentials
|
|
802
|
+
return NextResponse.json([]);
|
|
803
|
+
}
|
|
804
|
+
`;
|
|
805
|
+
fs.writeFileSync(path.join(devRoot, "app/api/workspaces/route.ts"), content);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Convert full block type name to simple name.
|
|
809
|
+
* "@cmssy-marketing/blocks.hero" -> "hero"
|
|
810
|
+
* "@vendor/blocks.pricing-table" -> "pricing-table"
|
|
811
|
+
* "hero" -> "hero" (already simple)
|
|
812
|
+
*/
|
|
813
|
+
function convertBlockTypeToSimple(blockType) {
|
|
814
|
+
let simple = blockType;
|
|
815
|
+
if (simple.includes("/")) {
|
|
816
|
+
simple = simple.split("/").pop();
|
|
817
|
+
}
|
|
818
|
+
if (simple.startsWith("blocks.")) {
|
|
819
|
+
simple = simple.substring(7);
|
|
820
|
+
}
|
|
821
|
+
else if (simple.startsWith("templates.")) {
|
|
822
|
+
simple = simple.substring(10);
|
|
823
|
+
}
|
|
824
|
+
return simple;
|
|
825
|
+
}
|
|
826
|
+
function generatePreviewPages(devRoot, projectRoot, resources) {
|
|
827
|
+
for (const resource of resources) {
|
|
828
|
+
if (resource.type === "template") {
|
|
829
|
+
generateTemplatePreviewPage(devRoot, projectRoot, resource);
|
|
830
|
+
}
|
|
831
|
+
else {
|
|
832
|
+
generateBlockPreviewPage(devRoot, projectRoot, resource);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function generateBlockPreviewPage(devRoot, projectRoot, resource) {
|
|
837
|
+
const pageDir = path.join(devRoot, "app/preview", resource.name);
|
|
838
|
+
fs.mkdirSync(pageDir, { recursive: true });
|
|
839
|
+
const blockSrcDir = path.join(projectRoot, "blocks", resource.name, "src");
|
|
840
|
+
const hasIndex = fs.existsSync(path.join(blockSrcDir, "index.tsx")) ||
|
|
841
|
+
fs.existsSync(path.join(blockSrcDir, "index.ts"));
|
|
842
|
+
const hasCss = fs.existsSync(path.join(blockSrcDir, "index.css"));
|
|
843
|
+
if (!hasIndex)
|
|
844
|
+
return;
|
|
845
|
+
const finalBlockImport = `@blocks/${resource.name}/src/index`;
|
|
846
|
+
const finalCssImport = `@blocks/${resource.name}/src/index.css`;
|
|
847
|
+
const pageContent = `"use client";
|
|
848
|
+
|
|
849
|
+
import { useState, useEffect } from "react";
|
|
850
|
+
import BlockComponent from "${finalBlockImport}";
|
|
851
|
+
${hasCss ? `import "${finalCssImport}";` : ""}
|
|
852
|
+
|
|
853
|
+
export default function ${toPascalCase(resource.name)}Preview() {
|
|
854
|
+
const [data, setData] = useState<Record<string, unknown>>({});
|
|
855
|
+
|
|
856
|
+
useEffect(() => {
|
|
857
|
+
fetch("/api/preview/${resource.name}")
|
|
858
|
+
.then((r) => r.json())
|
|
859
|
+
.then(setData)
|
|
860
|
+
.catch(console.error);
|
|
861
|
+
}, []);
|
|
862
|
+
|
|
863
|
+
useEffect(() => {
|
|
864
|
+
function handleMessage(e: MessageEvent) {
|
|
865
|
+
if (e.data?.type === "UPDATE_PROPS") {
|
|
866
|
+
setData(e.data.props);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
window.addEventListener("message", handleMessage);
|
|
870
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
871
|
+
}, []);
|
|
872
|
+
|
|
873
|
+
return (
|
|
874
|
+
<div>
|
|
875
|
+
<div style={{
|
|
876
|
+
position: "fixed", top: 0, left: 0, right: 0,
|
|
877
|
+
background: "white", borderBottom: "1px solid #e0e0e0",
|
|
878
|
+
padding: "1rem 2rem", zIndex: 1000,
|
|
879
|
+
display: "flex", justifyContent: "space-between", alignItems: "center",
|
|
880
|
+
}}>
|
|
881
|
+
<div style={{ fontSize: "1.25rem", fontWeight: 600 }}>${resource.displayName || resource.name}</div>
|
|
882
|
+
<a href="/" style={{ color: "#667eea", textDecoration: "none", fontWeight: 500 }} target="_parent">
|
|
883
|
+
← Back to Home
|
|
884
|
+
</a>
|
|
885
|
+
</div>
|
|
886
|
+
<div style={{ marginTop: "60px", minHeight: "calc(100vh - 60px)" }}>
|
|
887
|
+
<BlockComponent content={data} />
|
|
888
|
+
</div>
|
|
889
|
+
</div>
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
`;
|
|
893
|
+
fs.writeFileSync(path.join(pageDir, "page.tsx"), pageContent);
|
|
894
|
+
}
|
|
895
|
+
function generateTemplatePreviewPage(devRoot, projectRoot, resource) {
|
|
896
|
+
// Read pages.json from template directory
|
|
897
|
+
const templateDir = path.join(projectRoot, "templates", resource.name);
|
|
898
|
+
const pagesJsonPath = path.join(templateDir, "pages.json");
|
|
899
|
+
if (!fs.existsSync(pagesJsonPath))
|
|
900
|
+
return;
|
|
901
|
+
const pagesData = JSON.parse(fs.readFileSync(pagesJsonPath, "utf-8"));
|
|
902
|
+
const pages = pagesData.pages || [];
|
|
903
|
+
const layoutPositions = pagesData.layoutPositions || {};
|
|
904
|
+
// Collect all unique block types across all pages + layoutPositions
|
|
905
|
+
const blockTypesSet = new Set();
|
|
906
|
+
for (const page of pages) {
|
|
907
|
+
for (const block of page.blocks || []) {
|
|
908
|
+
blockTypesSet.add(convertBlockTypeToSimple(block.type));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
for (const data of Object.values(layoutPositions)) {
|
|
912
|
+
blockTypesSet.add(convertBlockTypeToSimple(data.type));
|
|
913
|
+
}
|
|
914
|
+
// Check which blocks exist in blocks/ dir with src/index.tsx
|
|
915
|
+
const blockImports = [];
|
|
916
|
+
const cssImports = [];
|
|
917
|
+
const componentMapEntries = [];
|
|
918
|
+
for (const blockName of Array.from(blockTypesSet)) {
|
|
919
|
+
const blockSrcDir = path.join(projectRoot, "blocks", blockName, "src");
|
|
920
|
+
const hasIndex = fs.existsSync(path.join(blockSrcDir, "index.tsx")) ||
|
|
921
|
+
fs.existsSync(path.join(blockSrcDir, "index.ts"));
|
|
922
|
+
const hasCss = fs.existsSync(path.join(blockSrcDir, "index.css"));
|
|
923
|
+
if (!hasIndex)
|
|
924
|
+
continue;
|
|
925
|
+
const pascalName = toPascalCase(blockName);
|
|
926
|
+
blockImports.push(`import ${pascalName} from "@blocks/${blockName}/src/index";`);
|
|
927
|
+
if (hasCss) {
|
|
928
|
+
cssImports.push(`import "@blocks/${blockName}/src/index.css";`);
|
|
929
|
+
}
|
|
930
|
+
componentMapEntries.push(` "${blockName}": ${pascalName},`);
|
|
931
|
+
}
|
|
932
|
+
// Generate [[...slug]] catch-all route
|
|
933
|
+
const pageDir = path.join(devRoot, "app/preview", resource.name, "[[...slug]]");
|
|
934
|
+
fs.mkdirSync(pageDir, { recursive: true });
|
|
935
|
+
const pageContent = `"use client";
|
|
936
|
+
|
|
937
|
+
import { useState, useEffect, useRef } from "react";
|
|
938
|
+
import { useParams, useRouter } from "next/navigation";
|
|
939
|
+
${blockImports.join("\n")}
|
|
940
|
+
${cssImports.join("\n")}
|
|
941
|
+
|
|
942
|
+
const BLOCK_COMPONENTS: Record<string, React.ComponentType<any>> = {
|
|
943
|
+
${componentMapEntries.join("\n")}
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
interface BlockData {
|
|
947
|
+
type: string;
|
|
948
|
+
content: Record<string, any>;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
interface PageData {
|
|
952
|
+
name: string;
|
|
953
|
+
slug: string;
|
|
954
|
+
blocks: BlockData[];
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
interface PagesJson {
|
|
958
|
+
layoutPositions?: Record<string, BlockData>;
|
|
959
|
+
pages: PageData[];
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function convertBlockType(type: string): string {
|
|
963
|
+
let simple = type;
|
|
964
|
+
if (simple.includes("/")) simple = simple.split("/").pop()!;
|
|
965
|
+
if (simple.startsWith("blocks.")) simple = simple.substring(7);
|
|
966
|
+
else if (simple.startsWith("templates.")) simple = simple.substring(10);
|
|
967
|
+
return simple;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
export default function ${toPascalCase(resource.name)}TemplatePreview() {
|
|
971
|
+
const params = useParams();
|
|
972
|
+
const router = useRouter();
|
|
973
|
+
const slugParts = (params.slug as string[]) || [];
|
|
974
|
+
const currentSlug = slugParts.length > 0 ? "/" + slugParts.join("/") : "/";
|
|
975
|
+
const tabsRef = useRef<HTMLDivElement>(null);
|
|
976
|
+
const activeTabRef = useRef<HTMLButtonElement>(null);
|
|
977
|
+
|
|
978
|
+
const [pagesData, setPagesData] = useState<PagesJson | null>(null);
|
|
979
|
+
const [contentOverrides, setContentOverrides] = useState<Record<string, BlockData[]>>({});
|
|
980
|
+
const [navVisible, setNavVisible] = useState(true);
|
|
981
|
+
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
982
|
+
const [paletteQuery, setPaletteQuery] = useState("");
|
|
983
|
+
const [navCollapsed, setNavCollapsed] = useState(false);
|
|
984
|
+
const paletteInputRef = useRef<HTMLInputElement>(null);
|
|
985
|
+
|
|
986
|
+
// Fetch pages data from config API
|
|
987
|
+
useEffect(() => {
|
|
988
|
+
fetch("/api/blocks/${resource.name}/config")
|
|
989
|
+
.then((r) => r.json())
|
|
990
|
+
.then((config) => {
|
|
991
|
+
if (config.pagesData) {
|
|
992
|
+
setPagesData(config.pagesData);
|
|
993
|
+
}
|
|
994
|
+
})
|
|
995
|
+
.catch(console.error);
|
|
996
|
+
}, []);
|
|
997
|
+
|
|
998
|
+
// Listen for live content updates from editor
|
|
999
|
+
useEffect(() => {
|
|
1000
|
+
function handleMessage(e: MessageEvent) {
|
|
1001
|
+
if (e.data?.type === "UPDATE_TEMPLATE_CONTENT") {
|
|
1002
|
+
setContentOverrides((prev) => ({
|
|
1003
|
+
...prev,
|
|
1004
|
+
[e.data.pageSlug]: e.data.blocks,
|
|
1005
|
+
}));
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
window.addEventListener("message", handleMessage);
|
|
1009
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
1010
|
+
}, []);
|
|
1011
|
+
|
|
1012
|
+
// Scroll active tab into view
|
|
1013
|
+
useEffect(() => {
|
|
1014
|
+
if (activeTabRef.current && tabsRef.current) {
|
|
1015
|
+
activeTabRef.current.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
|
|
1016
|
+
}
|
|
1017
|
+
}, [currentSlug, pagesData]);
|
|
1018
|
+
|
|
1019
|
+
// Ctrl+K / Cmd+K to open palette
|
|
1020
|
+
useEffect(() => {
|
|
1021
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
1022
|
+
if ((e.metaKey || e.ctrlKey) && e.key === "k") {
|
|
1023
|
+
e.preventDefault();
|
|
1024
|
+
setPaletteOpen((v) => !v);
|
|
1025
|
+
setPaletteQuery("");
|
|
1026
|
+
}
|
|
1027
|
+
if (e.key === "Escape") {
|
|
1028
|
+
setPaletteOpen(false);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
window.addEventListener("keydown", onKeyDown);
|
|
1032
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
1033
|
+
}, []);
|
|
1034
|
+
|
|
1035
|
+
// Focus input when palette opens
|
|
1036
|
+
useEffect(() => {
|
|
1037
|
+
if (paletteOpen && paletteInputRef.current) {
|
|
1038
|
+
paletteInputRef.current.focus();
|
|
1039
|
+
}
|
|
1040
|
+
}, [paletteOpen]);
|
|
1041
|
+
|
|
1042
|
+
// Auto-hide nav on scroll down, show on scroll up
|
|
1043
|
+
useEffect(() => {
|
|
1044
|
+
let lastY = 0;
|
|
1045
|
+
function onScroll() {
|
|
1046
|
+
const y = window.scrollY;
|
|
1047
|
+
if (y > 80 && y > lastY) setNavVisible(false);
|
|
1048
|
+
else setNavVisible(true);
|
|
1049
|
+
lastY = y;
|
|
1050
|
+
}
|
|
1051
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
1052
|
+
return () => window.removeEventListener("scroll", onScroll);
|
|
1053
|
+
}, []);
|
|
1054
|
+
|
|
1055
|
+
if (!pagesData) {
|
|
1056
|
+
return (
|
|
1057
|
+
<div style={{
|
|
1058
|
+
height: "100vh",
|
|
1059
|
+
display: "flex",
|
|
1060
|
+
alignItems: "center",
|
|
1061
|
+
justifyContent: "center",
|
|
1062
|
+
background: "#0a0a0a",
|
|
1063
|
+
}}>
|
|
1064
|
+
<div style={{ textAlign: "center" }}>
|
|
1065
|
+
<div style={{
|
|
1066
|
+
width: "24px",
|
|
1067
|
+
height: "24px",
|
|
1068
|
+
border: "2px solid rgba(255,255,255,0.1)",
|
|
1069
|
+
borderTopColor: "#667eea",
|
|
1070
|
+
borderRadius: "50%",
|
|
1071
|
+
animation: "spin 0.8s linear infinite",
|
|
1072
|
+
margin: "0 auto 16px",
|
|
1073
|
+
}} />
|
|
1074
|
+
<div style={{ color: "rgba(255,255,255,0.4)", fontSize: "13px", letterSpacing: "0.05em" }}>
|
|
1075
|
+
Loading template...
|
|
1076
|
+
</div>
|
|
1077
|
+
</div>
|
|
1078
|
+
<style>{\`@keyframes spin { to { transform: rotate(360deg) } }\`}</style>
|
|
1079
|
+
</div>
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// Find current page
|
|
1084
|
+
const currentPage = pagesData.pages.find((p) => p.slug === currentSlug);
|
|
1085
|
+
if (!currentPage) {
|
|
1086
|
+
return (
|
|
1087
|
+
<div style={{
|
|
1088
|
+
height: "100vh",
|
|
1089
|
+
display: "flex",
|
|
1090
|
+
alignItems: "center",
|
|
1091
|
+
justifyContent: "center",
|
|
1092
|
+
background: "#fafafa",
|
|
1093
|
+
}}>
|
|
1094
|
+
<div style={{ textAlign: "center" }}>
|
|
1095
|
+
<div style={{ fontSize: "48px", marginBottom: "12px", opacity: 0.3 }}>404</div>
|
|
1096
|
+
<div style={{ color: "#666", fontSize: "14px" }}>Page not found: {currentSlug}</div>
|
|
1097
|
+
<button
|
|
1098
|
+
onClick={() => router.push("/preview/${resource.name}")}
|
|
1099
|
+
style={{
|
|
1100
|
+
marginTop: "20px",
|
|
1101
|
+
padding: "8px 20px",
|
|
1102
|
+
background: "#667eea",
|
|
1103
|
+
color: "#fff",
|
|
1104
|
+
border: "none",
|
|
1105
|
+
borderRadius: "6px",
|
|
1106
|
+
fontSize: "13px",
|
|
1107
|
+
cursor: "pointer",
|
|
1108
|
+
}}
|
|
1109
|
+
>Go to homepage</button>
|
|
1110
|
+
</div>
|
|
1111
|
+
</div>
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// Use overrides if available, otherwise use pages.json content
|
|
1116
|
+
const pageBlocks = contentOverrides[currentSlug] || currentPage.blocks || [];
|
|
1117
|
+
|
|
1118
|
+
// Render header layout position
|
|
1119
|
+
const headerData = pagesData.layoutPositions?.header;
|
|
1120
|
+
const headerType = headerData ? convertBlockType(headerData.type) : null;
|
|
1121
|
+
const HeaderComponent = headerType ? BLOCK_COMPONENTS[headerType] : null;
|
|
1122
|
+
|
|
1123
|
+
// Render footer layout position
|
|
1124
|
+
const footerData = pagesData.layoutPositions?.footer;
|
|
1125
|
+
const footerType = footerData ? convertBlockType(footerData.type) : null;
|
|
1126
|
+
const FooterComponent = footerType ? BLOCK_COMPONENTS[footerType] : null;
|
|
1127
|
+
|
|
1128
|
+
// Render sidebar_left layout position
|
|
1129
|
+
const sidebarLeftData = pagesData.layoutPositions?.sidebar_left;
|
|
1130
|
+
const sidebarLeftType = sidebarLeftData ? convertBlockType(sidebarLeftData.type) : null;
|
|
1131
|
+
const SidebarLeftComponent = sidebarLeftType ? BLOCK_COMPONENTS[sidebarLeftType] : null;
|
|
1132
|
+
|
|
1133
|
+
const navigateTo = (slug: string) => {
|
|
1134
|
+
const path = slug === "/" ? "/preview/${resource.name}" : \`/preview/${resource.name}\${slug}\`;
|
|
1135
|
+
router.push(path);
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
return (
|
|
1139
|
+
<>
|
|
1140
|
+
<style>{\`
|
|
1141
|
+
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap');
|
|
1142
|
+
|
|
1143
|
+
.cmssy-nav {
|
|
1144
|
+
position: fixed;
|
|
1145
|
+
top: 0;
|
|
1146
|
+
left: 0;
|
|
1147
|
+
right: 0;
|
|
1148
|
+
z-index: 9999;
|
|
1149
|
+
transform: translateY(\${navVisible ? "0" : "-100%"});
|
|
1150
|
+
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
1151
|
+
}
|
|
1152
|
+
.cmssy-nav-inner {
|
|
1153
|
+
margin: 10px;
|
|
1154
|
+
background: rgba(10, 10, 10, 0.92);
|
|
1155
|
+
backdrop-filter: blur(20px) saturate(180%);
|
|
1156
|
+
-webkit-backdrop-filter: blur(20px) saturate(180%);
|
|
1157
|
+
border-radius: 14px;
|
|
1158
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1159
|
+
box-shadow:
|
|
1160
|
+
0 8px 32px rgba(0, 0, 0, 0.4),
|
|
1161
|
+
0 0 0 1px rgba(255, 255, 255, 0.05) inset;
|
|
1162
|
+
padding: 8px 12px;
|
|
1163
|
+
display: flex;
|
|
1164
|
+
align-items: center;
|
|
1165
|
+
gap: 8px;
|
|
1166
|
+
font-family: 'DM Sans', -apple-system, sans-serif;
|
|
1167
|
+
}
|
|
1168
|
+
.cmssy-back-btn {
|
|
1169
|
+
display: flex;
|
|
1170
|
+
align-items: center;
|
|
1171
|
+
gap: 6px;
|
|
1172
|
+
padding: 6px 12px;
|
|
1173
|
+
background: rgba(255, 255, 255, 0.06);
|
|
1174
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1175
|
+
border-radius: 8px;
|
|
1176
|
+
color: rgba(255, 255, 255, 0.7);
|
|
1177
|
+
font-size: 12px;
|
|
1178
|
+
font-weight: 500;
|
|
1179
|
+
cursor: pointer;
|
|
1180
|
+
text-decoration: none;
|
|
1181
|
+
white-space: nowrap;
|
|
1182
|
+
transition: all 0.15s ease;
|
|
1183
|
+
font-family: inherit;
|
|
1184
|
+
letter-spacing: 0.01em;
|
|
1185
|
+
}
|
|
1186
|
+
.cmssy-back-btn:hover {
|
|
1187
|
+
background: rgba(255, 255, 255, 0.12);
|
|
1188
|
+
color: #fff;
|
|
1189
|
+
}
|
|
1190
|
+
.cmssy-divider {
|
|
1191
|
+
width: 1px;
|
|
1192
|
+
height: 24px;
|
|
1193
|
+
background: rgba(255, 255, 255, 0.1);
|
|
1194
|
+
flex-shrink: 0;
|
|
1195
|
+
}
|
|
1196
|
+
.cmssy-template-name {
|
|
1197
|
+
font-size: 13px;
|
|
1198
|
+
font-weight: 600;
|
|
1199
|
+
color: #fff;
|
|
1200
|
+
white-space: nowrap;
|
|
1201
|
+
letter-spacing: -0.01em;
|
|
1202
|
+
flex-shrink: 0;
|
|
1203
|
+
}
|
|
1204
|
+
.cmssy-tabs-wrapper {
|
|
1205
|
+
flex: 1;
|
|
1206
|
+
overflow-x: auto;
|
|
1207
|
+
overflow-y: hidden;
|
|
1208
|
+
scrollbar-width: none;
|
|
1209
|
+
-ms-overflow-style: none;
|
|
1210
|
+
mask-image: linear-gradient(to right, transparent, black 20px, black calc(100% - 20px), transparent);
|
|
1211
|
+
-webkit-mask-image: linear-gradient(to right, transparent, black 20px, black calc(100% - 20px), transparent);
|
|
1212
|
+
}
|
|
1213
|
+
.cmssy-tabs-wrapper::-webkit-scrollbar {
|
|
1214
|
+
display: none;
|
|
1215
|
+
}
|
|
1216
|
+
.cmssy-tabs {
|
|
1217
|
+
display: flex;
|
|
1218
|
+
gap: 2px;
|
|
1219
|
+
padding: 0 8px;
|
|
1220
|
+
}
|
|
1221
|
+
.cmssy-tab {
|
|
1222
|
+
padding: 5px 12px;
|
|
1223
|
+
font-size: 12px;
|
|
1224
|
+
font-weight: 500;
|
|
1225
|
+
border: none;
|
|
1226
|
+
border-radius: 7px;
|
|
1227
|
+
cursor: pointer;
|
|
1228
|
+
white-space: nowrap;
|
|
1229
|
+
transition: all 0.15s ease;
|
|
1230
|
+
font-family: inherit;
|
|
1231
|
+
letter-spacing: 0.01em;
|
|
1232
|
+
}
|
|
1233
|
+
.cmssy-tab-inactive {
|
|
1234
|
+
background: transparent;
|
|
1235
|
+
color: rgba(255, 255, 255, 0.45);
|
|
1236
|
+
}
|
|
1237
|
+
.cmssy-tab-inactive:hover {
|
|
1238
|
+
background: rgba(255, 255, 255, 0.08);
|
|
1239
|
+
color: rgba(255, 255, 255, 0.8);
|
|
1240
|
+
}
|
|
1241
|
+
.cmssy-tab-active {
|
|
1242
|
+
background: #667eea;
|
|
1243
|
+
color: #fff;
|
|
1244
|
+
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.35);
|
|
1245
|
+
}
|
|
1246
|
+
.cmssy-page-count {
|
|
1247
|
+
font-size: 11px;
|
|
1248
|
+
font-weight: 500;
|
|
1249
|
+
color: rgba(255, 255, 255, 0.3);
|
|
1250
|
+
white-space: nowrap;
|
|
1251
|
+
flex-shrink: 0;
|
|
1252
|
+
padding-right: 4px;
|
|
1253
|
+
}
|
|
1254
|
+
.cmssy-collapse-btn {
|
|
1255
|
+
display: flex;
|
|
1256
|
+
align-items: center;
|
|
1257
|
+
justify-content: center;
|
|
1258
|
+
width: 28px;
|
|
1259
|
+
height: 28px;
|
|
1260
|
+
background: rgba(255, 255, 255, 0.06);
|
|
1261
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1262
|
+
border-radius: 7px;
|
|
1263
|
+
color: rgba(255, 255, 255, 0.5);
|
|
1264
|
+
cursor: pointer;
|
|
1265
|
+
flex-shrink: 0;
|
|
1266
|
+
transition: all 0.15s ease;
|
|
1267
|
+
font-family: inherit;
|
|
1268
|
+
}
|
|
1269
|
+
.cmssy-collapse-btn:hover {
|
|
1270
|
+
background: rgba(255, 255, 255, 0.12);
|
|
1271
|
+
color: #fff;
|
|
1272
|
+
}
|
|
1273
|
+
.cmssy-nav-collapsed .cmssy-nav-inner {
|
|
1274
|
+
padding: 6px 8px;
|
|
1275
|
+
width: fit-content;
|
|
1276
|
+
}
|
|
1277
|
+
.cmssy-nav-pill {
|
|
1278
|
+
display: flex;
|
|
1279
|
+
align-items: center;
|
|
1280
|
+
gap: 8px;
|
|
1281
|
+
font-family: 'DM Sans', -apple-system, sans-serif;
|
|
1282
|
+
}
|
|
1283
|
+
.cmssy-nav-pill-page {
|
|
1284
|
+
font-size: 12px;
|
|
1285
|
+
font-weight: 500;
|
|
1286
|
+
color: rgba(255, 255, 255, 0.7);
|
|
1287
|
+
white-space: nowrap;
|
|
1288
|
+
}
|
|
1289
|
+
.cmssy-search-btn {
|
|
1290
|
+
display: flex;
|
|
1291
|
+
align-items: center;
|
|
1292
|
+
gap: 6px;
|
|
1293
|
+
padding: 5px 10px;
|
|
1294
|
+
background: rgba(255, 255, 255, 0.06);
|
|
1295
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
1296
|
+
border-radius: 7px;
|
|
1297
|
+
color: rgba(255, 255, 255, 0.5);
|
|
1298
|
+
font-size: 11px;
|
|
1299
|
+
font-family: inherit;
|
|
1300
|
+
cursor: pointer;
|
|
1301
|
+
white-space: nowrap;
|
|
1302
|
+
transition: all 0.15s ease;
|
|
1303
|
+
flex-shrink: 0;
|
|
1304
|
+
}
|
|
1305
|
+
.cmssy-search-btn:hover {
|
|
1306
|
+
background: rgba(255, 255, 255, 0.1);
|
|
1307
|
+
color: rgba(255, 255, 255, 0.8);
|
|
1308
|
+
}
|
|
1309
|
+
.cmssy-search-kbd {
|
|
1310
|
+
font-size: 10px;
|
|
1311
|
+
padding: 1px 5px;
|
|
1312
|
+
border-radius: 4px;
|
|
1313
|
+
background: rgba(255, 255, 255, 0.08);
|
|
1314
|
+
color: rgba(255, 255, 255, 0.35);
|
|
1315
|
+
font-family: inherit;
|
|
1316
|
+
}
|
|
1317
|
+
.cmssy-palette-overlay {
|
|
1318
|
+
position: fixed;
|
|
1319
|
+
inset: 0;
|
|
1320
|
+
z-index: 10000;
|
|
1321
|
+
background: rgba(0, 0, 0, 0.5);
|
|
1322
|
+
backdrop-filter: blur(4px);
|
|
1323
|
+
display: flex;
|
|
1324
|
+
align-items: flex-start;
|
|
1325
|
+
justify-content: center;
|
|
1326
|
+
padding-top: 20vh;
|
|
1327
|
+
animation: cmssyFadeIn 0.15s ease;
|
|
1328
|
+
}
|
|
1329
|
+
.cmssy-palette {
|
|
1330
|
+
width: 480px;
|
|
1331
|
+
max-width: calc(100vw - 32px);
|
|
1332
|
+
background: #1a1a1a;
|
|
1333
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
1334
|
+
border-radius: 14px;
|
|
1335
|
+
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
|
|
1336
|
+
overflow: hidden;
|
|
1337
|
+
animation: cmssySlideUp 0.15s ease;
|
|
1338
|
+
font-family: 'DM Sans', -apple-system, sans-serif;
|
|
1339
|
+
}
|
|
1340
|
+
.cmssy-palette-input-wrapper {
|
|
1341
|
+
display: flex;
|
|
1342
|
+
align-items: center;
|
|
1343
|
+
padding: 14px 16px;
|
|
1344
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
|
1345
|
+
gap: 10px;
|
|
1346
|
+
}
|
|
1347
|
+
.cmssy-palette-input {
|
|
1348
|
+
flex: 1;
|
|
1349
|
+
background: none;
|
|
1350
|
+
border: none;
|
|
1351
|
+
outline: none;
|
|
1352
|
+
color: #fff;
|
|
1353
|
+
font-size: 15px;
|
|
1354
|
+
font-family: inherit;
|
|
1355
|
+
letter-spacing: -0.01em;
|
|
1356
|
+
}
|
|
1357
|
+
.cmssy-palette-input::placeholder {
|
|
1358
|
+
color: rgba(255, 255, 255, 0.3);
|
|
1359
|
+
}
|
|
1360
|
+
.cmssy-palette-list {
|
|
1361
|
+
max-height: 340px;
|
|
1362
|
+
overflow-y: auto;
|
|
1363
|
+
padding: 6px;
|
|
1364
|
+
scrollbar-width: thin;
|
|
1365
|
+
scrollbar-color: rgba(255,255,255,0.1) transparent;
|
|
1366
|
+
}
|
|
1367
|
+
.cmssy-palette-item {
|
|
1368
|
+
display: flex;
|
|
1369
|
+
align-items: center;
|
|
1370
|
+
justify-content: space-between;
|
|
1371
|
+
padding: 10px 12px;
|
|
1372
|
+
border-radius: 8px;
|
|
1373
|
+
cursor: pointer;
|
|
1374
|
+
transition: background 0.1s ease;
|
|
1375
|
+
border: none;
|
|
1376
|
+
background: none;
|
|
1377
|
+
width: 100%;
|
|
1378
|
+
text-align: left;
|
|
1379
|
+
font-family: inherit;
|
|
1380
|
+
}
|
|
1381
|
+
.cmssy-palette-item:hover {
|
|
1382
|
+
background: rgba(255, 255, 255, 0.06);
|
|
1383
|
+
}
|
|
1384
|
+
.cmssy-palette-item-active {
|
|
1385
|
+
background: rgba(102, 126, 234, 0.15);
|
|
1386
|
+
}
|
|
1387
|
+
.cmssy-palette-item-active:hover {
|
|
1388
|
+
background: rgba(102, 126, 234, 0.2);
|
|
1389
|
+
}
|
|
1390
|
+
.cmssy-palette-item-name {
|
|
1391
|
+
font-size: 14px;
|
|
1392
|
+
font-weight: 500;
|
|
1393
|
+
color: #fff;
|
|
1394
|
+
}
|
|
1395
|
+
.cmssy-palette-item-slug {
|
|
1396
|
+
font-size: 12px;
|
|
1397
|
+
color: rgba(255, 255, 255, 0.3);
|
|
1398
|
+
font-family: monospace;
|
|
1399
|
+
}
|
|
1400
|
+
.cmssy-palette-item-current {
|
|
1401
|
+
font-size: 10px;
|
|
1402
|
+
padding: 2px 8px;
|
|
1403
|
+
border-radius: 4px;
|
|
1404
|
+
background: #667eea;
|
|
1405
|
+
color: #fff;
|
|
1406
|
+
font-weight: 600;
|
|
1407
|
+
letter-spacing: 0.03em;
|
|
1408
|
+
}
|
|
1409
|
+
.cmssy-palette-empty {
|
|
1410
|
+
padding: 24px 16px;
|
|
1411
|
+
text-align: center;
|
|
1412
|
+
color: rgba(255, 255, 255, 0.3);
|
|
1413
|
+
font-size: 13px;
|
|
1414
|
+
}
|
|
1415
|
+
@keyframes cmssyFadeIn {
|
|
1416
|
+
from { opacity: 0; }
|
|
1417
|
+
to { opacity: 1; }
|
|
1418
|
+
}
|
|
1419
|
+
@keyframes cmssySlideUp {
|
|
1420
|
+
from { opacity: 0; transform: translateY(8px) scale(0.98); }
|
|
1421
|
+
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
1422
|
+
}
|
|
1423
|
+
\`}</style>
|
|
1424
|
+
|
|
1425
|
+
{/* Floating Navigation Bar */}
|
|
1426
|
+
<div className={\`cmssy-nav \${navCollapsed ? "cmssy-nav-collapsed" : ""}\`}>
|
|
1427
|
+
<div className="cmssy-nav-inner">
|
|
1428
|
+
{navCollapsed ? (
|
|
1429
|
+
<div className="cmssy-nav-pill">
|
|
1430
|
+
<a href="/" className="cmssy-back-btn">
|
|
1431
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1432
|
+
<polyline points="15 18 9 12 15 6" />
|
|
1433
|
+
</svg>
|
|
1434
|
+
Dev
|
|
1435
|
+
</a>
|
|
1436
|
+
<div className="cmssy-divider" />
|
|
1437
|
+
<div className="cmssy-nav-pill-page">{currentPage?.name || "—"}</div>
|
|
1438
|
+
<button
|
|
1439
|
+
className="cmssy-search-btn"
|
|
1440
|
+
onClick={() => { setPaletteOpen(true); setPaletteQuery(""); }}
|
|
1441
|
+
title="Search pages (Ctrl+K)"
|
|
1442
|
+
>
|
|
1443
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1444
|
+
<circle cx="11" cy="11" r="8" />
|
|
1445
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1446
|
+
</svg>
|
|
1447
|
+
<span className="cmssy-search-kbd">\u2318K</span>
|
|
1448
|
+
</button>
|
|
1449
|
+
<button
|
|
1450
|
+
className="cmssy-collapse-btn"
|
|
1451
|
+
onClick={() => setNavCollapsed(false)}
|
|
1452
|
+
title="Expand navigation"
|
|
1453
|
+
>
|
|
1454
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1455
|
+
<polyline points="6 9 12 15 18 9" />
|
|
1456
|
+
</svg>
|
|
1457
|
+
</button>
|
|
1458
|
+
</div>
|
|
1459
|
+
) : (
|
|
1460
|
+
<>
|
|
1461
|
+
<a href="/" className="cmssy-back-btn">
|
|
1462
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1463
|
+
<polyline points="15 18 9 12 15 6" />
|
|
1464
|
+
</svg>
|
|
1465
|
+
Dev
|
|
1466
|
+
</a>
|
|
1467
|
+
|
|
1468
|
+
<div className="cmssy-divider" />
|
|
1469
|
+
|
|
1470
|
+
<div className="cmssy-template-name">${resource.displayName || resource.name}</div>
|
|
1471
|
+
|
|
1472
|
+
<div className="cmssy-divider" />
|
|
1473
|
+
|
|
1474
|
+
<div className="cmssy-tabs-wrapper" ref={tabsRef}>
|
|
1475
|
+
<div className="cmssy-tabs">
|
|
1476
|
+
{pagesData.pages.map((page) => (
|
|
1477
|
+
<button
|
|
1478
|
+
key={page.slug}
|
|
1479
|
+
ref={page.slug === currentSlug ? activeTabRef : undefined}
|
|
1480
|
+
onClick={() => navigateTo(page.slug)}
|
|
1481
|
+
className={\`cmssy-tab \${page.slug === currentSlug ? "cmssy-tab-active" : "cmssy-tab-inactive"}\`}
|
|
1482
|
+
>
|
|
1483
|
+
{page.name}
|
|
1484
|
+
</button>
|
|
1485
|
+
))}
|
|
1486
|
+
</div>
|
|
1487
|
+
</div>
|
|
1488
|
+
|
|
1489
|
+
<button
|
|
1490
|
+
className="cmssy-search-btn"
|
|
1491
|
+
onClick={() => { setPaletteOpen(true); setPaletteQuery(""); }}
|
|
1492
|
+
title="Search pages (Ctrl+K)"
|
|
1493
|
+
>
|
|
1494
|
+
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1495
|
+
<circle cx="11" cy="11" r="8" />
|
|
1496
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1497
|
+
</svg>
|
|
1498
|
+
<span className="cmssy-search-kbd">\u2318K</span>
|
|
1499
|
+
</button>
|
|
1500
|
+
|
|
1501
|
+
<button
|
|
1502
|
+
className="cmssy-collapse-btn"
|
|
1503
|
+
onClick={() => setNavCollapsed(true)}
|
|
1504
|
+
title="Collapse navigation"
|
|
1505
|
+
>
|
|
1506
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1507
|
+
<polyline points="18 15 12 9 6 15" />
|
|
1508
|
+
</svg>
|
|
1509
|
+
</button>
|
|
1510
|
+
</>
|
|
1511
|
+
)}
|
|
1512
|
+
</div>
|
|
1513
|
+
</div>
|
|
1514
|
+
|
|
1515
|
+
{/* Command Palette */}
|
|
1516
|
+
{paletteOpen && (
|
|
1517
|
+
<div className="cmssy-palette-overlay" onClick={() => setPaletteOpen(false)}>
|
|
1518
|
+
<div className="cmssy-palette" onClick={(e) => e.stopPropagation()}>
|
|
1519
|
+
<div className="cmssy-palette-input-wrapper">
|
|
1520
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.4)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
1521
|
+
<circle cx="11" cy="11" r="8" />
|
|
1522
|
+
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
1523
|
+
</svg>
|
|
1524
|
+
<input
|
|
1525
|
+
ref={paletteInputRef}
|
|
1526
|
+
type="text"
|
|
1527
|
+
className="cmssy-palette-input"
|
|
1528
|
+
placeholder="Search pages..."
|
|
1529
|
+
value={paletteQuery}
|
|
1530
|
+
onChange={(e) => setPaletteQuery(e.target.value)}
|
|
1531
|
+
onKeyDown={(e) => {
|
|
1532
|
+
if (e.key === "Enter") {
|
|
1533
|
+
const q = paletteQuery.toLowerCase();
|
|
1534
|
+
const match = pagesData.pages.find(
|
|
1535
|
+
(p) => p.name.toLowerCase().includes(q) || p.slug.toLowerCase().includes(q)
|
|
1536
|
+
);
|
|
1537
|
+
if (match) {
|
|
1538
|
+
navigateTo(match.slug);
|
|
1539
|
+
setPaletteOpen(false);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}}
|
|
1543
|
+
/>
|
|
1544
|
+
</div>
|
|
1545
|
+
<div className="cmssy-palette-list">
|
|
1546
|
+
{(() => {
|
|
1547
|
+
const q = paletteQuery.toLowerCase();
|
|
1548
|
+
const filtered = pagesData.pages.filter(
|
|
1549
|
+
(p) => p.name.toLowerCase().includes(q) || p.slug.toLowerCase().includes(q)
|
|
1550
|
+
);
|
|
1551
|
+
if (filtered.length === 0) {
|
|
1552
|
+
return <div className="cmssy-palette-empty">No pages match “{paletteQuery}”</div>;
|
|
1553
|
+
}
|
|
1554
|
+
return filtered.map((page) => (
|
|
1555
|
+
<button
|
|
1556
|
+
key={page.slug}
|
|
1557
|
+
className={\`cmssy-palette-item \${page.slug === currentSlug ? "cmssy-palette-item-active" : ""}\`}
|
|
1558
|
+
onClick={() => {
|
|
1559
|
+
navigateTo(page.slug);
|
|
1560
|
+
setPaletteOpen(false);
|
|
1561
|
+
}}
|
|
1562
|
+
>
|
|
1563
|
+
<div>
|
|
1564
|
+
<div className="cmssy-palette-item-name">{page.name}</div>
|
|
1565
|
+
<div className="cmssy-palette-item-slug">{page.slug}</div>
|
|
1566
|
+
</div>
|
|
1567
|
+
{page.slug === currentSlug && (
|
|
1568
|
+
<span className="cmssy-palette-item-current">Current</span>
|
|
1569
|
+
)}
|
|
1570
|
+
</button>
|
|
1571
|
+
));
|
|
1572
|
+
})()}
|
|
1573
|
+
</div>
|
|
1574
|
+
</div>
|
|
1575
|
+
</div>
|
|
1576
|
+
)}
|
|
1577
|
+
|
|
1578
|
+
{/* Page Content */}
|
|
1579
|
+
<div>
|
|
1580
|
+
{HeaderComponent && headerData && (
|
|
1581
|
+
<HeaderComponent content={headerData.content || {}} />
|
|
1582
|
+
)}
|
|
1583
|
+
{SidebarLeftComponent && sidebarLeftData ? (
|
|
1584
|
+
<div style={{ display: "grid", gridTemplateColumns: "280px 1fr", minHeight: "100vh" }}>
|
|
1585
|
+
<SidebarLeftComponent content={sidebarLeftData.content || {}} />
|
|
1586
|
+
<main>
|
|
1587
|
+
{pageBlocks.map((block, idx) => {
|
|
1588
|
+
const blockType = convertBlockType(block.type);
|
|
1589
|
+
const Component = BLOCK_COMPONENTS[blockType];
|
|
1590
|
+
if (!Component) {
|
|
1591
|
+
return (
|
|
1592
|
+
<div key={idx} style={{
|
|
1593
|
+
padding: "2rem",
|
|
1594
|
+
background: "#fff3cd",
|
|
1595
|
+
textAlign: "center",
|
|
1596
|
+
margin: "1rem",
|
|
1597
|
+
borderRadius: "8px",
|
|
1598
|
+
fontSize: "14px",
|
|
1599
|
+
color: "#856404",
|
|
1600
|
+
}}>
|
|
1601
|
+
Missing block component: {blockType}
|
|
1602
|
+
</div>
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
return <Component key={idx} content={block.content || {}} />;
|
|
1606
|
+
})}
|
|
1607
|
+
</main>
|
|
1608
|
+
</div>
|
|
1609
|
+
) : (
|
|
1610
|
+
pageBlocks.map((block, idx) => {
|
|
1611
|
+
const blockType = convertBlockType(block.type);
|
|
1612
|
+
const Component = BLOCK_COMPONENTS[blockType];
|
|
1613
|
+
if (!Component) {
|
|
1614
|
+
return (
|
|
1615
|
+
<div key={idx} style={{
|
|
1616
|
+
padding: "2rem",
|
|
1617
|
+
background: "#fff3cd",
|
|
1618
|
+
textAlign: "center",
|
|
1619
|
+
margin: "1rem",
|
|
1620
|
+
borderRadius: "8px",
|
|
1621
|
+
fontSize: "14px",
|
|
1622
|
+
color: "#856404",
|
|
1623
|
+
}}>
|
|
1624
|
+
Missing block component: {blockType}
|
|
1625
|
+
</div>
|
|
1626
|
+
);
|
|
1627
|
+
}
|
|
1628
|
+
return <Component key={idx} content={block.content || {}} />;
|
|
1629
|
+
})
|
|
1630
|
+
)}
|
|
1631
|
+
{FooterComponent && footerData && (
|
|
1632
|
+
<FooterComponent content={footerData.content || {}} />
|
|
1633
|
+
)}
|
|
1634
|
+
</div>
|
|
1635
|
+
</>
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
`;
|
|
1639
|
+
fs.writeFileSync(path.join(pageDir, "page.tsx"), pageContent);
|
|
1640
|
+
}
|
|
1641
|
+
function toPascalCase(str) {
|
|
1642
|
+
return str
|
|
1643
|
+
.split(/[-_\s]+/)
|
|
1644
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
1645
|
+
.join("");
|
|
1646
|
+
}
|
|
1647
|
+
//# sourceMappingURL=dev-generator.js.map
|