2022-03-04 13:39:39 +01:00
|
|
|
/**
|
|
|
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
|
|
*/
|
|
|
|
|
2025-05-04 17:12:49 +03:00
|
|
|
import { Editor } from "ckeditor5";
|
2022-03-04 13:39:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for setting the `isOn` state of buttons.
|
|
|
|
*
|
|
|
|
* @private
|
2025-05-04 17:12:49 +03:00
|
|
|
* @param commandName Short name of the command.
|
2022-03-04 13:39:39 +01:00
|
|
|
*/
|
2025-05-04 17:12:49 +03:00
|
|
|
export function checkIsOn( editor: Editor, commandName: string ) {
|
2022-03-04 13:39:39 +01:00
|
|
|
const selection = editor.model.document.selection;
|
2025-05-04 17:12:49 +03:00
|
|
|
const mermaidItem = selection.getSelectedElement() || selection.getLastPosition()?.parent;
|
2022-03-04 13:39:39 +01:00
|
|
|
|
|
|
|
if ( mermaidItem && mermaidItem.is( 'element', 'mermaid' ) && mermaidItem.getAttribute( 'displayMode' ) === commandName ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|