2025-03-13 18:27:05 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2025-03-13 19:02:10 +02:00
|
|
|
* @module admonition/admonitionui
|
2025-03-13 18:27:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { Plugin, icons } from 'ckeditor5/src/core.js';
|
|
|
|
import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
|
|
|
|
|
|
|
|
import '../theme/blockquote.css';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The block quote UI plugin.
|
|
|
|
*
|
2025-03-13 19:02:10 +02:00
|
|
|
* It introduces the `'admonition'` button.
|
2025-03-13 18:27:05 +02:00
|
|
|
*
|
|
|
|
* @extends module:core/plugin~Plugin
|
|
|
|
*/
|
2025-03-13 18:33:39 +02:00
|
|
|
export default class AdmonitionUI extends Plugin {
|
2025-03-13 18:27:05 +02:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static get pluginName() {
|
2025-03-13 18:41:37 +02:00
|
|
|
return 'AdmonitionUI' as const;
|
2025-03-13 18:27:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public init(): void {
|
|
|
|
const editor = this.editor;
|
|
|
|
|
2025-03-13 19:02:10 +02:00
|
|
|
editor.ui.componentFactory.add( 'admonition', () => {
|
2025-03-13 18:27:05 +02:00
|
|
|
const buttonView = this._createButton( ButtonView );
|
|
|
|
|
|
|
|
buttonView.set( {
|
|
|
|
tooltip: true
|
|
|
|
} );
|
|
|
|
|
|
|
|
return buttonView;
|
|
|
|
} );
|
|
|
|
|
2025-03-13 19:02:10 +02:00
|
|
|
editor.ui.componentFactory.add( 'menuBar:admonition', () => {
|
2025-03-13 18:27:05 +02:00
|
|
|
const buttonView = this._createButton( MenuBarMenuListItemButtonView );
|
|
|
|
|
|
|
|
buttonView.set( {
|
|
|
|
role: 'menuitemcheckbox'
|
|
|
|
} );
|
|
|
|
|
|
|
|
return buttonView;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-03-13 19:05:20 +02:00
|
|
|
* Creates a button for admonition command to use either in toolbar or in menu bar.
|
2025-03-13 18:27:05 +02:00
|
|
|
*/
|
|
|
|
private _createButton<T extends typeof ButtonView | typeof MenuBarMenuListItemButtonView>( ButtonClass: T ): InstanceType<T> {
|
|
|
|
const editor = this.editor;
|
|
|
|
const locale = editor.locale;
|
2025-03-13 19:02:10 +02:00
|
|
|
const command = editor.commands.get( 'admonition' )!;
|
2025-03-13 18:27:05 +02:00
|
|
|
const view = new ButtonClass( editor.locale ) as InstanceType<T>;
|
|
|
|
const t = locale.t;
|
|
|
|
|
|
|
|
view.set( {
|
2025-03-13 19:05:20 +02:00
|
|
|
label: t( 'Admonition' ),
|
2025-03-13 18:27:05 +02:00
|
|
|
icon: icons.quote,
|
|
|
|
isToggleable: true
|
|
|
|
} );
|
|
|
|
|
|
|
|
view.bind( 'isEnabled' ).to( command, 'isEnabled' );
|
|
|
|
view.bind( 'isOn' ).to( command, 'value' );
|
|
|
|
|
|
|
|
// Execute the command.
|
|
|
|
this.listenTo( view, 'execute', () => {
|
2025-03-13 19:02:10 +02:00
|
|
|
editor.execute( 'admonition' );
|
2025-03-13 18:27:05 +02:00
|
|
|
editor.editing.view.focus();
|
|
|
|
} );
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|