Skip to content

Commit 2c8eea3

Browse files
feat: Custom Blocks (#191)
* simplify formattingtoolbar * Fixed React component types and added customizable formatting toolbar factory * Finished formatting toolbar customization with old props * Changed formatting toolbar props to use BlockNoteEditor * Fixed text alignment with basic selection object * Fixed block nesting tests * Removed multiple block shorthand for updateBlock * Added comments * Added basic mouse cursor position * Added drag handle menu customization API * Copied changes from PR and minor improvements * Table block test * wip: custom blocks typing and API * add comments * fix nodeConversions, add schema * comments * Implemented renderHTML and parseHTML for createCustomBlock * Temp changes * Mostly implemented stricter typing for custom blocks * Cleanup & fixed build issues * Fixed useBlockNote and improved some typing * Implemented PR feedback * Minor changes * Made custom blocks use node views * Created custom example and setup component testing * Changed custom block `renderHTML` implementation * Changed custom block `renderHTML` implementation * Changed custom block testing setup and added custom block examples * Slightly changed `blockConfig.render` type * Fixed merge issues * custom blocks react poc * Added internal custom block copy/paste tests * Small fix * Added external custom block copy/paste tests * Added expected serialized HTML for example custom blocks * Updated playwright scripts * Updated component tests and added serializer extension * Updated React custom block API * Reverted `App.tsx` * Fixed `test:updateSnaps` script * Added external copypaste snapshots * Fixed failing tests * Copy/paste tests are now skipped for WebKit * Removed old `console.log`s * Small change to `test-ct` script * Removed image block from `defaultBlocks.ts` * Updated component tests & snapshots * General cleanup * Updated firefox colors snapshot * remove unnecessary generics for slash menu items * fix types * hack around TextAlignButton types * Custom blocks example typing improvements (#202) * improve typings * add tests for types --------- Co-authored-by: Matthew Lipski <[email protected]> * Implemented most PR feedback * Implemented most PR feedback * Minor fixes to custom blocks * Custom blocks docs (#217) * Fixed custom block placeholders, formatting toolbar, and sizing * Small styling changes * Made text align button not show up when selected block/s doesn't/don't support the prop * Updated docs * Finished 1st draft custom block docs and demo * Added type arguments in custom block docs & minor changes * Implemented PR feedback * Updated unit tests * simplify docs * package lock update * add comment * retreat, fallback slash command to "any" * update packages incl prosemirror-view (#223) * update packages incl prosemirror-view * fix build * fix ReactAlert + add logs --------- Co-authored-by: yousefed <[email protected]>
1 parent 72103bd commit 2c8eea3

File tree

132 files changed

+9077
-1871
lines changed

Some content is hidden

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

132 files changed

+9077
-1871
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ yarn-error.log*
2929
.vercel
3030
test-results/
3131
playwright-report/
32-
release
32+
release
33+
/test-results/
34+
/playwright-report/
35+
/playwright/.cache/

examples/editor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@vitejs/plugin-react": "^3.1.0",
2121
"eslint": "^8.10.0",
2222
"eslint-config-react-app": "^7.0.0",
23-
"typescript": "^4.5.4",
23+
"typescript": "^5.0.4",
2424
"vite": "^4.1.2",
2525
"vite-plugin-eslint": "^1.8.1"
2626
},

examples/vanilla/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"devDependencies": {
1515
"eslint": "^8.10.0",
1616
"eslint-config-react-app": "^7.0.0",
17-
"typescript": "^4.5.4",
17+
"typescript": "^5.0.4",
1818
"vite": "^4.1.2",
1919
"vite-plugin-eslint": "^1.8.1"
2020
},

examples/vanilla/src/ui/blockSideMenuFactory.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { BlockSideMenuFactory } from "@blocknote/core";
1+
import { BlockSideMenuFactory, DefaultBlockSchema } from "@blocknote/core";
22
import { createButton } from "./util";
33

44
/**
55
* This menu is drawn next to a block, when it's hovered over
66
* It renders a drag handle and + button to create a new block
77
*/
8-
export const blockSideMenuFactory: BlockSideMenuFactory = (staticParams) => {
8+
export const blockSideMenuFactory: BlockSideMenuFactory<DefaultBlockSchema> = (
9+
staticParams
10+
) => {
911
const container = document.createElement("div");
1012
container.style.background = "gray";
1113
container.style.position = "absolute";

examples/vanilla/src/ui/formattingToolbarFactory.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { FormattingToolbarFactory } from "@blocknote/core";
1+
import { DefaultBlockSchema, FormattingToolbarFactory } from "@blocknote/core";
22
import { createButton } from "./util";
33

44
/**
55
* This menu is drawn when a piece of text is selected. We can use it to change formatting options
66
* such as bold, italic, indentation, etc.
77
*/
8-
export const formattingToolbarFactory: FormattingToolbarFactory = (
9-
staticParams
10-
) => {
8+
export const formattingToolbarFactory: FormattingToolbarFactory<
9+
DefaultBlockSchema
10+
> = (staticParams) => {
1111
const container = document.createElement("div");
1212
container.style.background = "gray";
1313
container.style.position = "absolute";
@@ -35,7 +35,9 @@ export const formattingToolbarFactory: FormattingToolbarFactory = (
3535
}
3636

3737
boldBtn.text =
38-
"bold" in staticParams.editor.getActiveStyles() ? "unset bold" : "set bold";
38+
"bold" in staticParams.editor.getActiveStyles()
39+
? "unset bold"
40+
: "set bold";
3941
container.style.top = params.referenceRect.y + "px";
4042
container.style.left = params.referenceRect.x + "px";
4143
},

examples/vanilla/src/ui/slashMenuFactory.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { BaseSlashMenuItem, SuggestionsMenuFactory } from "@blocknote/core";
1+
import {
2+
BaseSlashMenuItem,
3+
DefaultBlockSchema,
4+
SuggestionsMenuFactory,
5+
} from "@blocknote/core";
26
import { createButton } from "./util";
37

48
/**
59
* This menu is drawn when the cursor is moved to a hyperlink (using the keyboard),
610
* or when the mouse is hovering over a hyperlink
711
*/
8-
export const slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem> = (
9-
staticParams
10-
) => {
12+
export const slashMenuFactory: SuggestionsMenuFactory<
13+
BaseSlashMenuItem<DefaultBlockSchema>
14+
> = (staticParams) => {
1115
const container = document.createElement("div");
1216
container.style.background = "gray";
1317
container.style.position = "absolute";
@@ -17,8 +21,8 @@ export const slashMenuFactory: SuggestionsMenuFactory<BaseSlashMenuItem> = (
1721
document.body.appendChild(container);
1822

1923
function updateItems(
20-
items: BaseSlashMenuItem[],
21-
onClick: (item: BaseSlashMenuItem) => void,
24+
items: BaseSlashMenuItem<DefaultBlockSchema>[],
25+
onClick: (item: BaseSlashMenuItem<DefaultBlockSchema>) => void,
2226
selected: number
2327
) {
2428
container.innerHTML = "";

0 commit comments

Comments
 (0)