0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TIPS:BlockNoteを使ったときにSuggestionMenuのMediaを消したいとき

Posted at

BlockNoteを使ってますか?

Notionみたいに書けて、ユーザーフレンドリーで素晴らしいOSSですよね。
これを使って機能提供したいけど、スモールスタートしたくて、ファイルアップロード系のMenuを消したなぁと思ったので、無理矢理やってみました

Sample

import { BlockNoteEditor, filterSuggestionItems } from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
  DefaultReactSuggestionItem,
  getDefaultReactSlashMenuItems,
  SuggestionMenuController,
  useCreateBlockNote,
} from "@blocknote/react";

// defaultのSlashMenuItemsからMedia Groupに所属するものを排除します
const getCustomSlashMenuItems = (
  editor: BlockNoteEditor,
): DefaultReactSuggestionItem[] =>
  getDefaultReactSlashMenuItems(editor).filter(
    (item) => item.group !== "Media",
  );


export const Sample = () => {
  const editor = useCreateBlockNote();

  return (
    <BlockNoteView editor={editor} theme="light" slashMenu={false}>
       <SuggestionMenuController
          triggerCharacter={"/"}
          getItems={async (query) =>
              filterSuggestionItems(getCustomSlashMenuItems(editor), query)
          }
        />
    </BlockNoteView>
  )
};


デフォルトのItemsからMedia Groupを抜き、カスタマイズの設定しています。
他にいいやり方もなかったので、このような方法を無理矢理とっています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?