codex-team / codex-team/editor.js

Block Delete Permission

Open
#2,099 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
31.9k
Forks
2.2k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

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:
```typescript
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();
}
}
```

3. 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.