feat(admin): add MediaView, MediaPickerModal, MediaFinderField, unify MailImagePicker, and rebuild boardwalk dist
This commit is contained in:
179
admin/src/components/form/fields/MediaFinderField.vue
Normal file
179
admin/src/components/form/fields/MediaFinderField.vue
Normal file
@@ -0,0 +1,179 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { FileText, Image, Plus, Trash2, X } from '@lucide/vue'
|
||||
import { fileExtension } from '../../../api/media'
|
||||
import type { AdminMediaItem } from '../../../api/types'
|
||||
import { t } from '../../../app/i18n'
|
||||
import MediaPickerModal from '../../media/MediaPickerModal.vue'
|
||||
import Button from '../../ui/Button.vue'
|
||||
import type { FieldControlProps } from '../control'
|
||||
|
||||
// type: mediafinder form control (D-05): stores a public media URL (single)
|
||||
// or array of public media URLs (multiple: true).
|
||||
const props = defineProps<FieldControlProps>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: string | string[] | null] }>()
|
||||
|
||||
const pickerOpen = ref(false)
|
||||
|
||||
const isMultiple = computed(() => props.field.multiple === true)
|
||||
const finderMode = computed<'image' | 'file'>(() => (props.field.mode === 'file' ? 'file' : 'image'))
|
||||
const defaultFolder = computed(() => props.field.folder || undefined)
|
||||
const readOnly = computed(() => props.field.readOnly === true)
|
||||
|
||||
const urls = computed<string[]>(() => {
|
||||
const raw = props.modelValue
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.filter((v): v is string => typeof v === 'string' && v.trim() !== '')
|
||||
}
|
||||
if (typeof raw === 'string' && raw.trim() !== '') {
|
||||
return [raw.trim()]
|
||||
}
|
||||
return []
|
||||
})
|
||||
|
||||
function isImageUrl(url: string): boolean {
|
||||
if (finderMode.value === 'image') {
|
||||
return true
|
||||
}
|
||||
return /\.(?:jpe?g|png|gif|webp)(?:[?#].*)?$/i.test(url)
|
||||
}
|
||||
|
||||
function fileNameFromUrl(url: string): string {
|
||||
const clean = url.split(/[?#]/)[0] ?? url
|
||||
const slash = clean.lastIndexOf('/')
|
||||
return slash >= 0 ? clean.slice(slash + 1) || url : url
|
||||
}
|
||||
|
||||
function onSelect(payload: { items: AdminMediaItem[]; alt: string }): void {
|
||||
if (payload.items.length === 0) {
|
||||
return
|
||||
}
|
||||
if (isMultiple.value) {
|
||||
const existing = new Set(urls.value)
|
||||
const next = [...urls.value]
|
||||
for (const item of payload.items) {
|
||||
if (item.url && !existing.has(item.url)) {
|
||||
existing.add(item.url)
|
||||
next.push(item.url)
|
||||
}
|
||||
}
|
||||
emit('update:modelValue', next)
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', payload.items[0]!.url)
|
||||
}
|
||||
|
||||
function removeAt(index: number): void {
|
||||
if (readOnly.value) {
|
||||
return
|
||||
}
|
||||
if (isMultiple.value) {
|
||||
const next = urls.value.filter((_, i) => i !== index)
|
||||
emit('update:modelValue', next)
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', null)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div data-mediafinder class="flex flex-col gap-3">
|
||||
<!-- Single mode -->
|
||||
<div v-if="!isMultiple" class="flex items-center gap-4">
|
||||
<div
|
||||
class="flex size-[96px] shrink-0 items-center justify-center overflow-hidden rounded-inner border border-border bg-subtle"
|
||||
>
|
||||
<img
|
||||
v-if="urls[0] && isImageUrl(urls[0])"
|
||||
:src="urls[0]"
|
||||
:alt="fileNameFromUrl(urls[0])"
|
||||
class="size-full object-cover"
|
||||
/>
|
||||
<div v-else-if="urls[0]" class="flex flex-col items-center gap-1 text-muted">
|
||||
<FileText :size="24" aria-hidden="true" />
|
||||
<span class="rounded-tab bg-surface px-1.5 py-0.5 text-[10px] font-bold text-text uppercase">
|
||||
{{ fileExtension(fileNameFromUrl(urls[0])) }}
|
||||
</span>
|
||||
</div>
|
||||
<Image v-else-if="finderMode === 'image'" :size="24" class="text-muted" aria-hidden="true" />
|
||||
<FileText v-else :size="24" class="text-muted" aria-hidden="true" />
|
||||
</div>
|
||||
|
||||
<div class="flex min-w-0 flex-col gap-2">
|
||||
<p v-if="urls[0]" class="truncate text-[14px] font-medium" :title="urls[0]">
|
||||
{{ fileNameFromUrl(urls[0]) }}
|
||||
</p>
|
||||
<p v-else class="text-[13px] text-muted">{{ t('backend::lang.media.finder_empty') }}</p>
|
||||
<div v-if="!readOnly" class="flex flex-wrap gap-2">
|
||||
<Button variant="outline" size="sm" data-mediafinder-choose @click="pickerOpen = true">
|
||||
{{ urls[0] ? t('backend::lang.media.finder_change') : t('backend::lang.media.finder_choose') }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="urls[0]"
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
data-mediafinder-remove
|
||||
:icon="Trash2"
|
||||
@click="removeAt(0)"
|
||||
>
|
||||
{{ t('backend::lang.media.finder_remove') }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Multiple mode -->
|
||||
<template v-else>
|
||||
<div v-if="urls.length > 0" class="grid grid-cols-2 gap-2.5 sm:grid-cols-3 md:grid-cols-4">
|
||||
<div
|
||||
v-for="(url, index) in urls"
|
||||
:key="`${url}-${index}`"
|
||||
data-mediafinder-item
|
||||
class="relative flex flex-col gap-1.5 rounded-inner border border-border bg-surface p-1.5"
|
||||
>
|
||||
<div class="flex aspect-square w-full items-center justify-center overflow-hidden rounded-pager bg-subtle">
|
||||
<img
|
||||
v-if="isImageUrl(url)"
|
||||
:src="url"
|
||||
:alt="fileNameFromUrl(url)"
|
||||
class="size-full object-cover"
|
||||
/>
|
||||
<div v-else class="flex flex-col items-center gap-1 text-muted">
|
||||
<FileText :size="24" aria-hidden="true" />
|
||||
<span class="rounded-tab bg-surface px-1.5 py-0.5 text-[10px] font-bold text-text uppercase">
|
||||
{{ fileExtension(fileNameFromUrl(url)) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="truncate text-[12px] text-muted" :title="url">{{ fileNameFromUrl(url) }}</span>
|
||||
<button
|
||||
v-if="!readOnly"
|
||||
type="button"
|
||||
data-mediafinder-remove
|
||||
:aria-label="t('backend::lang.media.finder_remove')"
|
||||
:title="t('backend::lang.media.finder_remove')"
|
||||
class="absolute top-2 right-2 flex size-6 items-center justify-center rounded-full bg-surface/90 text-muted shadow-sm hover:bg-danger-soft hover:text-danger"
|
||||
@click="removeAt(index)"
|
||||
>
|
||||
<X :size="13" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="text-[13px] text-muted">{{ t('backend::lang.media.finder_empty') }}</p>
|
||||
|
||||
<div v-if="!readOnly">
|
||||
<Button variant="outline" size="sm" data-mediafinder-choose :icon="Plus" @click="pickerOpen = true">
|
||||
{{ t('backend::lang.media.finder_add') }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<MediaPickerModal
|
||||
v-model:open="pickerOpen"
|
||||
:mode="finderMode"
|
||||
:multiple="isMultiple"
|
||||
:default-folder="defaultFolder"
|
||||
@select="onSelect"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -60,6 +60,7 @@ import MailPreviewField from './fields/MailPreviewField.vue'
|
||||
import CodeEditorField from './fields/CodeEditorField.vue'
|
||||
import ColorPickerField from './fields/ColorPickerField.vue'
|
||||
import MailImageField from './fields/MailImageField.vue'
|
||||
import MediaFinderField from './fields/MediaFinderField.vue'
|
||||
import MoneyField from './fields/MoneyField.vue'
|
||||
import TaglistField from './fields/TaglistField.vue'
|
||||
import MLTextField from './fields/MLTextField.vue'
|
||||
@@ -109,6 +110,7 @@ const renderers = new Map<string, Component>([
|
||||
['codeeditor', CodeEditorField],
|
||||
['colorpicker', ColorPickerField],
|
||||
['mailimage', MailImageField],
|
||||
['mediafinder', MediaFinderField],
|
||||
])
|
||||
|
||||
/** Types whose control shows the label itself (toggle cards, relation manager). */
|
||||
@@ -139,6 +141,7 @@ const groupLabelledTypes = new Set<string>([
|
||||
'repeater',
|
||||
'mailpreview',
|
||||
'mailimage',
|
||||
'mediafinder',
|
||||
])
|
||||
|
||||
export function rendererFor(type: string): Component {
|
||||
|
||||
@@ -1,357 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import {
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogRoot,
|
||||
DialogTitle,
|
||||
} from 'reka-ui'
|
||||
import { Check, Search, Upload, X } from '@lucide/vue'
|
||||
import { api } from '../../api/client'
|
||||
import type { AdminMailImage, AdminMailImagesMeta } from '../../api/types'
|
||||
import { computed } from 'vue'
|
||||
import type { AdminMediaItem } from '../../api/types'
|
||||
import { t } from '../../app/i18n'
|
||||
import Button from '../ui/Button.vue'
|
||||
import MediaPickerModal from '../media/MediaPickerModal.vue'
|
||||
|
||||
// Mail image library picker (UI-SPEC C4): insert mode returns {url, alt};
|
||||
// choose mode returns the image id. Upload shows only when meta.canUpload.
|
||||
// Mail image library picker unified onto MediaPickerModal (D-05, D-13):
|
||||
// insert mode returns {url, alt}; choose mode returns the image id.
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
mode: 'insert' | 'choose'
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [open: boolean]
|
||||
insert: [payload: { url: string; alt: string }]
|
||||
choose: [id: number]
|
||||
}>()
|
||||
|
||||
const SEARCH_DEBOUNCE = 300
|
||||
|
||||
const search = ref('')
|
||||
const images = ref<AdminMailImage[]>([])
|
||||
const meta = ref<AdminMailImagesMeta | null>(null)
|
||||
const loading = ref(false)
|
||||
const loadFailed = ref(false)
|
||||
const loadFailedMessage = ref('')
|
||||
const uploading = ref(false)
|
||||
const uploadError = ref('')
|
||||
const chosen = ref<AdminMailImage | null>(null)
|
||||
const alt = ref('')
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
const grid = ref<HTMLElement | null>(null)
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let generation = 0
|
||||
|
||||
const title = computed(() =>
|
||||
props.mode === 'insert' ? t('backend::lang.mail.picker.insert_title') : t('backend::lang.mail.picker.choose_title'),
|
||||
)
|
||||
|
||||
const primaryLabel = computed(() =>
|
||||
props.mode === 'insert' ? t('backend::lang.mail.picker.insert') : t('backend::lang.mail.picker.use'),
|
||||
)
|
||||
const canUpload = computed(() => meta.value?.canUpload === true)
|
||||
const empty = computed(() => !loading.value && !loadFailed.value && images.value.length === 0 && search.value.trim() === '')
|
||||
const noResults = computed(() => !loading.value && !loadFailed.value && images.value.length === 0 && search.value.trim() !== '')
|
||||
const hasMore = computed(() => {
|
||||
if (!meta.value) {
|
||||
return false
|
||||
}
|
||||
return images.value.length < meta.value.total
|
||||
})
|
||||
|
||||
function setOpen(open: boolean): void {
|
||||
emit('update:open', open)
|
||||
}
|
||||
|
||||
function reset(): void {
|
||||
search.value = ''
|
||||
images.value = []
|
||||
meta.value = null
|
||||
loading.value = false
|
||||
loadFailed.value = false
|
||||
loadFailedMessage.value = ''
|
||||
uploading.value = false
|
||||
uploadError.value = ''
|
||||
chosen.value = null
|
||||
alt.value = ''
|
||||
generation++
|
||||
}
|
||||
|
||||
async function load(page: number, append: boolean): Promise<void> {
|
||||
const current = ++generation
|
||||
loading.value = true
|
||||
loadFailed.value = false
|
||||
loadFailedMessage.value = ''
|
||||
try {
|
||||
const { data, error, response } = await api.GET('/mail/images', {
|
||||
params: { query: { q: search.value.trim() || undefined, page } },
|
||||
})
|
||||
if (current !== generation) {
|
||||
return
|
||||
}
|
||||
if (!data) {
|
||||
loadFailed.value = true
|
||||
const message =
|
||||
(error as { error?: { message?: string } } | undefined)?.error?.message ??
|
||||
t('backend::lang.mail.picker.load_failed')
|
||||
loadFailedMessage.value = response.status === 409 ? message : t('backend::lang.mail.picker.load_failed')
|
||||
if (!append) {
|
||||
images.value = []
|
||||
meta.value = null
|
||||
}
|
||||
return
|
||||
}
|
||||
images.value = append ? [...images.value, ...data.data] : data.data
|
||||
meta.value = data.meta
|
||||
} catch {
|
||||
if (current !== generation) {
|
||||
return
|
||||
}
|
||||
loadFailed.value = true
|
||||
loadFailedMessage.value = t('backend::lang.mail.picker.load_failed')
|
||||
} finally {
|
||||
if (current === generation) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch(event: Event): void {
|
||||
search.value = (event.target as HTMLInputElement).value
|
||||
if (searchTimer !== null) {
|
||||
clearTimeout(searchTimer)
|
||||
}
|
||||
searchTimer = setTimeout(() => {
|
||||
searchTimer = null
|
||||
void load(1, false)
|
||||
}, SEARCH_DEBOUNCE)
|
||||
}
|
||||
|
||||
function select(image: AdminMailImage): void {
|
||||
chosen.value = image
|
||||
if (props.mode === 'insert') {
|
||||
alt.value = image.title || ''
|
||||
}
|
||||
}
|
||||
|
||||
function onGridKeydown(event: KeyboardEvent): void {
|
||||
if (!chosen.value || images.value.length === 0) {
|
||||
return
|
||||
}
|
||||
const index = images.value.findIndex((image) => image.id === chosen.value!.id)
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
let next = index
|
||||
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
||||
next = Math.min(index + 1, images.value.length - 1)
|
||||
} else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
||||
next = Math.max(index - 1, 0)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
select(images.value[next]!)
|
||||
}
|
||||
|
||||
function onScroll(event: Event): void {
|
||||
const el = event.target as HTMLElement
|
||||
if (!hasMore.value || loading.value) {
|
||||
return
|
||||
}
|
||||
if (el.scrollTop + el.clientHeight >= el.scrollHeight - 48) {
|
||||
void load((meta.value?.page ?? 1) + 1, true)
|
||||
}
|
||||
}
|
||||
|
||||
async function onUpload(event: Event): Promise<void> {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
input.value = ''
|
||||
if (!file) {
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
uploadError.value = ''
|
||||
try {
|
||||
const body = new FormData()
|
||||
body.append('file', file)
|
||||
const { data, error } = await api.POST('/mail/images', { body: body as never })
|
||||
if (!data) {
|
||||
const details = (error as { error?: { message?: string; details?: { message?: string } } } | undefined)?.error
|
||||
uploadError.value = details?.details?.message || details?.message || t('backend::lang.mail.picker.load_failed')
|
||||
return
|
||||
}
|
||||
images.value = [data.data, ...images.value.filter((image) => image.id !== data.data.id)]
|
||||
if (meta.value) {
|
||||
meta.value = { ...meta.value, total: meta.value.total + 1, canUpload: meta.value.canUpload }
|
||||
}
|
||||
select(data.data)
|
||||
} catch {
|
||||
uploadError.value = t('backend::lang.mail.picker.load_failed')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function confirm(): void {
|
||||
if (!chosen.value) {
|
||||
function onSelect(payload: { items: AdminMediaItem[]; alt: string }): void {
|
||||
const chosen = payload.items[0]
|
||||
if (!chosen) {
|
||||
return
|
||||
}
|
||||
if (props.mode === 'insert') {
|
||||
emit('insert', { url: chosen.value.url, alt: alt.value })
|
||||
emit('insert', { url: chosen.url, alt: payload.alt })
|
||||
} else {
|
||||
emit('choose', chosen.value.id)
|
||||
emit('choose', chosen.id)
|
||||
}
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
reset()
|
||||
void load(1, false)
|
||||
void nextTick(() => grid.value?.focus())
|
||||
} else if (searchTimer !== null) {
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = null
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (searchTimer !== null) {
|
||||
clearTimeout(searchTimer)
|
||||
}
|
||||
generation++
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DialogRoot :open="open" @update:open="setOpen">
|
||||
<DialogPortal>
|
||||
<DialogOverlay class="fixed inset-0 z-40 bg-overlay" />
|
||||
<DialogContent
|
||||
data-mail-image-picker
|
||||
class="fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-32px)] w-[calc(100%-32px)] max-w-[560px] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 rounded-modal bg-surface p-6 text-text shadow-pop"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em]">{{ title }}</DialogTitle>
|
||||
<DialogClose
|
||||
type="button"
|
||||
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text"
|
||||
:aria-label="t('backend::lang.form.cancel')"
|
||||
>
|
||||
<X :size="16" aria-hidden="true" />
|
||||
</DialogClose>
|
||||
</div>
|
||||
|
||||
<label class="relative block">
|
||||
<span class="sr-only">{{ t('backend::lang.mail.picker.search') }}</span>
|
||||
<Search :size="18" class="pointer-events-none absolute top-1/2 left-3.5 -translate-y-1/2 text-muted" aria-hidden="true" />
|
||||
<input
|
||||
type="search"
|
||||
data-mail-image-search
|
||||
:value="search"
|
||||
:placeholder="t('backend::lang.mail.picker.search')"
|
||||
class="h-input w-full rounded-control border border-border-strong bg-surface pr-3.5 pl-10"
|
||||
@input="onSearch"
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div v-if="canUpload" class="flex flex-col gap-1.5">
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
class="sr-only"
|
||||
accept="image/jpeg,image/png,image/gif,image/webp"
|
||||
@change="onUpload"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
data-mail-image-upload
|
||||
:disabled="uploading"
|
||||
:icon="Upload"
|
||||
@click="fileInput?.click()"
|
||||
>
|
||||
{{ uploading ? t('backend::lang.mail.picker.uploading') : t('backend::lang.mail.picker.upload') }}
|
||||
</Button>
|
||||
<p v-if="uploadError" role="alert" data-mail-image-upload-error class="text-[13px] text-danger">{{ uploadError }}</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
ref="grid"
|
||||
role="radiogroup"
|
||||
:aria-label="title"
|
||||
tabindex="0"
|
||||
data-mail-image-grid
|
||||
class="grid min-h-0 grid-cols-4 gap-2 overflow-y-auto"
|
||||
@keydown="onGridKeydown"
|
||||
@scroll="onScroll"
|
||||
>
|
||||
<template v-if="loading && images.length === 0">
|
||||
<div v-for="n in 12" :key="n" class="aspect-square rounded-inner bg-skel" aria-hidden="true" />
|
||||
</template>
|
||||
<p v-else-if="loadFailed" role="alert" data-mail-image-load-failed class="col-span-4 text-[13px] text-danger">
|
||||
{{ loadFailedMessage }}
|
||||
</p>
|
||||
<div v-else-if="empty" class="col-span-4 flex flex-col items-center gap-1 px-2 py-6 text-center">
|
||||
<p class="text-[14px] font-semibold">{{ t('backend::lang.mail.picker.empty_title') }}</p>
|
||||
<p class="text-[13px] text-muted">
|
||||
{{ canUpload ? t('backend::lang.mail.picker.empty_upload') : t('backend::lang.mail.picker.empty_pick_only') }}
|
||||
</p>
|
||||
</div>
|
||||
<p v-else-if="noResults" data-mail-image-no-results class="col-span-4 px-2 py-6 text-center text-[13px] text-muted">
|
||||
{{ t('backend::lang.mail.picker.no_results', { query: search.trim() }) }}
|
||||
</p>
|
||||
<button
|
||||
v-for="image in images"
|
||||
:key="image.id"
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="chosen?.id === image.id ? 'true' : 'false'"
|
||||
:data-mail-image-id="image.id"
|
||||
:class="
|
||||
chosen?.id === image.id
|
||||
? 'border-[#e0b020] bg-sel'
|
||||
: 'border-border hover:bg-hover'
|
||||
"
|
||||
class="relative flex flex-col gap-1 rounded-inner border p-1 text-left transition-colors duration-150 ease-out"
|
||||
@click="select(image)"
|
||||
>
|
||||
<span class="relative block aspect-square w-full overflow-hidden rounded-pager bg-subtle">
|
||||
<img :src="image.thumbUrl || image.url" :alt="image.title || image.fileName" class="size-full object-cover" />
|
||||
<span
|
||||
v-if="chosen?.id === image.id"
|
||||
class="absolute top-1 right-1 flex size-5 items-center justify-center rounded-full bg-primary text-on-primary"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<Check :size="14" />
|
||||
</span>
|
||||
</span>
|
||||
<span class="truncate text-[13px] text-muted">{{ image.fileName }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="mode === 'insert' && chosen" class="flex flex-col gap-1.5">
|
||||
<label class="text-[13px] font-semibold" for="mail-image-alt">{{ t('backend::lang.mail.picker.alt') }}</label>
|
||||
<p class="text-[13px] text-muted">{{ t('backend::lang.mail.picker.alt_comment') }}</p>
|
||||
<input
|
||||
id="mail-image-alt"
|
||||
v-model="alt"
|
||||
type="text"
|
||||
data-mail-image-alt
|
||||
class="h-input w-full rounded-control border border-border-strong bg-surface px-3.5"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-2.5">
|
||||
<Button variant="ghost" data-mail-image-cancel @click="setOpen(false)">{{ t('backend::lang.form.cancel') }}</Button>
|
||||
<Button variant="primary" data-mail-image-confirm :disabled="!chosen" @click="confirm">{{ primaryLabel }}</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</DialogPortal>
|
||||
</DialogRoot>
|
||||
<MediaPickerModal
|
||||
:open="open"
|
||||
mode="image"
|
||||
default-folder="mail"
|
||||
source="mail"
|
||||
:multiple="false"
|
||||
:show-alt="mode === 'insert'"
|
||||
:title="title"
|
||||
:confirm-label="primaryLabel"
|
||||
:alt-label="t('backend::lang.mail.picker.alt')"
|
||||
:alt-comment="t('backend::lang.mail.picker.alt_comment')"
|
||||
:search-placeholder="t('backend::lang.mail.picker.search')"
|
||||
:upload-label="t('backend::lang.mail.picker.upload')"
|
||||
:uploading-label="t('backend::lang.mail.picker.uploading')"
|
||||
:empty-title="t('backend::lang.mail.picker.empty_title')"
|
||||
:empty-upload-body="t('backend::lang.mail.picker.empty_upload')"
|
||||
:empty-read-only-body="t('backend::lang.mail.picker.empty_pick_only')"
|
||||
:load-failed-label="t('backend::lang.mail.picker.load_failed')"
|
||||
@update:open="emit('update:open', $event)"
|
||||
@select="onSelect"
|
||||
/>
|
||||
</template>
|
||||
|
||||
201
admin/src/components/media/MediaPickerModal.vue
Normal file
201
admin/src/components/media/MediaPickerModal.vue
Normal file
@@ -0,0 +1,201 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import {
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogRoot,
|
||||
DialogTitle,
|
||||
} from 'reka-ui'
|
||||
import { X } from '@lucide/vue'
|
||||
import type { AdminMediaItem } from '../../api/types'
|
||||
import { t } from '../../app/i18n'
|
||||
import Button from '../ui/Button.vue'
|
||||
import MediaBrowser from './MediaBrowser.vue'
|
||||
|
||||
// Shared Media Picker modal wrapping MediaBrowser in pick/insert mode.
|
||||
// Reused by MediaFinderField, MailImagePicker, and Blog Editor.
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
open: boolean
|
||||
mode?: 'all' | 'image' | 'file'
|
||||
multiple?: boolean
|
||||
defaultFolder?: string
|
||||
/** 'media' uses /media/*; 'mail' uses /mail/images (backed by album 'mail' folder). */
|
||||
source?: 'media' | 'mail'
|
||||
/** When true (single-select insert mode), displays an editable alt text field. */
|
||||
showAlt?: boolean
|
||||
title?: string
|
||||
confirmLabel?: string
|
||||
altLabel?: string
|
||||
altComment?: string
|
||||
searchPlaceholder?: string
|
||||
uploadLabel?: string
|
||||
uploadingLabel?: string
|
||||
emptyTitle?: string
|
||||
emptyUploadBody?: string
|
||||
emptyReadOnlyBody?: string
|
||||
loadFailedLabel?: string
|
||||
}>(),
|
||||
{
|
||||
mode: 'image',
|
||||
multiple: false,
|
||||
defaultFolder: undefined,
|
||||
source: 'media',
|
||||
showAlt: false,
|
||||
title: undefined,
|
||||
confirmLabel: undefined,
|
||||
altLabel: undefined,
|
||||
altComment: undefined,
|
||||
searchPlaceholder: undefined,
|
||||
uploadLabel: undefined,
|
||||
uploadingLabel: undefined,
|
||||
emptyTitle: undefined,
|
||||
emptyUploadBody: undefined,
|
||||
emptyReadOnlyBody: undefined,
|
||||
loadFailedLabel: undefined,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [open: boolean]
|
||||
select: [payload: { items: AdminMediaItem[]; alt: string }]
|
||||
}>()
|
||||
|
||||
const browserRef = ref<InstanceType<typeof MediaBrowser> | null>(null)
|
||||
const selected = ref<AdminMediaItem[]>([])
|
||||
const alt = ref('')
|
||||
|
||||
const isMailSource = computed(() => props.source === 'mail')
|
||||
const resolvedTitle = computed(() => props.title ?? t('backend::lang.media.picker_title'))
|
||||
const resolvedConfirmLabel = computed(() => {
|
||||
if (props.confirmLabel) {
|
||||
return props.confirmLabel
|
||||
}
|
||||
if (props.multiple && selected.value.length > 0) {
|
||||
return t('backend::lang.media.picker_select_count', { count: selected.value.length })
|
||||
}
|
||||
return t('backend::lang.media.picker_select')
|
||||
})
|
||||
|
||||
function setOpen(open: boolean): void {
|
||||
emit('update:open', open)
|
||||
}
|
||||
|
||||
function onSelectionChange(items: AdminMediaItem[]): void {
|
||||
selected.value = items
|
||||
if (props.showAlt && items.length > 0) {
|
||||
const first = items[0]!
|
||||
alt.value = first.alt || first.title || ''
|
||||
}
|
||||
}
|
||||
|
||||
function confirm(): void {
|
||||
if (selected.value.length === 0) {
|
||||
return
|
||||
}
|
||||
emit('select', { items: selected.value, alt: alt.value })
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
function onActivate(item: AdminMediaItem): void {
|
||||
selected.value = [item]
|
||||
if (props.showAlt) {
|
||||
alt.value = item.alt || item.title || ''
|
||||
return
|
||||
}
|
||||
confirm()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
selected.value = []
|
||||
alt.value = ''
|
||||
void nextTick(() => browserRef.value?.focusGrid())
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DialogRoot :open="open" @update:open="setOpen">
|
||||
<DialogPortal>
|
||||
<DialogOverlay class="fixed inset-0 z-40 bg-overlay" />
|
||||
<DialogContent
|
||||
data-media-picker-modal
|
||||
:data-mail-image-picker="isMailSource ? '' : undefined"
|
||||
:class="isMailSource ? 'max-w-[560px]' : 'max-w-[960px] h-[min(82vh,720px)]'"
|
||||
class="fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-32px)] w-[calc(100%-32px)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 rounded-modal bg-surface p-6 text-text shadow-pop"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<DialogTitle class="text-[20px] font-bold tracking-[-0.01em]">{{ resolvedTitle }}</DialogTitle>
|
||||
<DialogClose
|
||||
type="button"
|
||||
class="flex size-[34px] shrink-0 items-center justify-center rounded-tab bg-subtle text-muted hover:bg-hover hover:text-text"
|
||||
:aria-label="t('backend::lang.form.cancel')"
|
||||
>
|
||||
<X :size="16" aria-hidden="true" />
|
||||
</DialogClose>
|
||||
</div>
|
||||
|
||||
<MediaBrowser
|
||||
v-if="open"
|
||||
ref="browserRef"
|
||||
:mode="mode"
|
||||
:selectable="true"
|
||||
:multiple="multiple"
|
||||
:default-folder="defaultFolder"
|
||||
:source="source"
|
||||
:search-placeholder="searchPlaceholder"
|
||||
:upload-label="uploadLabel"
|
||||
:uploading-label="uploadingLabel"
|
||||
:empty-title="emptyTitle"
|
||||
:empty-upload-body="emptyUploadBody"
|
||||
:empty-read-only-body="emptyReadOnlyBody"
|
||||
:load-failed-label="loadFailedLabel"
|
||||
:grid-aria-label="resolvedTitle"
|
||||
@selection-change="onSelectionChange"
|
||||
@activate="onActivate"
|
||||
/>
|
||||
|
||||
<div v-if="showAlt && selected.length > 0" class="flex flex-col gap-1.5 border-t border-border pt-3">
|
||||
<label class="text-[13px] font-semibold" for="media-picker-alt">
|
||||
{{ altLabel ?? t('backend::lang.media.alt') }}
|
||||
</label>
|
||||
<p v-if="altComment" class="text-[13px] text-muted">{{ altComment }}</p>
|
||||
<input
|
||||
id="media-picker-alt"
|
||||
v-model="alt"
|
||||
type="text"
|
||||
:data-mail-image-alt="isMailSource ? '' : undefined"
|
||||
data-media-picker-alt
|
||||
class="h-input w-full rounded-control border border-border-strong bg-surface px-3.5 text-text"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-2.5 border-t border-border pt-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
:data-mail-image-cancel="isMailSource ? '' : undefined"
|
||||
data-media-picker-cancel
|
||||
@click="setOpen(false)"
|
||||
>
|
||||
{{ t('backend::lang.form.cancel') }}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
:data-mail-image-confirm="isMailSource ? '' : undefined"
|
||||
data-media-picker-confirm
|
||||
:disabled="selected.length === 0"
|
||||
@click="confirm"
|
||||
>
|
||||
{{ resolvedConfirmLabel }}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</DialogPortal>
|
||||
</DialogRoot>
|
||||
</template>
|
||||
@@ -25,6 +25,9 @@ const crumbs = computed<Crumb[]>(() => {
|
||||
if (route.name === 'account') {
|
||||
return [{ label: t('backend::lang.myaccount.menu_label') }]
|
||||
}
|
||||
if (route.name === 'media') {
|
||||
return [{ label: t('backend::lang.media.title') }]
|
||||
}
|
||||
if (route.name === 'plugins') {
|
||||
return [{ label: t('backend::lang.nav.settings'), to: '/settings' }, { label: t('backend::lang.plugins.title') }]
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { RouterLink, useRoute } from 'vue-router'
|
||||
import { Moon, PanelLeftOpen, Settings, Sun, SunMoon } from '@lucide/vue'
|
||||
import { Images, Moon, PanelLeftOpen, Settings, Sun, SunMoon } from '@lucide/vue'
|
||||
import { t } from '../../app/i18n'
|
||||
import { controllerIdFromPath } from '../../app/controllerRoutes'
|
||||
import { iconFor } from '../../app/icons'
|
||||
import { hasMedia } from '../../state/useMediaAccess'
|
||||
import { activeEntry, firstControllerPath, railEntries } from '../../state/useNavigation'
|
||||
import { cycleTheme, themeChoice } from '../../state/usePreferences'
|
||||
import { hasSettings, settingsEntryForPath, settingsLinkFor } from '../../state/useSettings'
|
||||
@@ -36,6 +37,7 @@ const themeIcon = computed(() => themeModes[themeChoice.value].icon)
|
||||
const themeLabel = computed(() => t('backend::lang.nav.theme', { mode: t(themeModes[themeChoice.value].key) }))
|
||||
|
||||
const active = computed(() => activeEntry(String(route.params.vendor ?? ''), String(route.params.plugin ?? '')))
|
||||
const inMedia = computed(() => route.path === '/media' || route.path.startsWith('/media/'))
|
||||
|
||||
// Ustawienia (D-21) is pinned to the bottom and shown only when the admin may
|
||||
// manage at least one settings page. It is also current on a controller a
|
||||
@@ -196,6 +198,17 @@ onBeforeUnmount(cancelClose)
|
||||
<component :is="item.icon" :size="20" aria-hidden="true" />
|
||||
<span class="max-w-full [overflow-wrap:anywhere]">{{ item.entry.label }}</span>
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
v-if="hasMedia"
|
||||
to="/media"
|
||||
data-rail-media
|
||||
:aria-current="inMedia ? 'page' : undefined"
|
||||
:class="inMedia ? 'bg-accent-soft font-bold text-accent' : 'text-side-text hover:bg-side-hover hover:text-white'"
|
||||
class="flex w-[92px] flex-col items-center gap-1 rounded-inner px-1 py-2 text-center text-[11px] leading-[1.2] tracking-[-0.01em] no-underline transition-colors duration-150 ease-out"
|
||||
>
|
||||
<Images :size="20" aria-hidden="true" />
|
||||
<span class="max-w-full [overflow-wrap:anywhere]">{{ t('backend::lang.nav.media') }}</span>
|
||||
</RouterLink>
|
||||
<SectionFlyout
|
||||
v-if="collapsed && openEntry"
|
||||
:id="flyoutId(openEntry.code)"
|
||||
|
||||
Reference in New Issue
Block a user