|
@@ -29,6 +29,7 @@
|
|
|
<script setup>
|
|
|
import { onMounted, reactive, markRaw } from 'vue';
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
+import { excludeGroupBlocks } from '@/utils/shared';
|
|
|
import { getReadableShortcut, getShortcut } from '@/composable/shortcut';
|
|
|
|
|
|
const props = defineProps({
|
|
@@ -37,7 +38,7 @@ const props = defineProps({
|
|
|
default: () => ({}),
|
|
|
},
|
|
|
});
|
|
|
-const emit = defineEmits(['copy', 'paste', 'duplicate']);
|
|
|
+const emit = defineEmits(['copy', 'paste', 'duplicate', 'group', 'ungroup']);
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
const state = reactive({
|
|
@@ -72,6 +73,18 @@ const menuItems = {
|
|
|
event: () => emit('copy', ctxData),
|
|
|
shortcut: getReadableShortcut('mod+c'),
|
|
|
},
|
|
|
+ group: {
|
|
|
+ id: 'group',
|
|
|
+ name: t('workflow.editor.group'),
|
|
|
+ icon: 'riFolderZipLine',
|
|
|
+ event: () => emit('group', ctxData),
|
|
|
+ },
|
|
|
+ ungroup: {
|
|
|
+ id: 'ungroup',
|
|
|
+ name: t('workflow.editor.ungroup'),
|
|
|
+ icon: 'riFolderOpenLine',
|
|
|
+ event: () => emit('ungroup', ctxData),
|
|
|
+ },
|
|
|
duplicate: {
|
|
|
id: 'duplicate',
|
|
|
name: t('workflow.editor.duplicate'),
|
|
@@ -110,8 +123,19 @@ function clearContextMenu() {
|
|
|
|
|
|
onMounted(() => {
|
|
|
props.editor.onNodeContextMenu(({ event, node }) => {
|
|
|
- showCtxMenu(['copy', 'duplicate', 'delete'], event);
|
|
|
- ctxData = { nodes: [node], edges: [] };
|
|
|
+ const items = ['copy', 'duplicate', 'delete'];
|
|
|
+ if (node.label === 'blocks-group') {
|
|
|
+ items.splice(2, 0, 'ungroup');
|
|
|
+ } else if (!excludeGroupBlocks.includes(node.label)) {
|
|
|
+ items.splice(2, 0, 'group');
|
|
|
+ }
|
|
|
+
|
|
|
+ showCtxMenu(items, event);
|
|
|
+ ctxData = {
|
|
|
+ edges: [],
|
|
|
+ nodes: [node],
|
|
|
+ position: { clientX: event.clientX, clientY: event.clientY },
|
|
|
+ };
|
|
|
});
|
|
|
props.editor.onEdgeContextMenu(({ event, edge }) => {
|
|
|
showCtxMenu(['delete'], event);
|
|
@@ -126,10 +150,11 @@ onMounted(() => {
|
|
|
};
|
|
|
});
|
|
|
props.editor.onSelectionContextMenu(({ event }) => {
|
|
|
- showCtxMenu(['copy', 'duplicate', 'delete'], event);
|
|
|
+ showCtxMenu(['copy', 'duplicate', 'group', 'delete'], event);
|
|
|
ctxData = {
|
|
|
nodes: props.editor.getSelectedNodes.value,
|
|
|
edges: props.editor.getSelectedEdges.value,
|
|
|
+ position: { clientX: event.clientX, clientY: event.clientY },
|
|
|
};
|
|
|
});
|
|
|
});
|