11<template >
22 <div >
3- <slot :onContextMenu =" showContextMenu" />
43 <ContextMenu
54 v-if =" contextMenuVisible"
65 v-on-click-outside =" () => (contextMenuVisible = false)"
1312</template >
1413
1514<script setup lang="ts">
16- import { ref , nextTick } from " vue"
15+ import { ref , Ref } from " vue"
1716import { vOnClickOutside } from " @vueuse/components"
1817import ContextMenu from " @/components/ContextMenu.vue"
1918import Block from " @/utils/block"
2019import useStudioStore from " @/stores/studioStore"
2120import { ContextMenuOption } from " @/types"
22- import { getComponentBlock } from " @/utils/helpers"
23-
24- const props = defineProps <{
25- block: Block
26- editable: boolean
27- }>()
21+ import { getComponentBlock , isObjectEmpty } from " @/utils/helpers"
2822
2923const store = useStudioStore ()
3024
3125const contextMenuVisible = ref (false )
3226const posX = ref (0 )
3327const posY = ref (0 )
3428
35- const showContextMenu = (e : MouseEvent ) => {
36- if (props .block .isRoot () || props .editable ) return
29+ const block = ref (null ) as unknown as Ref <Block >
30+ const showContextMenu = (e : MouseEvent , refBlock : Block ) => {
31+ block .value = refBlock
32+ if (block .value .isRoot ()) return
3733 contextMenuVisible .value = true
3834 posX .value = e .pageX
3935 posY .value = e .pageY
@@ -49,24 +45,28 @@ const handleContextMenuSelect = (action: CallableFunction) => {
4945const contextMenuOptions: ContextMenuOption [] = [
5046 {
5147 label: " Duplicate" ,
52- action : () => props . block .duplicateBlock (),
48+ action : () => block . value .duplicateBlock (),
5349 },
5450 {
5551 label: " Delete" ,
5652 action : () => {
57- props . block .getParentBlock ()?. removeChild ( props . block )
53+ block .value . deleteBlock ( )
5854 },
5955 condition : () => {
60- return ! props . block .isRoot () && Boolean (props . block .getParentBlock ())
56+ return ! block .value . isRoot () && Boolean (block . value .getParentBlock ())
6157 },
6258 },
6359 {
6460 label: " Wrap In Container" ,
6561 action : () => {
66- const newBlockObj = getComponentBlock (" FitContainer" )
67- const parentBlock = props .block .getParentBlock ()
62+ const parentBlock = block .value .getParentBlock ()
6863 if (! parentBlock ) return
6964
65+ const newBlockObj = getComponentBlock (" FitContainer" )
66+ if (block .value .isSlotBlock ()) {
67+ newBlockObj .parentSlotName = block .value .parentSlotName
68+ }
69+
7070 const selectedBlocks = store .selectedBlocks || []
7171 const blockPosition = Math .min (... selectedBlocks .map (parentBlock .getChildIndex .bind (parentBlock )))
7272 const newBlock = parentBlock ?.addChild (newBlockObj , blockPosition )
@@ -77,6 +77,9 @@ const contextMenuOptions: ContextMenuOption[] = [
7777 .sort ((a , b ) => parentBlock .getChildIndex (a ) - parentBlock .getChildIndex (b ))
7878 .forEach ((block ) => {
7979 parentBlock ?.removeChild (block )
80+ if (block .parentSlotName ) {
81+ delete block .parentSlotName
82+ }
8083 newBlock ?.addChild (block )
8184 if (! width ) {
8285 const blockWidth = block .getStyle (" width" ) as string | undefined
@@ -95,5 +98,17 @@ const contextMenuOptions: ContextMenuOption[] = [
9598 }
9699 },
97100 },
101+ {
102+ label: " Edit Slot" ,
103+ action : () => {
104+ store .showSlotEditorDialog = true
105+ },
106+ condition : () =>
107+ ! isObjectEmpty (block .value .componentSlots ) && block .value .isSlotEditable (store .selectedSlot ),
108+ },
98109]
110+
111+ defineExpose ({
112+ showContextMenu ,
113+ })
99114 </script >
0 commit comments