Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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 @@ -4,7 +4,7 @@ import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
FormattingToolbarController,
blockTypeSelectItems,
getDefaultBlockTypeSelectItems,
useCreateBlockNote,
BlockTypeSelectItem,
FormattingToolbar,
Expand Down Expand Up @@ -60,13 +60,12 @@ export default function App() {
// Sets the items in the Block Type Select.
blockTypeSelectItems={[
// Gets the default Block Type Select items.
...blockTypeSelectItems(editor.dictionary),
...getDefaultBlockTypeSelectItems(editor),
// Adds an item for the Alert block.
{
name: "Alert",
type: "alert",
icon: RiAlertFill,
isSelected: (block) => block.type === "alert",
} satisfies BlockTypeSelectItem,
]}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block } from "@blocknote/core";
import {
blockTypeSelectItems,
getDefaultBlockTypeSelectItems,
useBlockNoteEditor,
useEditorContentOrSelectionChange,
} from "@blocknote/react";
Expand Down Expand Up @@ -122,16 +122,23 @@ function MUIBlockTypeSelect() {

// Gets the default items for the select.
const defaultBlockTypeSelectItems = useMemo(
() => blockTypeSelectItems(editor.dictionary),
() => getDefaultBlockTypeSelectItems(editor),
[editor.dictionary],
);

// Gets the selected item.
const selectedItem = useMemo(
() =>
defaultBlockTypeSelectItems.find((item) =>
item.isSelected(block as any),
)!,
defaultBlockTypeSelectItems.find((item) => {
const typesMatch = item.type === block.type;
const propsMatch =
Object.entries(item.props || {}).filter(
([propName, propValue]) =>
propValue !== (block as any).props[propName],
).length === 0;

return typesMatch && propsMatch;
})!,
[defaultBlockTypeSelectItems, block],
);

Expand Down
5 changes: 2 additions & 3 deletions examples/06-custom-schema/05-alert-block-full-ux/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
FormattingToolbar,
FormattingToolbarController,
SuggestionMenuController,
blockTypeSelectItems,
getDefaultBlockTypeSelectItems,
getDefaultReactSlashMenuItems,
useCreateBlockNote,
} from "@blocknote/react";
Expand Down Expand Up @@ -93,13 +93,12 @@ export default function App() {
// Sets the items in the Block Type Select.
blockTypeSelectItems={[
// Gets the default Block Type Select items.
...blockTypeSelectItems(editor.dictionary),
...getDefaultBlockTypeSelectItems(editor),
// Adds an item for the Alert block.
{
name: "Alert",
type: "alert",
icon: RiAlertFill,
isSelected: (block) => block.type === "alert",
} satisfies BlockTypeSelectItem,
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function App() {
{
type: "paragraph",
content:
"Notice how only heading levels 1-3 are avaiable, and toggle headings are not shown.",
"Notice how only heading levels 1-3 are available, and toggle headings are not shown.",
},
{
type: "paragraph",
Expand Down
Loading
Loading