Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions examples/editor/examples/basic/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
BlockNoteView,
createReactInlineContentSpec,
DefaultPositionedSuggestionMenu,
SuggestionMenuItemProps,
MantineSuggestionMenuItemProps,
useBlockNote,
} from "@blocknote/react";
import "@blocknote/react/style.css";
Expand Down Expand Up @@ -57,9 +57,9 @@ async function getMentionMenuItems(
query: string,
closeMenu: () => void,
clearQuery: () => void
): Promise<SuggestionMenuItemProps[]> {
): Promise<MantineSuggestionMenuItemProps[]> {
const users = ["Steve", "Bob", "Joe", "Mike"];
const items: SuggestionMenuItemProps[] = users.map((user) => ({
const items: MantineSuggestionMenuItemProps[] = users.map((user) => ({
name: user,
execute: () => {
closeMenu();
Expand Down
4 changes: 2 additions & 2 deletions examples/editor/examples/react-custom-styles/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {
BlockNoteView,
createReactStyleSpec,
FormattingToolbarPositioner,
DefaultPositionedFormattingToolbar,
Toolbar,
ToolbarButton,
useActiveStyles,
Expand Down Expand Up @@ -130,7 +130,7 @@ export function ReactStyles() {

return (
<BlockNoteView className="root" editor={editor}>
<FormattingToolbarPositioner
<DefaultPositionedFormattingToolbar
editor={editor}
formattingToolbar={CustomFormattingToolbar}
/>
Expand Down
4 changes: 2 additions & 2 deletions examples/editor/examples/vanilla-custom-styles/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@blocknote/core";
import {
BlockNoteView,
FormattingToolbarPositioner,
DefaultPositionedFormattingToolbar,
Toolbar,
ToolbarButton,
useActiveStyles,
Expand Down Expand Up @@ -137,7 +137,7 @@ export function Styles() {

return (
<BlockNoteView className="root" editor={editor}>
<FormattingToolbarPositioner
<DefaultPositionedFormattingToolbar
editor={editor}
formattingToolbar={CustomFormattingToolbar}
/>
Expand Down
45 changes: 19 additions & 26 deletions examples/vanilla/src/ui/addFormattingToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,33 @@ import { BlockNoteEditor } from "@blocknote/core";
import { createButton } from "./util";

export const addFormattingToolbar = (editor: BlockNoteEditor) => {
let element: HTMLElement;
let boldBtn: HTMLAnchorElement;
const element = document.createElement("div");
element.style.background = "gray";
element.style.display = "none";
element.style.opacity = "0.8";
element.style.padding = "10px";
element.style.position = "absolute";

editor.formattingToolbar.onUpdate((formattingToolbarState) => {
if (!element) {
element = document.createElement("div");
element.style.background = "gray";
element.style.position = "absolute";
element.style.padding = "10px";
element.style.opacity = "0.8";
boldBtn = createButton("set bold", () => {
editor.toggleStyles({ bold: true });
});
element.appendChild(boldBtn);

const linkBtn = createButton("set link", () => {
editor.createLink("https://www.google.com");
});
const boldBtn = createButton("set bold", () => {
editor.toggleStyles({ bold: true });
});
element.appendChild(boldBtn);

element.appendChild(boldBtn);
element.appendChild(linkBtn);
element.style.display = "none";
const linkBtn = createButton("set link", () => {
editor.createLink("https://www.google.com");
});
element.appendChild(linkBtn);

document.getElementById("root")!.appendChild(element);
}
document.getElementById("root")!.appendChild(element);

if (formattingToolbarState.show) {
editor.formattingToolbar.onUpdate((state) => {
if (state.show) {
element.style.display = "block";

boldBtn.text =
"bold" in editor.getActiveStyles() ? "unset bold" : "set bold";
element.style.top = formattingToolbarState.referencePos.top + "px";
element.style.left =
formattingToolbarState.referencePos.x - element.offsetWidth + "px";
element.style.top = state.referencePos.top + "px";
element.style.left = state.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
Expand Down
57 changes: 26 additions & 31 deletions examples/vanilla/src/ui/addHyperlinkToolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,38 @@ import { BlockNoteEditor } from "@blocknote/core";
import { createButton } from "./util";

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

editor.hyperlinkToolbar.onUpdate((hyperlinkToolbarState) => {
if (!element) {
element = document.createElement("div");
element.style.background = "gray";
element.style.position = "absolute";
element.style.padding = "10px";
element.style.opacity = "0.8";

const url = hyperlinkToolbarState.url;
const text = hyperlinkToolbarState.text;

const editBtn = createButton("edit", () => {
const newUrl = prompt("new url") || url;
editor.hyperlinkToolbar.editHyperlink(newUrl, text);
});

element.appendChild(editBtn);
let text = "";
let url = "";

const element = document.createElement("div");
element.style.background = "gray";
element.style.display = "none";
element.style.opacity = "0.8";
element.style.padding = "10px";
element.style.position = "absolute";

const editBtn = createButton("edit", () => {
url = prompt("new url") || url;
editor.hyperlinkToolbar.editHyperlink(url, text);
});
element.appendChild(editBtn);

const removeBtn = createButton("remove", () => {
editor.hyperlinkToolbar.deleteHyperlink();
});
const removeBtn = createButton("remove", () => {
editor.hyperlinkToolbar.deleteHyperlink();
});
element.appendChild(removeBtn);

element.appendChild(editBtn);
element.appendChild(removeBtn);
element.style.display = "none";
document.getElementById("root")!.appendChild(element);

document.getElementById("root")!.appendChild(element);
}
editor.hyperlinkToolbar.onUpdate((state) => {
if (state.show) {
url = state.url;
text = state.text;

if (hyperlinkToolbarState.show) {
element.style.display = "block";

element.style.top = hyperlinkToolbarState.referencePos.top + "px";
element.style.left =
hyperlinkToolbarState.referencePos.x - element.offsetWidth + "px";
element.style.top = state.referencePos.top + "px";
element.style.left = state.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
Expand Down
49 changes: 22 additions & 27 deletions examples/vanilla/src/ui/addSideMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@ import { BlockNoteEditor } from "@blocknote/core";
import { createButton } from "./util";

export const addSideMenu = (editor: BlockNoteEditor) => {
let element: HTMLElement;
const element = document.createElement("div");
element.style.background = "gray";
element.style.display = "none";
element.style.opacity = "0.8";
element.style.padding = "10px";
element.style.position = "absolute";

editor.sideMenu.onUpdate((sideMenuState) => {
if (!element) {
element = document.createElement("div");
element.style.background = "gray";
element.style.position = "absolute";
element.style.padding = "10px";
element.style.opacity = "0.8";
const addBtn = createButton("+", () => {
editor.sideMenu.addBlock();
});
element.appendChild(addBtn);

const dragBtn = createButton("::", () => {
// TODO: render a submenu with a delete option that calls "props.deleteBlock"
});
const addBtn = createButton("+", () => {
editor.sideMenu.addBlock();
});
element.appendChild(addBtn);

dragBtn.addEventListener("dragstart", editor.sideMenu.blockDragStart);
dragBtn.addEventListener("dragend", editor.sideMenu.blockDragEnd);
dragBtn.draggable = true;
element.style.display = "none";
element.appendChild(dragBtn);
const dragBtn = createButton("::", () => {
// TODO: render a submenu with a delete option that calls "props.deleteBlock"
});
dragBtn.addEventListener("dragstart", editor.sideMenu.blockDragStart);
dragBtn.addEventListener("dragend", editor.sideMenu.blockDragEnd);
dragBtn.draggable = true;
element.appendChild(dragBtn);

document.getElementById("root")!.appendChild(element);
}
document.getElementById("root")!.appendChild(element);

if (sideMenuState.show) {
editor.sideMenu.onUpdate((state) => {
if (state.show) {
element.style.display = "block";

element.style.top = sideMenuState.referencePos.top + "px";
element.style.left =
sideMenuState.referencePos.x - element.offsetWidth + "px";
element.style.top = state.referencePos.top + "px";
element.style.left = state.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
Expand Down
Loading