Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getPageBreakReactSlashMenuItems<
S extends StyleSchema,
>(
editor: BlockNoteEditor<BSchema, I, S>,
): (Omit<DefaultReactSuggestionItem, "key"> & { key: "page_break" })[] {
): (DefaultReactSuggestionItem & { key: "page_break" })[] {
return getPageBreakSlashMenuItems(editor).map((item) => {
const Icon = icons[item.key];
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BlockNoteEditor,
BlockSchema,
Dictionary,
InlineContentSchema,
StyleSchema,
} from "@blocknote/core";
Expand Down Expand Up @@ -61,7 +62,11 @@ export function getDefaultReactSlashMenuItems<
BSchema extends BlockSchema,
I extends InlineContentSchema,
S extends StyleSchema,
>(editor: BlockNoteEditor<BSchema, I, S>): DefaultReactSuggestionItem[] {
>(
editor: BlockNoteEditor<BSchema, I, S>,
): (DefaultReactSuggestionItem & {
key: keyof Omit<Dictionary["slash_menu"], "page_break">;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct right? Aren't you marking all of the items as having a page_break key, when that is not actually the case. Shouldn't you change DefaultReactSuggestionItem instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look. I’ll check it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, Omit<Dictionary["slash_menu"], "page_break"> here represents "a union of keys excluding page_break", not "marking items as having a page_break key". This pattern follows the same approach used in the DefaultSuggestionItem.ts

I believe the current implementation is correct, but I do agree that modifying DefaultReactSuggestionItem could be a better approach.

However, changing DefaultReactSuggestionItem requires a deeper understanding of BlockNote's design decisions. The key property was removed from DefaultReactSuggestionItem in #652, but the PR doesn't explain why. I can only speculate on the reasons:

  • Potential conflicts with React's key prop
  • Custom suggestion items may not need a key

Making changes to DefaultReactSuggestionItem feels beyond my current understanding of the codebase. This PR at least addresses the immediate type issue.

})[] {
return getDefaultSlashMenuItems(editor).map((item) => {
const Icon = icons[item.key];
return {
Expand Down
Loading