Skip to content

Commit

Permalink
Merge pull request #342 from steven-tey/expose-command-list
Browse files Browse the repository at this point in the history
feat: expose editor command list
  • Loading branch information
andrewdoro authored Mar 11, 2024
2 parents ccfc227 + 8456652 commit c51b5ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
39 changes: 21 additions & 18 deletions apps/web/components/tailwind/advanced-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EditorContent,
type JSONContent,
EditorInstance,
EditorCommandList,
} from "novel";
import { ImageResizer, handleCommandNavigation } from "novel/extensions";
import { defaultExtensions } from "./extensions";
Expand Down Expand Up @@ -87,24 +88,26 @@ const TailwindAdvancedEditor = () => {
<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>
))}
<EditorCommandList>
{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>
))}
</EditorCommandList>
</EditorCommand>

<GenerativeMenuSwitch open={openAI} onOpenChange={setOpenAI}>
Expand Down
8 changes: 4 additions & 4 deletions packages/headless/src/components/editor-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ComponentPropsWithoutRef, FC } from "react";
import type { Range } from "@tiptap/core";

export const EditorCommandTunnelContext = createContext(
{} as ReturnType<typeof tunnel>
{} as ReturnType<typeof tunnel>,
);

interface EditorCommandOutProps {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const EditorCommandOut: FC<EditorCommandOutProps> = ({
key: e.key,
cancelable: true,
bubbles: true,
})
}),
);

return false;
Expand All @@ -67,7 +67,6 @@ export const EditorCommand = forwardRef<
HTMLDivElement,
ComponentPropsWithoutRef<typeof Command>
>(({ children, className, ...rest }, ref) => {
const commandListRef = useRef<HTMLDivElement>(null);
const [query, setQuery] = useAtom(queryAtom);

return (
Expand All @@ -88,12 +87,13 @@ export const EditorCommand = forwardRef<
onValueChange={setQuery}
style={{ display: "none" }}
/>
<Command.List ref={commandListRef}>{children}</Command.List>
{children}
</Command>
</tunnelInstance.In>
)}
</EditorCommandTunnelContext.Consumer>
);
});
export const EditorCommandList = Command.List;

EditorCommand.displayName = "EditorCommand";
2 changes: 1 addition & 1 deletion packages/headless/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export type { JSONContent } from "@tiptap/react";
export { EditorRoot, EditorContent, type EditorContentProps } from "./editor";
export { EditorBubble } from "./editor-bubble";
export { EditorBubbleItem } from "./editor-bubble-item";
export { EditorCommand } from "./editor-command";
export { EditorCommand, EditorCommandList } from "./editor-command";
export { EditorCommandItem, EditorCommandEmpty } from "./editor-command-item";

0 comments on commit c51b5ea

Please sign in to comment.