-
-
Notifications
You must be signed in to change notification settings - Fork 725
docs: Slash menu item grouping & ordering (BLO-1009) #2700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
examples/03-ui-components/19-suggestion-menus-grouping-ordering/.bnexample.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "playground": true, | ||
| "docs": true, | ||
| "author": "matthewlipski", | ||
| "tags": [ | ||
| "Intermediate", | ||
| "Blocks", | ||
| "UI Components", | ||
| "Suggestion Menus", | ||
| "Slash Menu" | ||
| ] | ||
| } |
11 changes: 11 additions & 0 deletions
11
examples/03-ui-components/19-suggestion-menus-grouping-ordering/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Slash Menu Grouping & Ordering | ||
|
|
||
| In this example, we filter and reorder the default Slash Menu items so that only the "Basic blocks" and "Headings" groups are shown, with "Basic blocks" appearing first. | ||
|
|
||
| **Try it out:** Press the "/" key to open the Slash Menu and see the reordered groups! | ||
|
|
||
| **Relevant Docs:** | ||
|
|
||
| - [Item Grouping & Ordering](/docs/react/components/suggestion-menus) | ||
| - [Changing Slash Menu Items](/docs/react/components/suggestion-menus) | ||
| - [Editor Setup](/docs/getting-started/editor-setup) |
14 changes: 14 additions & 0 deletions
14
examples/03-ui-components/19-suggestion-menus-grouping-ordering/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <html lang="en"> | ||
|
matthewlipski marked this conversation as resolved.
|
||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Slash Menu Grouping & Ordering</title> | ||
| <script> | ||
| <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./main.tsx"></script> | ||
| </body> | ||
| </html> | ||
11 changes: 11 additions & 0 deletions
11
examples/03-ui-components/19-suggestion-menus-grouping-ordering/main.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY | ||
| import React from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import App from "./src/App.jsx"; | ||
|
|
||
| const root = createRoot(document.getElementById("root")!); | ||
| root.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode> | ||
| ); |
31 changes: 31 additions & 0 deletions
31
examples/03-ui-components/19-suggestion-menus-grouping-ordering/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "name": "@blocknote/example-ui-components-suggestion-menus-grouping-ordering", | ||
| "description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
| "type": "module", | ||
| "private": true, | ||
| "version": "0.12.4", | ||
| "scripts": { | ||
| "start": "vite", | ||
| "dev": "vite", | ||
| "build:prod": "tsc && vite build", | ||
| "preview": "vite preview" | ||
| }, | ||
| "dependencies": { | ||
| "@blocknote/ariakit": "latest", | ||
| "@blocknote/core": "latest", | ||
| "@blocknote/mantine": "latest", | ||
| "@blocknote/react": "latest", | ||
| "@blocknote/shadcn": "latest", | ||
| "@mantine/core": "^8.3.11", | ||
| "@mantine/hooks": "^8.3.11", | ||
| "@mantine/utils": "^6.0.22", | ||
| "react": "^19.2.3", | ||
| "react-dom": "^19.2.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^19.2.3", | ||
| "@types/react-dom": "^19.2.3", | ||
| "@vitejs/plugin-react": "^6.0.1", | ||
| "vite": "^8.0.8" | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
examples/03-ui-components/19-suggestion-menus-grouping-ordering/src/App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { BlockNoteEditor } from "@blocknote/core"; | ||
| import { filterSuggestionItems } from "@blocknote/core/extensions"; | ||
| import "@blocknote/core/fonts/inter.css"; | ||
| import { BlockNoteView } from "@blocknote/mantine"; | ||
| import "@blocknote/mantine/style.css"; | ||
| import { | ||
| DefaultReactSuggestionItem, | ||
| getDefaultReactSlashMenuItems, | ||
| SuggestionMenuController, | ||
| useCreateBlockNote, | ||
| } from "@blocknote/react"; | ||
|
|
||
| // Returns the default Slash Menu items, keeping only the "Basic blocks" and | ||
| // "Headings" groups, with "Basic blocks" listed before "Headings". | ||
| const getCustomSlashMenuItems = ( | ||
| editor: BlockNoteEditor, | ||
| ): DefaultReactSuggestionItem[] => { | ||
| const defaultItems = getDefaultReactSlashMenuItems(editor); | ||
|
|
||
| const basicBlocks = defaultItems.filter( | ||
| (item) => item.group === "Basic blocks", | ||
| ); | ||
| const headings = defaultItems.filter((item) => item.group === "Headings"); | ||
|
|
||
| return [...basicBlocks, ...headings]; | ||
| }; | ||
|
|
||
| export default function App() { | ||
| // Creates a new editor instance. | ||
| const editor = useCreateBlockNote({ | ||
| initialContent: [ | ||
| { | ||
| type: "paragraph", | ||
| content: "Welcome to this demo!", | ||
| }, | ||
| { | ||
| type: "paragraph", | ||
| content: "Press the '/' key to open the Slash Menu", | ||
| }, | ||
| { | ||
| type: "paragraph", | ||
| content: | ||
| "Notice that only 'Basic blocks' and 'Headings' are shown, in that order", | ||
| }, | ||
| { | ||
| type: "paragraph", | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| // Renders the editor instance. | ||
| return ( | ||
| <BlockNoteView editor={editor} slashMenu={false}> | ||
| <SuggestionMenuController | ||
| triggerCharacter={"/"} | ||
| // Replaces the default Slash Menu items with our custom ones. | ||
| getItems={async (query) => | ||
| filterSuggestionItems(getCustomSlashMenuItems(editor), query) | ||
| } | ||
| /> | ||
| </BlockNoteView> | ||
| ); | ||
| } |
36 changes: 36 additions & 0 deletions
36
examples/03-ui-components/19-suggestion-menus-grouping-ordering/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "__comment": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "useDefineForClassFields": true, | ||
| "lib": [ | ||
| "DOM", | ||
| "DOM.Iterable", | ||
| "ESNext" | ||
| ], | ||
| "allowJs": false, | ||
| "skipLibCheck": true, | ||
| "esModuleInterop": false, | ||
| "allowSyntheticDefaultImports": true, | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
| "composite": true | ||
| }, | ||
| "include": [ | ||
| "." | ||
| ], | ||
| "__ADD_FOR_LOCAL_DEV_references": [ | ||
| { | ||
| "path": "../../../packages/core/" | ||
| }, | ||
| { | ||
| "path": "../../../packages/react/" | ||
| } | ||
| ] | ||
| } |
32 changes: 32 additions & 0 deletions
32
examples/03-ui-components/19-suggestion-menus-grouping-ordering/vite.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY | ||
| import react from "@vitejs/plugin-react"; | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import { defineConfig } from "vite"; | ||
| // import eslintPlugin from "vite-plugin-eslint"; | ||
| // https://vitejs.dev/config/ | ||
| export default defineConfig((conf) => ({ | ||
| plugins: [react()], | ||
| optimizeDeps: {}, | ||
| build: { | ||
| sourcemap: true, | ||
| }, | ||
| resolve: { | ||
| alias: | ||
| conf.command === "build" || | ||
| !fs.existsSync(path.resolve(__dirname, "../../packages/core/src")) | ||
| ? {} | ||
| : ({ | ||
| // Comment out the lines below to load a built version of blocknote | ||
| // or, keep as is to load live from sources with live reload working | ||
| "@blocknote/core": path.resolve( | ||
| __dirname, | ||
| "../../packages/core/src/" | ||
| ), | ||
| "@blocknote/react": path.resolve( | ||
| __dirname, | ||
| "../../packages/react/src/" | ||
| ), | ||
| } as any), | ||
| }, | ||
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.