deneljs 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +57 -2
- package/drizzle/0000_lonely_reptil.sql +27 -0
- package/drizzle/0001_misty_wendigo.sql +74 -0
- package/drizzle/meta/0000_snapshot.json +179 -0
- package/drizzle/meta/0001_snapshot.json +492 -0
- package/drizzle/meta/_journal.json +20 -0
- package/package.json +55 -4
- package/src/admin/auth.ts +851 -0
- package/src/admin/layout.ts +419 -0
- package/src/admin/pages/categories.ts +223 -0
- package/src/admin/pages/dashboard.ts +192 -0
- package/src/admin/pages/media.ts +270 -0
- package/src/admin/pages/posts.ts +804 -0
- package/src/admin/pages/settings.ts +169 -0
- package/src/admin/pages/themes.ts +461 -0
- package/src/admin/pages/users.ts +501 -0
- package/src/admin/routes.ts +455 -0
- package/src/admin/tiptap-bundle.ts +48 -0
- package/src/admin/tiptap-entry.ts +226 -0
- package/src/ai/generator.ts +296 -0
- package/src/ai/index.ts +22 -0
- package/src/ai/schema.ts +13 -0
- package/src/ai/spec.ts +193 -0
- package/src/cli.ts +151 -0
- package/src/db/index.ts +278 -0
- package/src/db/schema.ts +115 -0
- package/src/engine/index.ts +52 -0
- package/src/engine/renderer.ts +533 -0
- package/src/engine/sandbox.ts +108 -0
- package/src/engine/schema.ts +71 -0
- package/src/engine/validator.ts +404 -0
- package/src/routes/admin-api.ts +1035 -0
- package/src/routes/posts.ts +294 -0
- package/src/routes/uploads.ts +119 -0
- package/src/server.ts +672 -0
- package/src/utils/sanitize-html.ts +145 -0
- package/themes/.gitkeep +1 -0
- package/themes/default/assets/style.css +799 -0
- package/themes/default/layouts/base.liquid +31 -0
- package/themes/default/layouts/home.liquid +180 -0
- package/themes/default/layouts/page.liquid +21 -0
- package/themes/default/layouts/post.liquid +55 -0
- package/themes/default/partials/footer.liquid +33 -0
- package/themes/default/partials/navbar.liquid +49 -0
- package/themes/default/theme.json +59 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { escapeHtml } from "../layout";
|
|
2
|
+
|
|
3
|
+
export interface DashboardStats {
|
|
4
|
+
totalPosts: number;
|
|
5
|
+
publishedPosts: number;
|
|
6
|
+
categoriesCount: number;
|
|
7
|
+
mediaCount: number;
|
|
8
|
+
usersCount: number;
|
|
9
|
+
activeTheme: string;
|
|
10
|
+
activeThemeDetails: {
|
|
11
|
+
name: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
version: string;
|
|
14
|
+
author: string;
|
|
15
|
+
description: string;
|
|
16
|
+
} | null;
|
|
17
|
+
recentPosts: Array<{
|
|
18
|
+
id: number;
|
|
19
|
+
title: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
status: string;
|
|
22
|
+
categoryName: string | null;
|
|
23
|
+
updated_at: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function formatDate(epochSeconds: number): string {
|
|
28
|
+
if (!epochSeconds) return "—";
|
|
29
|
+
return new Date(epochSeconds * 1000).toLocaleDateString("en-US", {
|
|
30
|
+
year: "numeric",
|
|
31
|
+
month: "short",
|
|
32
|
+
day: "numeric",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render the Admin Dashboard overview page (/admin).
|
|
38
|
+
*/
|
|
39
|
+
export function renderDashboardPage(stats: DashboardStats, isAdmin: boolean): string {
|
|
40
|
+
const cards = [
|
|
41
|
+
{ label: "Total Posts", value: String(stats.totalPosts), icon: "file-text", color: "text-blue-600 bg-blue-50" },
|
|
42
|
+
{ label: "Published Posts", value: String(stats.publishedPosts), icon: "check-circle", color: "text-emerald-600 bg-emerald-50" },
|
|
43
|
+
{ label: "Categories", value: String(stats.categoriesCount), icon: "folder-tree", color: "text-indigo-600 bg-indigo-50" },
|
|
44
|
+
{ label: "Media Files", value: String(stats.mediaCount), icon: "image", color: "text-amber-600 bg-amber-50" },
|
|
45
|
+
{ label: "Users", value: String(stats.usersCount), icon: "users", color: "text-violet-600 bg-violet-50" },
|
|
46
|
+
{ label: "Active Theme", value: stats.activeThemeDetails?.name || stats.activeTheme, icon: "palette", color: "text-rose-600 bg-rose-50" },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const cardsHtml = cards
|
|
50
|
+
.map(
|
|
51
|
+
(card) => `
|
|
52
|
+
<div class="bg-white rounded-xl border border-slate-200 p-4 shadow-sm flex items-center justify-between gap-3">
|
|
53
|
+
<div class="min-w-0">
|
|
54
|
+
<p class="text-xs font-medium text-slate-500">${escapeHtml(card.label)}</p>
|
|
55
|
+
<p class="mt-1 text-xl font-bold text-slate-900 truncate">${escapeHtml(card.value)}</p>
|
|
56
|
+
</div>
|
|
57
|
+
<div class="w-10 h-10 rounded-lg ${card.color} flex items-center justify-center shrink-0">
|
|
58
|
+
<i data-lucide="${card.icon}" class="w-5 h-5"></i>
|
|
59
|
+
</div>
|
|
60
|
+
</div>`,
|
|
61
|
+
)
|
|
62
|
+
.join("");
|
|
63
|
+
|
|
64
|
+
const theme = stats.activeThemeDetails;
|
|
65
|
+
const activeThemeCardHtml = `
|
|
66
|
+
<div class="bg-white rounded-xl border border-slate-200 p-5 shadow-sm flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
67
|
+
<div class="space-y-1">
|
|
68
|
+
<div class="flex items-center gap-2 flex-wrap">
|
|
69
|
+
<span class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
|
70
|
+
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
|
|
71
|
+
Active Theme
|
|
72
|
+
</span>
|
|
73
|
+
<h2 class="text-base font-bold text-slate-900">${escapeHtml(theme?.name || stats.activeTheme)}</h2>
|
|
74
|
+
<span class="text-xs font-mono text-slate-500 bg-slate-100 px-2 py-0.5 rounded">${escapeHtml(theme?.slug || stats.activeTheme)}</span>
|
|
75
|
+
${theme?.version ? `<span class="text-xs text-slate-500">v${escapeHtml(theme.version)}</span>` : ""}
|
|
76
|
+
</div>
|
|
77
|
+
<p class="text-xs text-slate-600">${escapeHtml(theme?.description || "Active storefront LiquidJS theme.")}${theme?.author ? ` · By ${escapeHtml(theme.author)}` : ""}</p>
|
|
78
|
+
</div>
|
|
79
|
+
<div class="flex flex-wrap items-center gap-2 shrink-0">
|
|
80
|
+
<a href="/" target="_blank" rel="noopener" class="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg border border-slate-300 bg-white text-xs font-medium text-slate-700 hover:bg-slate-50">
|
|
81
|
+
<i data-lucide="external-link" class="w-3.5 h-3.5"></i>
|
|
82
|
+
Preview Site
|
|
83
|
+
</a>
|
|
84
|
+
${
|
|
85
|
+
isAdmin
|
|
86
|
+
? `<a href="/admin/themes/customize" class="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-lg bg-blue-600 text-white text-xs font-medium hover:bg-blue-700">
|
|
87
|
+
<i data-lucide="sliders-horizontal" class="w-3.5 h-3.5"></i>
|
|
88
|
+
Customize Theme
|
|
89
|
+
</a>
|
|
90
|
+
<a href="/admin/themes" class="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-slate-900 text-white text-xs font-medium hover:bg-slate-800">
|
|
91
|
+
<i data-lucide="palette" class="w-3.5 h-3.5"></i>
|
|
92
|
+
Manage Themes
|
|
93
|
+
</a>`
|
|
94
|
+
: ""
|
|
95
|
+
}
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
const recentRowsHtml =
|
|
101
|
+
stats.recentPosts.length === 0
|
|
102
|
+
? `<tr><td colspan="5" class="px-5 py-8 text-center text-sm text-slate-500">No posts found yet.</td></tr>`
|
|
103
|
+
: stats.recentPosts
|
|
104
|
+
.map((post) => {
|
|
105
|
+
const badgeCls =
|
|
106
|
+
post.status === "published"
|
|
107
|
+
? "bg-emerald-50 text-emerald-700 border-emerald-200"
|
|
108
|
+
: "bg-amber-50 text-amber-700 border-amber-200";
|
|
109
|
+
return `
|
|
110
|
+
<tr class="hover:bg-slate-50/70">
|
|
111
|
+
<td class="px-5 py-3.5 text-sm font-medium text-slate-900">
|
|
112
|
+
<a href="/admin/posts/${post.id}/edit" class="hover:text-blue-600">${escapeHtml(post.title)}</a>
|
|
113
|
+
</td>
|
|
114
|
+
<td class="px-5 py-3.5 text-xs text-slate-600">${escapeHtml(post.categoryName || "Uncategorized")}</td>
|
|
115
|
+
<td class="px-5 py-3.5">
|
|
116
|
+
<span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium border ${badgeCls}">${escapeHtml(post.status)}</span>
|
|
117
|
+
</td>
|
|
118
|
+
<td class="px-5 py-3.5 text-xs text-slate-500">${escapeHtml(formatDate(post.updated_at))}</td>
|
|
119
|
+
<td class="px-5 py-3.5 text-right text-xs font-medium space-x-2">
|
|
120
|
+
<a href="/admin/posts/${post.id}/edit" class="text-blue-600 hover:underline">Edit</a>
|
|
121
|
+
${post.status === "published" ? `<a href="/post/${escapeHtml(post.slug)}" target="_blank" rel="noopener" class="text-slate-500 hover:text-slate-900">View</a>` : ""}
|
|
122
|
+
</td>
|
|
123
|
+
</tr>`;
|
|
124
|
+
})
|
|
125
|
+
.join("");
|
|
126
|
+
|
|
127
|
+
return `
|
|
128
|
+
<div class="space-y-6">
|
|
129
|
+
<!-- Stat Cards -->
|
|
130
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4">
|
|
131
|
+
${cardsHtml}
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<!-- Active Theme Showcase -->
|
|
135
|
+
${activeThemeCardHtml}
|
|
136
|
+
|
|
137
|
+
<!-- Quick Actions -->
|
|
138
|
+
<div class="bg-white rounded-xl border border-slate-200 p-5 shadow-sm flex flex-wrap items-center justify-between gap-4">
|
|
139
|
+
<div>
|
|
140
|
+
<h2 class="text-sm font-semibold text-slate-900">Quick Actions</h2>
|
|
141
|
+
<p class="text-xs text-slate-500">Jump straight into common CMS workflows.</p>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="flex flex-wrap items-center gap-2.5">
|
|
144
|
+
<a href="/admin/posts/new" class="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-lg bg-slate-900 text-white text-xs font-medium hover:bg-slate-800 transition">
|
|
145
|
+
<i data-lucide="plus" class="w-4 h-4"></i>
|
|
146
|
+
New Post
|
|
147
|
+
</a>
|
|
148
|
+
<a href="/admin/media" class="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-lg border border-slate-300 bg-white text-slate-700 text-xs font-medium hover:bg-slate-50 transition">
|
|
149
|
+
<i data-lucide="upload" class="w-4 h-4"></i>
|
|
150
|
+
Upload Media
|
|
151
|
+
</a>
|
|
152
|
+
<a href="/admin/categories" class="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-lg border border-slate-300 bg-white text-slate-700 text-xs font-medium hover:bg-slate-50 transition">
|
|
153
|
+
<i data-lucide="folder-tree" class="w-4 h-4"></i>
|
|
154
|
+
Manage Categories
|
|
155
|
+
</a>
|
|
156
|
+
${
|
|
157
|
+
isAdmin
|
|
158
|
+
? `<a href="/admin/themes" class="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-lg border border-slate-300 bg-white text-slate-700 text-xs font-medium hover:bg-slate-50 transition">
|
|
159
|
+
<i data-lucide="palette" class="w-4 h-4"></i>
|
|
160
|
+
Upload Theme
|
|
161
|
+
</a>`
|
|
162
|
+
: ""
|
|
163
|
+
}
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<!-- 5 Most Recent Posts -->
|
|
168
|
+
<div class="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden">
|
|
169
|
+
<div class="px-5 py-4 border-b border-slate-200 flex items-center justify-between">
|
|
170
|
+
<h2 class="text-sm font-semibold text-slate-900">Recent Posts</h2>
|
|
171
|
+
<a href="/admin/posts" class="text-xs font-medium text-blue-600 hover:text-blue-700">View all →</a>
|
|
172
|
+
</div>
|
|
173
|
+
<div class="overflow-x-auto">
|
|
174
|
+
<table class="w-full text-left border-collapse">
|
|
175
|
+
<thead>
|
|
176
|
+
<tr class="bg-slate-50 border-b border-slate-200 text-[11px] font-semibold uppercase tracking-wider text-slate-500">
|
|
177
|
+
<th class="px-5 py-3">Title</th>
|
|
178
|
+
<th class="px-5 py-3">Category</th>
|
|
179
|
+
<th class="px-5 py-3">Status</th>
|
|
180
|
+
<th class="px-5 py-3">Updated</th>
|
|
181
|
+
<th class="px-5 py-3 text-right">Actions</th>
|
|
182
|
+
</tr>
|
|
183
|
+
</thead>
|
|
184
|
+
<tbody class="divide-y divide-slate-200">
|
|
185
|
+
${recentRowsHtml}
|
|
186
|
+
</tbody>
|
|
187
|
+
</table>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { serializeSafeJson } from "../layout";
|
|
2
|
+
|
|
3
|
+
export interface MediaListItem {
|
|
4
|
+
id: number;
|
|
5
|
+
filename: string;
|
|
6
|
+
original_name: string;
|
|
7
|
+
mime_type: string;
|
|
8
|
+
size_bytes: number;
|
|
9
|
+
url: string;
|
|
10
|
+
alt_text: string;
|
|
11
|
+
created_at: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Render the Media Library Manager (/admin/media).
|
|
16
|
+
*/
|
|
17
|
+
export function renderMediaPage(initialFiles: MediaListItem[]): string {
|
|
18
|
+
const seed = serializeSafeJson({ files: initialFiles });
|
|
19
|
+
|
|
20
|
+
return `
|
|
21
|
+
<script id="media-seed" type="application/json">${seed}</script>
|
|
22
|
+
<script>
|
|
23
|
+
document.addEventListener("alpine:init", () => {
|
|
24
|
+
Alpine.data("mediaLibrary", () => ({
|
|
25
|
+
files: [],
|
|
26
|
+
search: "",
|
|
27
|
+
typeFilter: "all",
|
|
28
|
+
isDragging: false,
|
|
29
|
+
uploading: false,
|
|
30
|
+
errors: [],
|
|
31
|
+
confirmDeleteId: null,
|
|
32
|
+
|
|
33
|
+
init() {
|
|
34
|
+
const el = document.getElementById("media-seed");
|
|
35
|
+
const seed = el ? JSON.parse(el.textContent || "{}") : {};
|
|
36
|
+
this.files = Array.isArray(seed.files) ? seed.files : [];
|
|
37
|
+
|
|
38
|
+
window.addEventListener("cms-media-uploaded", (e) => {
|
|
39
|
+
const incoming = e.detail?.files;
|
|
40
|
+
if (Array.isArray(incoming) && incoming.length > 0) {
|
|
41
|
+
this.prependFiles(incoming);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
get filteredFiles() {
|
|
47
|
+
const q = this.search.trim().toLowerCase();
|
|
48
|
+
return this.files.filter((file) => {
|
|
49
|
+
if (this.typeFilter === "images" && !this.isImage(file)) return false;
|
|
50
|
+
if (this.typeFilter === "documents" && this.isImage(file)) return false;
|
|
51
|
+
if (q) {
|
|
52
|
+
const hay = (String(file.original_name || "") + " " + String(file.alt_text || "")).toLowerCase();
|
|
53
|
+
if (!hay.includes(q)) return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
prependFiles(newFiles) {
|
|
60
|
+
const existingIds = new Set(this.files.map((f) => f.id));
|
|
61
|
+
const uniqueNew = newFiles.filter((f) => !existingIds.has(f.id));
|
|
62
|
+
this.files = [...uniqueNew, ...this.files];
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
isImage(file) {
|
|
66
|
+
return String(file?.mime_type || "").startsWith("image/") || /\\.(webp|png|jpe?g|gif)$/i.test(file?.filename || "");
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
formatBytes(bytes) {
|
|
70
|
+
if (!bytes) return "0 B";
|
|
71
|
+
if (bytes < 1024) return bytes + " B";
|
|
72
|
+
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
|
|
73
|
+
return (bytes / (1024 * 1024)).toFixed(2) + " MB";
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
async refresh() {
|
|
77
|
+
const res = await fetch("/api/admin/media?t=" + Date.now(), { cache: "no-store" });
|
|
78
|
+
if (res.ok) {
|
|
79
|
+
const data = await res.json();
|
|
80
|
+
this.files = Array.isArray(data.files) ? data.files : [];
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
handleDrop(e) {
|
|
85
|
+
this.isDragging = false;
|
|
86
|
+
if (e.dataTransfer?.files?.length) {
|
|
87
|
+
this.uploadFiles(e.dataTransfer.files);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
handleSelect(e) {
|
|
92
|
+
const input = e.target;
|
|
93
|
+
if (input?.files?.length) {
|
|
94
|
+
this.uploadFiles(input.files);
|
|
95
|
+
}
|
|
96
|
+
if (input) input.value = "";
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
async uploadFiles(fileList) {
|
|
100
|
+
this.uploading = true;
|
|
101
|
+
this.errors = [];
|
|
102
|
+
const fd = new FormData();
|
|
103
|
+
for (const f of fileList) {
|
|
104
|
+
fd.append("files", f);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetch("/api/admin/media/upload", { method: "POST", body: fd });
|
|
109
|
+
const data = await res.json();
|
|
110
|
+
if (!res.ok || !data.success) {
|
|
111
|
+
this.errors = Array.isArray(data.errors) ? data.errors : ["Upload failed."];
|
|
112
|
+
window.cmsToast("error", this.errors[0]);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (Array.isArray(data.files) && data.files.length > 0) {
|
|
116
|
+
this.prependFiles(data.files);
|
|
117
|
+
} else {
|
|
118
|
+
await this.refresh();
|
|
119
|
+
}
|
|
120
|
+
window.cmsToast("success", "Uploaded " + (data.files?.length || 1) + " file(s).");
|
|
121
|
+
} catch {
|
|
122
|
+
this.errors = ["Network error while uploading files."];
|
|
123
|
+
} finally {
|
|
124
|
+
this.uploading = false;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
async copyUrl(url) {
|
|
129
|
+
const absolute = window.location.origin + url;
|
|
130
|
+
try {
|
|
131
|
+
await navigator.clipboard.writeText(absolute);
|
|
132
|
+
window.cmsToast("success", "Copied URL to clipboard.");
|
|
133
|
+
} catch {
|
|
134
|
+
window.cmsToast("success", "URL: " + url);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
async saveAlt(file) {
|
|
139
|
+
try {
|
|
140
|
+
const res = await fetch("/api/admin/media/" + file.id, {
|
|
141
|
+
method: "PUT",
|
|
142
|
+
headers: { "content-type": "application/json" },
|
|
143
|
+
body: JSON.stringify({ alt_text: file.alt_text || "" })
|
|
144
|
+
});
|
|
145
|
+
if (res.ok) {
|
|
146
|
+
window.cmsToast("success", "Alt text saved.");
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
window.cmsToast("error", "Failed to update alt text.");
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
async deleteFile(id) {
|
|
154
|
+
try {
|
|
155
|
+
const res = await fetch("/api/admin/media/" + id, { method: "DELETE" });
|
|
156
|
+
const data = await res.json();
|
|
157
|
+
if (!res.ok || !data.success) {
|
|
158
|
+
window.cmsToast("error", "Failed to delete media.");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.confirmDeleteId = null;
|
|
162
|
+
this.files = this.files.filter((f) => f.id !== id);
|
|
163
|
+
window.cmsToast("success", "Media file deleted.");
|
|
164
|
+
} catch {
|
|
165
|
+
window.cmsToast("error", "Network error while deleting media.");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}));
|
|
169
|
+
});
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
<div x-data="mediaLibrary" class="space-y-6">
|
|
173
|
+
<!-- Multi-file Dropzone -->
|
|
174
|
+
<div
|
|
175
|
+
@dragover.prevent="isDragging = true"
|
|
176
|
+
@dragleave.prevent="isDragging = false"
|
|
177
|
+
@drop.prevent="handleDrop($event)"
|
|
178
|
+
:class="isDragging ? 'border-blue-500 bg-blue-50/70' : 'border-slate-300 bg-white'"
|
|
179
|
+
class="rounded-xl border-2 border-dashed p-6 text-center transition"
|
|
180
|
+
>
|
|
181
|
+
<input x-ref="fileInput" type="file" multiple accept=".webp,.png,.jpg,.jpeg,.gif,.pdf" class="hidden" @change="handleSelect($event)">
|
|
182
|
+
<div class="max-w-md mx-auto space-y-2">
|
|
183
|
+
<p class="text-sm font-medium text-slate-900" x-text="uploading ? 'Uploading files...' : 'Drag and drop images or PDFs here'"></p>
|
|
184
|
+
<p class="text-xs text-slate-500">Allowed extensions: <code>.webp</code>, <code>.png</code>, <code>.jpg</code>, <code>.jpeg</code>, <code>.gif</code>, <code>.pdf</code> (max 15MB each).</p>
|
|
185
|
+
<div class="pt-2">
|
|
186
|
+
<button type="button" :disabled="uploading" @click="$refs.fileInput.click()" class="px-4 py-2 rounded-lg bg-slate-900 text-white text-xs font-medium hover:bg-slate-800 disabled:opacity-50">
|
|
187
|
+
Select Files
|
|
188
|
+
</button>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
<div x-show="errors.length > 0" x-cloak class="mt-4 max-w-xl mx-auto text-left rounded-lg bg-red-50 border border-red-200 p-3 text-xs text-red-700 space-y-1">
|
|
193
|
+
<template x-for="(err, idx) in errors" :key="idx">
|
|
194
|
+
<p x-text="err"></p>
|
|
195
|
+
</template>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<!-- Filter Bar -->
|
|
200
|
+
<div class="flex flex-wrap items-center justify-between gap-3">
|
|
201
|
+
<div class="flex flex-wrap items-center gap-2.5">
|
|
202
|
+
<input
|
|
203
|
+
type="search"
|
|
204
|
+
x-model="search"
|
|
205
|
+
placeholder="Search filename or alt text..."
|
|
206
|
+
class="w-full sm:w-64 rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none"
|
|
207
|
+
>
|
|
208
|
+
<select
|
|
209
|
+
x-model="typeFilter"
|
|
210
|
+
class="rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none"
|
|
211
|
+
>
|
|
212
|
+
<option value="all">All types</option>
|
|
213
|
+
<option value="images">Images only</option>
|
|
214
|
+
<option value="documents">PDF documents</option>
|
|
215
|
+
</select>
|
|
216
|
+
</div>
|
|
217
|
+
<span class="text-xs font-medium text-slate-500">
|
|
218
|
+
Showing <span x-text="filteredFiles.length"></span> of <span x-text="files.length"></span> file(s)
|
|
219
|
+
</span>
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<!-- Responsive Grid -->
|
|
223
|
+
<div x-show="filteredFiles.length === 0" x-cloak class="bg-white rounded-xl border border-slate-200 p-10 text-center text-sm text-slate-500">
|
|
224
|
+
No media files found.
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<div x-show="filteredFiles.length > 0" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-5">
|
|
228
|
+
<template x-for="file in filteredFiles" :key="file.id">
|
|
229
|
+
<div class="bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden flex flex-col">
|
|
230
|
+
<div class="aspect-video bg-slate-100 flex items-center justify-center overflow-hidden">
|
|
231
|
+
<img x-show="isImage(file)" :src="file.url" :alt="file.alt_text || file.original_name" class="w-full h-full object-cover">
|
|
232
|
+
<div x-show="!isImage(file)" class="flex flex-col items-center gap-1 text-slate-500">
|
|
233
|
+
<span class="px-2.5 py-1 rounded bg-slate-200 text-slate-800 font-mono text-xs font-semibold">PDF</span>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<div class="p-4 space-y-3 flex-1 flex flex-col justify-between">
|
|
238
|
+
<div class="space-y-1">
|
|
239
|
+
<p class="text-sm font-semibold text-slate-900 truncate" x-text="file.original_name"></p>
|
|
240
|
+
<div class="flex items-center justify-between text-xs text-slate-500">
|
|
241
|
+
<span x-text="formatBytes(file.size_bytes)"></span>
|
|
242
|
+
<button type="button" @click="copyUrl(file.url)" class="text-blue-600 font-medium hover:underline">Copy URL</button>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
<div class="flex items-center gap-1.5">
|
|
247
|
+
<input
|
|
248
|
+
type="text"
|
|
249
|
+
x-model="file.alt_text"
|
|
250
|
+
placeholder="Alt text..."
|
|
251
|
+
class="flex-1 min-w-0 rounded border border-slate-300 px-2 py-1 text-xs focus:border-blue-500 focus:outline-none"
|
|
252
|
+
>
|
|
253
|
+
<button type="button" @click="saveAlt(file)" class="px-2.5 py-1 rounded bg-slate-100 border border-slate-200 text-xs font-medium text-slate-700 hover:bg-slate-200">Save</button>
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
<div class="pt-2 border-t border-slate-100 flex items-center justify-between">
|
|
257
|
+
<a :href="file.url" target="_blank" rel="noopener" class="text-xs text-slate-500 hover:text-slate-900">Open</a>
|
|
258
|
+
<button x-show="confirmDeleteId !== file.id" type="button" @click="confirmDeleteId = file.id" class="text-xs font-medium text-red-600 hover:underline">Delete</button>
|
|
259
|
+
<span x-show="confirmDeleteId === file.id" class="inline-flex items-center gap-1">
|
|
260
|
+
<button type="button" @click="deleteFile(file.id)" class="px-2 py-0.5 rounded bg-red-600 text-white text-xs font-medium">Confirm</button>
|
|
261
|
+
<button type="button" @click="confirmDeleteId = null" class="px-2 py-0.5 rounded bg-slate-100 text-slate-600 text-xs font-medium">Cancel</button>
|
|
262
|
+
</span>
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
</template>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
`;
|
|
270
|
+
}
|