@arch-cadre/blog-module 1.0.13 → 1.0.15

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.
Files changed (56) hide show
  1. package/dist/actions/index.cjs +158 -0
  2. package/dist/actions/index.d.ts +4 -37
  3. package/dist/actions/index.mjs +121 -0
  4. package/dist/components/BlogStatsWidget.cjs +45 -0
  5. package/dist/components/BlogStatsWidget.d.ts +2 -1
  6. package/dist/components/BlogStatsWidget.mjs +13 -0
  7. package/dist/components/RecentCommentsWidget.cjs +47 -0
  8. package/dist/components/RecentCommentsWidget.d.ts +2 -1
  9. package/dist/components/RecentCommentsWidget.mjs +28 -0
  10. package/dist/components/RecentPostsWidget.cjs +47 -0
  11. package/dist/components/RecentPostsWidget.d.ts +2 -1
  12. package/dist/components/RecentPostsWidget.mjs +28 -0
  13. package/dist/components/ui/button.cjs +54 -0
  14. package/dist/components/ui/button.mjs +47 -0
  15. package/dist/components/ui/card.cjs +47 -0
  16. package/dist/components/ui/card.mjs +36 -0
  17. package/dist/components/ui/input.cjs +24 -0
  18. package/dist/components/ui/input.mjs +17 -0
  19. package/dist/components/ui/table.cjs +68 -0
  20. package/dist/components/ui/table.mjs +65 -0
  21. package/dist/components/ui/textarea.cjs +22 -0
  22. package/dist/components/ui/textarea.mjs +16 -0
  23. package/dist/index.cjs +100 -0
  24. package/dist/index.mjs +95 -0
  25. package/dist/intl.d.ts +7 -0
  26. package/dist/lib/utils.cjs +11 -0
  27. package/dist/lib/{utils.js → utils.mjs} +1 -1
  28. package/dist/lib/validation.cjs +16 -0
  29. package/dist/lib/validation.d.ts +2 -2
  30. package/dist/lib/validation.mjs +10 -0
  31. package/dist/navigation.cjs +23 -0
  32. package/dist/navigation.mjs +21 -0
  33. package/dist/routes.cjs +74 -0
  34. package/dist/routes.mjs +68 -0
  35. package/dist/schema.cjs +62 -0
  36. package/dist/schema.mjs +53 -0
  37. package/dist/styles/globals.css +1 -0
  38. package/dist/ui/views.cjs +448 -0
  39. package/dist/ui/views.d.ts +6 -5
  40. package/dist/ui/views.mjs +232 -0
  41. package/package.json +14 -10
  42. package/dist/actions/index.js +0 -149
  43. package/dist/components/BlogStatsWidget.js +0 -17
  44. package/dist/components/RecentCommentsWidget.js +0 -24
  45. package/dist/components/RecentPostsWidget.js +0 -24
  46. package/dist/components/ui/button.js +0 -33
  47. package/dist/components/ui/card.js +0 -12
  48. package/dist/components/ui/input.js +0 -8
  49. package/dist/components/ui/table.js +0 -16
  50. package/dist/components/ui/textarea.js +0 -8
  51. package/dist/index.js +0 -98
  52. package/dist/lib/validation.js +0 -11
  53. package/dist/navigation.js +0 -21
  54. package/dist/routes.js +0 -55
  55. package/dist/schema.js +0 -60
  56. package/dist/ui/views.js +0 -119
