mirror of
https://github.com/codex-team/editor.js
synced 2024-05-20 15:26:48 +02:00
07b1ce2aca
* Add new popover class * Add flipper * confirmation * confirmation * Add confirmation support * Add search * Add toggle group support and update popover tests * Add custom content support * Fix scroll issue * Add mobile version * Integration * Fix animation * Cleanup * Fix popover position for narrow mode * Fix tests * Update version and changelog * Rename css classes * Move files * Stop using PopoverItem from outside of popover context * Fix jsdoc * Move error animation to popover item * Update css variables * Update docs/CHANGELOG.md Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com> * Update src/components/block-tunes/block-tune-move-down.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/block-tunes/block-tune-move-up.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Fixes * Fix imports * Fix toolbox close event * Move search-input file * Fix comment * Rename method * Cleanup * Remove onFlip callback from popover item * Rename * Fix removing event listener * Move popover animations to popover.css file * Cleanup styles * Fix jsdoc * Fix confirmation chains * Close toolbox oly when it's open * Change activation error animation * Update version and changelog * Fix overlay * Update icon border-radius on mobile * Disable item text select * Update changelog * Update yarn.lock * Add rc postfix to version --------- Co-authored-by: Ilya Maroz <37909603+ilyamore88@users.noreply.github.com> Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
89 lines
2 KiB
TypeScript
89 lines
2 KiB
TypeScript
/**
|
|
* @class MoveDownTune
|
|
* @classdesc Editor's default tune - Moves down highlighted block
|
|
* @copyright <CodeX Team> 2018
|
|
*/
|
|
|
|
import { API, BlockTune } from '../../../types';
|
|
import { IconChevronDown } from '@codexteam/icons';
|
|
import { TunesMenuConfig } from '../../../types/tools';
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
export default class MoveDownTune implements BlockTune {
|
|
/**
|
|
* Set Tool is Tune
|
|
*/
|
|
public static readonly isTune = true;
|
|
|
|
/**
|
|
* Property that contains Editor.js API methods
|
|
*
|
|
* @see {@link docs/api.md}
|
|
*/
|
|
private readonly api: API;
|
|
|
|
/**
|
|
* Styles
|
|
*/
|
|
private CSS = {
|
|
animation: 'wobble',
|
|
};
|
|
|
|
/**
|
|
* MoveDownTune constructor
|
|
*
|
|
* @param {API} api — Editor's API
|
|
*/
|
|
constructor({ api }) {
|
|
this.api = api;
|
|
}
|
|
|
|
/**
|
|
* Tune's appearance in block settings menu
|
|
*/
|
|
public render(): TunesMenuConfig {
|
|
return {
|
|
icon: IconChevronDown,
|
|
title: this.api.i18n.t('Move down'),
|
|
onActivate: (): void => this.handleClick(),
|
|
name: 'move-down',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Handle clicks on 'move down' button
|
|
*/
|
|
public handleClick(): void {
|
|
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
|
|
const nextBlock = this.api.blocks.getBlockByIndex(currentBlockIndex + 1);
|
|
|
|
// If Block is last do nothing
|
|
if (!nextBlock) {
|
|
throw new Error('Unable to move Block down since it is already the last');
|
|
}
|
|
|
|
const nextBlockElement = nextBlock.holder;
|
|
const nextBlockCoords = nextBlockElement.getBoundingClientRect();
|
|
|
|
let scrollOffset = Math.abs(window.innerHeight - nextBlockElement.offsetHeight);
|
|
|
|
/**
|
|
* Next block ends on screen.
|
|
* Increment scroll by next block's height to save element onscreen-position
|
|
*/
|
|
if (nextBlockCoords.top < window.innerHeight) {
|
|
scrollOffset = window.scrollY + nextBlockElement.offsetHeight;
|
|
}
|
|
|
|
window.scrollTo(0, scrollOffset);
|
|
|
|
/** Change blocks positions */
|
|
this.api.blocks.move(currentBlockIndex + 1);
|
|
|
|
this.api.toolbar.toggleBlockSettings(true);
|
|
}
|
|
}
|