From 2b293a0c1a7987c554a76c00ce853854a6654aea Mon Sep 17 00:00:00 2001 From: Peaceultime Date: Tue, 3 Sep 2024 16:42:57 +0200 Subject: [PATCH] New Canvas zoom with dbl click and starting to work on tag API --- components/canvas/CanvasRenderer.vue | 15 ++ components/explorer/PreviewContent.vue | 35 ++-- components/prose/ProseA.vue | 3 +- components/prose/live/LiveBlockquote.vue | 184 +++++++++++++++++- components/prose/live/LiveH1.vue | 10 +- components/prose/live/LiveH2.vue | 17 +- components/prose/live/LiveH3.vue | 12 +- components/prose/live/LiveH4.vue | 10 +- components/prose/live/LiveH5.vue | 12 +- components/prose/live/LiveH6.vue | 12 +- db.sqlite | Bin 839680 -> 839680 bytes layouts/default.vue | 2 +- server/api/project/[projectId]/comment.get.ts | 27 --- .../project/[projectId]/file/[path].get.ts | 41 ++++ .../api/project/[projectId]/tags/[tag].get.ts | 39 ++++ types/api.d.ts | 11 ++ 16 files changed, 353 insertions(+), 77 deletions(-) delete mode 100644 server/api/project/[projectId]/comment.get.ts create mode 100644 server/api/project/[projectId]/file/[path].get.ts create mode 100644 server/api/project/[projectId]/tags/[tag].get.ts diff --git a/components/canvas/CanvasRenderer.vue b/components/canvas/CanvasRenderer.vue index ed48fe9..3f1f5c8 100644 --- a/components/canvas/CanvasRenderer.vue +++ b/components/canvas/CanvasRenderer.vue @@ -10,11 +10,26 @@ const props = defineProps(); let dragging = false, posX = 0, posY = 0, dispX = ref(0), dispY = ref(0), minZoom = ref(0.1), zoom = ref(0.5); let lastDistance = 0; +let lastClickTime = 0; const onPointerDown = (event: PointerEvent) => { if (event.isPrimary === false) return; dragging = true; + const now = performance.now(); + if(now - lastClickTime < 500 && Math.abs(event.clientX - posX) < 20 && Math.abs(event.clientY - posY) < 20) + { + if(event.ctrlKey) + { + zoom.value = clamp(zoom.value * 0.9, minZoom.value, 3); + } + else + { + zoom.value = clamp(zoom.value * 1.1, minZoom.value, 3); + } + } + lastClickTime = now; + posX = event.clientX; posY = event.clientY; diff --git a/components/explorer/PreviewContent.vue b/components/explorer/PreviewContent.vue index 907b31a..dd184c3 100644 --- a/components/explorer/PreviewContent.vue +++ b/components/explorer/PreviewContent.vue @@ -1,15 +1,15 @@ + + diff --git a/components/prose/live/LiveH4.vue b/components/prose/live/LiveH4.vue index e149331..d6338c5 100644 --- a/components/prose/live/LiveH4.vue +++ b/components/prose/live/LiveH4.vue @@ -1,3 +1,9 @@ \ No newline at end of file +

+ +

+ + + diff --git a/components/prose/live/LiveH5.vue b/components/prose/live/LiveH5.vue index 9aa8d60..b85ab77 100644 --- a/components/prose/live/LiveH5.vue +++ b/components/prose/live/LiveH5.vue @@ -1,3 +1,11 @@ \ No newline at end of file +
+ +
+ + + diff --git a/components/prose/live/LiveH6.vue b/components/prose/live/LiveH6.vue index 60aeac8..9e63455 100644 --- a/components/prose/live/LiveH6.vue +++ b/components/prose/live/LiveH6.vue @@ -1,3 +1,11 @@ \ No newline at end of file +
+ +
+ + + diff --git a/db.sqlite b/db.sqlite index 382bbeccad458eeb6b935a33d2960c943eb203e5..147e74eed9775d537234af5631fe3ad9d8a89066 100644 GIT binary patch delta 838 zcmb7C-%C?b9KUDx?8mwHx_eg}*H}Yag^af5oVE>wZP_x)hmcu8rEc>YLh00zKOStG zIUgdJ-iJdGqCSKPhGXC@g<231QJ`dnkt9J7M9?1))>&2%zSP5q^Zk52=ll7db2!OK zcXHC5H5&#gih4nyCpbs&dCcwxgSl3%e_zyB>2XQb?T$l{Xv9%n>xeIzsVbfDIU-9!1+(pG6Kj5s*FG{2#_lXnk4F?qncWMj+tj>m>H6GlvbiI;iej) zIf@sXG$|wQSc69(cN5S!w+6kWq8{QeYjBATrc4^K$q9TZ6P_m);PNijT>vRcCE~zq z=*R2tV6HK3P8qeL(+P&9L?n7q>g~Q5ZAnO%;w?XEi))*})-{HL;ZS)vc(@@{Zr$d~ zx7fY%ePA+K+oaxDPe(k_(bZ{1;n10|ok4hP6^gn<=99XQ z{KAHMPZbzdtUELxN)#B--Qi_}a9V-O>Ti4|pveTZ+7X3`qb_YJY37g*l>y6?Biqmau1)w+5*hK0K4c$V=|cpJveL&^mh$=` ziiS&+{<^*%E~%c8IggdqEIV6bCQ&@{qy4}#A|f4?j%&CrdUXJIKIKF_HNiTS_Y#wN19Srm$}QV`c>1FA5_B5o*~v2L(Z+L#Ka9y@k-3eigdiJp_yd!<;S}(`mWTMCX-@Jv z=ic+Z-*@g!L*0d;?!u0AbBji!xj@25Vh@Sw&fG$(Wx&goW;z^&0bih~Ft0wauOaUt z*TcR%U%oStSLCZNa=GgLj=;Vm=~U_S=&Y{bT(8@UNPFrBVb-pN9hn2-T$-4&K(&|F!KM69CDRNG-H)SsXm>Gs*b&E7$)>szW{WgDX@TMq?19DK z$>9^Fj3|$fU>gND%#;OGwNK&XU6i84NN-(x5QH)mlwQ7Of!{9Txr9V@FULdrC0s5Q z-&k^Itw2lexXU={PPNhq#!6JB9FdvOd-V!_Mm-_nbr(E0hW)TRjS`fZVL3d@kOT6s zVgxY{QO=;43#5SSYTmb3^`HwXxIq9jGgu7t zRKkC&^yV_z=aaR)@Yy^SO6t`tkXkiO*T9bpr1r1V;3AP%)5qA_BjjQlpyvR4FG$7O zFyueW=0Z~mq5fCcYZGjszXfR>@;i$(f^4j!aY%`_3)X_7BzCghIr#4Vphv z&LH3M`cSfz4X-WJx?%kb5jPugbAuw=M;_r`?kVaxw12~-$?0z0b%ES73Q>!KOgHNm z7I`urn!a1Z9g_9Ue2_DABEi7Bcng)$lLwt`yc_ywbchohf{niV))VnIo`hbGw_(Q` zL1{+A8e_Y0D;m~*C7DfM$QL{CJ1K@^M_B`3%HL0A98ZI$FAZtX--Yc)tGKPHwI%33 z*wDH^*d&j4VXGMv6|LT>(FgQS^3-$n;2gqvhIdVR17F75sEltN@I)7010^?gCopyright Peaceultime - 2024

-
+
diff --git a/server/api/project/[projectId]/comment.get.ts b/server/api/project/[projectId]/comment.get.ts deleted file mode 100644 index 7f3a034..0000000 --- a/server/api/project/[projectId]/comment.get.ts +++ /dev/null @@ -1,27 +0,0 @@ -import useDatabase from '~/composables/useDatabase'; -import { Comment } from '~/types/api'; - -export default defineEventHandler(async (e) => { - const project = getRouterParam(e, "projectId"); - const query = getQuery(e); - - if(!project || !query.path) - { - setResponseStatus(e, 404); - return; - } - - const where = ["project = $project", "path = $path"]; - const criteria: Record = { $project: project, $path: query.path }; - - if(where.length > 1) - { - const db = useDatabase(); - - const content = db.query(`SELECT * FROM explorer_comments WHERE ${where.join(" and ")}`).all(criteria) as Comment[]; - - return content; - } - - setResponseStatus(e, 404); -}); \ No newline at end of file diff --git a/server/api/project/[projectId]/file/[path].get.ts b/server/api/project/[projectId]/file/[path].get.ts new file mode 100644 index 0000000..a03e65f --- /dev/null +++ b/server/api/project/[projectId]/file/[path].get.ts @@ -0,0 +1,41 @@ +import useDatabase from '~/composables/useDatabase'; +import type { CommentedFile, CommentSearch, File } from '~/types/api'; + +export default defineCachedEventHandler(async (e) => { + const project = getRouterParam(e, "projectId"); + const path = decodeURIComponent(getRouterParam(e, "path") ?? ''); + + if(!project) + { + setResponseStatus(e, 404); + return; + } + if(!path) + { + setResponseStatus(e, 404); + return; + } + + const where = ["project = $project", "path = $path"]; + const criteria: Record = { $project: project, $path: path }; + + if(where.length > 1) + { + const db = useDatabase(); + + const content = db.query(`SELECT * FROM explorer_files WHERE ${where.join(" and ")}`).get(criteria) as File; + + if(content !== undefined) + { + const comments = db.query(`SELECT comment.*, user.username FROM explorer_comments comment LEFT JOIN users user ON comment.user_id = user.id WHERE ${where.join(" and ")}`).all(criteria) as CommentSearch[]; + + return { ...content, comments } as CommentedFile; + } + } + + setResponseStatus(e, 404); + return; +}, { + maxAge: 60*60*24, + getKey: (e) => `file-${getRouterParam(e, "projectId")}-${getRouterParam(e, "path")}` + }); \ No newline at end of file diff --git a/server/api/project/[projectId]/tags/[tag].get.ts b/server/api/project/[projectId]/tags/[tag].get.ts new file mode 100644 index 0000000..b1bcb54 --- /dev/null +++ b/server/api/project/[projectId]/tags/[tag].get.ts @@ -0,0 +1,39 @@ +import useDatabase from '~/composables/useDatabase'; +import type { Tag } from '~/types/api'; + +export default defineCachedEventHandler(async (e) => { + const project = getRouterParam(e, "projectId"); + const tag = getRouterParam(e, "tag"); + const query = getQuery(e); + + if(!project) + { + setResponseStatus(e, 404); + return; + } + if(!tag) + { + setResponseStatus(e, 404); + return; + } + + const where = ["project = $project", "tag = $tag"]; + const criteria: Record = { $project: project, $tag: tag }; + + if(where.length > 1) + { + const db = useDatabase(); + + const content = db.query(`SELECT * FROM explorer_tags WHERE ${where.join(" and ")}`).get(criteria) as Tag; + + if(content !== undefined) + { + return content; + } + } + + setResponseStatus(e, 404); +}, { + maxAge: 60*60*24, + getKey: (e) => `tag-${getRouterParam(e, "projectId")}-${getRouterParam(e, "tag")}` + }); \ No newline at end of file diff --git a/types/api.d.ts b/types/api.d.ts index ebb271f..e79d033 100644 --- a/types/api.d.ts +++ b/types/api.d.ts @@ -52,6 +52,13 @@ export interface User { id: number; username: string; } +export interface Tag { + tag: string; + project: number; + description: string; +} + + export type ProjectSearch = Project & { pages: number; @@ -69,6 +76,10 @@ export type CommentSearch = Comment & export type UserSearch = User & { } +export type CommentedFile = File & +{ + comments: CommentSearch[]; +} export interface Search { projects: ProjectSearch[]; files: FileSearch[];