@@ -0,0 +1,232 @@
1
+ "use client";
2
+ import { useTranslation } from "@arch-cadre/intl/client";
3
+ import { zodResolver } from "@hookform/resolvers/zod";
4
+ import {
5
+ ArrowLeft,
6
+ Eye,
7
+ MessageSquare,
8
+ Pencil,
9
+ Plus,
10
+ Trash2,
11
+ User as UserIcon
12
+ } from "lucide-react";
13
+ import Link from "next/link";
14
+ import { useRouter } from "next/navigation";
15
+ import * as React from "react";
16
+ import { useForm } from "react-hook-form";
17
+ import { toast } from "sonner";
18
+ import { createComment, createPost, deletePost, updatePost } from "../actions/index.mjs";
19
+ import { Button } from "../components/ui/button.mjs";
20
+ import {
21
+ Card,
22
+ CardContent,
23
+ CardHeader,
24
+ CardTitle
25
+ } from "../components/ui/card.mjs";
26
+ import { Input } from "../components/ui/input.mjs";
27
+ import {
28
+ Table,
29
+ TableBody,
30
+ TableCell,
31
+ TableHead,
32
+ TableHeader,
33
+ TableRow
34
+ } from "../components/ui/table.mjs";
35
+ import { Textarea } from "../components/ui/textarea.mjs";
36
+ import { commentSchema, postSchema } from "../lib/validation.mjs";
37
+ export function BlogListPage({ posts = [] }) {
38
+ const { t } = useTranslation();
39
+ return /* @__PURE__ */ React.createElement("div", { className: "max-w-4xl mx-auto p-6 space-y-8" }, /* @__PURE__ */ React.createElement("header", { className: "border-b pb-6" }, /* @__PURE__ */ React.createElement("h1", { className: "text-4xl font-black tracking-tighter text-primary" }, t("Blog Posts")), /* @__PURE__ */ React.createElement("p", { className: "text-muted-foreground mt-2" }, t("Reading your blog posts"))), /* @__PURE__ */ React.createElement("div", { className: "grid gap-6" }, posts.map((post) => /* @__PURE__ */ React.createElement(Link, { href: `/blog/${post.slug}`, key: post.id }, /* @__PURE__ */ React.createElement(Card, { className: "group hover:shadow-lg transition-all cursor-pointer overflow-hidden border-primary/5" }, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(CardTitle, { className: "text-2xl group-hover:text-primary transition-colors" }, post.title), /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2 text-xs text-muted-foreground mt-1" }, /* @__PURE__ */ React.createElement(UserIcon, { className: "size-3" }), /* @__PURE__ */ React.createElement("span", null, post.author?.name), /* @__PURE__ */ React.createElement("span", null, "\u2022"), /* @__PURE__ */ React.createElement("span", null, new Date(post.createdAt).toLocaleDateString()))), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement("p", { className: "text-secondary-foreground line-clamp-2" }, post.content)))))));
40
+ }
41
+ function CommentForm({ postId }) {
42
+ const router = useRouter();
43
+ const { t } = useTranslation();
44
+ const {
45
+ register,
46
+ handleSubmit,
47
+ reset,
48
+ formState: { errors, isSubmitting }
49
+ } = useForm({
50
+ resolver: zodResolver(commentSchema.omit({ postId: true }))
51
+ });
52
+ const onSubmit = async (data) => {
53
+ const result = await createComment({ ...data, postId });
54
+ if (result.success) {
55
+ toast.success(t("Comment added"));
56
+ reset();
57
+ router.refresh();
58
+ } else {
59
+ toast.error(result.error);
60
+ }
61
+ };
62
+ return /* @__PURE__ */ React.createElement("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-4" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-1" }, /* @__PURE__ */ React.createElement(
63
+ Textarea,
64
+ {
65
+ ...register("content"),
66
+ placeholder: t("Add your comment here..."),
67
+ className: errors.content ? "border-destructive" : ""
68
+ }
69
+ ), errors.content && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive" }, errors.content.message)), /* @__PURE__ */ React.createElement(Button, { type: "submit", disabled: isSubmitting, size: "sm" }, isSubmitting ? t("Please wait...") : t("Create Comment")));
70
+ }
71
+ export function PostDetailPage({
72
+ post,
73
+ comments = [],
74
+ currentUser
75
+ }) {
76
+ const { t } = useTranslation();
77
+ if (!post)
78
+ return /* @__PURE__ */ React.createElement("div", { className: "p-20 text-center" }, t("Post not found"));
79
+ return /* @__PURE__ */ React.createElement("div", { className: "max-w-3xl mx-auto p-6 space-y-10 pb-20" }, /* @__PURE__ */ React.createElement(Button, { asChild: true, variant: "ghost", size: "sm", className: "gap-2" }, /* @__PURE__ */ React.createElement(Link, { href: "/blog" }, /* @__PURE__ */ React.createElement(ArrowLeft, { className: "size-4" }), " ", t("Back to posts"))), /* @__PURE__ */ React.createElement("article", { className: "space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("h1", { className: "text-5xl font-black tracking-tighter leading-tight" }, post.title), /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-3 text-muted-foreground" }, /* @__PURE__ */ React.createElement("div", { className: "size-8 rounded-full bg-primary/10 flex items-center justify-center" }, /* @__PURE__ */ React.createElement(UserIcon, { className: "size-4 text-primary" })), /* @__PURE__ */ React.createElement("div", { className: "text-sm" }, /* @__PURE__ */ React.createElement("p", { className: "font-bold text-foreground leading-none" }, post.author?.name), /* @__PURE__ */ React.createElement("p", { className: "text-xs" }, new Date(post.createdAt).toLocaleDateString())))), /* @__PURE__ */ React.createElement("div", { className: "prose prose-lg dark:prose-invert max-w-none whitespace-pre-wrap pt-4 border-t" }, post.content)), /* @__PURE__ */ React.createElement("section", { className: "pt-10 border-t space-y-8" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(MessageSquare, { className: "size-5" }), /* @__PURE__ */ React.createElement("h3", { className: "text-2xl font-bold tracking-tight" }, t("Comments"), " (", comments.length, ")")), currentUser ? /* @__PURE__ */ React.createElement("div", { className: "bg-muted/30 p-6 rounded-2xl border" }, /* @__PURE__ */ React.createElement("p", { className: "text-sm font-bold mb-4" }, t("Leave a comment")), /* @__PURE__ */ React.createElement(CommentForm, { postId: post.id })) : /* @__PURE__ */ React.createElement("div", { className: "p-6 bg-amber-50 border border-amber-100 rounded-2xl text-center" }, /* @__PURE__ */ React.createElement("p", { className: "text-sm font-medium text-amber-800" }, "Please", " ", /* @__PURE__ */ React.createElement(Link, { href: "/signin", className: "underline font-bold" }, t("Sign in")), " ", t("to join the conversation."))), /* @__PURE__ */ React.createElement("div", { className: "space-y-6" }, comments.map((comment) => /* @__PURE__ */ React.createElement("div", { key: comment.id, className: "flex gap-4" }, /* @__PURE__ */ React.createElement("div", { className: "size-10 rounded-full bg-muted flex items-center justify-center shrink-0" }, /* @__PURE__ */ React.createElement(UserIcon, { className: "size-5 opacity-40" })), /* @__PURE__ */ React.createElement("div", { className: "space-y-1" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement("span", { className: "font-bold text-sm" }, comment.author?.name), /* @__PURE__ */ React.createElement("span", { className: "text-[10px] opacity-50" }, new Date(comment.createdAt).toLocaleDateString())), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-secondary-foreground leading-relaxed" }, comment.content)))), comments.length === 0 && /* @__PURE__ */ React.createElement("p", { className: "text-center text-muted-foreground text-sm py-10 italic" }, t("No comments yet. Be the first to comment!")))));
80
+ }
81
+ export function BlogAdminPage({ posts = [] }) {
82
+ const router = useRouter();
83
+ const { t } = useTranslation();
84
+ const handleDelete = async (id) => {
85
+ if (!confirm(t("Confirm deletion of this post?"))) return;
86
+ const result = await deletePost(id);
87
+ if (result.success) {
88
+ toast.success(t("Post deleted"));
89
+ router.refresh();
90
+ } else {
91
+ toast.error(t("UnexpectedError") + result.error);
92
+ }
93
+ };
94
+ return /* @__PURE__ */ React.createElement("div", { className: "p-6 space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "flex justify-between items-center" }, /* @__PURE__ */ React.createElement("h1", { className: "text-3xl font-black tracking-tight text-foreground" }, t("Blog posts")), /* @__PURE__ */ React.createElement(Button, { asChild: true, size: "sm", className: "gap-2" }, /* @__PURE__ */ React.createElement(Link, { href: "/kryo/blog/new" }, /* @__PURE__ */ React.createElement(Plus, { className: "size-4" }), " ", t("New Post")))), /* @__PURE__ */ React.createElement(Card, { className: "border-primary/10 shadow-sm overflow-hidden" }, /* @__PURE__ */ React.createElement(Table, null, /* @__PURE__ */ React.createElement(TableHeader, null, /* @__PURE__ */ React.createElement(TableRow, null, /* @__PURE__ */ React.createElement(TableHead, { className: "w-[40%]" }, t("Title")), /* @__PURE__ */ React.createElement(TableHead, null, t("Author")), /* @__PURE__ */ React.createElement(TableHead, null, t("Date")), /* @__PURE__ */ React.createElement(TableHead, { className: "text-right" }, t("Actions")))), /* @__PURE__ */ React.createElement(TableBody, null, posts.length === 0 && /* @__PURE__ */ React.createElement(TableRow, null, /* @__PURE__ */ React.createElement(
95
+ TableCell,
96
+ {
97
+ colSpan: 4,
98
+ className: "h-24 text-center text-muted-foreground italic"
99
+ },
100
+ t("No posts found. Create your first post!")
101
+ )), posts.map((post) => /* @__PURE__ */ React.createElement(TableRow, { key: post.id, className: "transition-colors" }, /* @__PURE__ */ React.createElement(TableCell, { className: "font-bold" }, post.title), /* @__PURE__ */ React.createElement(TableCell, { className: "text-xs" }, post.author?.name), /* @__PURE__ */ React.createElement(TableCell, { className: "text-muted-foreground text-xs" }, new Date(post.createdAt).toLocaleDateString()), /* @__PURE__ */ React.createElement(TableCell, { className: "text-right" }, /* @__PURE__ */ React.createElement("div", { className: "flex justify-end gap-2" }, /* @__PURE__ */ React.createElement(
102
+ Button,
103
+ {
104
+ asChild: true,
105
+ variant: "ghost",
106
+ size: "icon",
107
+ className: "size-8"
108
+ },
109
+ /* @__PURE__ */ React.createElement(Link, { href: `/blog/${post.slug}`, target: "_blank" }, /* @__PURE__ */ React.createElement(Eye, { className: "size-4" }))
110
+ ), /* @__PURE__ */ React.createElement(
111
+ Button,
112
+ {
113
+ asChild: true,
114
+ variant: "ghost",
115
+ size: "icon",
116
+ className: "size-8"
117
+ },
118
+ /* @__PURE__ */ React.createElement(Link, { href: `/kryo/blog/edit/${post.id}` }, /* @__PURE__ */ React.createElement(Pencil, { className: "size-4" }))
119
+ ), /* @__PURE__ */ React.createElement(
120
+ Button,
121
+ {
122
+ variant: "ghost",
123
+ size: "icon",
124
+ className: "size-8 text-destructive hover:text-destructive hover:bg-destructive/10",
125
+ onClick: () => handleDelete(post.id)
126
+ },
127
+ /* @__PURE__ */ React.createElement(Trash2, { className: "size-4" })
128
+ )))))))));
129
+ }
130
+ export function CreatePostForm() {
131
+ const router = useRouter();
132
+ const { t } = useTranslation();
133
+ const {
134
+ register,
135
+ handleSubmit,
136
+ formState: { errors, isSubmitting }
137
+ } = useForm({
138
+ resolver: zodResolver(postSchema.omit({ slug: true }))
139
+ });
140
+ const onSubmit = async (data) => {
141
+ const slug = data.title.toLowerCase().replace(/ /g, "-").replace(/[^\w-]+/g, "");
142
+ const result = await createPost({ ...data, slug });
143
+ if (result.success) {
144
+ toast.success(t("Post created"));
145
+ router.push("/kryo/blog");
146
+ router.refresh();
147
+ } else {
148
+ toast.error(t("UnexpectedError") + result.error);
149
+ }
150
+ };
151
+ return /* @__PURE__ */ React.createElement("div", { className: "max-w-2xl mx-auto p-6 space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-4" }, /* @__PURE__ */ React.createElement(Button, { asChild: true, variant: "outline", size: "icon", className: "rounded-lg" }, /* @__PURE__ */ React.createElement(Link, { href: "/kryo/blog" }, /* @__PURE__ */ React.createElement(ArrowLeft, { className: "size-4" }))), /* @__PURE__ */ React.createElement("h1", { className: "text-2xl font-black text-foreground" }, t("New Post"))), /* @__PURE__ */ React.createElement(Card, { className: "border-primary/10 shadow-lg" }, /* @__PURE__ */ React.createElement(CardContent, { className: "pt-6" }, /* @__PURE__ */ React.createElement("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1" }, t("Title")), /* @__PURE__ */ React.createElement(
152
+ Input,
153
+ {
154
+ ...register("title"),
155
+ className: errors.title ? "border-destructive font-bold" : "font-bold",
156
+ placeholder: t("Title of your post")
157
+ }
158
+ ), errors.title && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive font-bold" }, errors.title.message)), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1" }, t("Content")), /* @__PURE__ */ React.createElement(
159
+ Textarea,
160
+ {
161
+ ...register("content"),
162
+ rows: 12,
163
+ className: errors.content ? "border-destructive resize-none" : "resize-none",
164
+ placeholder: t("Content of your post")
165
+ }
166
+ ), errors.content && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive font-bold" }, errors.content.message)), /* @__PURE__ */ React.createElement(
167
+ Button,
168
+ {
169
+ type: "submit",
170
+ disabled: isSubmitting,
171
+ className: "w-full text-sm uppercase tracking-widest transition-all"
172
+ },
173
+ isSubmitting ? t("Please wait...") : t("Publish")
174
+ )))));
175
+ }
176
+ export function EditPostForm({ post }) {
177
+ const router = useRouter();
178
+ const { t } = useTranslation();
179
+ const {
180
+ register,
181
+ handleSubmit,
182
+ formState: { errors, isSubmitting }
183
+ } = useForm({
184
+ resolver: zodResolver(postSchema),
185
+ defaultValues: {
186
+ title: post.title,
187
+ content: post.content,
188
+ slug: post.slug
189
+ }
190
+ });
191
+ const onSubmit = async (data) => {
192
+ const result = await updatePost(post.id, data);
193
+ if (result.success) {
194
+ toast.success(t("Post updated"));
195
+ router.push("/kryo/blog");
196
+ router.refresh();
197
+ } else {
198
+ toast.error(t("UnexpectedError") + result.error);
199
+ }
200
+ };
201
+ return /* @__PURE__ */ React.createElement("div", { className: "max-w-2xl mx-auto p-6 space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-4" }, /* @__PURE__ */ React.createElement(Button, { asChild: true, variant: "outline", size: "icon", className: "rounded-lg" }, /* @__PURE__ */ React.createElement(Link, { href: "/kryo/blog" }, /* @__PURE__ */ React.createElement(ArrowLeft, { className: "size-4" }))), /* @__PURE__ */ React.createElement("h1", { className: "text-2xl font-black text-foreground" }, t("Edit Post"))), /* @__PURE__ */ React.createElement(Card, { className: "border-primary/10 shadow-lg" }, /* @__PURE__ */ React.createElement(CardContent, { className: "pt-6" }, /* @__PURE__ */ React.createElement("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1" }, t("Title")), /* @__PURE__ */ React.createElement(
202
+ Input,
203
+ {
204
+ ...register("title"),
205
+ className: errors.title ? "border-destructive font-bold" : "font-bold",
206
+ placeholder: t("Title of your post")
207
+ }
208
+ ), errors.title && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive font-bold" }, errors.title.message)), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1" }, t("Slug")), /* @__PURE__ */ React.createElement(
209
+ Input,
210
+ {
211
+ ...register("slug"),
212
+ className: errors.slug ? "border-destructive font-mono text-sm" : "font-mono text-sm",
213
+ placeholder: t("Slug URL")
214
+ }
215
+ ), errors.slug && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive font-bold" }, errors.slug.message)), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1" }, t("Content")), /* @__PURE__ */ React.createElement(
216
+ Textarea,
217
+ {
218
+ ...register("content"),
219
+ rows: 12,
220
+ className: errors.content ? "border-destructive resize-none" : "resize-none",
221
+ placeholder: t("Content of your post")
222
+ }
223
+ ), errors.content && /* @__PURE__ */ React.createElement("p", { className: "text-xs text-destructive font-bold" }, errors.content.message)), /* @__PURE__ */ React.createElement(
224
+ Button,
225
+ {
226
+ type: "submit",
227
+ disabled: isSubmitting,
228
+ className: "w-full text-sm uppercase tracking-widest transition-all"
229
+ },
230
+ isSubmitting ? t("Please wait...") : t("Update")
231
+ )))));
232
+ }
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@arch-cadre/blog-module",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A sample module for Kryo framework",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
+ "main": "./dist/index.mjs",
7
8
  "exports": {
8
9
  "./package.json": "./package.json",
9
- ".": "./dist/index.js"
10
+ ".": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
10
14
  },
