/
paragraphbuttonui.ts
68 lines (58 loc) · 1.73 KB
/
paragraphbuttonui.ts
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
59
60
61
62
63
64
65
66
67
68
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module paragraph/paragraphbuttonui
*/
import { Plugin, icons } from '@ckeditor/ckeditor5-core';
import { ButtonView } from '@ckeditor/ckeditor5-ui';
import Paragraph from './paragraph.js';
import type ParagraphCommand from './paragraphcommand.js';
const icon = icons.paragraph;
/**
* This plugin defines the `'paragraph'` button. It can be used together with
* {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
*
* This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
* be added manually.
*
* ```ts
* ClassicEditor
* .create( {
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
* } )
* .then( ... )
* .catch( ... );
* ```
*/
export default class ParagraphButtonUI extends Plugin {
/**
* @inheritDoc
*/
public static get requires() {
return [ Paragraph ] as const;
}
/**
* @inheritDoc
*/
public init(): void {
const editor = this.editor;
const t = editor.t;
editor.ui.componentFactory.add( 'paragraph', locale => {
const view = new ButtonView( locale );
const command: ParagraphCommand = editor.commands.get( 'paragraph' )!;
view.label = t( 'Paragraph' );
view.icon = icon;
view.tooltip = true;
view.isToggleable = true;
view.bind( 'isEnabled' ).to( command );
view.bind( 'isOn' ).to( command, 'value' );
view.on( 'execute', () => {
editor.execute( 'paragraph' );
} );
return view;
} );
}
}