editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Block Delete Permission

Open ziqiangai opened this issue 3 years ago • 1 comments

  1. Describe a problem. I cannot prevent the ToolBar Tunnel button delete blocks, or the backspace key from deleting blocks.
  2. 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();
    }
  }
  1. 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.

ziqiangai avatar Jul 15 '22 09:07 ziqiangai

It may affect the re deletion of Ctrl + AA (Select All)

ziqiangai avatar Jul 15 '22 10:07 ziqiangai