-
-
Notifications
You must be signed in to change notification settings - Fork 558
feat: Toggle blocks #1707
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
Open
matthewlipski
wants to merge
29
commits into
main
Choose a base branch
from
toggle-blocks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,703
−1,031
Open
feat: Toggle blocks #1707
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d893c6a
Added toggle heading
matthewlipski d77eca5
Changed collapsible heading to toggle and added react implementation
matthewlipski ec26e4d
Removed duplicate code
matthewlipski 00fbdae
Small changes
matthewlipski 9d148ae
Extracted toggle to separate component
matthewlipski 7a7a2db
Added missing export
matthewlipski a484779
Added vanilla toggle heading block
matthewlipski 7ce587d
Added translations
matthewlipski cb159d6
Typing fix
matthewlipski d7a6d7d
Made heading custom block to extend for toggle heading
matthewlipski a3a88f9
Small fix
matthewlipski 2c12f1b
Removed toggle heading block and added `isTogglable` prop to regular …
matthewlipski 238843a
Slightly changed how the toggle wrapper works
matthewlipski 9378ef0
Changed heading block to again use `createStronglyTypedTiptapNode` in…
matthewlipski c603d4c
Added toggle list item default block
matthewlipski 1f78656
Merge branch 'main' into toggle-blocks
matthewlipski 1c2786e
Updated lock file
matthewlipski 9b27b94
Updated unit tests
matthewlipski ff157b3
Updated PW tests
matthewlipski 0b0f210
fix tests
YousefED 90a029d
Merge branch 'main' into toggle-blocks
matthewlipski d322a9f
update snaps
YousefED b1848f3
Merge remote-tracking branch 'origin/main' into toggle-blocks
YousefED 88bb5c3
Small cleanup
matthewlipski cbf23a2
Merge branch 'toggle-blocks' of github.com:TypeCellOS/BlockNote into …
matthewlipski 860bcd5
Improved keyboard handling
matthewlipski c3b2f58
Updated `ToggleWrapper` keyboard handling
matthewlipski 3533091
Skip AI tests
matthewlipski 7ee4788
Updated PW snap
matthewlipski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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
6 changes: 6 additions & 0 deletions
6
examples/06-custom-schema/06-togglable-blocks/.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,6 @@ | ||
{ | ||
"playground": true, | ||
"docs": true, | ||
"author": "matthewlipski", | ||
"tags": ["Basic"] | ||
} |
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,55 @@ | ||
import { BlockNoteSchema, defaultBlockSpecs } from "@blocknote/core"; | ||
import "@blocknote/core/fonts/inter.css"; | ||
import { BlockNoteView } from "@blocknote/mantine"; | ||
import "@blocknote/mantine/style.css"; | ||
import { useCreateBlockNote } from "@blocknote/react"; | ||
|
||
import { ToggleBlock } from "./Toggle.js"; | ||
|
||
// Our schema with block specs, which contain the configs and implementations for | ||
// blocks that we want our editor to use. | ||
const schema = BlockNoteSchema.create({ | ||
blockSpecs: { | ||
// Adds all default blocks. | ||
...defaultBlockSpecs, | ||
// Adds the Toggle block. | ||
toggle: ToggleBlock, | ||
}, | ||
}); | ||
|
||
export default function App() { | ||
// Creates a new editor instance. | ||
const editor = useCreateBlockNote({ | ||
schema, | ||
initialContent: [ | ||
{ | ||
type: "paragraph", | ||
content: "Welcome to this demo!", | ||
}, | ||
{ | ||
type: "toggle", | ||
content: "This is an example toggle", | ||
children: [ | ||
{ | ||
type: "paragraph", | ||
content: "This is the first child of the toggle block.", | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "This is the second child of the toggle block.", | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: "Click the '>' icon to show/hide its children", | ||
}, | ||
{ | ||
type: "paragraph", | ||
}, | ||
], | ||
}); | ||
|
||
// Renders the editor instance. | ||
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 @@ | ||
# Togglable Blocks | ||
|
||
This example shows how to create blocks with a toggle button to show/hide their children, like with the default toggle heading and list item blocks. This is done using the use the `ToggleWrapper` component from `@blocknote/react`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make explicit (both in the example name and description) that this is about custom blocks |
||
|
||
**Relevant Docs:** | ||
|
||
- [Custom Blocks](/docs/custom-schemas/custom-blocks) | ||
- [Editor Setup](/docs/editor-basics/setup) |
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,23 @@ | ||
import { defaultProps } from "@blocknote/core"; | ||
import { createReactBlockSpec, ToggleWrapper } from "@blocknote/react"; | ||
|
||
// The Toggle block that we want to add to our editor. | ||
export const ToggleBlock = createReactBlockSpec( | ||
{ | ||
type: "toggle", | ||
propSchema: { | ||
...defaultProps, | ||
}, | ||
content: "inline", | ||
}, | ||
{ | ||
render: (props) => ( | ||
// The `ToggleWrapper` component renders a button on the left which | ||
// toggles the visibility of the block's children. It also adds a button | ||
// to add child blocks if there are none. | ||
<ToggleWrapper block={props.block} editor={props.editor}> | ||
<p ref={props.contentRef} /> | ||
</ToggleWrapper> | ||
), | ||
}, | ||
); |
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>Togglable Blocks</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.jsx"; | ||
|
||
const root = createRoot(document.getElementById("root")!); | ||
root.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); |
27 changes: 27 additions & 0 deletions
27
examples/06-custom-schema/06-togglable-blocks/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,27 @@ | ||
{ | ||
"name": "@blocknote/example-togglable-blocks", | ||
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY", | ||
"private": true, | ||
"version": "0.12.4", | ||
"scripts": { | ||
"start": "vite", | ||
"dev": "vite", | ||
"build:prod": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"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.3.1", | ||
"vite": "^5.3.4" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/06-custom-schema/06-togglable-blocks/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/06-custom-schema/06-togglable-blocks/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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use isToggleable to be more inline with notion (https://developers.notion.com/reference/block#toggle-blocks)