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

Separate React package #74

merged 65 commits into from
Jan 18, 2023

Conversation

matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Dec 13, 2022

This PR separates the React UI components from BlockNote:

  • UI implementation (React + Mantine) is now in the @blocknote/react package
  • Core of BlockNote is in the @blocknote/core package
  • A "vanilla js" example has been added, to demonstrate how you can consume @blocknote/core and create your own UI layer

BlockNote is currently written for React, though the core package should be decoupled from our implementation of the UI so it can be more easily integrated into non-React projects. This PR moves all React-based functionality to a new react package, namely the custom useEditor hook and all menu implementations (bubble menu, suggestions menu, drag handle menu, hyperlink menus). This will also allow users to add their own custom UI to BlockNote.

@matthewlipski matthewlipski added the WIP Work in progress label Dec 13, 2022
@vercel
Copy link

vercel bot commented Dec 13, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
blocknote ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 18, 2023 at 2:29PM (UTC)

@YousefED
Copy link
Collaborator

YousefED commented Dec 13, 2022 via email

Moved animation delay timeout to bubble menu plugin
Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 1 comment, which I don't think is high prio. I also think we need to put some extra thought on API design (setBlockType). Will discuss on discord

blockMenu: BlockSideMenu;

hoveredBlock: HTMLElement | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how safe this is. We call getBoundingClientRect at a moment that we're not sure thism element still exists. Consider the following scenario:

  • hover element
  • click draghandle
  • a different plugin, let's say a spellchecker or whatsoever, changes an attribute of the block
  • now we click "add"

I think this won't work, as the htmlelement of the block can have changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the safest way to do it would be to save a hoveredBlockId instead and each time we need to get the block HTML element & bounding box for a function we could call:

document.querySelectorAll('[data-id=this.hoveredBlockId]')

This would imo be relatively clean but pretty inefficient.

We could also save the hovered block's bounding box instead which would be nicer and more efficient, but could still cause problems if another extension changes e.g. the block type in the meantime.

Any thoughts on which solution is better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the easiest is to stick to the current solution, but use your document.querySelectorAll('[data-id=this.hoveredBlockId]') idea if hoveredBlockId.isConnected is false?

@matthewlipski matthewlipski merged commit ebe3c97 into main Jan 18, 2023
This was referenced Jan 18, 2023
fogle pushed a commit to fogle/BlockNote that referenced this pull request May 20, 2023
* upgrade to react 18

* Maybe fixed React error in build

* Added early implementation of bubble menu & editor in separate react package

* Moved all hyperlink menus to react package

* Major structural overhaul to menu factories

* Added suggestions menu factory with new (hopefully final) factory structure

* Refactored bubble menu code to use improved factory structure

* Changes to bubble menu code and documentation

* Changes to bubble menu code and documentation

* General improvements, mostly to bubble and hyperlink menus

* comments after call

* Split bubble menu props into init & update props
Moved animation delay timeout to bubble menu plugin

* clean up packaging

* fix react error

* Changed bubble menu plugin view back to use a separate class

* Split hyperlink menu props into init & update props

* Changed hyperlink menu plugin view to use a separate class

* fix gitignore

* fix tsconfig

* Major cleanup for bubble menu factory code

* Major cleanup for hyperlink menu factory code

* Minor fixes

* Converted suggestion plugin view to use a class

* Changed editor example to use React as before

* Improved file structure and minor tweaks

* Minor refactor

* Fixed hyperlink menu behaviour

* Separated drag handle UI elements to react package

* Separated drag handle UI elements to react package

* Minor improvements

* fix lint

* refactor entrypoints (TypeCellOS#77)

* refactor entrypoints

* fix packages

* fix build

* move some more files / remove root.module.css

* Fixed hyperlink edit menu bugs

* re-add font

* Removed bubble menu animation update delay hack

* Changed bubble menu placement to be at the start of the selection bounding box

* Fixed hyperlink menu naming inconsistencies

* Refactored block/drag menu to use one factory and separate view class

* Fixed bubble menu sometimes attempting to hide when already hidden

* Fixed drag preview styling

* Fixed tooltip styling

* Removed unnecessary updates from block menu

* Vanilla example (TypeCellOS#78)

* add vanilla example

* add bold toggle

* add other factories to vanilla example

* add dragging

* Updated naming for bubble, block, and hyperlink menus

* Fixed drag handle tests

* Fixed drag and drop tests

* Improved how UI element factories are passed to extensions

* Updated suggestions/slash menu naming

* Updated slash menu selector for tests

* Split factory params into static and dynamic

* Minor fix to `BNSetContentType()`

* Improved getting & setting block type in formatting toolbar factory API

* Minor typing fix

* Combined factory `update()` and `show()` functions into single `render()` function

* rename props -> staticParams in vanilla example

Co-authored-by: yousefed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants