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

Fixing Bug #1270 and resolve all yarn lint warning. #1292

Merged
merged 4 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- `Improvements` - Unuseful log about missed i18n section has been removed [#1269](https://github.com/codex-team/editor.js/issues/1269)
- `Fix` - Fixed issue with enter key in inputs and textareas [#920](https://github.com/codex-team/editor.js/issues/920)
- `Improvements` - Allowed to set `false` as `toolbox` config in order to hide Toolbox button [#1221](https://github.com/codex-team/editor.js/issues/1221)
- `Fix` - blocks.getBlockByIndex() API method now returns void for indexes out of range [#1270](https://github.com/codex-team/editor.js/issues/1270)

### 2.18

Expand Down
1 change: 0 additions & 1 deletion src/components/__module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ export default class Module {
protected get isRtl(): boolean {
return this.config.i18n.direction === 'rtl';
}

}
5 changes: 5 additions & 0 deletions src/components/block-tunes/block-tune-move-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export default class MoveDownTune implements BlockTune {
}

const nextBlock = this.api.blocks.getBlockByIndex(currentBlockIndex + 1);

if (!nextBlock) {
return;
}

const nextBlockElement = nextBlock.holder;
const nextBlockCoords = nextBlockElement.getBoundingClientRect();

Expand Down
7 changes: 6 additions & 1 deletion src/components/block-tunes/block-tune-move-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ export default class MoveUpTune implements BlockTune {
}

const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
const currentBlockElement = currentBlock.holder;
const previousBlock = this.api.blocks.getBlockByIndex(currentBlockIndex - 1);

if (!currentBlock || !previousBlock){
return;
}

const currentBlockElement = currentBlock.holder;
const previousBlockElement = previousBlock.holder;

/**
Expand Down
1 change: 0 additions & 1 deletion src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { SavedData } from '../../../types/data-formats';
import $ from '../dom';
import * as _ from '../utils';
import ApiModule from '../modules/api';
import SelectionUtils from '../selection';
import BlockAPI from './api';
import { ToolType } from '../modules/tools';

Expand Down
14 changes: 9 additions & 5 deletions src/components/modules/api/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class BlocksAPI extends Module {
delete: (index?: number): void => this.delete(index),
swap: (fromIndex: number, toIndex: number): void => this.swap(fromIndex, toIndex),
move: (toIndex: number, fromIndex?: number): void => this.move(toIndex, fromIndex),
getBlockByIndex: (index: number): BlockAPIInterface => this.getBlockByIndex(index),
getBlockByIndex: (index: number): BlockAPIInterface | void => this.getBlockByIndex(index),
getCurrentBlockIndex: (): number => this.getCurrentBlockIndex(),
getBlocksCount: (): number => this.getBlocksCount(),
stretchBlock: (index: number, status = true): void => this.stretchBlock(index, status),
Expand Down Expand Up @@ -51,15 +51,19 @@ export default class BlocksAPI extends Module {
}

/**
* Returns Block holder by Block index
* Returns BlockAPI object by Block index
*
* @param {number} index - index to get
*
* @returns {HTMLElement}
*/
public getBlockByIndex(index: number): BlockAPIInterface {
public getBlockByIndex(index: number): BlockAPIInterface | void {
const block = this.Editor.BlockManager.getBlockByIndex(index);

if (block === undefined) {
_.log('There is no block at index `' + index + '`', 'warn');

return;
}

return new BlockAPI(block);
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class ConversionToolbar extends Module {
public make(): HTMLElement {
this.nodes.wrapper = $.make('div', [
ConversionToolbar.CSS.conversionToolbarWrapper,
...(this.isRtl ? [this.Editor.UI.CSS.editorRtlFix] : []),
...(this.isRtl ? [ this.Editor.UI.CSS.editorRtlFix ] : []),
]);
this.nodes.tools = $.make('div', ConversionToolbar.CSS.conversionToolbarTools);

Expand Down Expand Up @@ -298,8 +298,8 @@ export default class ConversionToolbar extends Module {
* @param {string} title - button title
*/
private addTool(toolName: string, toolIcon: string, title: string): void {
const tool = $.make('div', [ConversionToolbar.CSS.conversionTool]);
const icon = $.make('div', [ConversionToolbar.CSS.conversionToolIcon]);
const tool = $.make('div', [ ConversionToolbar.CSS.conversionTool ]);
const icon = $.make('div', [ ConversionToolbar.CSS.conversionToolIcon ]);

tool.dataset.tool = toolName;
icon.innerHTML = toolIcon;
Expand All @@ -310,7 +310,7 @@ export default class ConversionToolbar extends Module {
$.append(this.nodes.tools, tool);
this.tools[toolName] = tool;

this.Editor.Listeners.on(tool, 'click', async() => {
this.Editor.Listeners.on(tool, 'click', async () => {
await this.replaceWithBlock(toolName);
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class InlineToolbar extends Module {
focusedButton: 'ce-inline-tool--focused',
conversionToggler: 'ce-inline-toolbar__dropdown',
conversionTogglerHidden: 'ce-inline-toolbar__dropdown--hidden',
conversionTogglerContent: 'ce-inline-toolbar__dropdown-content'
conversionTogglerContent: 'ce-inline-toolbar__dropdown-content',
};

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class InlineToolbar extends Module {
public make(): void {
this.nodes.wrapper = $.make('div', [
this.CSS.inlineToolbar,
...(this.isRtl ? [this.Editor.UI.CSS.editorRtlFix] : []),
...(this.isRtl ? [ this.Editor.UI.CSS.editorRtlFix ] : []),
]);
this.nodes.buttons = $.make('div', this.CSS.buttonsWrapper);
this.nodes.actions = $.make('div', this.CSS.actionsWrapper);
Expand Down Expand Up @@ -572,7 +572,7 @@ export default class InlineToolbar extends Module {

return (toolClass as ToolSettings).class[Tools.INTERNAL_SETTINGS.IS_INLINE];
})
.map(([name]: [string, InlineToolConstructable | ToolSettings]) => name);
.map(([ name ]: [string, InlineToolConstructable | ToolSettings]) => name);

/**
* 1) For internal tools, check public getter 'shortcut'
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default class UI extends Module {
*/
this.nodes.wrapper = $.make('div', [
this.CSS.editorWrapper,
...(this.isRtl ? [this.CSS.editorRtlFix] : []),
...(this.isRtl ? [ this.CSS.editorRtlFix ] : []),
]);
this.nodes.redactor = $.make('div', this.CSS.editorZone);

Expand Down
5 changes: 2 additions & 3 deletions types/api/blocks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ export interface Blocks {
move(toIndex: number, fromIndex?: number): void;

/**
* Returns Block holder by Block index
* Returns Block API object by passed Block index
* @param {number} index
* @returns {HTMLElement}
*/
getBlockByIndex(index: number): BlockAPI;
getBlockByIndex(index: number): BlockAPI | void;

/**
* Returns current Block index
Expand Down