-
-
Learn more about the President
-
+
+
+
Learn more about the President
+
+
Acknowledge with the Federal Government
diff --git a/components/drafts.tsx b/components/drafts.tsx
index 163aba8..d71ab52 100644
--- a/components/drafts.tsx
+++ b/components/drafts.tsx
@@ -17,8 +17,6 @@ import { Spinner } from "@/components/ui/spinner";
type Draft = { id: string; title: string; slug: string; updatedAt: Date };
-
-
export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
const [isDeletingId, setIsDeletingId] = useState("");
diff --git a/components/editor.tsx b/components/editor.tsx
index 141899c..3c580c1 100644
--- a/components/editor.tsx
+++ b/components/editor.tsx
@@ -1,23 +1,19 @@
"use client";
-import { useState, useEffect } from "react";
+import { useState, useEffect, useRef } from "react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
-import {
- Field,
- FieldGroup,
- FieldLabel,
- FieldSet,
-} from "@/components/ui/field";
-import {
- InputGroup,
- InputGroupAddon,
- InputGroupButton,
- InputGroupInput,
-} from "@/components/ui/input-group";
+import { Field, 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 { Globe2, Plus, Trash2, X } from "lucide-react";
+import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, GripVerticalIcon, ChevronDownIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon } 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";
+import { Input } from "./ui/input";
+import { Separator } from "./ui/separator";
+import { Alert } from "./ui/alert";
+import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
export type EditorData = {
title: string;
@@ -35,20 +31,42 @@ type EditorProps = {
onChange: (data: EditorData) => void;
};
-export default function Editor({
- page,
- initialBlocks = [],
- onChange,
-}: EditorProps) {
+const BLOCK_ICONS: Record
= {
+ PARAGRAPH: ,
+ HEADING: ,
+ IMAGE: ,
+ QUOTE: ,
+ CALLOUT: ,
+ DIVIDER: ,
+ LIST: ,
+ TABLE: ,
+ LINK:
+};
+
+const BLOCK_LABELS: Record = {
+ PARAGRAPH: "Text",
+ HEADING: "Heading",
+ IMAGE: "Image",
+ QUOTE: "Quote",
+ CALLOUT: "Callout",
+ DIVIDER: "Divider",
+ LIST: "List",
+ TABLE: "Table",
+ LINK: "Link"
+};
+
+export default function Editor({ page, initialBlocks = [], onChange }: EditorProps) {
const meta = (page?.meta as PageMeta) ?? {};
const [title, setTitle] = useState(page?.title ?? "");
- const [type, setType] = useState(page?.type ?? "NEWS");
+ const [type, setType] = useState(page?.type ?? "NEWS");
const [slug, setSlug] = useState(page?.slug ?? "");
const [location, setLocation] = useState(meta.location ?? "");
const [tags, setTags] = useState(meta.tags ?? []);
const [tagInput, setTagInput] = useState("");
const [blocks, setBlocks] = useState(initialBlocks);
+ const [dragIndex, setDragIndex] = useState(null);
+ const [dropIndex, setDropIndex] = useState(null);
useEffect(() => {
onChange({
@@ -72,16 +90,16 @@ export default function Editor({
setTags(tags.filter((t) => t !== tag));
}
- function addBlock(type: BlockType) {
+ function addBlock(blockType: BlockType) {
setBlocks([
...blocks,
{
id: crypto.randomUUID(),
pageId: page?.id ?? "",
parentId: null,
- type,
+ type: blockType,
position: blocks.length,
- content: getDefaultContent(type),
+ content: getDefaultContent(blockType),
},
]);
}
@@ -94,10 +112,32 @@ export default function Editor({
setBlocks(blocks.map((b) => (b.id === id ? { ...b, content } : b)));
}
+ function moveBlock(from: number, to: number) {
+ const updated = [...blocks];
+ const [moved] = updated.splice(from, 1);
+ updated.splice(to, 0, moved);
+ setBlocks(updated.map((b, i) => ({ ...b, position: i })));
+ }
+
+ function handleDragStart(index: number) {
+ setDragIndex(index);
+ }
+
+ function handleDragOver(e: React.DragEvent, index: number) {
+ e.preventDefault();
+ setDropIndex(index);
+ }
+
+ function handleDrop(index: number) {
+ if (dragIndex !== null && dragIndex !== index) moveBlock(dragIndex, index);
+ setDragIndex(null);
+ setDropIndex(null);
+ }
+
return (
-