From 687fbaf3a612cafde61bd47b4acc6d7eee3b8000 Mon Sep 17 00:00:00 2001 From: Ivan Rezchikov Date: Wed, 15 Jul 2026 22:19:26 +0300 Subject: [PATCH] feat: image resizer --- app/[type]/[slug]/page.tsx | 4 +-- app/create/client.tsx | 2 +- app/list/page.tsx | 8 +++-- components/drafts-dialog.tsx | 2 +- components/editor.tsx | 65 +++++++++++++++++++++++++++++------ components/image-uploader.tsx | 20 ++++++++--- components/news-card.tsx | 2 +- 7 files changed, 80 insertions(+), 23 deletions(-) diff --git a/app/[type]/[slug]/page.tsx b/app/[type]/[slug]/page.tsx index 084c4c6..b30f46d 100644 --- a/app/[type]/[slug]/page.tsx +++ b/app/[type]/[slug]/page.tsx @@ -141,10 +141,10 @@ function BlockRenderer({ block }: { block: Block }) { {b.caption diff --git a/app/create/client.tsx b/app/create/client.tsx index 6da12b7..6bf05b8 100644 --- a/app/create/client.tsx +++ b/app/create/client.tsx @@ -39,7 +39,7 @@ export default function CreatePageClient() { return (
-
+

Create page

)) :

There are no pages yet...

diff --git a/components/drafts-dialog.tsx b/components/drafts-dialog.tsx index 53aa743..fa6d044 100644 --- a/components/drafts-dialog.tsx +++ b/components/drafts-dialog.tsx @@ -31,7 +31,7 @@ function DraftItem({ draft, onDeleted }: { draft: Draft; onDeleted: (id: string) {draft.title}
- + + ) : null + } /> - {content.url && ( + + {content.url && !supportsDrag && (
- {currentWidth}% + {currentWidth ?? 800}px
onChange({ type: "IMAGE", url: content.url, caption: content.caption ?? "", width: v })} />
@@ -701,7 +744,7 @@ function getDefaultContent(type: BlockType): Block["content"] { case "DIVIDER": return { type: "DIVIDER" }; case "LIST": return { type: "LIST", style: "BULLET", items: [""] }; case "TABLE": return { type: "TABLE", headers: ["", ""], rows: [["", ""]] }; - case "IMAGE": return { type: "IMAGE", url: "", caption: "", width: 100 }; + case "IMAGE": return { type: "IMAGE", url: "", caption: "", width: undefined }; case "LINK": return { type: "LINK", label: "", href: "" }; default: return { type: "PARAGRAPH", text: "" }; } diff --git a/components/image-uploader.tsx b/components/image-uploader.tsx index 0ea1e8c..0a6479d 100644 --- a/components/image-uploader.tsx +++ b/components/image-uploader.tsx @@ -26,6 +26,8 @@ type Props = { children?: React.ReactNode; caption?: string; onCaptionChange?: (caption: string) => void; + imgRef?: React.Ref; + resizeHandle?: React.ReactNode; }; const MAX_SIZE = 5 * 1024 * 1024; @@ -56,7 +58,7 @@ function fileToFileList(file: File): FileList { return dt.files; } -export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, previewStyle, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange }: Props) { +export function ImageUploader({ id, name, label, description, error, variant = "default", previewClassName, previewStyle, accept = DEFAULT_ACCEPT, required, value, onFileSelect, onRemove, isUploading, children, caption, onCaptionChange, imgRef, resizeHandle }: Props) { const inputRef = useRef(null); const [previewUrl, setPreviewUrl] = useState(null); const [fileInfo, setFileInfo] = useState<{ name: string; size: number } | null>(null); @@ -124,16 +126,26 @@ export function ImageUploader({ id, name, label, description, error, variant = " {displayUrl ? (
-
- +
+ -
+
+ {resizeHandle} + {isUploading && (
diff --git a/components/news-card.tsx b/components/news-card.tsx index 57bec29..1e254f6 100644 --- a/components/news-card.tsx +++ b/components/news-card.tsx @@ -8,7 +8,7 @@ export function NewsCard({ news }: { news: PagePublic }) { return (
-

{news.title}

+

{news.title}