diff --git a/components/Editor.vue b/components/Editor.vue index 3b5e5e7..0a22a43 100644 --- a/components/Editor.vue +++ b/components/Editor.vue @@ -3,11 +3,11 @@ const External = Annotation.define(); \ No newline at end of file diff --git a/pages/explore/edit/index.vue b/pages/explore/edit/index.vue index 0c67441..49a3f89 100644 --- a/pages/explore/edit/index.vue +++ b/pages/explore/edit/index.vue @@ -1,110 +1,164 @@ \ No newline at end of file diff --git a/server/api/project.post.ts b/server/api/project.post.ts index dd2fb72..3f9ef73 100644 --- a/server/api/project.post.ts +++ b/server/api/project.post.ts @@ -20,22 +20,27 @@ export default defineEventHandler(async (e) => { throw body.error; } - const items = buildOrder(body.data.items); + const items = buildOrder(body.data.items) as Array; const db = useDatabase(); - const { content, ...cols } = getTableColumns(explorerContentTable); - const full = db.select(cols).from(explorerContentTable).all(); + const { ...cols } = getTableColumns(explorerContentTable); + const full = db.select(cols).from(explorerContentTable).all() as Record[]; for(let i = full.length - 1; i >= 0; i--) { - if(items.find(e => (e.path === '' ? [e.parent, parsePath(e.name === '' ? e.title : e.name)].filter(e => !!e).join('/') : e.path) === full[i].path)) - full.splice(i, 1); + const item = items.find(e => (e.path === '' ? [e.parent, parsePath(e.name === '' ? e.title : e.name)].filter(e => !!e).join('/') : e.path) === full[i].path); + if(item) + { + item.match = i; + full[i].include = true; + } } db.transaction((tx) => { for(let i = 0; i < items.length; i++) { const item = items[i]; + const old = full[item.match!]; tx.insert(explorerContentTable).values({ path: item.path, @@ -45,7 +50,7 @@ export default defineEventHandler(async (e) => { navigable: item.navigable, private: item.private, order: item.order, - content: null, + content: item.content ?? old.content, }).onConflictDoUpdate({ set: { path: [item.parent, parsePath(item.name === '' ? item.title : item.name)].filter(e => !!e).join('/'), @@ -55,13 +60,15 @@ export default defineEventHandler(async (e) => { private: item.private, order: item.order, timestamp: new Date(), + content: item.content ?? old.content, }, target: explorerContentTable.path, }).run(); } for(let i = 0; i < full.length; i++) { - tx.delete(explorerContentTable).where(eq(explorerContentTable.path, full[i].path)).run(); + if(full[i].include !== true) + tx.delete(explorerContentTable).where(eq(explorerContentTable.path, full[i].path)).run(); } }); });