import { useState } from "react"; import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, type DragEndEvent } from "@dnd-kit/core"; import { SortableContext, arrayMove, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import type { Block, PageSummary } from "../../shared/api-types.js"; import { api, useApi } from "../api.js"; import { useAction } from "./ui.js"; function SortableBlock({ block, onChange }: { block: Block; onChange: (blocks: Block[]) => void }) { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: block.id }); const [editing, setEditing] = useState(false); const [text, setText] = useState(block.kind === "text" ? (block.markdown ?? "") : (block.label ?? "")); const { busy, run } = useAction(); const save = () => run(async () => { onChange(await api("PATCH", `/blocks/${block.id}`, block.kind === "text" ? { markdown: text } : { label: text })); setEditing(false); }); const remove = () => run(async () => onChange(await api("DELETE", `/blocks/${block.id}`))); return (
{block.kind === "text" ? "Text" : `Link → ${block.target?.path}`}
{editing ? ( block.kind === "text" ? (