Line data Source code
1 : import type { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'
2 : import type { InjectionKey, ModelRef, Ref } from 'vue'
3 :
4 : import type { MenuItem } from '@comfyorg/design-system/lib/menu/types'
5 :
6 : export interface TreeNode<T = unknown> {
7 : key: string
8 : label: string
9 : children?: this[]
10 : data?: T
11 : icon?: string
12 : leaf?: boolean
13 : }
14 :
15 : export interface TreeExplorerNode<T = unknown> extends TreeNode<T> {
16 : /** Extra context menu items */
17 : contextMenuItems?:
18 : | MenuItem[]
19 : | ((targetNode: RenderedTreeExplorerNode<T>) => MenuItem[])
20 : /** Whether the node is draggable */
21 : draggable?: boolean
22 : /** Whether the node is droppable */
23 : droppable?: boolean
24 : /**
25 : * Function to override what text to use for the leaf-count badge on a folder node.
26 : * Return undefined to fallback to default badge text, which is the subtree's leaf count.
27 : * Return empty string to hide the badge.
28 : */
29 : getBadgeText?: (this: TreeExplorerNode<T>) => string | undefined
30 : /**
31 : * Function to override what icon to use for the node.
32 : * Return undefined to fallback to {@link icon} property.
33 : */
34 : getIcon?: (this: TreeExplorerNode<T>) => string | undefined
35 : getIconColor?: (this: TreeExplorerNode<T>) => string | undefined
36 : getIconImage?: (this: TreeExplorerNode<T>) => string | undefined
37 : /** Function to handle adding a folder */
38 : handleAddFolder?: (
39 : this: TreeExplorerNode<T>,
40 : folderName: string
41 : ) => void | Promise<void>
42 : /** Function to handle clicking a node */
43 : handleClick?: (
44 : this: TreeExplorerNode<T>,
45 : event: MouseEvent
46 : ) => void | Promise<void>
47 : /** Function to handle deleting the node */
48 : handleDelete?: (this: TreeExplorerNode<T>) => void | Promise<void>
49 : /** Function to handle dropping a node */
50 : handleDrop?: (
51 : this: TreeExplorerNode<T>,
52 : data: TreeExplorerDragAndDropData<T>
53 : ) => void | Promise<void>
54 : /** Function to handle errors */
55 : handleError?: (this: TreeExplorerNode<T>, error: unknown) => void
56 : /** Function to handle renaming the node */
57 : handleRename?: (
58 : this: TreeExplorerNode<T>,
59 : newName: string
60 : ) => void | Promise<void>
61 : /** Function to render a drag preview */
62 : renderDragPreview?: (
63 : this: TreeExplorerNode<T>,
64 : container: HTMLElement
65 : ) => void | (() => void)
66 : }
67 :
68 : export interface RenderedTreeExplorerNode<
69 : T = unknown
70 : > extends TreeExplorerNode<T> {
71 : icon: string
72 : /** Total number of leaves in the subtree */
73 : totalLeaves: number
74 : type: 'folder' | 'node'
75 : /** Text to display on the leaf-count badge. Empty string means no badge. */
76 : badgeText?: string
77 : iconColor?: string
78 : iconImage?: string
79 : /** Whether the node label is currently being edited */
80 : isEditingLabel?: boolean
81 : }
82 :
83 : export type TreeExplorerDragAndDropData<T = unknown> = {
84 : type: 'tree-explorer-node'
85 : data: RenderedTreeExplorerNode<T>
86 : }
87 :
88 2355 : export const InjectKeyHandleEditLabelFunction: InjectionKey<
89 : (node: RenderedTreeExplorerNode, newName: string) => void
90 : > = Symbol()
91 :
92 2355 : export const InjectKeyExpandedKeys: InjectionKey<
93 : ModelRef<Record<string, boolean>>
94 : > = Symbol()
95 :
96 2355 : export const InjectKeyContextMenuNode: InjectionKey<
97 : Ref<RenderedTreeExplorerNode<ComfyNodeDefImpl> | null>
98 : > = Symbol()
|