ImageEditor -> InputImage

This commit is contained in:
lightling 2025-03-23 15:21:09 -04:00
parent 7b414f0715
commit 93f4fffcaf
Signed by: lightling
GPG key ID: F1F29650D537C773
7 changed files with 42 additions and 30 deletions

View file

@ -9,6 +9,12 @@
{ {
"identifier": "fs:scope", "identifier": "fs:scope",
"allow": [ "allow": [
{
"path": "$HOME"
},
{
"path": "$HOME/*"
},
{ {
"path": "$APPCONFIG" "path": "$APPCONFIG"
}, },
@ -22,6 +28,8 @@
"opener:default", "opener:default",
"dialog:default", "dialog:default",
"fs:allow-write-text-file", "fs:allow-write-text-file",
"fs:allow-home-read-recursive",
"fs:allow-home-write-recursive",
"fs:default" "fs:default"
] ]
} }

View file

@ -13,13 +13,13 @@ import InputGroupAddon from 'primevue/inputgroupaddon'
import InputText from 'primevue/inputtext' import InputText from 'primevue/inputtext'
import { useAppStore } from 'src/store' import { useAppStore } from 'src/store'
import { type EditingRow } from './types' import type { EditingRow } from 'src/types/editing'
const store = useAppStore() const store = useAppStore()
const visible = defineModel<boolean>('visible', { default: false })
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'saved', val: string): void (e: 'saved', val: string): void
(e: 'canceled'): void
}>() }>()
const row = defineModel<EditingRow | null>('row') const row = defineModel<EditingRow | null>('row')
const filePath = ref(store.currentInventory.filePath.replace('.json', '/')) const filePath = ref(store.currentInventory.filePath.replace('.json', '/'))
@ -56,6 +56,7 @@ const onBrowseForImage = async (e: Event) => {
const onCancel = (e: Event) => { const onCancel = (e: Event) => {
e.preventDefault() e.preventDefault()
emit('canceled')
reset() reset()
} }
@ -76,7 +77,6 @@ function convertToDataUrlViaCanvas(url: string, callback: (val: string) => void,
} }
const reset = () => { const reset = () => {
visible.value = false
row.value = null row.value = null
currentSrc.value = '' currentSrc.value = ''
} }
@ -91,11 +91,7 @@ const onSave = async (e: Event) => {
</script> </script>
<template lang="pug"> <template lang="pug">
Dialog( .input-image
v-model:visible='visible'
modal
header='Edit Image'
)
.content( .content(
v-if='!renderedSrc' v-if='!renderedSrc'
) )
@ -110,7 +106,7 @@ Dialog(
ImageComponent( ImageComponent(
:src='renderedSrc' :src='renderedSrc'
) )
template(#footer) .footer
Button( Button(
label='Save' label='Save'
@click='onSave' @click='onSave'

9
src/types/editing.ts Normal file
View file

@ -0,0 +1,9 @@
import {
type Row,
} from './data'
export interface EditingRow {
data: Row
index: number
field: string
}

View file

@ -11,6 +11,7 @@ import Checkbox from 'primevue/checkbox'
import Column from 'primevue/column' import Column from 'primevue/column'
import Chip from 'primevue/chip' import Chip from 'primevue/chip'
import DataTable from 'primevue/datatable' import DataTable from 'primevue/datatable'
import Dialog from 'primevue/dialog'
import Image from 'primevue/image' import Image from 'primevue/image'
import InputGroup from 'primevue/inputgroup' import InputGroup from 'primevue/inputgroup'
import InputGroupAddon from 'primevue/inputgroupaddon' import InputGroupAddon from 'primevue/inputgroupaddon'
@ -23,8 +24,8 @@ import {
type Column as DataColumn, type Column as DataColumn,
} from 'src/types/data' } from 'src/types/data'
import DataEditorModal from './DataEditorModal.vue' import DataEditorModal from './DataEditorModal.vue'
import ImageEditor from './ImageEditor.vue' import InputImage from 'src/components/InputImage.vue'
import { type EditingRow } from './types' import type { EditingRow } from 'src/types/editing'
const props = defineProps<{ const props = defineProps<{
columns: DataColumn[], columns: DataColumn[],
@ -121,9 +122,16 @@ const onSaveImage = (image: string) => {
rows.splice(indexOfEditing, 1) rows.splice(indexOfEditing, 1)
editingRows.value = rows editingRows.value = rows
emits('dirty') emits('dirty')
editingImage.value = false
editingImageRow.value = null
} }
} }
const onCancelImage = () => {
editingImageRow.value = null
editingImage.value = false
}
const onSaveRow = (row: DataRow, editingRow: EditingRow) => { const onSaveRow = (row: DataRow, editingRow: EditingRow) => {
model.value[editingRow.index] = row model.value[editingRow.index] = row
emits('dirty') emits('dirty')
@ -131,11 +139,16 @@ const onSaveRow = (row: DataRow, editingRow: EditingRow) => {
</script> </script>
<template lang="pug"> <template lang="pug">
ImageEditor( Dialog(
v-model:visible='editingImage' v-model:visible='editingImage'
v-model:row='editingImageRow' modal
@saved='onSaveImage' header='Edit Image'
) )
InputImage(
v-model:row='editingImageRow'
@saved='onSaveImage'
@canceled='onCancelImage'
)
DataEditorModal( DataEditorModal(
v-model:visible='editingRow' v-model:visible='editingRow'
:row='editingRowData' :row='editingRowData'

View file

@ -14,7 +14,7 @@ import MultiSelect from 'primevue/multiselect'
import Select from 'primevue/select' import Select from 'primevue/select'
import { useAppStore } from 'src/store' import { useAppStore } from 'src/store'
import { type EditingRow } from './types' import type { EditingRow } from 'src/types/editing'
import type { Row as DataRow, Column as DataColumn } from 'src/types/data' import type { Row as DataRow, Column as DataColumn } from 'src/types/data'
const store = useAppStore() const store = useAppStore()
@ -45,11 +45,6 @@ const onSave = async (e: Event) => {
</script> </script>
<template lang="pug"> <template lang="pug">
ImageEditor(
v-model:visible='editingImage'
v-model:row='editingImageRow'
@saved='onSaveImage'
)
Dialog( Dialog(
v-model:visible='visible' v-model:visible='visible'
modal modal

View file

@ -1,9 +0,0 @@
import {
type Row,
} from 'src/types/data'
export interface EditingRow {
data: Row
index: number
field: string
}

View file

@ -16,7 +16,7 @@ import Panel from 'primevue/panel'
import { useAppStore } from 'src/store' import { useAppStore } from 'src/store'
import { getConfig, readJson } from 'src/utils/io' import { getConfig, readJson } from 'src/utils/io'
import { Inventory } from 'src/types/data' import type { Inventory } from 'src/types/data'
const router = useRouter() const router = useRouter()
const toast = useToast() const toast = useToast()