11
15
  "files": [
12
16
  "dist",
@@ -19,12 +23,13 @@
19
23
  "clean": "rm -rf ./dist",
20
24
  "switch:dev": "node scripts/switchToSrc.js",
21
25
  "switch:prod": "node scripts/switchToDist.js",
22
- "builds": "unbuild",
26
+ "build": "unbuild",
23
27
  "devs": "unbuild --stub",
24
- "build": "pnpm clean && tsc --module esnext"
28
+ "builds": "pnpm clean && tsc --module esnext"
25
29
  },
26
30
  "dependencies": {
27
- "@arch-cadre/modules": "^0.0.82",
31
+ "@arch-cadre/core": "^0.0.58",
32
+ "@arch-cadre/modules": "^0.0.84",
28
33
  "@hookform/resolvers": "^3.10.0",
29
34
  "@radix-ui/react-slot": "^1.2.3",
30
35
  "class-variance-authority": "^0.7.1",
@@ -47,10 +52,9 @@
47
52
  "unbuild": "^3.6.1"
48
53
  },
49
54
  "peerDependencies": {
50
- "@arch-cadre/core": "^0.0.56",
51
- "@arch-cadre/intl": "^0.0.56",
52
- "@arch-cadre/ui": "^0.0.56",
55
+ "@arch-cadre/core": "^0.0.58",
56
+ "@arch-cadre/intl": "^0.0.58",
57
+ "@arch-cadre/ui": "^0.0.58",
53
58
  "react": "^19.0.0"
54
- },
55
- "main": "./dist/index.mjs"
59
+ }
56
60
  }
