forked from codex-team/editor.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolbar.ts
More file actions
58 lines (52 loc) · 1.42 KB
/
toolbar.ts
File metadata and controls
58 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();
}
}
}