basic text editor

This commit is contained in:
2025-09-06 01:21:13 +02:00
parent 73d3b2a27f
commit a4c2c039d2
13 changed files with 315 additions and 24 deletions

View File

@@ -6,9 +6,6 @@ import { getParentPath } from '~/utils/files';
export const useWarrenStore = defineStore('warrens', {
state: () => ({
warrens: {} as Record<string, WarrenData>,
imageViewer: {
src: null as string | null,
},
current: null as {
warrenId: string;
path: string;

View File

@@ -0,0 +1,13 @@
export const useImageViewer = defineStore('image-viewer', {
state: () => ({
src: null as string | null,
}),
actions: {
open(src: string) {
this.src = src;
},
close() {
this.src = null;
},
},
});

View File

@@ -0,0 +1,4 @@
import { useImageViewer } from './image';
import { useTextEditor } from './text';
export { useImageViewer, useTextEditor };

View File

@@ -0,0 +1,71 @@
import { uploadToWarren } from '~/lib/api/warrens';
import type { DirectoryEntry } from '~/shared/types';
export const useTextEditor = defineStore('text-editor', {
state: () => ({
data: null as {
warrenId: string;
parentPath: string;
entry: DirectoryEntry;
content: string;
editedContent: string;
} | null,
saving: false as boolean,
}),
actions: {
async open(
warrenId: string,
parentPath: string,
entry: DirectoryEntry,
content: Blob
) {
const contentString = await content.text();
this.data = {
warrenId,
parentPath,
entry,
content: contentString,
editedContent: contentString,
};
},
async save(): Promise<boolean> {
if (this.saving || this.data == null) {
return false;
}
this.saving = true;
const dt = new DataTransfer();
dt.items.add(
new File([this.data.editedContent], this.data.entry.name)
);
const result = await uploadToWarren(
this.data.warrenId,
this.data.parentPath,
dt.files,
undefined
);
this.$patch({
data: {
content: this.data.editedContent,
},
saving: false,
});
return result.success;
},
discardEdits() {
if (this.data == null) {
return;
}
this.data.editedContent = this.data.content;
},
close() {
this.data = null;
},
},
});