fixes
This commit is contained in:
+14
-11
@@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
|
||||
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
|
||||
import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, ChevronDownIcon, ChevronUpIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon, MoveDiagonalIcon, MoveDiagonal2Icon } from "lucide-react";
|
||||
import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, ChevronDownIcon, ChevronUpIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon, MoveDiagonal2Icon } from "lucide-react";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -73,8 +73,13 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E
|
||||
const [previewUrls, setPreviewUrls] = useState<Map<string, string>>(new Map());
|
||||
const previewCacheRef = useRef<Map<string, string>>(new Map());
|
||||
|
||||
const onChangeRef = useRef(onChange);
|
||||
useEffect(() => {
|
||||
onChange({
|
||||
onChangeRef.current = onChange;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
onChangeRef.current({
|
||||
title,
|
||||
type,
|
||||
slug: slug || title.toLowerCase().replace(/\s+/g, "-"),
|
||||
@@ -82,7 +87,7 @@ export default function Editor({ page, initialBlocks = [], onChange, errors }: E
|
||||
tags,
|
||||
blocks,
|
||||
});
|
||||
}, [title, slug, location, tags, blocks]);
|
||||
}, [title, type, slug, location, tags, blocks]);
|
||||
|
||||
useEffect(() => {
|
||||
const imageBlocks = blocks.filter(
|
||||
@@ -626,15 +631,13 @@ function TableEditor({ content, onChange }: { content: { type: "TABLE"; headers:
|
||||
function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Block; previewUrl?: string; onChange: (c: Block["content"]) => void; onPreviewReady: (id: string, url: string) => void }) {
|
||||
const content = block.content as { type: "IMAGE"; url: string; caption?: string; width?: number };
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [supportsDrag, setSupportsDrag] = useState(false);
|
||||
const [supportsDrag] = useState(
|
||||
() => typeof window !== "undefined" && window.matchMedia("(hover: hover) and (pointer: fine)").matches
|
||||
);
|
||||
const isDraggingRef = useRef(false);
|
||||
const dragStartRef = useRef<{ x: number; width: number } | null>(null);
|
||||
const imgRef = useRef<HTMLImageElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setSupportsDrag(window.matchMedia("(hover: hover) and (pointer: fine)").matches);
|
||||
}, []);
|
||||
|
||||
const currentWidth = content.width;
|
||||
|
||||
function handleDragStart(e: React.PointerEvent) {
|
||||
@@ -642,7 +645,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
|
||||
e.stopPropagation();
|
||||
const startWidth = imgRef.current?.offsetWidth ?? 500;
|
||||
dragStartRef.current = { x: e.clientX, width: startWidth };
|
||||
setIsDragging(true);
|
||||
isDraggingRef.current = true;
|
||||
|
||||
function handleMove(ev: PointerEvent) {
|
||||
if (!dragStartRef.current) return;
|
||||
@@ -654,7 +657,7 @@ function ImageBlock({ block, previewUrl, onChange, onPreviewReady }: { block: Bl
|
||||
}
|
||||
|
||||
function handleUp() {
|
||||
setIsDragging(false);
|
||||
isDraggingRef.current = false;
|
||||
dragStartRef.current = null;
|
||||
window.removeEventListener("pointermove", handleMove);
|
||||
window.removeEventListener("pointerup", handleUp);
|
||||
|
||||
Reference in New Issue
Block a user