-
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from andrewdoro/main
RFC: Headless core components & imperative support
- Loading branch information
Showing
81 changed files
with
3,033 additions
and
8,694 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,170 @@ | ||
import { Github } from "@/ui/icons"; | ||
import Menu from "@/ui/menu"; | ||
import Editor from "@/ui/editor"; | ||
"use client"; | ||
|
||
import { Github } from "@/components/ui/icons"; | ||
import { | ||
defaultEditorProps, | ||
Editor, | ||
EditorRoot, | ||
EditorBubble, | ||
EditorCommand, | ||
EditorCommandItem, | ||
EditorCommandEmpty, | ||
EditorContent, | ||
type JSONContent, | ||
} from "novel"; | ||
import { useState } from "react"; | ||
import { | ||
taskItem, | ||
taskList, | ||
tiptapImage, | ||
tiptapLink, | ||
updatedImage, | ||
horizontalRule, | ||
slashCommand, | ||
starterKit, | ||
placeholder, | ||
} from "../lib/extensions"; | ||
import { NodeSelector } from "../lib/selectors/node-selector"; | ||
import { LinkSelector } from "../lib/selectors/link-selector"; | ||
import { ColorSelector } from "../lib/selectors/color-selector"; | ||
import TextButtons from "../lib/selectors/text-buttons"; | ||
import { suggestionItems } from "../lib/suggestions"; | ||
import { ImageResizer } from "novel/extensions"; | ||
import { defaultEditorContent } from "@/lib/content"; | ||
import { AISelector } from "@/lib/selectors/ai-selector"; | ||
import Magic from "@/components/ui/icons/magic"; | ||
import { Button } from "@/components/ui/button"; | ||
import Menu from "@/components/ui/menu"; | ||
import { Separator } from "@/components/ui/separator"; | ||
import useLocalStorage from "@/lib/hooks/use-local-storage"; | ||
import { useDebouncedCallback } from "use-debounce"; | ||
|
||
const extensions = [ | ||
starterKit, | ||
horizontalRule, | ||
tiptapLink, | ||
tiptapImage, | ||
updatedImage, | ||
taskList, | ||
taskItem, | ||
slashCommand, | ||
placeholder, | ||
]; | ||
export default function Page() { | ||
const [content, setContent] = useLocalStorage<JSONContent | null>( | ||
"novel-content", | ||
defaultEditorContent, | ||
); | ||
const [saveStatus, setSaveStatus] = useState("Saved"); | ||
|
||
const [openNode, setOpenNode] = useState(false); | ||
const [openColor, setOpenColor] = useState(false); | ||
const [openLink, setOpenLink] = useState(false); | ||
const [openAI, setOpenAI] = useState(false); | ||
|
||
const debouncedUpdates = useDebouncedCallback(async (editor: Editor) => { | ||
const json = editor.getJSON(); | ||
setContent(json); | ||
setSaveStatus("Saved"); | ||
}, 500); | ||
return ( | ||
<div className="flex min-h-screen flex-col items-center sm:px-5 sm:pt-[calc(20vh)]"> | ||
<a | ||
href="https://github.com/steven-tey/novel" | ||
target="_blank" | ||
className="absolute bottom-5 left-5 z-10 max-h-fit rounded-lg p-2 transition-colors duration-200 hover:bg-stone-100 sm:bottom-auto sm:top-5" | ||
<Button | ||
size="icon" | ||
variant="outline" | ||
className="absolute bottom-5 left-5 z-10 max-h-fit rounded-lg p-2 transition-colors duration-200 sm:bottom-auto sm:top-5" | ||
> | ||
<Github /> | ||
</a> | ||
<a href="https://github.com/steven-tey/novel" target="_blank"> | ||
<Github /> | ||
</a> | ||
</Button> | ||
<Menu /> | ||
<Editor /> | ||
<div className="relative w-full max-w-screen-lg"> | ||
<div className="absolute right-5 top-5 z-10 mb-5 rounded-lg bg-accent px-2 py-1 text-sm text-muted-foreground"> | ||
{saveStatus} | ||
</div> | ||
<EditorRoot> | ||
<EditorContent | ||
extensions={extensions} | ||
content={content} | ||
className="relative min-h-[500px] w-full max-w-screen-lg border-muted bg-background sm:mb-[calc(20vh)] sm:rounded-lg sm:border sm:shadow-lg" | ||
editorProps={{ | ||
...defaultEditorProps, | ||
attributes: { | ||
class: `prose-lg prose-stone dark:prose-invert prose-headings:font-title font-default focus:outline-none max-w-full`, | ||
}, | ||
}} | ||
onUpdate={({ editor }) => { | ||
debouncedUpdates(editor); | ||
setSaveStatus("Unsaved"); | ||
}} | ||
slotAfter={<ImageResizer />} | ||
> | ||
<EditorCommand className="z-50 h-auto max-h-[330px] w-72 overflow-y-auto rounded-md border border-muted bg-background px-1 py-2 shadow-md transition-all"> | ||
<EditorCommandEmpty className="px-2 text-muted-foreground"> | ||
No results | ||
</EditorCommandEmpty> | ||
{suggestionItems.map((item) => ( | ||
<EditorCommandItem | ||
value={item.title} | ||
onCommand={(val) => item.command(val)} | ||
className={`flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-accent aria-selected:bg-accent `} | ||
key={item.title} | ||
> | ||
<div className="flex h-10 w-10 items-center justify-center rounded-md border border-muted bg-background"> | ||
{item.icon} | ||
</div> | ||
<div> | ||
<p className="font-medium">{item.title}</p> | ||
<p className="text-xs text-muted-foreground"> | ||
{item.description} | ||
</p> | ||
</div> | ||
</EditorCommandItem> | ||
))} | ||
</EditorCommand> | ||
|
||
<EditorBubble | ||
tippyOptions={{ | ||
placement: openAI ? "bottom-start" : "top", | ||
onHidden: () => { | ||
setOpenAI(false); | ||
}, | ||
}} | ||
className="flex w-fit max-w-[90vw] overflow-hidden rounded border border-muted bg-background shadow-xl" | ||
> | ||
{openAI ? ( | ||
<AISelector open={openAI} onOpenChange={setOpenAI} /> | ||
) : ( | ||
<> | ||
<Button | ||
variant="ghost" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setOpenAI(!openAI); | ||
}} | ||
className="items-center justify-between gap-2 rounded-none" | ||
> | ||
<Magic className="h-5 w-5" /> Ask AI | ||
</Button> | ||
<Separator orientation="vertical" /> | ||
<NodeSelector open={openNode} onOpenChange={setOpenNode} /> | ||
<Separator orientation="vertical" /> | ||
|
||
<LinkSelector open={openLink} onOpenChange={setOpenLink} /> | ||
|
||
<Separator orientation="vertical" /> | ||
|
||
<TextButtons /> | ||
<Separator orientation="vertical" /> | ||
|
||
<ColorSelector open={openColor} onOpenChange={setOpenColor} /> | ||
</> | ||
)} | ||
</EditorBubble> | ||
</EditorContent> | ||
</EditorRoot> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "default", | ||
"rsc": true, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.ts", | ||
"css": "styles/globals.css", | ||
"baseColor": "slate", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from "react" | ||
import { Slot } from "@radix-ui/react-slot" | ||
import { cva, type VariantProps } from "class-variance-authority" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: | ||
"bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: | ||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground", | ||
secondary: | ||
"bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 rounded-md px-3", | ||
lg: "h-11 rounded-md px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
} | ||
) | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button" | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
} | ||
) | ||
Button.displayName = "Button" | ||
|
||
export { Button, buttonVariants } |
Oops, something went wrong.