Skip to content

Separate React package #74

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

Merged
merged 65 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c91cdd9
upgrade to react 18
YousefED Nov 22, 2022
fe61e49
Merge branch 'main' into react-18
matthewlipski Dec 7, 2022
4358f15
Merge branch 'main' into react-18
matthewlipski Dec 7, 2022
329ca8b
Merge remote-tracking branch 'origin/react-18' into react-18
matthewlipski Dec 7, 2022
47665f8
Merge remote-tracking branch 'origin/react-18' into react-18
matthewlipski Dec 7, 2022
808897e
Merge remote-tracking branch 'origin/react-18' into react-18
matthewlipski Dec 7, 2022
e687338
Maybe fixed React error in build
matthewlipski Dec 8, 2022
a25032a
Added early implementation of bubble menu & editor in separate react …
matthewlipski Dec 13, 2022
81867ee
Moved all hyperlink menus to react package
matthewlipski Dec 13, 2022
3a87e4b
Major structural overhaul to menu factories
matthewlipski Dec 14, 2022
1a2fd17
Added suggestions menu factory with new (hopefully final) factory str…
matthewlipski Dec 17, 2022
b4c5dcc
Refactored bubble menu code to use improved factory structure
matthewlipski Dec 19, 2022
176e88b
Changes to bubble menu code and documentation
matthewlipski Dec 19, 2022
d5d6515
Changes to bubble menu code and documentation
matthewlipski Dec 19, 2022
bac3b6a
General improvements, mostly to bubble and hyperlink menus
matthewlipski Dec 20, 2022
1a94d1c
Merge remote-tracking branch 'origin/react-separation' into react-sep…
matthewlipski Dec 20, 2022
267a238
comments after call
YousefED Dec 21, 2022
e22446b
Split bubble menu props into init & update props
matthewlipski Dec 21, 2022
55b1149
clean up packaging
YousefED Dec 21, 2022
1bc1a76
fix react error
YousefED Dec 21, 2022
b3b2266
Changed bubble menu plugin view back to use a separate class
matthewlipski Dec 21, 2022
f6f7836
Split hyperlink menu props into init & update props
matthewlipski Dec 21, 2022
0294da0
Changed hyperlink menu plugin view to use a separate class
matthewlipski Dec 21, 2022
e827f49
fix gitignore
YousefED Dec 21, 2022
b51092d
fix tsconfig
YousefED Dec 22, 2022
fea3a0f
Major cleanup for bubble menu factory code
matthewlipski Dec 22, 2022
ebc7d8a
Major cleanup for hyperlink menu factory code
matthewlipski Dec 22, 2022
ca42838
Merge branch 'react-separation-packages' into react-separation
matthewlipski Dec 22, 2022
95b1d6e
Minor fixes
matthewlipski Dec 22, 2022
86d34b3
Converted suggestion plugin view to use a class
matthewlipski Jan 4, 2023
09ebc39
Changed editor example to use React as before
matthewlipski Jan 5, 2023
6db79ff
Improved file structure and minor tweaks
matthewlipski Jan 5, 2023
a3617c3
Minor refactor
matthewlipski Jan 9, 2023
03154f7
Fixed hyperlink menu behaviour
matthewlipski Jan 9, 2023
7e2ef52
Separated drag handle UI elements to react package
matthewlipski Jan 10, 2023
baea3e2
Separated drag handle UI elements to react package
matthewlipski Jan 10, 2023
af5dabd
Merge remote-tracking branch 'origin/react-separation' into react-sep…
matthewlipski Jan 10, 2023
4853a5c
Minor improvements
matthewlipski Jan 10, 2023
496c020
fix lint
YousefED Jan 11, 2023
3f88072
refactor entrypoints (#77)
YousefED Jan 11, 2023
f6a6364
Fixed hyperlink edit menu bugs
matthewlipski Jan 11, 2023
82be286
re-add font
YousefED Jan 11, 2023
34686c5
Merge branch 'react-separation' of github.com:YousefED/BlockNote into…
YousefED Jan 11, 2023
9446637
Removed bubble menu animation update delay hack
matthewlipski Jan 11, 2023
d2f2f36
Merge remote-tracking branch 'origin/react-separation' into react-sep…
matthewlipski Jan 11, 2023
07c38f1
Changed bubble menu placement to be at the start of the selection bou…
matthewlipski Jan 11, 2023
89897f3
Fixed hyperlink menu naming inconsistencies
matthewlipski Jan 11, 2023
038f22b
Refactored block/drag menu to use one factory and separate view class
matthewlipski Jan 12, 2023
8b20dee
Fixed bubble menu sometimes attempting to hide when already hidden
matthewlipski Jan 12, 2023
9c3cdc8
Fixed drag preview styling
matthewlipski Jan 12, 2023
421d0b6
Fixed tooltip styling
matthewlipski Jan 12, 2023
1824718
Removed unnecessary updates from block menu
matthewlipski Jan 12, 2023
3665146
Vanilla example (#78)
YousefED Jan 13, 2023
c5e8479
Updated naming for bubble, block, and hyperlink menus
matthewlipski Jan 13, 2023
1be11e5
Fixed drag handle tests
matthewlipski Jan 13, 2023
a7a8c61
Fixed drag and drop tests
matthewlipski Jan 13, 2023
e931b3d
Improved how UI element factories are passed to extensions
matthewlipski Jan 13, 2023
4ce7ed9
Updated suggestions/slash menu naming
matthewlipski Jan 13, 2023
5a29c71
Updated slash menu selector for tests
matthewlipski Jan 13, 2023
275341a
Split factory params into static and dynamic
matthewlipski Jan 16, 2023
f6cd54e
Minor fix to `BNSetContentType()`
matthewlipski Jan 16, 2023
378b7d7
Improved getting & setting block type in formatting toolbar factory API
matthewlipski Jan 17, 2023
ff61295
Minor typing fix
matthewlipski Jan 17, 2023
bdde1e6
Combined factory `update()` and `show()` functions into single `rende…
matthewlipski Jan 18, 2023
7211217
rename props -> staticParams in vanilla example
YousefED Jan 18, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# dependencies
node_modules
dist
types
packages/*/types
examples/*/types
/.pnp
.pnp.js

Expand Down
9 changes: 5 additions & 4 deletions examples/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
},
"dependencies": {
"@blocknote/core": "^0.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"@blocknote/react": "^0.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.12",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@vitejs/plugin-react": "^1.0.7",
"eslint": "^8.10.0",
"eslint-config-react-app": "^7.0.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/editor/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import logo from './logo.svg'
import { EditorContent, useEditor } from "@blocknote/core";
import "@blocknote/core/style.css";
import { BlockNoteView, useBlockNote } from "@blocknote/react";
import { Editor } from "@tiptap/core";
import styles from "./App.module.css";

type WindowWithProseMirror = Window &
typeof globalThis & { ProseMirror: Editor };

function App() {
const editor = useEditor({
const editor = useBlockNote({
onUpdate: ({ editor }) => {
console.log(editor.getJSON());
(window as WindowWithProseMirror).ProseMirror = editor; // Give tests a way to get editor instance
Expand All @@ -21,7 +21,7 @@ function App() {
},
});

return <EditorContent editor={editor} />;
return <BlockNoteView editor={editor} />;
}

export default App;
9 changes: 4 additions & 5 deletions examples/editor/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from "react";
import ReactDOM from "react-dom";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./index.css";

window.React = React;
window.ReactDOM = ReactDOM;

ReactDOM.render(
const root = createRoot(document.getElementById("root")!);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
</React.StrictMode>
);
9 changes: 8 additions & 1 deletion examples/editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ export default defineConfig((conf) => ({
optimizeDeps: {
// link: ['vite-react-ts-components'],
},
build: {
sourcemap: true,
},
resolve: {
alias:
conf.command === "build"
? {}
: {
// Comment out the line below to load a built version of blocknote
// Comment out the lines below to load a built version of blocknote
// or, keep as is to load live from sources with live reload working
"@blocknote/core": path.resolve(
__dirname,
"../../packages/core/src/"
),
"@blocknote/react": path.resolve(
__dirname,
"../../packages/react/src/"
),
},
},
}));
24 changes: 24 additions & 0 deletions examples/vanilla/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions examples/vanilla/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Vanilla editor example

This is an example client application that consumes @blocknote/core.
13 changes: 13 additions & 0 deletions examples/vanilla/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BlockNote demo vanilla js</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions examples/vanilla/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@blocknote/example-vanilla",
"private": true,
"version": "0.1.2",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint src --max-warnings 0"
},
"dependencies": {
"@blocknote/core": "^0.1.2"
},
"devDependencies": {
"eslint": "^8.10.0",
"eslint-config-react-app": "^7.0.0",
"typescript": "^4.5.4",
"vite": "^3.0.5",
"vite-plugin-eslint": "^1.7.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
],
"rules": {
"curly": 1
}
}
}
10 changes: 10 additions & 0 deletions examples/vanilla/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
html,
body,
#root {
height: 100%;
}

.editor {
padding: 0 calc((100% - 731px) / 2);
height: 100%;
}
31 changes: 31 additions & 0 deletions examples/vanilla/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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";

const editor = new BlockNoteEditor({
element: 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,
},
onUpdate: ({ editor }) => {
console.log(editor.getJSON());
(window as any).ProseMirror = editor; // Give tests a way to get editor instance
},
editorProps: {
attributes: {
class: "editor",
},
},
});

console.log("editor created", editor);
46 changes: 46 additions & 0 deletions examples/vanilla/src/ui/blockSideMenuFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { BlockSideMenuFactory } from "@blocknote/core";
import { createButton } from "./util";

/**
* This menu is drawn next to a block, when it's hovered over
* It renders a drag handle and + button to create a new block
*/
export const blockSideMenuFactory: BlockSideMenuFactory = (staticParams) => {
const container = document.createElement("div");
container.style.background = "gray";
container.style.position = "absolute";
container.style.padding = "10px";
container.style.opacity = "0.8";
const addBtn = createButton("+", () => {
staticParams.addBlock();
});
container.appendChild(addBtn);

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

dragBtn.addEventListener("dragstart", staticParams.blockDragStart);
dragBtn.addEventListener("dragend", staticParams.blockDragEnd);
container.style.display = "none";
container.appendChild(dragBtn);

document.body.appendChild(container);

return {
element: container,
render: (params, isHidden) => {
if (isHidden) {
container.style.display = "block";
}

console.log("show blockmenu", params);
container.style.top = params.blockBoundingBox.y + "px";
container.style.left =
params.blockBoundingBox.x - container.offsetWidth + "px";
},
hide: () => {
container.style.display = "none";
},
};
};
45 changes: 45 additions & 0 deletions examples/vanilla/src/ui/formattingToolbarFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { FormattingToolbarFactory } from "@blocknote/core";
import { createButton } from "./util";

/**
* This menu is drawn when a piece of text is selected. We can use it to change formatting options
* such as bold, italic, indentation, etc.
*/
export const formattingToolbarFactory: FormattingToolbarFactory = (
staticParams
) => {
const container = document.createElement("div");
container.style.background = "gray";
container.style.position = "absolute";
container.style.padding = "10px";
container.style.opacity = "0.8";
const boldBtn = createButton("set bold", () => {
staticParams.toggleBold();
});
container.appendChild(boldBtn);

const linkBtn = createButton("set link", () => {
staticParams.setHyperlink("https://www.google.com");
});

container.appendChild(boldBtn);
container.appendChild(linkBtn);
container.style.display = "none";
document.body.appendChild(container);

return {
element: container,
render: (params, isHidden) => {
if (isHidden) {
container.style.display = "block";
}

boldBtn.text = params.boldIsActive ? "unset bold" : "set bold";
container.style.top = params.selectionBoundingBox.y + "px";
container.style.left = params.selectionBoundingBox.x + "px";
},
hide: () => {
container.style.display = "none";
},
};
};
54 changes: 54 additions & 0 deletions examples/vanilla/src/ui/hyperlinkToolbarFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { HyperlinkToolbarFactory } from "@blocknote/core";
import { createButton } from "./util";

/**
* This menu is drawn when the cursor is moved to a hyperlink (using the keyboard),
* or when the mouse is hovering over a hyperlink
*/
export const hyperlinkToolbarFactory: HyperlinkToolbarFactory = (
staticParams
) => {
const container = document.createElement("div");
container.style.background = "gray";
container.style.position = "absolute";
container.style.padding = "10px";
container.style.opacity = "0.8";

let url = "";
let text = "";

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

container.appendChild(editBtn);

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

container.appendChild(editBtn);
container.appendChild(removeBtn);
container.style.display = "none";
document.body.appendChild(container);

return {
element: container,
render: (params, isHidden) => {
if (isHidden) {
url = params.url;
text = params.text;

container.style.display = "block";
}

console.log("show", params);
container.style.top = params.boundingBox.y + "px";
container.style.left = params.boundingBox.x + "px";
},
hide: () => {
container.style.display = "none";
},
};
};
Loading