Line data Source code
1 : import { t } from '@/i18n'
2 : import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
3 : import { LGraphBadge, LiteGraph } from '@/lib/litegraph/src/litegraph'
4 : import { useThemeStore } from '@/platform/theme/themeStore'
5 : import { forEachNode } from '@/utils/graphTraversalUtil'
6 :
7 0 : function waitingBadge(): LGraphBadge {
8 0 : const colors = useThemeStore().activeTheme.canvas
9 0 : return new LGraphBadge({
10 : text: t('lateCustomNodes.waitingBadge'),
11 : fgColor: colors.badgeForegroundColor,
12 : bgColor: colors.badgeBackgroundColor
13 : })
14 : }
15 :
16 0 : function isPlaceholder(node: LGraphNode): boolean {
17 0 : return (
18 : node.last_serialization !== undefined &&
19 : !(node.type in LiteGraph.registered_node_types)
20 : )
21 : }
22 :
23 0 : function hideMissingOutline(node: LGraphNode): void {
24 0 : node.strokeStyles = { ...node.strokeStyles, error: () => undefined }
25 : }
26 :
27 0 : function showTypeWhenUntitled(node: LGraphNode): void {
28 0 : const titleOf = node.getTitle
29 0 : node.getTitle = () => titleOf.call(node) || node.type
30 : }
31 :
32 : /** Shows the nodes whose type is not registered yet as waiting for their pack instead of missing; they stay placeholders and change nothing they save. */
33 0 : export function showPlaceholdersAsWaiting(graph: LGraph): void {
34 0 : forEachNode(graph, (node) => {
35 0 : if (!isPlaceholder(node) || node.badges.includes(waitingBadge)) return
36 0 : hideMissingOutline(node)
37 0 : showTypeWhenUntitled(node)
38 0 : node.badges.push(waitingBadge)
39 : })
40 0 : graph.setDirtyCanvas(true, true)
41 : }
|