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: React re-architecture #270

Merged
merged 44 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
33f5213
test react components as children
YousefED Jun 29, 2023
1e3d421
slashmenu
YousefED Jun 30, 2023
44fb0d2
Major refactor
matthewlipski Jul 10, 2023
784bdc0
Exported plugin keys & cleaned up slash menu plugin
matthewlipski Jul 10, 2023
8237395
Removed redundant type
matthewlipski Jul 10, 2023
3accd8c
Commented out old factory & component wrapper
matthewlipski Jul 10, 2023
1c251a3
Removed old files & fixed build
matthewlipski Jul 10, 2023
c7f26e7
Small cleanup
matthewlipski Jul 10, 2023
251fc94
Fixed some bugs in the slash and side menus
matthewlipski Jul 10, 2023
7c2cc05
Made menu & toolbar plugins load with the highest priority instead of…
matthewlipski Jul 10, 2023
fb37efa
Disabled strict mode
matthewlipski Jul 10, 2023
f2ed0f3
Fixed a bug which caused plugin views to be created multiple times
matthewlipski Jul 10, 2023
ca32ce3
several fixes for react rearchitecture (#272)
YousefED Jul 11, 2023
52d26cd
Major cleanup for menus & toolbars
matthewlipski Jul 12, 2023
5547704
Major cleanup for menus & toolbars
matthewlipski Jul 12, 2023
cdd2cfb
Merge remote-tracking branch 'origin/react-rearchitecture' into react…
matthewlipski Jul 12, 2023
c2c9a94
Cleaned up `useBlockNote`, menu & toolbar components
matthewlipski Jul 12, 2023
827e7e4
Changed menu & toolbar APIs to work with the new rendering architecture
matthewlipski Jul 13, 2023
46dca36
Numerous changes:
matthewlipski Jul 25, 2023
1efce16
Fixed menus being initialized early
matthewlipski Jul 25, 2023
8c46892
Merge branch 'main' into react-rearchitecture
matthewlipski Jul 25, 2023
79f617d
Fixed some deps
matthewlipski Jul 25, 2023
a3616c3
Reverted some deps
matthewlipski Jul 25, 2023
7eebdff
Added lint ignore annotations to deps
matthewlipski Jul 26, 2023
c488712
Cleaned up slash menu and suggestion items
matthewlipski Jul 26, 2023
5409f8b
Cleaned up `BlockNoteEditor`
matthewlipski Jul 26, 2023
07a774c
Revert "Cleaned up `BlockNoteEditor`"
matthewlipski Jul 26, 2023
cca7268
Minor changes
matthewlipski Jul 26, 2023
0af18e6
Minor changes & update to formatting toolbar docs
matthewlipski Jul 27, 2023
aaad427
simplify ui elements (#288)
YousefED Jul 31, 2023
6cf90d1
Implemented PR feedback
matthewlipski Jul 31, 2023
bbecf89
Implemented PR feedback
matthewlipski Jul 31, 2023
5e68b91
Implemented PR feedback
matthewlipski Jul 31, 2023
95fdc42
Implemented PR feedback
matthewlipski Jul 31, 2023
e127546
Added docs & small tweaks
matthewlipski Jul 31, 2023
c417714
Renamed remaining slashCommand references to slashMenuItems
matthewlipski Jul 31, 2023
61cddaf
Implemented PR feedback
matthewlipski Jul 31, 2023
0cad478
Fixed lint warning
matthewlipski Jul 31, 2023
be406b7
fix initialcontent and uniqueid (#289)
YousefED Aug 1, 2023
f954d67
Added pre-made components for side menu
matthewlipski Aug 1, 2023
a161632
Added custom side menu docs
matthewlipski Aug 1, 2023
934e515
Updated docs
matthewlipski Aug 1, 2023
3f1ba86
Updated unit tests & snapshots
matthewlipski Aug 1, 2023
c034cd1
Updated `useBlockNote` deps
matthewlipski Aug 1, 2023
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
8 changes: 3 additions & 5 deletions examples/editor/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import "./index.css";
window.React = React;

const root = createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
root.render(<App />);

// root.render(<App />);
23 changes: 9 additions & 14 deletions examples/vanilla/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { BlockNoteEditor } from "@blocknote/core";
import "./index.css";
import { blockSideMenuFactory } from "./ui/blockSideMenuFactory";
import { formattingToolbarFactory } from "./ui/formattingToolbarFactory";
import { hyperlinkToolbarFactory } from "./ui/hyperlinkToolbarFactory";
import { slashMenuFactory } from "./ui/slashMenuFactory";
import { addSideMenu } from "./ui/addSideMenu";
import { addFormattingToolbar } from "./ui/addFormattingToolbar";
import { addSlashMenu } from "./ui/addSlashMenu";
import { addHyperlinkToolbar } from "./ui/addHyperlinkToolbar";

const editor = new BlockNoteEditor({
parentElement: document.getElementById("root")!,
uiFactories: {
// Create an example formatting toolbar which just consists of a bold toggle
formattingToolbarFactory,
// Create an example menu for hyperlinks
hyperlinkToolbarFactory,
// Create an example menu for the /-menu
slashMenuFactory: slashMenuFactory,
// Create an example menu for when a block is hovered
blockSideMenuFactory,
},
onEditorContentChange: () => {
console.log(editor.topLevelBlocks);
},
Expand All @@ -26,3 +16,8 @@ const editor = new BlockNoteEditor({
});

console.log("editor created", editor);

addSideMenu(editor);
addFormattingToolbar(editor);
addSlashMenu(editor);
addHyperlinkToolbar(editor);
43 changes: 43 additions & 0 deletions examples/vanilla/src/ui/addFormattingToolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BlockNoteEditor, createFormattingToolbar } from "@blocknote/core";
import { createButton } from "./util";

export const addFormattingToolbar = (editor: BlockNoteEditor) => {
let element: HTMLElement;
let boldBtn: HTMLAnchorElement;

createFormattingToolbar(editor, (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");
});

element.appendChild(boldBtn);
element.appendChild(linkBtn);
element.style.display = "none";

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

if (formattingToolbarState.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";
} else {
element.style.display = "none";
}
});
};
46 changes: 46 additions & 0 deletions examples/vanilla/src/ui/addHyperlinkToolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { BlockNoteEditor, createHyperlinkToolbar } from "@blocknote/core";
import { createButton } from "./util";

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

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

let url = hyperlinkToolbarState.url;
let text = hyperlinkToolbarState.text;

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

element.appendChild(editBtn);

const removeBtn = createButton("remove", () => {
hyperlinkToolbarState.deleteHyperlink();
});

element.appendChild(editBtn);
element.appendChild(removeBtn);
element.style.display = "none";

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

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

element.style.top = hyperlinkToolbarState.referencePos.top + "px";
element.style.left =
hyperlinkToolbarState.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
});
};
42 changes: 42 additions & 0 deletions examples/vanilla/src/ui/addSideMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BlockNoteEditor, createSideMenu } from "@blocknote/core";
import { createButton } from "./util";

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

