mirror of
https://github.com/codex-team/editor.js
synced 2024-06-07 16:32:22 +02:00
ff91466b14
* chore(block-tune-toggler): toggler moved to the left (draft) * toolbox ui updated * fixd caret jumpling, improved some styles * toolbar moving by block-hover - 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 * the dark-theme to the example-dev.html * positioning improved * fix(rectangle-selection): first click after RS does not clears selection state * toolbox position fixed * the toolbox module became a standalone class - 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. * new(api.listeners): `on()` now returns the listener id. The new `offById()` method added * fix bug with Tab pressing on hovered but not focused block * mobile version improved * upd example dev * small updaets * add nested-list * linting * (api.toolbar): `toggleBlockSettings` now fires toggling event with the same state * EventDispatcher used instead of callbacks for the Toolbox * UIApi added * fix ci * git submodules removed from the ci flow * add paragraph submodule to the ci flow * Update CHANGELOG.md * Update package.json * use ubuntu-latest for chrome ci
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { Toolbar } from '../../../../types/api';
|
|
import Module from '../../__module';
|
|
import * as _ from './../../utils';
|
|
/**
|
|
* @class ToolbarAPI
|
|
* Provides methods for working with the Toolbar
|
|
*/
|
|
export default class ToolbarAPI extends Module {
|
|
/**
|
|
* Available methods
|
|
*
|
|
* @returns {Toolbar}
|
|
*/
|
|
public get methods(): Toolbar {
|
|
return {
|
|
close: (): void => this.close(),
|
|
open: (): void => this.open(),
|
|
toggleBlockSettings: (openingState?: boolean): void => this.toggleBlockSettings(openingState),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Open toolbar
|
|
*/
|
|
public open(): void {
|
|
this.Editor.Toolbar.moveAndOpen();
|
|
}
|
|
|
|
/**
|
|
* Close toolbar and all included elements
|
|
*/
|
|
public close(): void {
|
|
this.Editor.Toolbar.close();
|
|
}
|
|
|
|
/**
|
|
* Toggles Block Setting of the current block
|
|
*
|
|
* @param {boolean} openingState — opening state of Block Setting
|
|
*/
|
|
public toggleBlockSettings(openingState?: boolean): void {
|
|
if (this.Editor.BlockManager.currentBlockIndex === -1) {
|
|
_.logLabeled('Could\'t toggle the Toolbar because there is no block selected ', 'warn');
|
|
|
|
return;
|
|
}
|
|
|
|
/** Check that opening state is set or not */
|
|
const canOpenBlockSettings = openingState ?? !this.Editor.BlockSettings.opened;
|
|
|
|
if (canOpenBlockSettings) {
|
|
this.Editor.Toolbar.moveAndOpen();
|
|
this.Editor.BlockSettings.open();
|
|
} else {
|
|
this.Editor.BlockSettings.close();
|
|
}
|
|
}
|
|
}
|