Line data Source code
1 : <template>
2 109 : <div
3 : ref="toolboxRef"
4 : style="transform: translate(var(--tb-x), var(--tb-y))"
5 : class="pointer-events-none fixed top-0 left-0 z-40"
6 : >
7 : <Transition name="slide-up">
8 : <div
9 : v-if="visible"
10 : data-testid="selection-toolbox"
11 : class="selection-toolbox pointer-events-auto floating-panel"
12 : @wheel="canvasInteractions.forwardEventToCanvas"
13 : >
14 : <TooltipProvider :delay-duration="1000">
15 : <div class="flex h-8 gap-1">
16 : <template v-if="hasLinkSelection">
17 : <ToolboxButton
18 : v-if="linksHidden"
19 : :label="$t('commands.Comfy_Canvas_ShowSelectedLinks.label')"
20 : icon="icon-[lucide--eye]"
21 : @click="commandStore.execute('Comfy.Canvas.ShowSelectedLinks')"
22 : />
23 : <ToolboxButton
24 : v-else
25 : :label="$t('commands.Comfy_Canvas_HideSelectedLinks.label')"
26 : icon="icon-[lucide--eye-off]"
27 : @click="commandStore.execute('Comfy.Canvas.HideSelectedLinks')"
28 : />
29 : <ToolboxButton
30 : :label="$t('commands.Comfy_Canvas_DeleteSelectedLinks.label')"
31 : icon="icon-[lucide--trash-2]"
32 : @click="
33 : commandStore.execute('Comfy.Canvas.DeleteSelectedLinks')
34 : "
35 : />
36 : </template>
37 : <template v-else>
38 : <ToolboxButton
39 : v-if="isDeletable"
40 : :label="$t('commands.Comfy_Canvas_DeleteSelectedItems.label')"
41 : icon="icon-[lucide--trash-2]"
42 : @click="
43 : commandStore.execute('Comfy.Canvas.DeleteSelectedItems')
44 : "
45 : />
46 : <VerticalDivider v-if="canOpenNodeInfo && hasAnySelection" />
47 : <ToolboxButton
48 : v-if="canOpenNodeInfo"
49 : :label="$t('g.info')"
50 : icon="icon-[lucide--info]"
51 : @click="onInfoClick"
52 : />
53 :
54 : <ColorPickerButton v-if="hasAnySelection" />
55 : <ArrangeButton v-if="hasMultipleSelection" />
56 : <ToolboxButton
57 : v-if="hasMultipleSelection"
58 : :label="$t('g.frameNodes')"
59 : icon="icon-[lucide--frame]"
60 : @click="frameNodes"
61 : />
62 : <ToolboxButton
63 : v-if="isSingleSubgraph"
64 : :label="$t('commands.Comfy_Graph_UnpackSubgraph.label')"
65 : icon="icon-[lucide--expand]"
66 : @click="commandStore.execute('Comfy.Graph.UnpackSubgraph')"
67 : />
68 : <ToolboxButton
69 : v-else-if="hasAnySelection"
70 : :label="$t('commands.Comfy_Graph_ConvertToSubgraph.label')"
71 : icon="icon-[lucide--shrink]"
72 : size="icon"
73 : @click="commandStore.execute('Comfy.Graph.ConvertToSubgraph')"
74 : />
75 : <template v-if="isSingleSubgraph">
76 : <ToolboxButton
77 : :label="$t('commands.Comfy_Graph_EditSubgraphWidgets.label')"
78 : icon="icon-[lucide--settings-2]"
79 : @click="propertiesPanelStore.openPanel('subgraph')"
80 : />
81 : <ToolboxButton
82 : :label="$t('commands.Comfy_PublishSubgraph.label')"
83 : icon="icon-[lucide--book-open]"
84 : @click="commandStore.execute('Comfy.PublishSubgraph')"
85 : />
86 : </template>
87 : <ToolboxButton
88 : v-if="isSingleImageNode"
89 : :label="$t('commands.Comfy_MaskEditor_OpenMaskEditor.label')"
90 : icon="icon-[comfy--mask]"
91 : @click="commandStore.execute('Comfy.MaskEditor.OpenMaskEditor')"
92 : />
93 : <VerticalDivider v-if="hasAnySelection && showBypass" />
94 :
95 : <ToolboxButton
96 : v-if="showBypass"
97 : :label="
98 : $t('commands.Comfy_Canvas_ToggleSelectedNodes_Bypass.label')
99 : "
100 : icon="icon-[lucide--redo-dot]"
101 : class="hover:bg-secondary"
102 : @click="
103 : commandStore.execute(
104 : 'Comfy.Canvas.ToggleSelectedNodes.Bypass'
105 : )
106 : "
107 : />
108 : <ToolboxButton
109 : v-if="hasAnySelection && isRefreshable"
110 : :label="$t('g.refreshNode')"
111 : icon="icon-[lucide--refresh-cw]"
112 : @click="refreshSelected"
113 : />
114 : <ToolboxButton
115 : v-if="hasAny3DNodeSelected"
116 : :label="$t('commands.Comfy_3DViewer_Open3DViewer.label')"
117 : icon="icon-[lucide--pencil]"
118 : @click="commandStore.execute('Comfy.3DViewer.Open3DViewer')"
119 : />
120 :
121 2 : <ToolboxButton
122 : v-for="command in extensionToolboxCommands"
123 : :key="command.id"
124 : :label="
125 : st(
126 : `commands.${normalizeI18nKey(command.id)}.label`,
127 : command.label ?? ''
128 : )
129 : "
130 : :icon="command.icon"
131 : @click="commandStore.execute(command.id)"
132 : />
133 : <ExecuteButton v-if="hasOutputNodesSelected" />
134 : <ToolboxButton
135 : :label="$t('g.moreOptions')"
136 : icon="icon-[lucide--more-vertical]"
137 : @click="toggleNodeOptions"
138 : />
139 : </template>
140 : </div>
141 : </TooltipProvider>
142 : </div>
143 : </Transition>
144 : </div>
145 : </template>
146 :
147 : <script setup lang="ts">
148 : import { computed, ref } from 'vue'
149 :
150 : import ArrangeButton from '@/components/graph/selectionToolbox/ArrangeButton.vue'
151 : import ColorPickerButton from '@/components/graph/selectionToolbox/ColorPickerButton.vue'
152 : import ExecuteButton from '@/components/graph/selectionToolbox/ExecuteButton.vue'
153 : import ToolboxButton from '@/components/graph/selectionToolbox/ToolboxButton.vue'
154 : import TooltipProvider from '@comfyorg/design-system/tooltip/TooltipProvider'
155 : import { useSelectionToolboxPosition } from '@/composables/canvas/useSelectionToolboxPosition'
156 : import { useFrameNodes } from '@/composables/graph/useFrameNodes'
157 : import { toggleNodeOptions } from '@/composables/graph/useMoreOptionsMenu'
158 : import { useSelectionState } from '@/composables/graph/useSelectionState'
159 : import { useRefreshableSelection } from '@/composables/useRefreshableSelection'
160 : import { st } from '@/i18n'
161 : import { areSelectedLinksHidden } from '@/lib/litegraph/src/canvas/linkSelection'
162 : import { useTelemetry } from '@comfyorg/telemetry'
163 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
164 : import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions'
165 : import { useExtensionService } from '@/platform/extensions/services/extensionService'
166 : import { useCommandStore } from '@/platform/keybindings/commandStore'
167 : import { useLinkSelectionStore } from '@/stores/linkSelectionStore'
168 : import type { ComfyCommandImpl } from '@comfyorg/keybindings/commandStore'
169 : import { usePropertiesPanelStore } from '@/renderer/extensions/propertiesPanel/propertiesPanelStore'
170 : import { normalizeI18nKey } from '@/utils/formatUtil'
171 :
172 : import VerticalDivider from '@comfyorg/design-system/common/VerticalDivider'
173 :
174 109 : const commandStore = useCommandStore()
175 109 : const canvasStore = useCanvasStore()
176 109 : const extensionService = useExtensionService()
177 109 : const canvasInteractions = useCanvasInteractions()
178 109 : const linkSelectionStore = useLinkSelectionStore()
179 109 : const propertiesPanelStore = usePropertiesPanelStore()
180 109 : const { frameNodes } = useFrameNodes()
181 109 : const { isRefreshable, refreshSelected } = useRefreshableSelection()
182 :
183 109 : const toolboxRef = ref<HTMLElement | undefined>()
184 109 : const { visible } = useSelectionToolboxPosition(toolboxRef)
185 :
186 109 : const extensionToolboxCommands = computed<ComfyCommandImpl[]>(() => {
187 171 : const commandIds = new Set<string>(
188 : canvasStore.selectedItems
189 : .map(
190 : (item) =>
191 : extensionService
192 : .invokeExtensions('getSelectionToolboxCommands', item)
193 : .flat() as string[]
194 : )
195 : .flat()
196 : )
197 171 : return Array.from(commandIds)
198 : .map((commandId) => commandStore.getCommand(commandId))
199 : .filter((command): command is ComfyCommandImpl => command !== undefined)
200 : })
201 :
202 109 : const {
203 : selectedItems,
204 : hasAnySelection,
205 : hasGroupedNodesSelection,
206 : hasMultipleSelection,
207 : isSingleNode,
208 : isSingleSubgraph,
209 : isSingleImageNode,
210 : hasAny3DNodeSelected,
211 : hasOutputNodesSelected,
212 : canOpenNodeInfo,
213 : openNodeInfo
214 : } = useSelectionState()
215 :
216 109 : const showBypass = computed(
217 : () =>
218 : isSingleNode.value ||
219 : isSingleSubgraph.value ||
220 : hasMultipleSelection.value ||
221 : hasGroupedNodesSelection.value
222 : )
223 109 : const hasLinkSelection = computed(
224 : () => !hasAnySelection.value && linkSelectionStore.selection !== null
225 : )
226 :
227 109 : const isDeletable = computed(() =>
228 : selectedItems.value.some((item) => item.removable !== false)
229 : )
230 :
231 109 : const linksHidden = computed(() => {
232 7 : if (!linkSelectionStore.selection) return false
233 7 : const graph = canvasStore.canvas?.graph
234 7 : return !!graph && areSelectedLinksHidden(graph)
235 : })
236 :
237 10 : function onInfoClick() {
238 10 : if (!openNodeInfo()) return
239 :
240 10 : useTelemetry()?.trackUiButtonClicked({
241 : button_id: 'selection_toolbox_node_info_opened',
242 : element_group: 'selection_toolbox'
243 : })
244 : }
245 : </script>
246 :
247 : <style scoped>
248 : .selection-toolbox {
249 : transform: translateX(-50%) translateY(-120%);
250 : }
251 :
252 : @keyframes slideUp {
253 : 0% {
254 : transform: translateX(-50%) translateY(-100%);
255 : opacity: 0;
256 : }
257 : 50% {
258 : transform: translateX(-50%) translateY(-125%);
259 : opacity: 0.5;
260 : }
261 : 100% {
262 : transform: translateX(-50%) translateY(-120%);
263 : opacity: 1;
264 : }
265 : }
266 :
267 : .slide-up-enter-active {
268 : animation: slideUp 125ms ease-out;
269 : }
270 :
271 : .slide-up-leave-active {
272 : animation: slideUp 25ms ease-out reverse;
273 : }
274 : </style>
|