diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9ec200e..3c1d1f5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1512,6 +1512,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" + [[package]] name = "httparse" version = "1.10.0" @@ -3770,6 +3776,7 @@ dependencies = [ "gtk", "heck 0.5.0", "http", + "http-range", "jni", "libc", "log", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5c0e75e..da7808b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"] tauri-build = { version = "2", features = [] } [dependencies] -tauri = { version = "2", features = [] } +tauri = { version = "2", features = ["protocol-asset"] } tauri-plugin-opener = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 3a2c28d..b6ab739 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -7,6 +7,7 @@ ], "permissions": [ "core:default", + "core:image:allow-from-path", "opener:default", "dialog:default", "fs:allow-write-text-file", diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ac32f4a..5b51cfe 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -18,7 +18,11 @@ } ], "security": { - "csp": null + "assetProtocol": { + "enable": true, + "scope": ["*/**"] + }, + "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost" } }, "bundle": { diff --git a/src/types/data.ts b/src/types/data.ts index 6cc56d3..025992c 100644 --- a/src/types/data.ts +++ b/src/types/data.ts @@ -8,6 +8,11 @@ export const FieldTypes = [ export type FieldType = typeof FieldTypes[number] +export interface Image { + src: string + alt?: string +} + export interface Column { name: string type: FieldType diff --git a/src/views/Editor/DataEditor.vue b/src/views/Editor/DataEditor.vue index c80eb51..ded0e1a 100644 --- a/src/views/Editor/DataEditor.vue +++ b/src/views/Editor/DataEditor.vue @@ -11,6 +11,13 @@ import { type Row as DataRow, type Column as DataColumn, } from 'src/types/data' +import ImageEditor from './ImageEditor.vue' + +interface EditingRow { + data: DataRow + index: number + field: string +} const props = defineProps<{ columns: DataColumn[], @@ -20,6 +27,8 @@ const emits = defineEmits<{ }>() const model = defineModel({ required: true }) const editingRows = ref([]) +const editingImage = ref(false) +const editingImageRow = ref(null as EditingRow | null) const onRowEditSave = (event: { newData: any, index: number }) => { let { newData, index } = event @@ -45,9 +54,28 @@ const onDeleteRow = (event: Event, slotProps: { index: number }) => { model.value.splice(slotProps.index, 1) emits('dirty') } + +const onEditImage = (event: Event, slotProps: { data: DataRow, index: number, field: string }) => { + event.preventDefault() + editingImage.value = true + editingImageRow.value = slotProps +} + +const onSaveImage = (image: string) => { + const row = { ...model.value[editingImageRow.value!.index] } as any + row[editingImageRow.value!.field] = { + src: image, + } + model.value[editingImageRow.value!.index] = row +}