Skip to content

Commit c51b5ea

Browse files
authored
Merge pull request #342 from steven-tey/expose-command-list
feat: expose editor command list
2 parents ccfc227 + 8456652 commit c51b5ea

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

apps/web/components/tailwind/advanced-editor.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
EditorContent,
1111
type JSONContent,
1212
EditorInstance,
13+
EditorCommandList,
1314
} from "novel";
1415
import { ImageResizer, handleCommandNavigation } from "novel/extensions";
1516
import { defaultExtensions } from "./extensions";
@@ -87,24 +88,26 @@ const TailwindAdvancedEditor = () => {
8788
<EditorCommandEmpty className="px-2 text-muted-foreground">
8889
No results
8990
</EditorCommandEmpty>
90-
{suggestionItems.map((item) => (
91-
<EditorCommandItem
92-
value={item.title}
93-
onCommand={(val) => item.command(val)}
94-
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 `}
95-
key={item.title}
96-
>
97-
<div className="flex h-10 w-10 items-center justify-center rounded-md border border-muted bg-background">
98-
{item.icon}
99-
</div>
100-
<div>
101-
<p className="font-medium">{item.title}</p>
102-
<p className="text-xs text-muted-foreground">
103-
{item.description}
104-
</p>
105-
</div>
106-
</EditorCommandItem>
107-
))}
91+
<EditorCommandList>
92+
{suggestionItems.map((item) => (
93+
<EditorCommandItem
94+
value={item.title}
95+
onCommand={(val) => item.command(val)}
96+
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 `}
97+
key={item.title}
98+
>
99+
<div className="flex h-10 w-10 items-center justify-center rounded-md border border-muted bg-background">
100+
{item.icon}
101+
</div>
102+
<div>
103+
<p className="font-medium">{item.title}</p>
104+
<p className="text-xs text-muted-foreground">
105+
{item.description}
106+
</p>
107+
</div>
108+
</EditorCommandItem>
109+
))}
110+
</EditorCommandList>
108111
</EditorCommand>
109112

110113
<GenerativeMenuSwitch open={openAI} onOpenChange={setOpenAI}>

packages/headless/src/components/editor-command.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { ComponentPropsWithoutRef, FC } from "react";
88
import type { Range } from "@tiptap/core";
99

1010
export const EditorCommandTunnelContext = createContext(
11-
{} as ReturnType<typeof tunnel>
11+
{} as ReturnType<typeof tunnel>,
1212
);
1313

1414
interface EditorCommandOutProps {
@@ -44,7 +44,7 @@ export const EditorCommandOut: FC<EditorCommandOutProps> = ({
4444
key: e.key,
4545
cancelable: true,
4646
bubbles: true,
47-
})
47+
}),
4848
);
4949

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

7372
return (
@@ -88,12 +87,13 @@ export const EditorCommand = forwardRef<
8887
onValueChange={setQuery}
8988
style={{ display: "none" }}
9089
/>
91-
<Command.List ref={commandListRef}>{children}</Command.List>
90+
{children}
9291
</Command>
9392
</tunnelInstance.In>
9493
)}
9594
</EditorCommandTunnelContext.Consumer>
9695
);
9796
});
97+
export const EditorCommandList = Command.List;
9898

9999
EditorCommand.displayName = "EditorCommand";

packages/headless/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export type { JSONContent } from "@tiptap/react";
55
export { EditorRoot, EditorContent, type EditorContentProps } from "./editor";
66
export { EditorBubble } from "./editor-bubble";
77
export { EditorBubbleItem } from "./editor-bubble-item";
8-
export { EditorCommand } from "./editor-command";
8+
export { EditorCommand, EditorCommandList } from "./editor-command";
99
export { EditorCommandItem, EditorCommandEmpty } from "./editor-command-item";

0 commit comments

Comments
 (0)