Line data Source code
1 : import type { MaybeRefOrGetter } from 'vue'
2 : import { computed, toValue } from 'vue'
3 :
4 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
5 : import { useSettingStore } from '@/platform/settings/settingStore'
6 : import {
7 : deriveWidgetVisibility,
8 : isWidgetVisibleOnSurface
9 : } from '@/types/widgetVisibility'
10 : import type { IBaseWidget } from '@comfyorg/graph-model/widgets'
11 :
12 : export type NodeWidgetsList = Array<{ node: LGraphNode; widget: IBaseWidget }>
13 : export type NodeWidgetsListList = Array<{
14 : node: LGraphNode
15 : widgets: NodeWidgetsList
16 : }>
17 :
18 98 : export function computedSectionDataList(nodes: MaybeRefOrGetter<LGraphNode[]>) {
19 98 : const settingStore = useSettingStore()
20 :
21 98 : const includesAdvanced = computed(() =>
22 : settingStore.get('Comfy.Node.AlwaysShowAdvancedWidgets')
23 : )
24 :
25 : const widgetsSectionDataList = computed((): NodeWidgetsListList => {
26 108 : return toValue(nodes).map((node) => {
27 156 : const { widgets = [] } = node
28 : const shownWidgets = widgets
29 : .filter((w) =>
30 : isWidgetVisibleOnSurface(
31 : w.visibility ?? deriveWidgetVisibility(w),
32 : 'panel',
33 : { showAdvanced: includesAdvanced.value }
34 : )
35 : )
36 : .map((widget) => ({ node, widget }))
37 156 : return { widgets: shownWidgets, node }
38 : })
39 : })
40 :
41 98 : return {
42 : widgetsSectionDataList,
43 : includesAdvanced
44 : }
45 : }
|