mirror of
https://github.com/codex-team/editor.js
synced 2024-06-09 17:32:31 +02:00
Changes for toggleBlockById
This commit is contained in:
parent
9542551d84
commit
0a42123ba8
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,3 +17,4 @@ dist/
|
|||
|
||||
coverage/
|
||||
.nyc_output/
|
||||
pnpm-lock.yaml
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
2
types/api/toolbar.d.ts
vendored
2
types/api/toolbar.d.ts
vendored
|
@ -23,4 +23,6 @@ export interface Toolbar {
|
|||
* @param {boolean} openingState — opening state of the toolbox
|
||||
*/
|
||||
toggleToolbox(openingState?: boolean): void;
|
||||
|
||||
toggleBlockSettingsById(id:string): void;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue