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

#665 API to open and close inline-toolbar #711

Merged
merged 13 commits into from
Apr 11, 2019
16 changes: 8 additions & 8 deletions dist/editor.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.13

- `New` *API* — Added [API methods](api.md) to open and close inline toolbar [#665](https://github.com/codex-team/editor.js/issues/665)

### 2.12.4

- `Improvements` CodeX.Shortcuts version updated to the v1.1 [#684](https://github.com/codex-team/editor.js/issues/684)
Expand Down
8 changes: 8 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ Methods that working with Toolbar

`close()` - closes toolbar, toolbox and blockSettings if they are opened

### InlineToolbarAPI

Methods that works with inline toolbar

`open()` - opens inline toolbar, (opens for the current selection)

`close()` - closes inline toolbar

### ListenerAPI

Methods that allows to work with DOM listener. Useful when you forgot to remove listener. Module collects all listeners and destroys automatically
Expand Down
1 change: 1 addition & 0 deletions src/components/modules/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class API extends Module {
selection: this.Editor.SelectionAPI.methods,
styles: this.Editor.StylesAPI.classes,
toolbar: this.Editor.ToolbarAPI.methods,
inlineToolbar: this.Editor.InlineToolbarAPI.methods,
} as APIInterfaces;
}
}
33 changes: 33 additions & 0 deletions src/components/modules/api/inlineToolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Module from '../../__module';
import { InlineToolbar } from '../../../../types/api/inline-toolbar';

/**
* @class InlineToolbarAPI
* Provides methods for working with the Inline Toolbar
*/
export default class InlineToolbarAPI extends Module {
/**
* Available methods
* @return {InlineToolbar}
*/
get methods(): InlineToolbar {
return {
close: () => this.close(),
open: () => this.open(),
};
}

/**
* Open Inline Toolbar
*/
public open(): void {
this.Editor.InlineToolbar.open();
}

/**
* Close Inline Toolbar
*/
public close(): void {
this.Editor.InlineToolbar.close();
}
}
2 changes: 1 addition & 1 deletion src/components/modules/api/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Toolbar} from '../../../../types/api';

/**
* @class ToolbarAPI
* provides with methods working with Toolbar
* Provides methods for working with the Toolbar
*/
export default class ToolbarAPI extends Module {
/**
Expand Down
9 changes: 8 additions & 1 deletion src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ export default class InlineToolbar extends Module {
/**
* Shows Inline Toolbar
*/
private open(): void {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neSpecc This file is also named inline.ts. Should we rename this as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it's included at the /toolbar/ directory, so this is a redundant addition

public open(): void {
/**
* Check if inline toolbar is allowed to show or not
*/
if (!this.allowedToShow()) {
return;
}

/**
* Filter inline-tools and show only allowed by Block's Tool
*/
Expand Down
2 changes: 2 additions & 0 deletions src/types-internal/editor-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import SaverAPI from '../components/modules/api/saver';
import Saver from '../components/modules/saver';
import BlockSelection from '../components/modules/blockSelection';
import RectangleSelection from '../components/modules/RectangleSelection';
import InlineToolbarAPI from '../components/modules/api/inlineToolbar';

export interface EditorModules {
UI: UI;
Expand Down Expand Up @@ -63,5 +64,6 @@ export interface EditorModules {
SelectionAPI: SelectionAPI;
StylesAPI: StylesAPI;
ToolbarAPI: ToolbarAPI;
InlineToolbarAPI: InlineToolbarAPI;
NotifierAPI: NotifierAPI;
}
1 change: 1 addition & 0 deletions types/api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './styles';
export * from './caret';
export * from './toolbar';
export * from './notifier';
export * from './inline-toolbar'
15 changes: 15 additions & 0 deletions types/api/inline-toolbar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Describes InlineToolbar API methods
*/
export interface InlineToolbar {
/**
* Closes InlineToolbar
*/
close(): void;

/**
* Opens InlineToolbar
*/
open(): void;
}

5 changes: 3 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import {EditorConfig} from './configs';
import {Blocks, Caret, Events, Listeners, Notifier, Sanitizer, Saver, Selection, Styles, Toolbar} from './api';
import {Blocks, Caret, Events, Listeners, Notifier, Sanitizer, Saver, Selection, Styles, Toolbar, InlineToolbar} from './api';

/**
* Interfaces used for development
Expand Down Expand Up @@ -51,6 +51,7 @@ export interface API {
selection: Selection;
styles: Styles;
toolbar: Toolbar;
inlineToolbar: InlineToolbar;
}

/**
Expand All @@ -70,7 +71,7 @@ declare class EditorJS {
public selection: Selection;
public styles: Styles;
public toolbar: Toolbar;

public inlineToolbar: InlineToolbar;
constructor(configuration?: EditorConfig|string);

public destroy(): void;
Expand Down