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 :
7 : import FieldSwitch from '@comfyorg/design-system/field/FieldSwitch'
8 :
9 : type PickedNode = Pick<LGraphNode, 'pinned' | 'pin'>
10 :
11 : /**
12 : * Good design limits dependencies and simplifies the interface of the abstraction layer.
13 : * Here, we only care about the pinned and pin methods,
14 : * and do not concern ourselves with other methods.
15 : */
16 : const { nodes } = defineProps<{ nodes: PickedNode[] }>()
17 2355 : const emit = defineEmits<{ (e: 'changed'): void }>()
18 :
19 11 : const { t } = useI18n()
20 :
21 : // Pinned state
22 11 : const isPinned = computed<boolean>({
23 : get() {
24 21 : return nodes.some((node) => node.pinned)
25 : },
26 : set(value) {
27 3 : nodes.forEach((node) => node.pin(value))
28 3 : emit('changed')
29 : }
30 : })
31 11 : </script>
32 :
33 : <template>
34 21 : <FieldSwitch v-model="isPinned" :label="t('rightSidePanel.pinned')" />
35 : </template>
|