zelune 1.5.7 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,11 +8,17 @@ import {
8
8
  inspectElement,
9
9
  patchElement,
10
10
  reorderElement,
11
+ insertElement,
12
+ duplicateElement,
13
+ deleteElement,
11
14
  undoLastPatch,
12
15
  redoLastPatch,
13
16
  getHistoryStatus,
14
17
  type PatchPayload,
15
18
  type ReorderPayload,
19
+ type InsertElementPayload,
20
+ type DuplicateElementPayload,
21
+ type DeleteElementPayload,
16
22
  } from './astEngine';
17
23
 
18
24
  const MAX_BODY_BYTES = 1_000_000;
@@ -285,6 +291,48 @@ export function viteCanvasApiMiddleware(workspaceRoot: string): Plugin {
285
291
  });
286
292
  }
287
293
 
294
+ // POST /api/insert
295
+ if (req.method === 'POST' && pathname === '/api/insert') {
296
+ const body = await readJsonBody<InsertElementPayload>(req);
297
+ const result = await insertElement(workspaceRoot, body);
298
+ return sendJson(res, 200, {
299
+ ok: true,
300
+ element: result.element,
301
+ history: {
302
+ undoAvailable: result.undoAvailable,
303
+ redoAvailable: result.redoAvailable,
304
+ },
305
+ });
306
+ }
307
+
308
+ // POST /api/duplicate
309
+ if (req.method === 'POST' && pathname === '/api/duplicate') {
310
+ const body = await readJsonBody<DuplicateElementPayload>(req);
311
+ const result = await duplicateElement(workspaceRoot, body);
312
+ return sendJson(res, 200, {
313
+ ok: true,
314
+ element: result.element,
315
+ history: {
316
+ undoAvailable: result.undoAvailable,
317
+ redoAvailable: result.redoAvailable,
318
+ },
319
+ });
320
+ }
321
+
322
+ // POST /api/delete
323
+ if (req.method === 'POST' && pathname === '/api/delete') {
324
+ const body = await readJsonBody<DeleteElementPayload>(req);
325
+ const result = await deleteElement(workspaceRoot, body);
326
+ return sendJson(res, 200, {
327
+ ok: true,
328
+ deletedAstPath: result.deletedAstPath,
329
+ history: {
330
+ undoAvailable: result.undoAvailable,
331
+ redoAvailable: result.redoAvailable,
332
+ },
333
+ });
334
+ }
335
+
288
336
  // POST /api/undo
289
337
  if (req.method === 'POST' && pathname === '/api/undo') {
290
338
  const result = await undoLastPatch(workspaceRoot);