-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #297 from steven-tey/ai-features
feat: add ai features example
- Loading branch information
Showing
24 changed files
with
693 additions
and
179 deletions.
There are no files selected for viewing
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
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
67 changes: 67 additions & 0 deletions
67
apps/web/components/tailwind/generative/ai-completion-command.tsx
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,67 @@ | ||
import React from "react"; | ||
import { CommandGroup, CommandItem, CommandSeparator } from "../ui/command"; | ||
import { useEditor } from "novel"; | ||
import { Check, TextQuote, TrashIcon } from "lucide-react"; | ||
|
||
const AICompletionCommands = ({ | ||
completion, | ||
onDiscard, | ||
}: { | ||
completion: string; | ||
onDiscard: () => void; | ||
}) => { | ||
const { editor } = useEditor(); | ||
return ( | ||
<> | ||
<CommandGroup> | ||
<CommandItem | ||
className="gap-2 px-4" | ||
value="replace" | ||
onSelect={() => { | ||
const selection = editor.view.state.selection; | ||
|
||
editor | ||
.chain() | ||
.focus() | ||
.insertContentAt( | ||
{ | ||
from: selection.from, | ||
to: selection.to, | ||
}, | ||
completion, | ||
) | ||
.run(); | ||
}} | ||
> | ||
<Check className="h-4 w-4 text-muted-foreground" /> | ||
Replace selection | ||
</CommandItem> | ||
<CommandItem | ||
className="gap-2 px-4" | ||
value="insert" | ||
onSelect={() => { | ||
const selection = editor.view.state.selection; | ||
editor | ||
.chain() | ||
.focus() | ||
.insertContentAt(selection.to + 1, completion) | ||
.run(); | ||
}} | ||
> | ||
<TextQuote className="h-4 w-4 text-muted-foreground" /> | ||
Insert below | ||
</CommandItem> | ||
</CommandGroup> | ||
<CommandSeparator /> | ||
|
||
<CommandGroup> | ||
<CommandItem onSelect={onDiscard} value="thrash" className="gap-2 px-4"> | ||
<TrashIcon className="h-4 w-4 text-muted-foreground" /> | ||
Discard | ||
</CommandItem> | ||
</CommandGroup> | ||
</> | ||
); | ||
}; | ||
|
||
export default AICompletionCommands; |
Oops, something went wrong.