+
+
@@ -50,6 +54,7 @@ import { Icon } from '@iconify/vue/dist/iconify.js';
import type { Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/dist/types/tree-item';
import { parsePath } from '#shared/general.utils';
import type { ProjectItem } from '~/schemas/project';
+import type { FileType } from '~/schemas/file';
definePageMeta({
rights: ['admin', 'editor'],
@@ -63,7 +68,7 @@ const toaster = useToast();
const saveStatus = ref<'idle' | 'pending' | 'success' | 'error'>('idle');
const { data: project } = await useFetch(`/api/project`);
-const navigation = computed({
+const navigation = computed
({
get: () => project.value?.items,
set: (value) => {
const proj = project.value;
@@ -78,6 +83,7 @@ const selected = ref();
useShortcuts({
meta_s: { usingInput: true, handler: () => save(false) },
+ meta_n: { usingInput: true, handler: () => add('markdown') },
meta_shift_z: { usingInput: true, handler: () => router.push({ name: 'explore-path', params: { path: path.value }}) }
})
@@ -184,6 +190,22 @@ const tree = {
},
}
+function add(type: FileType): void
+{
+ if(!navigation.value)
+ {
+ return;
+ }
+
+ if(!selected.value)
+ {
+ navigation.value = [...navigation.value, { }]
+ }
+ if(selected.value?.children)
+ {
+ tree.insertChild(selected.value)
+ }
+}
function updateTree(instruction: Instruction, itemId: string, targetId: string) : ProjectItem[] | undefined {
if(!navigation.value)
return;
diff --git a/schemas/file.ts b/schemas/file.ts
index a58fcc1..71b95f6 100644
--- a/schemas/file.ts
+++ b/schemas/file.ts
@@ -1,14 +1,16 @@
import { z } from "zod";
+export const fileType = z.enum(['folder', 'file', 'markdown', 'canvas']);
export const schema = z.object({
path: z.string(),
owner: z.number().finite(),
title: z.string(),
- type: z.enum(['folder', 'file', 'markdown', 'canvas']),
+ type: fileType,
content: z.string(),
navigable: z.boolean(),
private: z.boolean(),
order: z.number().finite(),
});
+export type FileType = z.infer;
export type File = z.infer;
\ No newline at end of file
diff --git a/schemas/navigation.ts b/schemas/navigation.ts
index 13d6ee2..c1d9bc6 100644
--- a/schemas/navigation.ts
+++ b/schemas/navigation.ts
@@ -1,10 +1,11 @@
import { z } from "zod";
+import { fileType } from "./file";
export const single = z.object({
path: z.string(),
owner: z.number().finite(),
title: z.string(),
- type: z.enum(['folder', 'file', 'markdown', 'canvas']),
+ type: fileType,
navigable: z.boolean(),
private: z.boolean(),
order: z.number().finite(),
diff --git a/schemas/project.ts b/schemas/project.ts
index 37cbf1f..26360ad 100644
--- a/schemas/project.ts
+++ b/schemas/project.ts
@@ -1,11 +1,12 @@
import { z } from "zod";
+import { fileType } from "./file";
const baseItem = z.object({
path: z.string(),
parent: z.string(),
name: z.string().optional(),
title: z.string(),
- type: z.enum(['folder', 'file', 'markdown', 'canvas']),
+ type: fileType,
navigable: z.boolean(),
private: z.boolean(),
order: z.number().finite(),