Skip to content
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

feat: File blocks #731

Merged
merged 53 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0dfe4c1
WIP file blocks
matthewlipski May 3, 2024
7737077
Refactored API for extending file block previews
matthewlipski May 8, 2024
5a2dc3c
Added `parse`/`toExternalHTML` to vanilla file block API
matthewlipski May 13, 2024
a0200f7
Added `parse`/`toExternalHTML` to React file block API
matthewlipski May 14, 2024
dca1fcb
Merged main
matthewlipski May 15, 2024
309da3b
Fixed issues from merge
matthewlipski May 15, 2024
fda09b8
Added audio/video file extensions, file UI buttons, and code improvem…
matthewlipski May 16, 2024
e7db2c5
wip
YousefED May 17, 2024
2a7100b
update formatting toolbar buttons
YousefED May 17, 2024
a6cac7a
Added `parse` & `toExternalHTML`
matthewlipski May 17, 2024
3510762
Moved `parse` & `toExternalHTML` for file block
matthewlipski May 17, 2024
21905d9
wip
YousefED May 17, 2024
ed9c3df
Finished core refactor
matthewlipski May 17, 2024
d67ab4e
Refactored react package
matthewlipski May 20, 2024
0289c9e
Merge pull request #751 from TypeCellOS/file-blocks-separate-blocks
YousefED May 20, 2024
450971a
small improvements
YousefED May 20, 2024
dc5f08f
Updated CSS
matthewlipski May 20, 2024
4f9c9f0
fix build
YousefED May 20, 2024
885dcd3
Merge branch 'file-blocks' of github.com:TypeCellOS/BlockNote into fi…
YousefED May 20, 2024
4ce7fe9
Updated examples
matthewlipski May 20, 2024
f534286
Implemented PR feedback
matthewlipski May 20, 2024
6934c5c
Implemented PR feedback
matthewlipski May 20, 2024
72b701e
Fixed issues with `toExternalHTML`
matthewlipski May 20, 2024
3a2c63d
Updated core unit tests
matthewlipski May 20, 2024
9067754
Updated React unit tests
matthewlipski May 20, 2024
dda2fc2
Fixed build
matthewlipski May 20, 2024
ee109a7
small fixes
YousefED May 20, 2024
def6472
Merge branch 'file-blocks' of github.com:TypeCellOS/BlockNote into fi…
YousefED May 20, 2024
74eac81
fix build
YousefED May 20, 2024
f5cfc86
Updated PW tests
matthewlipski May 20, 2024
d818a09
Fixed PW tests
matthewlipski May 20, 2024
18fc9f7
small cleanup
YousefED May 21, 2024
fddc0bd
small fixes + add accept for file uploads
YousefED May 21, 2024
2c7fa6d
Small fix to buttons & PDF example
matthewlipski May 21, 2024
fedac25
Merge remote-tracking branch 'origin/file-blocks' into file-blocks
matthewlipski May 21, 2024
c6e4a9d
fix dictionary
YousefED May 21, 2024
bd5915d
Merge branch 'file-blocks' of github.com:TypeCellOS/BlockNote into fi…
YousefED May 21, 2024
b131e11
Merge branch 'main' into file-blocks
matthewlipski May 21, 2024
54747f5
Merge branch 'main' into file-blocks
matthewlipski May 21, 2024
018a026
Updated locales
matthewlipski May 21, 2024
1f47ab9
Updated test screenshots
matthewlipski May 21, 2024
1eb6a02
Reverted test editor changes
matthewlipski May 21, 2024
2578871
Updated snapshots
matthewlipski May 21, 2024
7470908
Updated snapshots
matthewlipski May 21, 2024
57c0466
Changed how focus is set in toolbar buttons
matthewlipski May 21, 2024
b5343fa
tmp fix for resetting fileId
YousefED May 21, 2024
52f7310
Merge branch 'file-blocks' of github.com:TypeCellOS/BlockNote into fi…
YousefED May 21, 2024
f42a846
Simplified React unit tests
matthewlipski May 21, 2024
5bcfadf
Merge remote-tracking branch 'origin/file-blocks' into file-blocks
matthewlipski May 21, 2024
b8d8a29
Small CSS fix
matthewlipski May 21, 2024
29270d3
Removed text alignment from default file block
matthewlipski May 21, 2024
8d51664
Updated unit test snapshots
matthewlipski May 21, 2024
7b93d70
Updated PW tests
matthewlipski May 21, 2024
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
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react": "^18",
"react-dom": "^18",
"react-github-btn": "^1.4.0",
"react-icons": "^4.3.1",
"react-icons": "^5.2.1",
"y-partykit": "^0.0.25",
"yjs": "^13.6.1"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/advanced/vanilla-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ While it's up to you to decide how you want the elements to be rendered, BlockNo
type UIElement =
| "formattingToolbar"
| "linkToolbar"
| "imageToolbar"
| "filePanel"
| "sideMenu"
| "suggestionMenu"
| "tableHandles"
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/docs/editor-basics/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type BlockNoteViewProps = {
linkToolbar?: boolean;
sideMenu?: boolean;
slashMenu?: boolean;
imageToolbar?: boolean;
filePanel?: boolean;
tableHandles?: boolean;
children?:
} & HTMLAttributes<HTMLDivElement>;
Expand All @@ -120,7 +120,7 @@ export type BlockNoteViewProps = {

`slashMenu`: Whether the [Slash Menu](/docs/ui-components/suggestion-menus#slash-menu) should be enabled.

`imageToolbar`: Whether the Image Toolbar should be enabled.
`filePanel`: Whether the File Toolbar should be enabled.

`tableHandles`: Whether the Table Handles should be enabled.

Expand Down
30 changes: 27 additions & 3 deletions examples/01-basic/03-all-blocks/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ export default function App() {
type: "numberedListItem",
content: "Numbered List Item",
},
{
type: "image",
},
{
type: "table",
content: {
Expand All @@ -60,6 +57,33 @@ export default function App() {
],
},
},
{
type: "file",
},
{
type: "image",
props: {
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
caption:
"From https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
},
},
{
type: "video",
props: {
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm",
caption:
"From https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm",
},
},
{
type: "audio",
props: {
url: "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
caption:
"From https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
},
},
{
type: "paragraph",
},
Expand Down
2 changes: 1 addition & 1 deletion examples/01-basic/testing/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { uploadToTmpFilesDotOrg_DEV_ONLY } from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { useCreateBlockNote } from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";

export default function App() {
// Creates a new editor instance.
Expand Down
4 changes: 2 additions & 2 deletions examples/02-ui-components/01-ui-elements-remove/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@blocknote/core/fonts/inter.css";
import { useCreateBlockNote } from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";

export default function App() {
// Creates a new editor instance.
Expand Down Expand Up @@ -34,7 +34,7 @@ export default function App() {
// Removes all menus and toolbars.
formattingToolbar={false}
linkToolbar={false}
imageToolbar={false}
filePanel={false}
sideMenu={false}
slashMenu={false}
tableHandles={false}
Expand Down
12 changes: 6 additions & 6 deletions examples/02-ui-components/02-formatting-toolbar-buttons/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
BasicTextStyleButton,
BlockTypeSelect,
ColorStyleButton,
CreateLinkButton,
FileCaptionButton,
FileReplaceButton,
FormattingToolbar,
FormattingToolbarController,
ImageCaptionButton,
NestBlockButton,
ReplaceImageButton,
TextAlignButton,
UnnestBlockButton,
useCreateBlockNote,
} from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";

import { BlueButton } from "./BlueButton";

Expand Down Expand Up @@ -77,8 +77,8 @@ export default function App() {
{/* Extra button to toggle blue text & background */}
<BlueButton key={"customButton"} />

<ImageCaptionButton key={"imageCaptionButton"} />
<ReplaceImageButton key={"replaceImageButton"} />
<FileCaptionButton key={"fileCaptionButton"} />
<FileReplaceButton key={"replaceFileButton"} />

<BasicTextStyleButton
basicTextStyle={"bold"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"tags": ["Intermediate", "Blocks", "UI Components", "Formatting Toolbar", "Custom Schemas"],
"dependencies": {
"@mantine/core": "^7.7.1",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@mantine/core": "^7.7.1",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"author": "matthewlipski",
"tags": ["Intermediate", "Blocks", "UI Components", "Block Side Menu"],
"dependencies": {
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@blocknote/shadcn": "^0.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"author": "matthewlipski",
"tags": ["Intermediate", "Blocks", "UI Components", "Block Side Menu"],
"dependencies": {
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@blocknote/shadcn": "^0.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"Slash Menu"
],
"dependencies": {
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@blocknote/shadcn": "^0.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
2 changes: 1 addition & 1 deletion examples/02-ui-components/08-custom-ui/.bnexample.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"author": "matthewlipski",
"tags": ["Advanced", "Inline Content", "UI Components", "Block Side Menu", "Formatting Toolbar", "Suggestion Menus", "Slash Menu", "Appearance & Styling"],
"dependencies": {
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
84 changes: 44 additions & 40 deletions examples/02-ui-components/08-custom-ui/CustomFormattingToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
useBlockNoteEditor,
useEditorChange,
useEditorSelectionChange,
useEditorContentOrSelectionChange,
} from "@blocknote/react";
import { useState } from "react";
import {
Expand All @@ -16,6 +15,7 @@ import {
MdFormatUnderlined,
} from "react-icons/md";

import { checkBlockHasDefaultProp } from "@blocknote/core";
import { ColorMenu } from "./ColorMenu";
import { LinkMenu } from "./LinkMenu";

Expand All @@ -24,7 +24,7 @@ type CustomFormattingToolbarState = {
italic: boolean;
underline: boolean;

textAlignment: "left" | "center" | "right" | "justify";
textAlignment: "left" | "center" | "right" | "justify" | undefined;

textColor: string;
backgroundColor: string;
Expand All @@ -35,6 +35,7 @@ export function CustomFormattingToolbar() {
const editor = useBlockNoteEditor();

// Function to get the state of toolbar buttons (active/inactive).
// TODO: this is a bit weird, better to use useSelectedBlocks and useActiveStyles hooks
const getState = (): CustomFormattingToolbarState => {
const block = editor.getTextCursorPosition().block;
const activeStyles = editor.getActiveStyles();
Expand All @@ -44,7 +45,9 @@ export function CustomFormattingToolbar() {
italic: (activeStyles.italic as boolean) || false,
underline: (activeStyles.underline as boolean) || false,

textAlignment: block.props.textAlignment,
textAlignment: checkBlockHasDefaultProp("textAlignment", block, editor)
? block.props.textAlignment
: undefined,

textColor: (activeStyles.textColor as string) || "default",
backgroundColor: (activeStyles.backgroundColor as string) || "default",
Expand Down Expand Up @@ -80,8 +83,7 @@ export function CustomFormattingToolbar() {
const [linkMenuOpen, setLinkMenuOpen] = useState(false);

// Updates toolbar state when the editor content or selection changes.
useEditorChange(() => setState(getState()), editor);
useEditorSelectionChange(() => setState(getState()), editor);
useEditorContentOrSelectionChange(() => setState(getState()), editor);

return (
<div className={"formatting-toolbar"}>
Expand Down Expand Up @@ -111,40 +113,42 @@ export function CustomFormattingToolbar() {
</button>
</div>
{/* Button group for text alignment */}
<div className={"formatting-toolbar-group"}>
{/*Left align button*/}
<button
className={`formatting-toolbar-button${
state.textAlignment === "left" ? " active" : ""
}`}
onClick={() => setTextAlignment("left")}>
<MdFormatAlignLeft />
</button>
{/* Center align button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "center" ? " active" : ""
}`}
onClick={() => setTextAlignment("center")}>
<MdFormatAlignCenter />
</button>
{/* Right align button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "right" ? " active" : ""
}`}
onClick={() => setTextAlignment("right")}>
<MdFormatAlignRight />
</button>
{/* Justify text button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "justify" ? " active" : ""
}`}
onClick={() => setTextAlignment("justify")}>
<MdFormatAlignJustify />
</button>
</div>
{state.textAlignment && (
<div className={"formatting-toolbar-group"}>
{/*Left align button*/}
<button
className={`formatting-toolbar-button${
state.textAlignment === "left" ? " active" : ""
}`}
onClick={() => setTextAlignment("left")}>
<MdFormatAlignLeft />
</button>
{/* Center align button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "center" ? " active" : ""
}`}
onClick={() => setTextAlignment("center")}>
<MdFormatAlignCenter />
</button>
{/* Right align button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "right" ? " active" : ""
}`}
onClick={() => setTextAlignment("right")}>
<MdFormatAlignRight />
</button>
{/* Justify text button */}
<button
className={`formatting-toolbar-button${
state.textAlignment === "justify" ? " active" : ""
}`}
onClick={() => setTextAlignment("justify")}>
<MdFormatAlignJustify />
</button>
</div>
)}
{/* Button group for color menu */}
<div className={"formatting-toolbar-group"}>
<div className={"color-menu-button"}>
Expand Down
2 changes: 1 addition & 1 deletion examples/02-ui-components/08-custom-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@blocknote/shadcn": "^0.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
2 changes: 1 addition & 1 deletion examples/05-custom-schema/01-alert-block/.bnexample.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"tags": ["Intermediate", "Blocks", "Custom Schemas", "Suggestion Menus", "Slash Menu"],
"dependencies": {
"@mantine/core": "^7.7.1",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
}
}
2 changes: 1 addition & 1 deletion examples/05-custom-schema/01-alert-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@mantine/core": "^7.7.1",
"react-icons": "^4.3.1"
"react-icons": "^5.2.1"
},
"devDependencies": {
"@types/react": "^18.0.25",
Expand Down
Loading
Loading