Line data Source code
1 : <script setup lang="ts">
2 : import { computed } from 'vue'
3 : import { useI18n } from 'vue-i18n'
4 :
5 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
6 : import { LGraphEventMode } from '@/lib/litegraph/src/litegraph'
7 : import FormSelectButton from './FormSelectButton.vue'
8 :
9 : import LayoutField from '@comfyorg/design-system/field/LayoutField'
10 :
11 : /**
12 : * Good design limits dependencies and simplifies the interface of the abstraction layer.
13 : * Here, we only care about the mode method,
14 : * and do not concern ourselves with other methods.
15 : */
16 : type PickedNode = Pick<LGraphNode, 'mode'>
17 :
18 : const { nodes } = defineProps<{ nodes: PickedNode[] }>()
19 2355 : const emit = defineEmits<{ (e: 'changed'): void }>()
20 :
21 11 : const { t } = useI18n()
22 :
23 11 : const nodeState = computed({
24 : get() {
25 21 : let mode: LGraphNode['mode'] | null = null
26 :
27 21 : if (nodes.length === 0) return null
28 :
29 : // For multiple nodes, if all nodes have the same mode, return that mode, otherwise return null
30 21 : if (nodes.length > 1) {
31 0 : mode = nodes[0].mode
32 0 : if (!nodes.every((node) => node.mode === mode)) {
33 0 : mode = null
34 : }
35 : } else {
36 21 : mode = nodes[0].mode
37 : }
38 :
39 21 : return mode
40 : },
41 : set(value: LGraphNode['mode']) {
42 4 : nodes.forEach((node) => {
43 4 : node.mode = value
44 : })
45 4 : emit('changed')
46 : }
47 : })
48 11 : </script>
49 :
50 : <template>
51 21 : <LayoutField :label="t('rightSidePanel.nodeState')">
52 : <FormSelectButton
53 : v-model="nodeState"
54 : class="w-full"
55 : :options="[
56 : {
57 : label: t('rightSidePanel.normal'),
58 : value: LGraphEventMode.ALWAYS
59 : },
60 : {
61 : label: t('rightSidePanel.bypass'),
62 : value: LGraphEventMode.BYPASS
63 : },
64 : {
65 : label: t('rightSidePanel.mute'),
66 : value: LGraphEventMode.NEVER
67 : }
68 : ]"
69 : />
70 : </LayoutField>
71 : </template>
|