Skip to content

Commit

Permalink
feat: Hide element while deleting element from breakpoints other than…
Browse files Browse the repository at this point in the history
… desktop
  • Loading branch information
surajshetty3416 committed Jan 9, 2025
1 parent d3783fd commit d933bde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/BlockContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const contextMenuOptions: ContextMenuOption[] = [
{
label: "Delete",
action: () => {
block.value.getParentBlock()?.removeChild(block.value);
store.activeCanvas?.removeBlock(block.value);
},
condition: () => {
return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ class Block implements BlockOptions {
setInnerHTML(innerHTML: string) {
this.innerHTML = innerHTML;
}
toggleVisibility() {
if (this.getStyle("display") === "none") {
toggleVisibility(show: boolean | null = null) {
if (this.getStyle("display") === "none" || show === false) {
this.setStyle("display", this.getStyle("__last_display") || "flex");
this.setStyle("__last_display", null);
} else {
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/utils/useCanvasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,26 @@ export function useCanvasUtils(
return null;
}

function removeBlock(block: Block) {
function removeBlock(block: Block, force: boolean = false) {
if (block.blockId === "root") {
toast.warning("Warning", {
description: "Cannot delete root block",
});
return;
}
if (block.isChildOfComponentBlock()) {
toast.warning("Warning", {
description: "Cannot delete block inside component",
});
return;
block.toggleVisibility(false);
}
const parentBlock = block.parentBlock;
if (!parentBlock) {
return;
}
const index = parentBlock.children.indexOf(block);
parentBlock.removeChild(block);
if (store.activeBreakpoint === "desktop" || force) {
parentBlock.removeChild(block);
} else {
block.toggleVisibility(false);
}
nextTick(() => {
if (parentBlock.children.length) {
const nextSibling = parentBlock.children[index] || parentBlock.children[index - 1];
Expand Down

0 comments on commit d933bde

Please sign in to comment.