UNPKG

1.8 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module paragraph/paragraphbuttonui
7 */
8import { Plugin, icons } from '@ckeditor/ckeditor5-core';
9import { ButtonView } from '@ckeditor/ckeditor5-ui';
10import Paragraph from './paragraph.js';
11const icon = icons.paragraph;
12/**
13 * This plugin defines the `'paragraph'` button. It can be used together with
14 * {@link module:heading/headingbuttonsui~HeadingButtonsUI} to replace the standard heading dropdown.
15 *
16 * This plugin is not loaded automatically by the {@link module:paragraph/paragraph~Paragraph} plugin. It must
17 * be added manually.
18 *
19 * ```ts
20 * ClassicEditor
21 * .create( {
22 * plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
23 * toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
24 * } )
25 * .then( ... )
26 * .catch( ... );
27 * ```
28 */
29export default class ParagraphButtonUI extends Plugin {
30 /**
31 * @inheritDoc
32 */
33 static get requires() {
34 return [Paragraph];
35 }
36 /**
37 * @inheritDoc
38 */
39 init() {
40 const editor = this.editor;
41 const t = editor.t;
42 editor.ui.componentFactory.add('paragraph', locale => {
43 const view = new ButtonView(locale);
44 const command = editor.commands.get('paragraph');
45 view.label = t('Paragraph');
46 view.icon = icon;
47 view.tooltip = true;
48 view.isToggleable = true;
49 view.bind('isEnabled').to(command);
50 view.bind('isOn').to(command, 'value');
51 view.on('execute', () => {
52 editor.execute('paragraph');
53 });
54 return view;
55 });
56 }
57}