-
-
Notifications
You must be signed in to change notification settings - Fork 642
feat. add example in docs for removing default blocks #902
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 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c61fa1f
feat. add example in docs for removing default blocks
hunxjunedo 6c0b44a
minor fixes as suggested
hunxjunedo 4c062b4
fixed file structure
hunxjunedo a133f53
Merge remote-tracking branch 'origin/main' into pr/hunxjunedo/902
YousefED 86b1218
small cleanup
YousefED 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "playground": true, | ||
| "docs": true, | ||
| "author": "hunxjunedo", | ||
| "tags": ["Basic", "removing", "custom"] | ||
| } |
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,54 @@ | ||
| import "@blocknote/core/fonts/inter.css"; | ||
| import { useCreateBlockNote } from "@blocknote/react"; | ||
| import { BlockNoteView } from "@blocknote/mantine"; | ||
| import "@blocknote/mantine/style.css"; | ||
| import { BlockNoteSchema, defaultBlockSpecs, defaultInlineContentSpecs, defaultStyleSpecs } from "@blocknote/core"; | ||
|
|
||
| export default function App() { | ||
| //create custom schema | ||
| let editedSchema : any = {} | ||
|
|
||
| //define the blocks which are not allowed | ||
| const unwantedBlocks = ['audio', 'image'] | ||
|
|
||
| //Loop thru default schema and remove the unwanted blocks | ||
| Object.entries(defaultBlockSpecs).forEach(([blockName, blockSchema])=>{ | ||
| if(!unwantedBlocks.includes(blockName)){ | ||
|
|
||
| //only allow to to pass if the blockName is not unwanted | ||
| editedSchema[blockName] = blockSchema | ||
| } | ||
| }) | ||
|
|
||
| //now create the schema | ||
| const schema = BlockNoteSchema.create({ | ||
| blockSpecs: { | ||
hunxjunedo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ...editedSchema, | ||
|
|
||
| // Add your own custom blocks: | ||
| // customBlock: CustomBlock, | ||
| }, | ||
| inlineContentSpecs: { | ||
| // enable the default inline content if desired | ||
| ...defaultInlineContentSpecs, | ||
|
|
||
| // Add your own custom inline content: | ||
| // customInlineContent: CustomInlineContent, | ||
| }, | ||
| styleSpecs: { | ||
| // enable the default styles if desired | ||
| ...defaultStyleSpecs, | ||
|
|
||
| // Add your own custom styles: | ||
| // customStyle: CustomStyle | ||
| }, | ||
| }); | ||
|
|
||
| // Creates a new editor instance. | ||
| const editor = useCreateBlockNote({ | ||
| schema | ||
| }); | ||
|
|
||
| // Renders the editor instance using a React component. | ||
| return <BlockNoteView editor={editor} />; | ||
| } | ||
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,7 @@ | ||
| # Removing Default Blocks Options | ||
hunxjunedo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| In this example, we pass a custom schema to the editor function, which retuurns an editor which has our custom schema. While create thi schema we remove the blocks which we don't want, by using simple logic. | ||
|
|
||
| **Relevant Docs:** | ||
|
|
||
| - [Editor Setup](/docs/editor-basics/setup) | ||
hunxjunedo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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"> | ||
| <head> | ||
| <script> | ||
| <!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY --> | ||
| </script> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Removing Default Blocks Options</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./main.tsx"></script> | ||
| </body> | ||
| </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,11 @@ | ||
| // AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY | ||
| import React from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import App from "./App"; | ||
|
|
||
| const root = createRoot(document.getElementById("root")!); | ||
| root.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode> | ||
| ); |
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,37 @@ | ||
| { | ||
| "name": "@blocknote/example-removing-block-option", | ||
| "description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
| "private": true, | ||
| "version": "0.12.4", | ||
| "scripts": { | ||
| "start": "vite", | ||
| "dev": "vite", | ||
| "build": "tsc && vite build", | ||
| "preview": "vite preview", | ||
| "lint": "eslint . --max-warnings 0" | ||
| }, | ||
| "dependencies": { | ||
| "@blocknote/core": "latest", | ||
| "@blocknote/react": "latest", | ||
| "@blocknote/ariakit": "latest", | ||
| "@blocknote/mantine": "latest", | ||
| "@blocknote/shadcn": "latest", | ||
| "react": "^18.3.1", | ||
| "react-dom": "^18.3.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^18.0.25", | ||
| "@types/react-dom": "^18.0.9", | ||
| "@vitejs/plugin-react": "^4.0.4", | ||
| "eslint": "^8.10.0", | ||
| "vite": "^4.4.8" | ||
| }, | ||
| "eslintConfig": { | ||
| "extends": [ | ||
| "../../../.eslintrc.js" | ||
| ] | ||
| }, | ||
| "eslintIgnore": [ | ||
| "dist" | ||
| ] | ||
| } |
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": "Node", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "noEmit": true, | ||
| "jsx": "react-jsx", | ||
| "composite": true | ||
| }, | ||
| "include": [ | ||
| "." | ||
| ], | ||
| "__ADD_FOR_LOCAL_DEV_references": [ | ||
| { | ||
| "path": "../../../packages/core/" | ||
| }, | ||
| { | ||
| "path": "../../../packages/react/" | ||
| } | ||
| ] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "playground": true, | ||
| "docs": true, | ||
| "author": "hunxjunedo", | ||
| "tags": ["Basic", "removing", "custom"] | ||
| } |
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,41 @@ | ||
| import "@blocknote/core/fonts/inter.css"; | ||
| import { useCreateBlockNote } from "@blocknote/react"; | ||
| import { BlockNoteView } from "@blocknote/mantine"; | ||
| import "@blocknote/mantine/style.css"; | ||
| import { BlockNoteSchema, BlockSpec, defaultBlockSpecs, defaultInlineContentSpecs, defaultStyleSpecs } from "@blocknote/core"; | ||
|
|
||
| export default function App() { | ||
|
|
||
| // create the schema | ||
| const schema = BlockNoteSchema.create({ | ||
| blockSpecs: { | ||
| //first pass all the blocks | ||
| ...defaultBlockSpecs, | ||
| //now make the unwanted blocks undefined | ||
| audio: undefined as any, | ||
| image: undefined as any | ||
| }, | ||
| inlineContentSpecs: { | ||
| // enable the default inline content if desired | ||
| ...defaultInlineContentSpecs, | ||
|
|
||
| // Add your own custom inline content: | ||
| // customInlineContent: CustomInlineContent, | ||
| }, | ||
| styleSpecs: { | ||
| // enable the default styles if desired | ||
| ...defaultStyleSpecs, | ||
|
|
||
| // Add your own custom styles: | ||
| // customStyle: CustomStyle | ||
| }, | ||
| }); | ||
|
|
||
| // Creates a new editor instance. | ||
| const editor = useCreateBlockNote({ | ||
| schema | ||
| }); | ||
|
|
||
| // Renders the editor instance using a React component. | ||
| return <BlockNoteView editor={editor} />; | ||
| } |
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,8 @@ | ||
| # Removing Default Blocks Options | ||
|
|
||
| In this example, we pass a custom schema to the editor function, which returns an editor which has our custom schema. While creating this schema we remove the blocks - audio and image in this example - which we don't want, by making those blocks undefined. | ||
|
|
||
| **Relevant Docs:** | ||
|
|
||
| - [Editor Setup](/docs/editor-basics/setup) | ||
| - [Custom Schemas](/docs/custom-schemas) |
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.