editor.js
editor.js copied to clipboard
Block Delete Permission
- Describe a problem. I cannot prevent the ToolBar Tunnel button delete blocks, or the backspace key from deleting blocks.
- Describe the solution you'd like. Mockups are welcome.
why not add if statement in:
https://github.com/codex-team/editor.js/blob/f7368edee3fd5af32a6a9e9903bb9a00a94cff68/src/components/block-tunes/block-tune-delete.ts#L90-L119
It will be:
public handleClick(event: MouseEvent): void {
if (!this.api.blocks.canDelete()) {
return;
}
/**
* if block is not waiting the confirmation, subscribe on block-settings-closing event to reset
* otherwise delete block
*/
if (!this.needConfirmation) {
this.setConfirmation(true);
/**
* Subscribe on event.
* When toolbar block settings is closed but block deletion is not confirmed,
* then reset confirmation state
*/
this.api.events.on('block-settings-closed', this.resetConfirmation);
} else {
/**
* Unsubscribe from block-settings closing event
*/
this.api.events.off('block-settings-closed', this.resetConfirmation);
this.api.blocks.delete();
this.api.toolbar.close();
this.api.tooltip.hide();
/**
* Prevent firing ui~documentClicked that can drop currentBlock pointer
*/
event.stopPropagation();
}
}
- Are there any alternatives? In some scenarios that require permission control, some blocks may not be deleted, or only the specified person is allowed to delete.
It may affect the re deletion of Ctrl + AA (Select All)