Changes for toggleBlockById

This commit is contained in:
Vishal Pradhan 2024-01-25 17:14:08 +05:30
parent 9542551d84
commit 0a42123ba8
4 changed files with 27 additions and 2 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ dist/
coverage/
.nyc_output/
pnpm-lock.yaml

View file

@ -1,5 +1,5 @@
{
"name": "@editorjs/editorjs",
"name": "editor-js",
"version": "2.29.0",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editorjs.umd.js",
@ -76,4 +76,4 @@
"type": "opencollective",
"url": "https://opencollective.com/editorjs"
}
}
}

View file

@ -1,5 +1,6 @@
import { Toolbar } from '../../../../types/api';
import Module from '../../__module';
import Block from '../../block';
import * as _ from './../../utils';
/**
* @class ToolbarAPI
@ -16,6 +17,7 @@ export default class ToolbarAPI extends Module {
close: (): void => this.close(),
open: (): void => this.open(),
toggleBlockSettings: (openingState?: boolean): void => this.toggleBlockSettings(openingState),
toggleBlockSettingsById: (id:string): void => this.toggleBlockSettingsById(id),
toggleToolbox: (openingState?: boolean): void => this.toggleToolbox(openingState),
};
}
@ -56,6 +58,26 @@ export default class ToolbarAPI extends Module {
this.Editor.BlockSettings.close();
}
}
/**
* Toggles Block Setting of the current block
*
* @param {boolean} openingState opening state of Block Setting
*/
public toggleBlockSettingsById(id: String): void {
const block = this.Editor.BlockManager.getBlockById(id)
if (!block) {
_.logLabeled('Block not found', 'warn');
return;
}
this.Editor.BlockSelection.selectBlock(block);
this.Editor.BlockManager.currentBlock = block;
if (this.Editor.BlockManager.currentBlockIndex === -1) {
_.logLabeled('Could\'t toggle the Toolbar because there is no block selected ', 'warn');
return;
}
this.Editor.Toolbar.moveAndOpen();
this.Editor.BlockSettings.open();
}
/**

View file

@ -23,4 +23,6 @@ export interface Toolbar {
* @param {boolean} openingState opening state of the toolbox
*/
toggleToolbox(openingState?: boolean): void;
toggleBlockSettingsById(id:string): void;
}