zelune 0.0.0-stage → 1.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/CHANGELOG.md +57 -0
- package/DESIGN.md +90 -0
- package/PRODUCT.md +31 -0
- package/README.md +63 -2
- package/assets/logo.svg +8 -0
- package/bin/cli.mjs +243 -0
- package/index.html +18 -0
- package/mcp/server.ts +140 -0
- package/mcp_config.json +8 -0
- package/package.json +77 -4
- package/plugin.json +12 -0
- package/plugins/viteRnSourceInject.ts +117 -0
- package/plugins/viteVirtualScreensPlugin.ts +85 -0
- package/rules/AGENTS.md +21 -0
- package/skills/rn-canvas/SKILL.md +33 -0
- package/src/canvas/CanvasApp.tsx +1203 -0
- package/src/canvas/FlowArrowsLayer.tsx +197 -0
- package/src/canvas/InspectorPanel.tsx +979 -0
- package/src/canvas/ScreenArtboard.tsx +451 -0
- package/src/canvas/types.ts +23 -0
- package/src/main.tsx +10 -0
- package/src/runtime/MockNavigationContext.tsx +199 -0
- package/src/runtime/ScreenErrorBoundary.tsx +86 -0
- package/src/screens/CheckoutScreen.tsx +229 -0
- package/src/screens/HomeScreen.tsx +288 -0
- package/src/screens/LoginScreen.tsx +176 -0
- package/src/screens/ProductDetailScreen.tsx +234 -0
- package/src/screens/ProfileScreen.tsx +172 -0
- package/src/screens/index.ts +1 -0
- package/src/server/apiMiddleware.ts +154 -0
- package/src/server/astEngine.ts +877 -0
- package/src/styles.css +298 -0
- package/src/vite-env.d.ts +7 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +81 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import type { Plugin } from 'vite';
|
|
5
|
+
import {
|
|
6
|
+
discoverScreens,
|
|
7
|
+
inspectElement,
|
|
8
|
+
patchElement,
|
|
9
|
+
undoLastPatch,
|
|
10
|
+
redoLastPatch,
|
|
11
|
+
getHistoryStatus,
|
|
12
|
+
type PatchPayload,
|
|
13
|
+
} from './astEngine';
|
|
14
|
+
|
|
15
|
+
async function readJsonBody<T>(req: IncomingMessage): Promise<T> {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
let raw = '';
|
|
18
|
+
req.on('data', (chunk) => {
|
|
19
|
+
raw += chunk.toString();
|
|
20
|
+
if (raw.length > 1_000_000) {
|
|
21
|
+
reject(new Error('Request payload too large'));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
req.on('end', () => {
|
|
25
|
+
try {
|
|
26
|
+
resolve(raw ? (JSON.parse(raw) as T) : ({} as T));
|
|
27
|
+
} catch (err) {
|
|
28
|
+
reject(err);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
req.on('error', reject);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function sendJson(res: ServerResponse, status: number, payload: unknown) {
|
|
36
|
+
res.statusCode = status;
|
|
37
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
38
|
+
res.end(JSON.stringify(payload));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function viteCanvasApiMiddleware(workspaceRoot: string): Plugin {
|
|
42
|
+
const layoutFilePath = path.resolve(workspaceRoot, '.canvas-layout.json');
|
|
43
|
+
|
|
44
|
+
async function resolveConnectedProjectName(): Promise<string> {
|
|
45
|
+
const dirName = path.basename(workspaceRoot);
|
|
46
|
+
try {
|
|
47
|
+
const appJsonRaw = await fs.readFile(path.join(workspaceRoot, 'app.json'), 'utf-8');
|
|
48
|
+
const appJson = JSON.parse(appJsonRaw) as {
|
|
49
|
+
expo?: { name?: string };
|
|
50
|
+
name?: string;
|
|
51
|
+
};
|
|
52
|
+
if (appJson?.expo?.name) return appJson.expo.name;
|
|
53
|
+
if (appJson?.name) return appJson.name;
|
|
54
|
+
} catch {
|
|
55
|
+
// No app.json present
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const pkgRaw = await fs.readFile(path.join(workspaceRoot, 'package.json'), 'utf-8');
|
|
59
|
+
const pkg = JSON.parse(pkgRaw) as { name?: string };
|
|
60
|
+
if (pkg?.name && pkg.name.toLowerCase() !== 'zelune') {
|
|
61
|
+
return pkg.name;
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
// Fallback to directory name
|
|
65
|
+
}
|
|
66
|
+
return dirName;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
name: 'vite-canvas-api-middleware',
|
|
71
|
+
configureServer(server) {
|
|
72
|
+
server.middlewares.use(async (req, res, next) => {
|
|
73
|
+
if (!req.url || !req.url.startsWith('/api/')) {
|
|
74
|
+
return next();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const urlObj = new URL(req.url, 'http://127.0.0.1');
|
|
78
|
+
const pathname = urlObj.pathname;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
// GET /api/screens
|
|
82
|
+
if (req.method === 'GET' && pathname === '/api/screens') {
|
|
83
|
+
const [screens, projectName] = await Promise.all([
|
|
84
|
+
discoverScreens(workspaceRoot),
|
|
85
|
+
resolveConnectedProjectName(),
|
|
86
|
+
]);
|
|
87
|
+
const history = getHistoryStatus();
|
|
88
|
+
return sendJson(res, 200, { ok: true, projectName, screens, history });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// GET /api/inspect?file=...&astPath=...&line=...
|
|
92
|
+
if (req.method === 'GET' && pathname === '/api/inspect') {
|
|
93
|
+
const file = urlObj.searchParams.get('file') ?? '';
|
|
94
|
+
const astPath = urlObj.searchParams.get('astPath') ?? '';
|
|
95
|
+
const lineParam = urlObj.searchParams.get('line');
|
|
96
|
+
const line = lineParam ? Number.parseInt(lineParam, 10) : undefined;
|
|
97
|
+
|
|
98
|
+
const element = await inspectElement(workspaceRoot, { file, astPath, line });
|
|
99
|
+
const history = getHistoryStatus();
|
|
100
|
+
return sendJson(res, 200, { ok: true, element, history });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// POST /api/patch
|
|
104
|
+
if (req.method === 'POST' && pathname === '/api/patch') {
|
|
105
|
+
const body = await readJsonBody<PatchPayload>(req);
|
|
106
|
+
const result = await patchElement(workspaceRoot, body);
|
|
107
|
+
return sendJson(res, 200, {
|
|
108
|
+
ok: true,
|
|
109
|
+
element: result.element,
|
|
110
|
+
history: {
|
|
111
|
+
undoAvailable: result.undoAvailable,
|
|
112
|
+
redoAvailable: result.redoAvailable,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// POST /api/undo
|
|
118
|
+
if (req.method === 'POST' && pathname === '/api/undo') {
|
|
119
|
+
const result = await undoLastPatch(workspaceRoot);
|
|
120
|
+
return sendJson(res, 200, { ok: true, ...result });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// POST /api/redo
|
|
124
|
+
if (req.method === 'POST' && pathname === '/api/redo') {
|
|
125
|
+
const result = await redoLastPatch(workspaceRoot);
|
|
126
|
+
return sendJson(res, 200, { ok: true, ...result });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// GET /api/layout
|
|
130
|
+
if (req.method === 'GET' && pathname === '/api/layout') {
|
|
131
|
+
try {
|
|
132
|
+
const raw = await fs.readFile(layoutFilePath, 'utf-8');
|
|
133
|
+
return sendJson(res, 200, { ok: true, layout: JSON.parse(raw) });
|
|
134
|
+
} catch {
|
|
135
|
+
return sendJson(res, 200, { ok: true, layout: null });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// POST /api/layout
|
|
140
|
+
if (req.method === 'POST' && pathname === '/api/layout') {
|
|
141
|
+
const body = await readJsonBody<Record<string, unknown>>(req);
|
|
142
|
+
await fs.writeFile(layoutFilePath, JSON.stringify(body, null, 2), 'utf-8');
|
|
143
|
+
return sendJson(res, 200, { ok: true });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return sendJson(res, 404, { ok: false, error: `Unknown API route: ${pathname}` });
|
|
147
|
+
} catch (err) {
|
|
148
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
149
|
+
return sendJson(res, 400, { ok: false, error: message });
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|