createSideMenu(editor, (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("+", () => {
sideMenuState.addBlock();
});
element.appendChild(addBtn);

const dragBtn = createButton("::", () => {
// TODO: render a submenu with a delete option that calls "props.deleteBlock"
});

dragBtn.addEventListener("dragstart", sideMenuState.blockDragStart);
dragBtn.addEventListener("dragend", sideMenuState.blockDragEnd);
dragBtn.draggable = true;
element.style.display = "none";
element.appendChild(dragBtn);

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

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

element.style.top = sideMenuState.referencePos.top + "px";
element.style.left =
sideMenuState.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
});
};
68 changes: 68 additions & 0 deletions examples/vanilla/src/ui/addSlashMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
BaseSlashMenuItem,
BlockNoteEditor,
createSlashMenu,
defaultSlashMenuItems,
DefaultBlockSchema,
} from "@blocknote/core";
import { createButton } from "./util";

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

function updateItems(
items: BaseSlashMenuItem<DefaultBlockSchema>[],
onClick: (item: BaseSlashMenuItem<DefaultBlockSchema>) => void,
selected: number
) {
element.innerHTML = "";
const domItems = items.map((val, i) => {
const element = createButton(val.name, () => {
onClick(val);
});
element.style.display = "block";
if (selected === i) {
element.style.fontWeight = "bold";
}
return element;
});
element.append(...domItems);
return domItems;
}

createSlashMenu<BaseSlashMenuItem<DefaultBlockSchema>>(
editor,
(slashMenuState) => {
if (!element) {
element = document.createElement("div");
element.style.background = "gray";
element.style.position = "absolute";
element.style.padding = "10px";
element.style.opacity = "0.8";
element.style.display = "none";

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

if (slashMenuState.show) {
updateItems(
slashMenuState.items,
slashMenuState.itemCallback,
slashMenuState.keyboardHoveredItemIndex
);

element.style.display = "block";

element.style.top = slashMenuState.referencePos.top + "px";
element.style.left =
slashMenuState.referencePos.x - element.offsetWidth + "px";
} else {
element.style.display = "none";
}
},
(query) =>
defaultSlashMenuItems.filter(
(cmd: BaseSlashMenuItem<DefaultBlockSchema>) => cmd.match(query)
)
);
};
48 changes: 0 additions & 48 deletions examples/vanilla/src/ui/blockSideMenuFactory.ts

This file was deleted.

48 changes: 0 additions & 48 deletions examples/vanilla/src/ui/formattingToolbarFactory.ts

This file was deleted.

Loading