Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Context menu option to delete a block #44

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend/src/components/BlockContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,18 @@ const contextMenuOptions: ContextMenuOption[] = [
},
condition: () => Boolean(props.block.extendedFromComponent),
},
{
label: "Delete",
action: () => {
props.block.getParentBlock()?.removeChild(props.block);
},
condition: () => {
return (
!props.block.isRoot() &&
!props.block.isChildOfComponentBlock() &&
Boolean(props.block.getParentBlock())
);
},
},
];
</script>
6 changes: 3 additions & 3 deletions frontend/src/components/BlockEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</template>
<script setup lang="ts">
import Block from "@/utils/block";
import { addPxToNumber, getNumberFromPx } from "@/utils/helpers";
import { addPxToNumber } from "@/utils/helpers";
import { Ref, computed, inject, nextTick, onMounted, ref, watch, watchEffect } from "vue";
import blockController from "@/utils/blockController";
Expand Down Expand Up @@ -213,8 +213,8 @@ const handleMove = (ev: MouseEvent) => {
const target = ev.target as HTMLElement;
const startX = ev.clientX;
const startY = ev.clientY;
const startLeft = getNumberFromPx(props.block.getStyle("left"));
const startTop = getNumberFromPx(props.block.getStyle("top"));
const startLeft = props.target.offsetLeft || 0;
const startTop = props.target.offsetTop || 0;
moving.value = true;
guides.showX();
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/BuilderCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ const getFirstBlock = () => {
const setRootBlock = (newBlock: Block, resetCanvas = false) => {
block.value = newBlock;
if (canvasHistory.value) {
canvasHistory.value.clear();
canvasHistory.value.dispose();
setupHistory();
}
if (resetCanvas) {
nextTick(() => {
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/pages/PageBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { BuilderPage } from "@/types/Builder/BuilderPage";
import Block, { styleProperty } from "@/utils/block";
import blockController from "@/utils/blockController";
import getBlockTemplate from "@/utils/blockTemplate";
import convertHTMLToBlocks from "@/utils/convertHTMLToBlocks";
import { copyToClipboard, getBlockCopy, isHTMLString, isJSONString, isTargetEditable } from "@/utils/helpers";
import { useActiveElement, useDebounceFn, useEventListener, useMagicKeys } from "@vueuse/core";
import { computed, nextTick, onActivated, provide, ref, watch, watchEffect } from "vue";
Expand Down Expand Up @@ -183,12 +182,8 @@ useEventListener(document, "paste", async (e) => {
blockController.setInnerHTML(text);
} else {
let block = null as unknown as Block | BlockOptions;
if (text.startsWith("<svg")) {
block = convertHTMLToBlocks(text, true);
} else {
block = getBlockTemplate("html");
block.innerHTML = text;
}
block = getBlockTemplate("html");
block.innerHTML = text;
const parentBlock = blockController.getSelectedBlocks()[0];
if (parentBlock) {
parentBlock.addChild(block);
Expand Down Expand Up @@ -417,7 +412,7 @@ useEventListener(document, "keydown", (e) => {
if (isTargetEditable(e)) return;
if (e.key === "Backspace" && blockController.isBLockSelected()) {
if ((e.key === "Backspace" || e.key === "Delete") && blockController.isBLockSelected()) {
function findBlockAndRemove(blocks: Array<Block>, blockId: string) {
if (blockId === "root") {
toast.warning("Warning", {
Expand Down
Loading