@@ -1,149 +0,0 @@
1
- "use server";
2
- import { db, getCurrentSession, userTable } from "@arch-cadre/core/server";
3
- import { desc, eq } from "drizzle-orm";
4
- import { revalidatePath } from "next/cache";
5
- import { commentSchema, postSchema } from "../lib/validation";
6
- import { commentsTable, postsTable } from "../schema";
7
- // --- Posts ---
8
- export async function createPost(data) {
9
- try {
10
- const { user } = await getCurrentSession();
11
- if (!user)
12
- throw new Error("Unauthorized");
13
- const validated = postSchema.parse(data);
14
- await db.insert(postsTable).values({
15
- ...validated,
16
- authorId: user.id,
17
- });
18
- revalidatePath("/blog");
19
- return { success: true };
20
- }
21
- catch (error) {
22
- console.error("[BlogModule:Actions] createPost failed:", error);
23
- return { success: false, error: error.message };
24
- }
25
- }
26
- export async function getPosts() {
27
- try {
28
- return await db
29
- .select({
30
- id: postsTable.id,
31
- title: postsTable.title,
32
- slug: postsTable.slug,
33
- content: postsTable.content,
34
- createdAt: postsTable.createdAt,
35
- author: {
36
- name: userTable.name,
37
- },
38
- })
39
- .from(postsTable)
40
- .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
41
- .orderBy(desc(postsTable.createdAt));
42
- }
43
- catch (error) {
44
- console.error("[BlogModule:Actions] getPosts failed:", error);
45
- throw error;
46
- }
47
- }
48
- export async function getPostBySlug(slug) {
49
- try {
50
- const [post] = await db
51
- .select({
52
- id: postsTable.id,
53
- title: postsTable.title,
54
- slug: postsTable.slug,
55
- content: postsTable.content,
56
- createdAt: postsTable.createdAt,
57
- author: {
58
- name: userTable.name,
59
- },
60
- })
61
- .from(postsTable)
62
- .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
63
- .where(eq(postsTable.slug, slug));
64
- return post || null;
65
- }
66
- catch (error) {
67
- console.error("[BlogModule:Actions] getPostBySlug failed:", error);
68
- throw error;
69
- }
70
- }
71
- export async function getPostById(id) {
72
- try {
73
- const [post] = await db
74
- .select()
75
- .from(postsTable)
76
- .where(eq(postsTable.id, id));
77
- return post || null;
78
- }
79
- catch (error) {
80
- console.error("[BlogModule:Actions] getPostById failed:", error);
81
- throw error;
82
- }
83
- }
84
- // --- Comments ---
85
- export async function getComments(postId) {
86
- try {
87
- return await db
88
- .select({
89
- id: commentsTable.id,
90
- content: commentsTable.content,
91
- createdAt: commentsTable.createdAt,
92
- author: {
93
- name: userTable.name,
94
- image: userTable.image,
95
- },
96
- })
97
- .from(commentsTable)
98
- .innerJoin(userTable, eq(commentsTable.authorId, userTable.id))
99
- .where(eq(commentsTable.postId, postId))
100
- .orderBy(desc(commentsTable.createdAt));
101
- }
102
- catch (error) {
103
- console.error("[BlogModule:Actions] getComments failed:", error);
104
- throw error;
105
- }
106
- }
107
- export async function createComment(data) {
108
- try {
109
- const { user } = await getCurrentSession();
110
- if (!user)
111
- throw new Error("Must be logged in to comment");
112
- const validated = commentSchema.parse(data);
113
- await db.insert(commentsTable).values({
114
- content: validated.content,
115
- postId: validated.postId,
116
- authorId: user.id,
117
- });
118
- revalidatePath(`/blog`);
119
- return { success: true };
120
- }
121
- catch (error) {
122
- console.error("[BlogModule:Actions] createComment failed:", error);
123
- return { success: false, error: error.message };
124
- }
125
- }
126
- export async function deletePost(id) {
127
- try {
128
- await db.delete(postsTable).where(eq(postsTable.id, id));
129
- revalidatePath("/blog");
130
- return { success: true };
131
- }
132
- catch (error) {
133
- console.error("[BlogModule:Actions] deletePost failed:", error);
134
- return { success: false, error: error.message };
135
- }
136
- }
137
- export async function updatePost(id, data) {
138
- try {
139
- const validated = postSchema.parse(data);
140
- await db.update(postsTable).set(validated).where(eq(postsTable.id, id));
141
- revalidatePath("/blog");
142
- revalidatePath(`/blog/${validated.slug}`);
143
- return { success: true };
144
- }
145
- catch (error) {
146
- console.error("[BlogModule:Actions] updatePost failed:", error);
147
- return { success: false, error: error.message };
148
- }
149
- }
@@ -1,17 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { db } from "@arch-cadre/core/server";
3
- import { getTranslation } from "@arch-cadre/intl/server";
4
- import { Card, CardContent, CardHeader, CardTitle } from "@arch-cadre/ui";
5
- import { sql } from "drizzle-orm";
6
- import { FileText, MessageSquare } from "lucide-react";
7
- import { commentsTable, postsTable } from "../schema";
8
- export default async function BlogStatsWidget() {
9
- const { t } = await getTranslation();
10
- const [postsCount] = await db
11
- .select({ count: sql `count(*)` })
12
- .from(postsTable);
13
- const [commentsCount] = await db
14
- .select({ count: sql `count(*)` })
15
- .from(commentsTable);
16
- return (_jsxs("div", { className: "grid gap-4 md:grid-cols-2 lg:grid-cols-2", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Posts") }), _jsx(FileText, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: postsCount?.count || 0 }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Comments") }), _jsx(MessageSquare, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: commentsCount?.count || 0 }) })] })] }));
17
- }
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { db, userTable } from "@arch-cadre/core/server";
3
- import { getTranslation } from "@arch-cadre/intl/server";
4
- import { Avatar, AvatarFallback, AvatarImage, Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@arch-cadre/ui";
5
- import { desc, eq } from "drizzle-orm";
6
- import { commentsTable } from "../schema";
7
- export default async function RecentCommentsWidget() {
8
- const { t } = await getTranslation();
9
- const comments = await db
10
- .select({
11
- id: commentsTable.id,
12
- content: commentsTable.content,
13
- createdAt: commentsTable.createdAt,
14
- author: {
15
- name: userTable.name,
16
- image: userTable.image,
17
- },
18
- })
19
- .from(commentsTable)
20
- .leftJoin(userTable, eq(commentsTable.authorId, userTable.id))
21
- .orderBy(desc(commentsTable.createdAt))
22
- .limit(5);
23
- return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("Recent Comments") }), _jsx(CardDescription, { children: t("What readers are saying about your posts.") })] }), _jsxs(CardContent, { className: "grid gap-8", children: [comments.map((comment) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs(Avatar, { className: "h-9 w-9", children: [_jsx(AvatarImage, { src: comment.author?.image || "", alt: "Avatar" }), _jsx(AvatarFallback, { children: comment.author?.name?.substring(0, 2).toUpperCase() || "CM" })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx("p", { className: "text-sm font-medium leading-none line-clamp-1", children: comment.content }), _jsxs("p", { className: "text-sm text-muted-foreground", children: [comment.author?.name || t("Anonymous"), " \u2022", " ", new Date(comment.createdAt).toLocaleDateString()] })] })] }, comment.id))), comments.length === 0 && (_jsx("div", { className: "text-center py-4 text-muted-foreground", children: t("No comments yet.") }))] })] }));
24
- }
@@ -1,24 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { db, userTable } from "@arch-cadre/core/server";
3
- import { getTranslation } from "@arch-cadre/intl/server";
4
- import { Avatar, AvatarFallback, AvatarImage, Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@arch-cadre/ui";
5
- import { desc, eq } from "drizzle-orm";
6
- import { postsTable } from "../schema";
7
- export default async function RecentPostsWidget() {
8
- const { t } = await getTranslation();
9
- const posts = await db
10
- .select({
11
- id: postsTable.id,
12
- title: postsTable.title,
13
- createdAt: postsTable.createdAt,
14
- author: {
15
- name: userTable.name,
16
- image: userTable.image,
17
- },
18
- })
19
- .from(postsTable)
20
- .leftJoin(userTable, eq(postsTable.authorId, userTable.id))
21
- .orderBy(desc(postsTable.createdAt))
22
- .limit(5);
23
- return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("Recent Posts") }), _jsx(CardDescription, { children: t("The latest articles published on your blog.") })] }), _jsxs(CardContent, { className: "grid gap-8", children: [posts.map((post) => (_jsxs("div", { className: "flex items-center gap-4", children: [_jsxs(Avatar, { className: "h-9 w-9", children: [_jsx(AvatarImage, { src: post.author?.image || "", alt: "Avatar" }), _jsx(AvatarFallback, { children: post.author?.name?.substring(0, 2).toUpperCase() || "AU" })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx("p", { className: "text-sm font-medium leading-none", children: post.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: new Date(post.createdAt).toLocaleDateString() })] })] }, post.id))), posts.length === 0 && (_jsx("div", { className: "text-center py-4 text-muted-foreground", children: t("No posts found.") }))] })] }));
24
- }
@@ -1,33 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Slot } from "@radix-ui/react-slot";
3
- import { cva } from "class-variance-authority";
4
- import * as React from "react";
5
- import { cn } from "../../lib/utils";
6
- const buttonVariants = cva("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", {
7
- variants: {
8
- variant: {
9
- default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
10
- destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
11
- outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
12
- secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
13
- ghost: "hover:bg-accent hover:text-accent-foreground",
14
- link: "text-primary underline-offset-4 hover:underline",
15
- },
16
- size: {
17
- default: "h-9 px-4 py-2",
18
- sm: "h-8 rounded-md px-3 text-xs",
19
- lg: "h-10 rounded-md px-8",
20
- icon: "size-9",
21
- },
22
- },
23
- defaultVariants: {
24
- variant: "default",
25
- size: "default",
26
- },
27
- });
28
- const Button = React.forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => {
29
- const Comp = asChild ? Slot : "button";
30
- return (_jsx(Comp, { className: cn(buttonVariants({ variant, size, className })), ref: ref, ...props }));
31
- });
32
- Button.displayName = "Button";
33
- export { Button, buttonVariants };
@@ -1,12 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { cn } from "../../lib/utils";
4
- const Card = React.forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("rounded-xl border bg-card text-card-foreground shadow", className), ...props })));
5
- Card.displayName = "Card";
6
- const CardHeader = React.forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("flex flex-col space-y-1.5 p-6", className), ...props })));
7
- CardHeader.displayName = "CardHeader";
8
- const CardTitle = React.forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("font-semibold leading-none tracking-tight", className), ...props })));
9
- CardTitle.displayName = "CardTitle";
10
- const CardContent = React.forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn("p-6 pt-0", className), ...props })));
11
- CardContent.displayName = "CardContent";
12
- export { Card, CardHeader, CardTitle, CardContent };
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { cn } from "../../lib/utils";
4
- const Input = React.forwardRef(({ className, type, ...props }, ref) => {
5
- return (_jsx("input", { type: type, className: cn("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref, ...props }));
6
- });
7
- Input.displayName = "Input";
8
- export { Input };
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { cn } from "../../lib/utils";
4
- const Table = React.forwardRef(({ className, ...props }, ref) => (_jsx("div", { className: "relative w-full overflow-auto", children: _jsx("table", { ref: ref, className: cn("w-full caption-bottom text-sm", className), ...props }) })));
5
- Table.displayName = "Table";
6
- const TableHeader = React.forwardRef(({ className, ...props }, ref) => (_jsx("thead", { ref: ref, className: cn("[&_tr]:border-b", className), ...props })));
7
- TableHeader.displayName = "TableHeader";
8
- const TableBody = React.forwardRef(({ className, ...props }, ref) => (_jsx("tbody", { ref: ref, className: cn("[&_tr:last-child]:border-0", className), ...props })));
9
- TableBody.displayName = "TableBody";
10
- const TableRow = React.forwardRef(({ className, ...props }, ref) => (_jsx("tr", { ref: ref, className: cn("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className), ...props })));
11
- TableRow.displayName = "TableRow";
12
- const TableHead = React.forwardRef(({ className, ...props }, ref) => (_jsx("th", { ref: ref, className: cn("h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className), ...props })));
13
- TableHead.displayName = "TableHead";
14
- const TableCell = React.forwardRef(({ className, ...props }, ref) => (_jsx("td", { ref: ref, className: cn("p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className), ...props })));
15
- TableCell.displayName = "TableCell";
16
- export { Table, TableHeader, TableBody, TableHead, TableRow, TableCell };
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { cn } from "../../lib/utils";
4
- const Textarea = React.forwardRef(({ className, ...props }, ref) => {
5
- return (_jsx("textarea", { className: cn("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref, ...props }));
6
- });
7
- Textarea.displayName = "Textarea";
8
- export { Textarea };