basic text editor
This commit is contained in:
@@ -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;
|
||||
|
||||
13
frontend/stores/viewers/image.ts
Normal file
13
frontend/stores/viewers/image.ts
Normal 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;
|
||||
},
|
||||
},
|
||||
});
|
||||
4
frontend/stores/viewers/index.ts
Normal file
4
frontend/stores/viewers/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { useImageViewer } from './image';
|
||||
import { useTextEditor } from './text';
|
||||
|
||||
export { useImageViewer, useTextEditor };
|
||||
71
frontend/stores/viewers/text.ts
Normal file
71
frontend/stores/viewers/text.ts
Normal 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;
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user