Repository navigation
fix(toolbar): align toolbar with stretched block content #3058
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
base: next
Are you sure you want to change the base?
Changes from all commits
1ada468
8e2a0c4
8a5f1e5
0e2ac99
bf15d1d
0a180e6
b0b128d
c012be2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type Block from '../block'; | ||
|
|
||
| /** | ||
| * Fired when the stretched state of a Block is toggled | ||
| */ | ||
| export const BlockStretchToggled = 'block stretch toggled'; | ||
|
|
||
| /** | ||
| * Payload that will be passed with the event | ||
| */ | ||
| export interface BlockStretchToggledPayload { | ||
| /** | ||
| * Block whose stretched state was toggled | ||
| */ | ||
| block: Block; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import type Block from '../../block'; | |
| import Toolbox, { ToolboxEvent } from '../../ui/toolbox'; | ||
| import { IconMenu, IconPlus } from '@codexteam/icons'; | ||
| import { BlockHovered } from '../../events/BlockHovered'; | ||
| import { BlockStretchToggled } from '../../events/BlockStretchToggled'; | ||
| import { beautifyShortcut } from '../../utils'; | ||
| import { getKeyboardKeyForCode } from '../../utils/keyboard'; | ||
|
|
||
|
|
@@ -130,6 +131,7 @@ export default class Toolbar extends Module<ToolbarNodes> { | |
| actionsOpened: 'ce-toolbar__actions--opened', | ||
|
|
||
| toolbarOpened: 'ce-toolbar--opened', | ||
| toolbarStretched: 'ce-toolbar--stretched', | ||
| openedToolboxHolderModifier: 'codex-editor--toolbox-opened', | ||
|
|
||
| plusButton: 'ce-toolbar__plus', | ||
|
|
@@ -354,6 +356,11 @@ export default class Toolbar extends Module<ToolbarNodes> { | |
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| this.nodes.wrapper!.style.top = `${Math.floor(toolbarY)}px`; | ||
|
|
||
| /** | ||
| * Align Toolbar with the content width of the hovered Block | ||
| */ | ||
| this.nodes.wrapper.classList.toggle(this.CSS.toolbarStretched, block.stretched); | ||
|
|
||
| /** | ||
| * Do not show Block Tunes Toggler near single and empty block | ||
| */ | ||
|
|
@@ -388,6 +395,7 @@ export default class Toolbar extends Module<ToolbarNodes> { | |
| */ | ||
| private reset(): void { | ||
| this.nodes.wrapper.style.top = 'unset'; | ||
| this.nodes.wrapper.classList.remove(this.CSS.toolbarStretched); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -597,6 +605,26 @@ export default class Toolbar extends Module<ToolbarNodes> { | |
|
|
||
| this.moveAndOpen(data.block); | ||
| }); | ||
|
|
||
| /** | ||
| * Re-align Toolbar when the hovered Block changes its stretched state | ||
| */ | ||
| this.eventsDispatcher.on(BlockStretchToggled, ({ block }) => { | ||
| if (!this.opened || block !== this.hoveredBlock) { | ||
| return; | ||
| } | ||
|
|
||
| this.nodes.wrapper.classList.toggle(this.CSS.toolbarStretched, block.stretched); | ||
|
|
||
| /** | ||
| * Do not move toolbar if Block Settings or Toolbox opened | ||
| */ | ||
| if (this.Editor.BlockSettings.opened || this.toolboxInstance?.opened) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked locally: stretching an image via the Image tool's Stretch tune still leaves the toolbar at the narrow column. The tune keeps Block Settings open after the click, so |
||
| return; | ||
| } | ||
|
|
||
| this.moveAndOpen(block); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.