mirror of
https://github.com/codex-team/editor.js
synced 2026-03-18 00:19:53 +01:00
Default tunes to popover
This commit is contained in:
parent
f7368edee3
commit
1aa1017e47
4 changed files with 37 additions and 10 deletions
|
|
@ -5,7 +5,8 @@
|
|||
* @copyright <CodeX Team> 2018
|
||||
*/
|
||||
import $ from '../dom';
|
||||
import { API, BlockTune } from '../../../types';
|
||||
import { API, BlockTune, BlockAPI } from '../../../types';
|
||||
import { PopoverItem } from '../../components/utils/popover';
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -69,29 +70,40 @@ export default class MoveUpTune implements BlockTune {
|
|||
return moveUpButton;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public get blockSettings(): PopoverItem {
|
||||
return {
|
||||
icon: $.svg('arrow-up', 14, 14).outerHTML,
|
||||
label: this.api.i18n.t('Move up'),
|
||||
onClick: (item): void => this.handleClick(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Move current block up
|
||||
*
|
||||
* @param {MouseEvent} event - click event
|
||||
* @param {HTMLElement} button - clicked button
|
||||
*/
|
||||
public handleClick(event: MouseEvent, button: HTMLElement): void {
|
||||
public handleClick(event?: MouseEvent, button?: HTMLElement): void {
|
||||
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
|
||||
const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
|
||||
const previousBlock = this.api.blocks.getBlockByIndex(currentBlockIndex - 1);
|
||||
|
||||
if (currentBlockIndex === 0 || !currentBlock || !previousBlock) {
|
||||
button.classList.add(this.CSS.animation);
|
||||
// button.classList.add(this.CSS.animation);
|
||||
|
||||
window.setTimeout(() => {
|
||||
button.classList.remove(this.CSS.animation);
|
||||
}, 500);
|
||||
// window.setTimeout(() => {
|
||||
// button.classList.remove(this.CSS.animation);
|
||||
// }, 500);
|
||||
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
const currentBlockElement = currentBlock.holder;
|
||||
const previousBlockElement = previousBlock.holder;
|
||||
const currentBlockElement = (currentBlock as BlockAPI).holder;
|
||||
const previousBlockElement = (previousBlock as BlockAPI).holder;
|
||||
|
||||
/**
|
||||
* Here is two cases:
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import BlockTune from '../tools/tune';
|
|||
import { BlockTuneData } from '../../../types/block-tunes/block-tune-data';
|
||||
import ToolsCollection from '../tools/collection';
|
||||
import EventsDispatcher from '../utils/events';
|
||||
import { PopoverItem } from '../utils/popover';
|
||||
|
||||
/**
|
||||
* Interface describes Block class constructor argument
|
||||
|
|
@ -660,6 +661,14 @@ export default class Block extends EventsDispatcher<BlockEvents> {
|
|||
return [tunesElement, defaultTunesElement];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public getTunesItems(): PopoverItem[] {
|
||||
return Array.from(this.defaultTunesInstances.values()).map(tune => tune.blockSettings)
|
||||
.filter(item => !!item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update current input index with selection anchor node
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export interface PopoverItem {
|
|||
secondaryLabel?: string;
|
||||
|
||||
/**
|
||||
* Itm click handler
|
||||
* Item click handler
|
||||
*
|
||||
* @param item - clicked item
|
||||
*/
|
||||
|
|
|
|||
6
types/block-tunes/block-tune.d.ts
vendored
6
types/block-tunes/block-tune.d.ts
vendored
|
|
@ -1,5 +1,6 @@
|
|||
import {API, BlockAPI, SanitizerConfig, ToolConfig} from '../index';
|
||||
import { BlockTuneData } from './block-tune-data';
|
||||
import { PopoverItem } from '../../src/components/utils/popover';
|
||||
|
||||
/**
|
||||
* Describes BLockTune blueprint
|
||||
|
|
@ -29,6 +30,11 @@ export interface BlockTune {
|
|||
* @return {BlockTuneData}
|
||||
*/
|
||||
save?(): BlockTuneData;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
blockSettings?: PopoverItem
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue