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(toolbar): toolbar refactored and ui improved #1815

Merged
merged 26 commits into from
Nov 24, 2021
Merged

Conversation

neSpecc
Copy link
Member

@neSpecc neSpecc commented Nov 20, 2021

This PR introduces several updates of the Toolbar code and UI.

This is the first part of updates due to upcoming feature called "Unified menu".

List of changes

  1. Block Tunes toggler moved to the left

image

  1. Block Actions (BT toggler + Plus Button) will appear on block hovering instead of click
  • The UI module triggers block-hovered event
  • Toolbar uses block-hovered for appearing
  • currentBlock setter added to the BlockManager. We use it to set the Current Block on clicks on the BT Toggler or the Plus Button (and some other cases as well)
  1. Block Tunes toggler icon and Plus button icon updated
  2. Dev Example Page / menu with helpful buttons added to the bottom of the screen

image

  1. Dev Example Page / 'dark' theme added. Now we can code at night more comfortably.

image

  1. Rectangle Selection (optimization): the throttling added to the mousemove and scroll handlers
  2. Rectangle Selection (fix): the first click after RS was not clear selection state. Now does.
  3. Blocks API: the getBlockIndex() method added
  4. Blocks API: toolbar moving logic removed from blocks.move() and blocks.swap() methods. Instead, you should use Toolbar API (it was used by MoveUp and MoveDown tunes, they were updated).
  5. Blocks API: the insert() method now has the replace: boolean parameter
  6. Blocks API: the insert() method now returns the inserted Block API
  7. Listeners API: the on() method now returns the listener id.
  8. Listeners API: the new offById() method added
  9. Toolbox became a standalone class instead of a Module. It can be accessed only through the Toolbar module. Block Settings will be refactored the same way in the next updates.
  10. The new UiApi section was added. It allows accessing some editor UI nodes and methods.
  11. Git submodules removed from the CI flow.

Related editor-js/header#72

- UI module triggers 'block-hovered' event
- Toolbar uses 'block-hovered' for appearing
- `currentBlock` setter added to the BlockManager
- (reactangle-selection): the throttling added to the mousemove and scroll handlers
- `getBlockIndex` method added to the Api
- (api-blocks): toolbar moving logic removed from `blocks.move()` and `blocks.swap()` methods. Instead, MoveUp and MoveDown tunes uses Toolbar API
- Toolbox became a standalone class from the editor module. It can be accessed only via the owner (the Toolbar module)
- (api.blocks) the insert() method now has the `replace` param. Also, it returns inserted Block API now.
@@ -109,6 +109,9 @@ export default class MoveDownTune implements BlockTune {
/** Change blocks positions */
Copy link
Member Author

Choose a reason for hiding this comment

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

Toolbar moving logic removed from the api.blocks.move() method, so we do it manually.

/**
* Prevent caret jumping (to last block) when clicking between blocks
*/
lastBlockBottomCoord < clickedCoord;
Copy link
Member Author

Choose a reason for hiding this comment

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

have improved the isClickedBottom statement:

some blocks can have margins, so when a user clicks on such margins between .ce-block, caret was jumping to the bottom of the document. For now, it checks the exact coordinate of the last block bottom.

Comment on lines 112 to 113
this.api.toolbar.open();
this.api.toolbar.toggleBlockSettings(true);
Copy link
Member

Choose a reason for hiding this comment

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

Looks not really convenient, maybe we can at least use just one method?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +286 to +288
this.plusButton.show();
} else {
this.plusButton.hide();
Copy link
Member

Choose a reason for hiding this comment

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

Might be a good idea to move plus button into toolbox as well

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that it would be better. Toolbox is the list of buttons. It is about to become vertical. And it can be appeared in several ways, not only by Plus Button. And the Plus Button is just a part of Toolbar UI.

*/
let blockHoveredEmitted;

this.readOnlyMutableListeners.on(this.nodes.redactor, 'mousemove', _.throttle((event: MouseEvent | TouchEvent) => {
Copy link
Member

Choose a reason for hiding this comment

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

Why not mouseenter and mousemove. Also would be great to check on pointer devices and mobile devices with connected touchpad/mouse

Copy link
Member Author

@neSpecc neSpecc Nov 22, 2021

Choose a reason for hiding this comment

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

The mouseenter would have to be bound to every Block, and there can be a large amount of them. I think it's better to use the single event on the redactor node.

Also would be great to check on pointer devices and mobile devices with connected touchpad/mouse

I will test the RC version in CodeX Docs, so I will try to use various hardware.

Comment on lines 131 to 133
this.onOpen = onOpen;
this.onClose = onClose;
this.onBlockAdded = onBlockAdded;
Copy link
Member

Choose a reason for hiding this comment

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

In case API would grow, might be better to just extend EventEmitter interface and provide enum of possible events

toolbox.on(ToolboxEvents.Close, () => {});
toolbox.on(ToolboxEvents.Open, () => {});

Using typescript we can strictly type that

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +404 to +409
toolName,
undefined,
undefined,
index,
undefined,
currentBlock.isEmpty
Copy link
Member

Choose a reason for hiding this comment

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

We should go with object here

Copy link
Member Author

@neSpecc neSpecc Nov 23, 2021

Choose a reason for hiding this comment

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

I've decided not to change the interface of the existed API method. Should I create an overload for that?

this.toolboxInstance = new Toolbox({
api: this.Editor.API.methods,
tools: this.Editor.Tools.blockTools,
shortcutsScopeElement: this.Editor.UI.nodes.redactor,
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to provide some nodes from Editor API

editorAPI.nodes.redactor

// or

editorAPI.ui.redactor

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@neSpecc neSpecc merged commit ff91466 into next Nov 24, 2021
@neSpecc neSpecc deleted the feature/block-tune-left branch November 24, 2021 18:14
jschanker added a commit to navgurukul/bhanwari-devi that referenced this pull request Nov 11, 2022
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