add admin media library with image management and block picker integration

- Schema: alt, caption, tags fields on images table with metadata changeset
- Context: list_images with filters, find_usages, used_image_ids, delete_with_cleanup
- Admin UI: /admin/media with grid view, upload, filters, detail panel, metadata editing
- Block editor: :image field type for image_text and content_body blocks
- Page renderer: image_id resolution with legacy URL fallback
- Mobile: bottom sheet detail panel with slide-up animation
- CSS: uses correct --t-* admin theme tokens, admin-badge colour variants

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-27 22:20:51 +00:00
parent a039c8d53c
commit 847b5f3e5e
15 changed files with 1828 additions and 17 deletions

View File

@@ -474,11 +474,31 @@
font-size: 0.625rem;
}
.admin-badge-info {
background-color: color-mix(in oklch, var(--t-accent) 15%, transparent);
color: var(--t-accent);
}
.admin-badge-accent {
background-color: color-mix(in oklch, var(--t-status-success, #22c55e) 15%, transparent);
color: var(--t-status-success, #16a34a);
}
.admin-badge-warning {
background-color: color-mix(in oklch, var(--t-status-warning, #f59e0b) 15%, transparent);
color: var(--t-status-warning, #b45309);
}
.admin-badge-danger {
background-color: color-mix(in oklch, var(--t-status-error, #ef4444) 15%, transparent);
color: var(--t-status-error, #dc2626);
}
.admin-badge-neutral {
background-color: var(--t-surface-sunken);
color: color-mix(in oklch, var(--t-text-primary) 60%, transparent);
}
/* ── Dropdown ── */
.admin-dropdown {
@@ -677,7 +697,7 @@
.analytics-y-labels,
.analytics-x-labels {
font-size: 0.6875rem;
color: color-mix(in oklch, var(--color-base-content) 55%, transparent);
color: color-mix(in oklch, var(--t-text-primary) 55%, transparent);
font-variant-numeric: tabular-nums;
}
@@ -1566,4 +1586,356 @@
}
}
/* ═══════════════════════════════════════════════════════════════════
Image field (block editor)
═══════════════════════════════════════════════════════════════════ */
.image-field {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.image-field-preview {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem;
border: 1px solid var(--t-surface-sunken);
border-radius: 0.375rem;
background: var(--t-surface-base);
}
.image-field-thumb {
width: 48px;
height: 48px;
object-fit: cover;
border-radius: 0.25rem;
flex-shrink: 0;
}
.image-field-svg {
width: 48px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
background: var(--t-surface-sunken);
border-radius: 0.25rem;
flex-shrink: 0;
color: var(--t-text-primary);
opacity: 0.5;
}
.image-field-info {
display: flex;
flex-direction: column;
min-width: 0;
}
.image-field-filename {
font-size: 0.8125rem;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.image-field-alt {
font-size: 0.75rem;
color: var(--t-text-primary);
opacity: 0.6;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.image-field-empty {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem;
border: 2px dashed var(--t-border-default);
border-radius: 0.375rem;
color: var(--t-text-primary);
opacity: 0.5;
font-size: 0.8125rem;
}
/* ═══════════════════════════════════════════════════════════════════
Media library
═══════════════════════════════════════════════════════════════════ */
.media-layout {
display: flex;
flex-direction: column;
gap: 1rem;
margin-top: 1rem;
}
.media-upload-zone {
border: 2px dashed var(--t-border-default);
border-radius: 0.5rem;
padding: 1rem;
transition: border-color 0.2s;
}
.media-upload-zone[phx-drop-active] {
border-color: var(--color-accent);
background: color-mix(in srgb, var(--color-accent) 5%, transparent);
}
.media-upload-form {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.media-upload-row {
display: flex;
gap: 0.5rem;
align-items: center;
}
.media-upload-progress {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
margin-top: 0.5rem;
}
.media-upload-progress progress {
flex: 1;
height: 0.5rem;
}
.media-main {
display: flex;
gap: 1rem;
min-height: 400px;
}
.media-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: 0.75rem;
flex: 1;
min-width: 0;
align-content: start;
}
.media-card {
border: 2px solid var(--t-surface-sunken);
border-radius: 0.5rem;
overflow: hidden;
cursor: pointer;
transition: border-color 0.15s, box-shadow 0.15s;
background: var(--t-surface-base);
}
.media-card:hover {
border-color: var(--t-border-default);
}
.media-card-selected {
border-color: var(--color-accent);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 25%, transparent);
}
.media-card-thumb {
aspect-ratio: 1;
overflow: hidden;
background: var(--t-surface-sunken);
display: flex;
align-items: center;
justify-content: center;
}
.media-card-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.media-card-svg-placeholder {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.25rem;
color: var(--t-text-primary);
opacity: 0.5;
font-size: 0.75rem;
}
.media-card-info {
padding: 0.5rem;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.media-card-filename {
font-size: 0.75rem;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.media-card-meta {
display: flex;
align-items: center;
gap: 0.25rem;
color: var(--t-text-primary);
opacity: 0.7;
}
.media-card-no-alt {
display: flex;
align-items: center;
gap: 0.25rem;
font-size: 0.625rem;
color: var(--color-warning);
}
/* Detail panel */
.media-detail {
width: 320px;
min-width: 320px;
border: 1px solid var(--t-surface-sunken);
border-radius: 0.5rem;
background: var(--t-surface-base);
padding: 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
max-height: calc(100vh - 12rem);
overflow-y: auto;
position: sticky;
top: 5rem;
}
.media-detail-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.media-detail-header h3 {
font-size: 1rem;
font-weight: 600;
margin: 0;
}
.media-detail-preview {
aspect-ratio: 16/9;
overflow: hidden;
border-radius: 0.375rem;
background: var(--t-surface-sunken);
display: flex;
align-items: center;
justify-content: center;
}
.media-detail-preview img {
width: 100%;
height: 100%;
object-fit: contain;
}
.media-detail-svg {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
color: var(--t-text-primary);
opacity: 0.5;
}
.media-detail-meta {
display: grid;
grid-template-columns: auto 1fr;
gap: 0.25rem 0.75rem;
font-size: 0.8125rem;
}
.media-detail-meta dt {
font-weight: 500;
color: var(--t-text-primary);
opacity: 0.7;
}
.media-detail-meta dd {
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.media-detail-form {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.media-detail-usages {
border-top: 1px solid var(--t-surface-sunken);
padding-top: 0.75rem;
}
.media-detail-usages h4 {
font-size: 0.875rem;
font-weight: 600;
margin: 0 0 0.5rem;
}
.media-detail-usages ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 0.25rem;
font-size: 0.8125rem;
}
.media-detail-usages li {
display: flex;
align-items: center;
gap: 0.5rem;
}
.media-detail-actions {
border-top: 1px solid var(--t-surface-sunken);
padding-top: 0.75rem;
}
@media (max-width: 47.99em) {
.media-grid {
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.media-detail {
position: fixed;
bottom: 0;
left: 0;
right: 0;
width: 100%;
min-width: unset;
max-height: 70vh;
border-radius: 0.75rem 0.75rem 0 0;
box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
z-index: 40;
animation: media-sheet-up 0.25s ease-out;
}
}
@keyframes media-sheet-up {
from { transform: translateY(100%); }
to { transform: translateY(0); }
}
} /* @layer admin */