From 62950be0320234914cc83e8f340c0bcf81ed60d8 Mon Sep 17 00:00:00 2001 From: Peaceultime Date: Thu, 9 Jan 2025 16:41:36 +0100 Subject: [PATCH] Minimal history handler, handle node move. Auto parse JSON content for accurate typing. --- components/CanvasEditor.vue | 283 ++++++++++++++++--------- components/canvas/CanvasNodeEditor.vue | 105 +++++++++ pages/explore/edit/index.vue | 8 +- server/api/file/content/[path].get.ts | 4 +- shared/general.utils.ts | 15 ++ types/content.d.ts | 2 +- 6 files changed, 315 insertions(+), 102 deletions(-) create mode 100644 components/canvas/CanvasNodeEditor.vue diff --git a/components/CanvasEditor.vue b/components/CanvasEditor.vue index 410578c..9f3bbb7 100644 --- a/components/CanvasEditor.vue +++ b/components/CanvasEditor.vue @@ -8,7 +8,22 @@ const rotation: Record = { right: "270" }; +interface ActionMap { + move: Position; + edit: string; + resize: string; +} +type Action = keyof ActionMap; +interface HistoryAction +{ + event: T; + element: number | number[]; + from: ActionMap[T]; + to: ActionMap[T]; +} + const cancelEvent = (e: Event) => e.preventDefault(); +const stopPropagation = (e: Event) => e.stopImmediatePropagation(); function center(touches: TouchList): Position { const pos = { x: 0, y: 0 }; @@ -28,38 +43,37 @@ function distance(touches: TouchList): number const [A, B] = touches; return Math.hypot(B.clientX - A.clientX, B.clientY - A.clientY); } +function contains(group: CanvasNode, node: CanvasNode): boolean +{ + return group.x < node.x && group.y < node.y && group.x + group.width > node.x + node.width && group.y + group.height > node.y + node.height; +} @@ -287,29 +400,7 @@ function resizeNode(e: MouseEvent, x: number, y: number) }" class="h-full">
-
-
-
-
- -
-
-
- - - - - - - - -
-
-
- -
-
{{ node.label }}
-
+