Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8f3aab4
fix: Docs home page demo styling fix (#507)
matthewlipski Jan 10, 2024
877c4f0
Fixed styling for code styles (#517)
matthewlipski Jan 15, 2024
2890440
Made suggestions plugin control multiple menus
matthewlipski Jan 17, 2024
818b13a
Added hook to create suggestion menu
matthewlipski Jan 18, 2024
42e5483
Fixed add block button behaviour on blocks with different content (#526)
matthewlipski Jan 21, 2024
5e94a75
Small CSS fix (#527)
matthewlipski Jan 21, 2024
352c8e7
fix: List item shortcuts (#528)
matthewlipski Jan 21, 2024
6bb6271
Added code toggle formatting toolbar example (#531)
matthewlipski Jan 21, 2024
03177d2
fix: Errors when hovering image block while editor is uneditable (#533)
matthewlipski Jan 22, 2024
cd6e1ae
fix: Formatting toolbar not hiding while dragging blocks (#529)
matthewlipski Jan 22, 2024
5062e0b
Updated Mantine (#535)
matthewlipski Jan 22, 2024
16d0094
Updated `package-lock.json` (#536)
matthewlipski Jan 22, 2024
37564e3
v0.11.1
matthewlipski Jan 22, 2024
6dba56f
fix collaboration and editable: false bug (#538)
YousefED Jan 22, 2024
5cd01c7
pair refactoring
YousefED Jan 22, 2024
076893c
wip
YousefED Jan 22, 2024
83569c0
fix type annotations on some of the docs (#539)
YousefED Jan 23, 2024
e3f40d9
Cleanup and continue refactor
matthewlipski Jan 26, 2024
b5ccd1a
docs: Dark mode styling fix (#548)
matthewlipski Jan 29, 2024
0876ee6
Implemented PR feedback
matthewlipski Jan 29, 2024
b6c5ce2
Add Liveblocks info and BlockNote download command (#540)
CTNicholas Jan 30, 2024
69801a5
Implemented PR feedback
matthewlipski Jan 30, 2024
c70ee4d
fix: Mantine styles (#553)
matthewlipski Feb 1, 2024
9f4907e
Fixed paragraph shortcut (#556)
matthewlipski Feb 1, 2024
6ce6e57
v0.11.2
matthewlipski Feb 1, 2024
46c001a
Fixed build issues
matthewlipski Feb 1, 2024
eea1de6
Merge branch 'main' into mentions-suggestions-refactor
matthewlipski Feb 1, 2024
c6de323
Fixed add block button behaviour
matthewlipski Feb 1, 2024
51f1b19
Small fix
matthewlipski Feb 1, 2024
8a5d6f7
Small fix
matthewlipski Feb 1, 2024
97a8f28
Fixed tests
matthewlipski Feb 1, 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
62 changes: 26 additions & 36 deletions examples/editor/examples/basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ import {
uploadToTmpFilesDotOrg_DEV_ONLY,
} from "@blocknote/core";
import {
BlockNoteDefaultUI,
BlockNoteView,
createReactInlineContentSpec,
DefaultSlashMenu,
FormattingToolbarPositioner,
HyperlinkToolbarPositioner,
ImageToolbarPositioner,
SideMenuPositioner,
SlashMenuPositioner,
SuggestionMenuPositioner,
TableHandlesPositioner,
DefaultPositionedSuggestionMenu,
SuggestionMenuItemProps,
useBlockNote,
} from "@blocknote/react";
import "@blocknote/react/style.css";
Expand Down Expand Up @@ -53,17 +48,23 @@ const customInlineContentSchema = {
mention: MentionInlineContent.config,
} satisfies InlineContentSchema;

async function getMentionMenuItems(query: string) {
async function getMentionMenuItems(
editor: BlockNoteEditor<
DefaultBlockSchema,
typeof customInlineContentSchema,
DefaultStyleSchema
>,
query: string,
closeMenu: () => void,
clearQuery: () => void
): Promise<SuggestionMenuItemProps[]> {
const users = ["Steve", "Bob", "Joe", "Mike"];
const items = users.map((user) => ({
const items: SuggestionMenuItemProps[] = users.map((user) => ({
name: user,
execute: (
editor: BlockNoteEditor<
DefaultBlockSchema,
typeof customInlineContentSchema,
DefaultStyleSchema
>
) => {
execute: () => {
closeMenu();
clearQuery();

editor._tiptapEditor.commands.insertContent({
type: "mention",
attrs: {
Expand Down Expand Up @@ -94,32 +95,21 @@ export function App() {
},
},
uploadFile: uploadToTmpFilesDotOrg_DEV_ONLY,
extraSuggestionMenus: [
{
name: "mentions",
triggerCharacter: "@",
getItems: getMentionMenuItems,
},
],
});

// Give tests a way to get prosemirror instance
(window as WindowWithProseMirror).ProseMirror = editor?._tiptapEditor;

// TODO: Figure out cleaner API for adding/changing/removing menus & toolbars
return (
<BlockNoteView className="root" editor={editor}>
<FormattingToolbarPositioner editor={editor} />
<HyperlinkToolbarPositioner editor={editor} />
<SlashMenuPositioner editor={editor} />
<SideMenuPositioner editor={editor} />
<ImageToolbarPositioner editor={editor} />
{editor.blockSchema.table && (
<TableHandlesPositioner editor={editor as any} />
)}
<SuggestionMenuPositioner
editor={editor as any}
suggestionsMenuName={"mentions"}
suggestionsMenuComponent={DefaultSlashMenu}
<BlockNoteDefaultUI editor={editor} />
<DefaultPositionedSuggestionMenu
editor={editor}
triggerCharacter={"@"}
getItems={(query, closeMenu, clearQuery) =>
getMentionMenuItems(editor, query, closeMenu, clearQuery)
}
/>
</BlockNoteView>
);
Expand Down
8 changes: 4 additions & 4 deletions examples/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@blocknote/example-editor",
"private": true,
"version": "0.11.0",
"version": "0.11.2",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
Expand All @@ -10,9 +10,9 @@
"clean": "rimraf dist"
},
"dependencies": {
"@blocknote/core": "^0.11.0",
"@blocknote/react": "^0.11.0",
"@mantine/core": "^7.3.1",
"@blocknote/core": "^0.11.2",
"@blocknote/react": "^0.11.2",
"@mantine/core": "^7.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.20.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/editor/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
createBrowserRouter,
} from "react-router-dom";

import "./style.css";
import { App } from "../examples/basic/App";
import { ReactCustomBlocks } from "../examples/react-custom-blocks/App";
import { ReactInlineContent } from "../examples/react-custom-inline-content/App";
import { ReactStyles } from "../examples/react-custom-styles/App";
import { CustomBlocks } from "../examples/vanilla-custom-blocks/App";
import { InlineContent } from "../examples/vanilla-custom-inline-content/App";
import "./style.css";

window.React = React;

Expand Down
4 changes: 1 addition & 3 deletions examples/editor/src/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
body {
height: auto;
}
@import url("@mantine/core/styles.css");

.editor {
margin: 8px calc((100% - 731px) / 2) 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/vanilla/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@blocknote/example-vanilla",
"private": true,
"version": "0.11.0",
"version": "0.11.2",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint src --max-warnings 0"
},
"dependencies": {
"@blocknote/core": "^0.11.0"
"@blocknote/core": "^0.11.2"
},
"devDependencies": {
"eslint": "^8.10.0",
Expand Down
108 changes: 76 additions & 32 deletions examples/vanilla/src/ui/addSlashMenu.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import {
BlockNoteEditor,
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema,
SuggestionItem,
} from "@blocknote/core";
import { BlockNoteEditor } from "@blocknote/core";
import { createButton } from "./util";

export const addSlashMenu = async (editor: BlockNoteEditor) => {
let element: HTMLElement;

async function updateItems(
query: string,
getItems: (
query: string
) => Promise<
SuggestionItem<
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema
>[]
>,
onClick: (
item: SuggestionItem<
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema
>
) => void
getItems: (query: string) => Promise<any[]>
) {
element.innerHTML = "";
const items = await getItems(query);
const domItems = items.map((val, i) => {
const element = createButton(val.name, () => {
onClick(val);
const domItems = items.map((val) => {
const element = createButton(val.text, () => {
val.executeItem();
});
element.style.display = "block";
return element;
Expand All @@ -42,7 +21,7 @@ export const addSlashMenu = async (editor: BlockNoteEditor) => {
return domItems;
}

editor.suggestionMenus.slashMenu.onUpdate(async (slashMenuState) => {
editor.suggestionMenus.onUpdate("slashMenu", async (slashMenuState) => {
if (!element) {
element = document.createElement("div");
element.style.background = "gray";
Expand All @@ -55,11 +34,76 @@ export const addSlashMenu = async (editor: BlockNoteEditor) => {
}

if (slashMenuState.show) {
await updateItems(
slashMenuState.query,
editor.suggestionMenus.slashMenu.getItems,
editor.suggestionMenus.slashMenu.executeItem
);
// TODO: Default vanilla getItems data type?
const getItems = async (query: string) => {
const items = [
{
text: "Heading",
aliases: ["h", "heading1", "h1"],
executeItem: () => {
editor.suggestionMenus.closeMenu();
editor.suggestionMenus.clearQuery();

editor.insertBlocks(
[
{
type: "heading",
},
],
editor.getTextCursorPosition().block,
"after"
);
},
},
{
text: "List",
aliases: ["ul", "li", "list", "bulletlist", "bullet list"],
executeItem: () => {
editor.suggestionMenus.closeMenu();
editor.suggestionMenus.clearQuery();

editor.insertBlocks(
[
{
type: "bulletListItem",
},
],
editor.getTextCursorPosition().block,
"after"
);
},
},
{
text: "Paragraph",
aliases: ["p", "paragraph"],
executeItem: () => {
editor.suggestionMenus.closeMenu();
editor.suggestionMenus.clearQuery();

editor.insertBlocks(
[
{
type: "paragraph",
},
],
editor.getTextCursorPosition().block,
"after"
);
},
},
];

return items.filter(
({ text, aliases }) =>
text.toLowerCase().startsWith(query.toLowerCase()) ||
(aliases &&
aliases.filter((alias) =>
alias.toLowerCase().startsWith(query.toLowerCase())
).length !== 0)
);
};

await updateItems(slashMenuState.query, getItems);

element.style.display = "block";

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": false,
"useWorkspaces": true,
"version": "0.11.0"
"version": "0.11.2"
}
Loading