Skip to content

Commit 022a617

Browse files
BlockNote Api (#97)
* update v * wip poc * poc * api poc * Implemented basic block retrieval API functions * tiny fixes * Added marks API support, block conversion/insertion functions, and WIP markdown conversion * Changed markdown parsing to use remark * Added API support for serializing blocks to HTML and Markdown * General cleanup & refactor * vite 4 * add vitest * fix build * Implemented PR feedback * Added documentation to API functions * Added basic HTML/Markdown conversion test cases and fixed some bugs * Added more HTML/Markdown conversion test cases * Fixed comments * Added HTML/Markdown conversion test snapshots * Small changes * Added API functions to update and remove blocks, improved distinction between `Block` and `BlockSpec` types * Added remaining unit tests * temp expose api * Changed `BlockSpec` to `PartialBlock` and improved error messages * add draggable to vanillajs example * Added `replaceBlock` function, updated others. * Added global props * Fixed node conversion tests & snapshots * Fixed format conversion tests & snapshots * Fixed block manipulation tests & snapshots * Commented out failing format conversion tests * Fixed build failures * Fixed list item parsing issue * Changed API file structure * Moved type import to dev dependencies * make api accessible via editor, hide tiptap initialization options (#106) * make api accessible via editor, hide tiptap initialization options * remove comment * Fixed tests * Fixed tests * small renames + expose domElement * improve block types * Small fix to PartialBlock type * Removed logs * add comments about waitForEditor --------- Co-authored-by: Matthew Lipski <[email protected]> * add comment * clean up timeout * small cleanup * rename to InlineContent --------- Co-authored-by: Matthew Lipski <[email protected]>
1 parent 33e7a96 commit 022a617

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6880
-427
lines changed

examples/editor/src/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ type WindowWithProseMirror = Window & typeof globalThis & { ProseMirror: any };
77

88
function App() {
99
const editor = useBlockNote({
10-
onUpdate: ({ editor }) => {
11-
console.log(editor.getJSON());
12-
(window as WindowWithProseMirror).ProseMirror = editor; // Give tests a way to get editor instance
10+
onUpdate: () => {
11+
// console.log(editor.getJSON());
1312
},
14-
editorProps: {
15-
attributes: {
16-
class: styles.editor,
17-
"data-test": "editor",
18-
},
13+
editorDOMAttributes: {
14+
class: styles.editor,
15+
"data-test": "editor",
1916
},
2017
});
2118

19+
// Give tests a way to get prosemirror instance
20+
(window as WindowWithProseMirror).ProseMirror = editor?._tiptapEditor;
21+
2222
return <BlockNoteView editor={editor} />;
2323
}
2424

examples/vanilla/src/main.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { hyperlinkToolbarFactory } from "./ui/hyperlinkToolbarFactory";
66
import { slashMenuFactory } from "./ui/slashMenuFactory";
77

88
const editor = new BlockNoteEditor({
9-
element: document.getElementById("root")!,
9+
parentElement: document.getElementById("root")!,
1010
uiFactories: {
1111
// Create an example formatting toolbar which just consists of a bold toggle
1212
formattingToolbarFactory,
@@ -17,14 +17,11 @@ const editor = new BlockNoteEditor({
1717
// Create an example menu for when a block is hovered
1818
blockSideMenuFactory,
1919
},
20-
onUpdate: ({ editor }) => {
21-
console.log(editor.getJSON());
22-
(window as any).ProseMirror = editor; // Give tests a way to get editor instance
20+
onUpdate: () => {
21+
console.log(editor.allBlocks);
2322
},
24-
editorProps: {
25-
attributes: {
26-
class: "editor",
27-
},
23+
editorDOMAttributes: {
24+
class: "editor",
2825
},
2926
});
3027

examples/vanilla/src/ui/blockSideMenuFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const blockSideMenuFactory: BlockSideMenuFactory = (staticParams) => {
2222

2323
dragBtn.addEventListener("dragstart", staticParams.blockDragStart);
2424
dragBtn.addEventListener("dragend", staticParams.blockDragEnd);
25+
dragBtn.draggable = true;
2526
container.style.display = "none";
2627
container.appendChild(dragBtn);
2728

0 commit comments

Comments
 (0)